Starsector API
Loading...
Searching...
No Matches
HADefensiveMeasuresFactor.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import java.awt.Color;
4import java.util.List;
5
6import com.fs.starfarer.api.campaign.econ.MarketAPI;
7import com.fs.starfarer.api.impl.campaign.ids.Industries;
8import com.fs.starfarer.api.impl.campaign.ids.Strings;
9import com.fs.starfarer.api.ui.Alignment;
10import com.fs.starfarer.api.ui.TooltipMakerAPI;
11import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
12import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipLocation;
13import com.fs.starfarer.api.util.Misc;
14
15@Deprecated public class HADefensiveMeasuresFactor extends BaseEventFactor {
16
17 public static int PATROL_HQ_POINTS = 5;
18 public static float MILITARY_SIZE_MULT = 2;
19 public static float HIGH_COMMAND_SIZE_MULT = 3;
20
23
24 @Override
25 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
26 return new BaseFactorTooltip() {
27 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
28 Color h = Misc.getHighlightColor();
29 float opad = 10f;
30
31 tooltip.addPara("Defensive measures taken by your colonies.", 0f);
32 }
33 };
34 }
35
36
37 @Override
38 public boolean shouldShow(BaseEventIntel intel) {
39 MarketAPI biggest = getBiggestColony();
40 MarketAPI mil = getBestMilitaryMarket();
41 return biggest != null || mil != null;
42 }
43
44 @Override
45 public void addExtraRows(TooltipMakerAPI info, BaseEventIntel intel) {
46 MarketAPI biggest = getBiggestColony();
47 MarketAPI mil = getBestMilitaryMarket();
48 Color tc = Misc.getTextColor();
49
50 if (biggest != null) {
51 int p = getColonyIncreasedDefensesScore(intel, biggest);
52 if (p != 0) {
53 //info.addRowWithGlow(Alignment.LMID, tc, " Largest colony",
54 info.addRowWithGlow(Alignment.LMID, tc, " Increased defenses",
55 Alignment.RMID, intel.getProgressColor(p), "" + p);
56
57 TooltipCreator t = new BaseFactorTooltip() {
58 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
59 float opad = 10f;
60 tooltip.addPara("Based on the size and stability of the largest colony "
61 + "under your control. If multiple colonies have the same size, the one with higher "
62 + "stability is used.", 0f);
63 MarketAPI biggest = getBiggestColony();
64 if (biggest != null && biggest.getStarSystem() != null) {
65 tooltip.addPara("Biggest colony: %s, size: %s, stability: %s", opad, Misc.getHighlightColor(),
66 biggest.getName(),
67 "" + biggest.getSize(),
68 "" + (int) biggest.getStabilityValue());
69 float w = tooltip.getWidthSoFar();
70 float h2 = Math.round(w / 1.6f);
71 tooltip.addSectorMap(w, h2, biggest.getStarSystem(), opad);
72 }
73 }
74 };
75 info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
76 }
77 }
78
79 int p = getMilitaryScore(mil);
80 if (mil != null && mil.hasFunctionalIndustry(Industries.HIGHCOMMAND)) {
81 info.addRowWithGlow(Alignment.LMID, tc, " High Command",
82 Alignment.RMID, intel.getProgressColor(p), "" + p);
83 } else if (Misc.isMilitary(mil)) {
84 info.addRowWithGlow(Alignment.LMID, tc, " Military base",
85 Alignment.RMID, intel.getProgressColor(p), "" + p);
86 } else if (mil != null && mil.hasFunctionalIndustry(Industries.PATROLHQ)) {
87 info.addRowWithGlow(Alignment.LMID, tc, " Patrol HQ",
88 Alignment.RMID, intel.getProgressColor(p), "" + p);
89 } else {
90 info.addRowWithGlow(Alignment.LMID, Misc.getGrayColor(), " Military infrastructure",
91 Alignment.RMID, intel.getProgressColor(p), "");
92 }
93
94 TooltipCreator t = new BaseFactorTooltip() {
95 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
96 float opad = 10f;
97 tooltip.addPara("Based on the size the largest colony under your control that has a Patrol HQ, "
98 + "a Military Base, or a High Command.", 0f);
99
100 tooltip.addPara("A Patrol HQ reduces monthly progress by %s points. A Military Base and a High Command "
101 + "reduce progress by %s and %s the colony's size, respectively. Only the highest-scoring colony is used, "
102 + "building multiple military bases has no effect.", opad, Misc.getHighlightColor(),
103 "" + PATROL_HQ_POINTS,
104 "" + (int)MILITARY_SIZE_MULT + Strings.X,
105 "" + (int)HIGH_COMMAND_SIZE_MULT + Strings.X);
106
107 MarketAPI mil = getBestMilitaryMarket();
108 if (mil != null && mil.getStarSystem() != null) {
109 int score = -1 * getMilitaryScore(mil);
110 if (score > 0) {
111 tooltip.addPara("Best military colony: %s, size: %s, score: %s points", opad, Misc.getHighlightColor(),
112 mil.getName(),
113 "" + mil.getSize(),
114 "" + score);
115 float w = tooltip.getWidthSoFar();
116 float h2 = Math.round(w / 1.6f);
117 tooltip.addSectorMap(w, h2, mil.getStarSystem(), opad);
118 }
119 }
120 }
121 };
122 info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
123
124// int def = getIncreasedDefensesScore(intel);
125// if (def != 0) {
126// info.addRowWithGlow(Alignment.LMID, tc, " Increased defenses",
127// Alignment.RMID, intel.getProgressColor(def), "" + def);
128//
129// t = new BaseFactorTooltip() {
130// public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
131// tooltip.addPara("Event progress reduced further by %s the other defense factors.", 0f,
132// Misc.getHighlightColor(), "" + (int)INCREASED_DEFENSES_MULT + Strings.X);
133// }
134// };
135// info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
136// }
137 }
138
139// public int getProgress(BaseEventIntel intel) {
140// return getProgress(intel, true);
141// }
146
147 public float getAllProgressMult(BaseEventIntel intel) {
148 return 1f;
149 }
150
151// public int getIncreasedDefensesScore(BaseEventIntel intel) {
152// if (intel.isStageOrOneOffEventReached(Stage.INCREASED_DEFENSES)) {
153// return (int) Math.round(getProgress(intel, false) * INCREASED_DEFENSES_MULT);
154// }
155// return 0;
156// }
157
158 public int getColonyIncreasedDefensesScore(BaseEventIntel intel, MarketAPI market) {
159 if (market == null) return 0;
160// if (intel.isStageOrOneOffEventReached(Stage.INCREASED_DEFENSES)) {
161// return -1 * Math.round(market.getSize() + market.getStabilityValue());
162// }
163 return 0;
164 }
165
166 @Override
167 public String getProgressStr(BaseEventIntel intel) {
168 return "";
169 }
170
171 public String getDesc(BaseEventIntel intel) {
172 return "Defensive measures";
173 }
174
175 @Override
176 public Color getDescColor(BaseEventIntel intel) {
177 if (getProgress(intel) == 0) {
178 return Misc.getGrayColor();
179 }
180 return super.getDescColor(intel);
181 }
182
183 public MarketAPI getBiggestColony() {
184 List<MarketAPI> markets = Misc.getPlayerMarkets(false);
185 MarketAPI biggest = null;
186 float max = 0;
187 for (MarketAPI market : markets) {
188 float size = market.getSize();
189 if (size >= max) {
190 if (size == max && biggest != null) {
191 if (biggest.getStabilityValue() > market.getStabilityValue()) {
192 continue;
193 }
194 }
195 max = size;
196 biggest = market;
197 }
198 }
199 return biggest;
200 }
201
202 public int getMilitaryScore(MarketAPI market) {
203 if (market == null) return 0;
204
205 if (market.hasFunctionalIndustry(Industries.PATROLHQ)) {
206 return -1 * PATROL_HQ_POINTS;
207 }
208 if (Misc.isMilitary(market)) {
209 if (market.hasFunctionalIndustry(Industries.HIGHCOMMAND)) {
210 return -1 * Math.round(market.getSize() * HIGH_COMMAND_SIZE_MULT);
211 }
212 return -1 * Math.round(market.getSize() * MILITARY_SIZE_MULT);
213 }
214 return 0;
215 }
216
217 public MarketAPI getBestMilitaryMarket() {
218 List<MarketAPI> markets = Misc.getPlayerMarkets(false);
219 MarketAPI best = null;
220 int max = 0;
221 for (MarketAPI market : markets) {
222 int curr = -1 * getMilitaryScore(market);
223 if (curr > max) {
224 max = curr;
225 best = market;
226 }
227 }
228 return best;
229 }
230}