Starsector API
Loading...
Searching...
No Matches
HAColonyDefensesFactor.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.Industry;
7import com.fs.starfarer.api.campaign.econ.MarketAPI;
8import com.fs.starfarer.api.impl.campaign.ids.Industries;
9import com.fs.starfarer.api.impl.campaign.ids.Strings;
10import com.fs.starfarer.api.ui.TooltipMakerAPI;
11import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
12import com.fs.starfarer.api.util.Misc;
13
15
16 public static float PATROL_HQ_MULT = 0.9f;
17 public static float MILITARY_BASE_MULT = 0.7f;
18 public static float HIGH_COMMAND_MULT = 0.5f;
19
20 public static class HAColonyDefenseData {
21 public MarketAPI market;
22 public Industry industry;
23 public float mult = 1f;
24 }
25
27 }
28
29 @Override
30 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
31 return new BaseFactorTooltip() {
32 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
33 Color h = Misc.getHighlightColor();
34 float opad = 10f;
35
36
37 tooltip.addPara("The presence of military infrastructure slows down event progress, but does not actually stop or reverse it. "
38 + "The highest level military structure present on any of your colonies determines the multiplier.", 0f);
39
40 HAColonyDefenseData data = getDefenseData(null);
41
42 tooltip.beginTable(Misc.getBasePlayerColor(), Misc.getDarkPlayerColor(), Misc.getBrightPlayerColor(),
43 20f, "Infrastructure", 200f, "Multiplier", 100f);
44
45 Color c = Misc.getGrayColor();
46 Color c2 = Misc.getGrayColor();
47 if (data.industry != null && data.industry.getId().equals(Industries.PATROLHQ)) {
48 c = Misc.getHighlightColor();
49 c2 = Misc.getPositiveHighlightColor();
50 }
51 tooltip.addRow(c, "Patrol HQ", c2, Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(PATROL_HQ_MULT));
52
53 c = Misc.getGrayColor();
54 c2 = Misc.getGrayColor();
55 if (data.industry != null && data.industry.getId().equals(Industries.MILITARYBASE)) {
56 c = Misc.getHighlightColor();
57 c2 = Misc.getPositiveHighlightColor();
58 }
59 tooltip.addRow(c, "Military Base", c2, Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(MILITARY_BASE_MULT));
60
61 c = Misc.getGrayColor();
62 c2 = Misc.getGrayColor();
63 if (data.industry != null && data.industry.getId().equals(Industries.HIGHCOMMAND)) {
64 c = Misc.getHighlightColor();
65 c2 = Misc.getPositiveHighlightColor();
66 }
67 tooltip.addRow(c, "High Command", c2, Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(HIGH_COMMAND_MULT));
68
69 tooltip.addTable("None", 0, opad);
70 tooltip.addSpacer(5f);
71
72 if (data.industry != null && data.market != null) {
73 tooltip.addPara("You have a %s at %s.", opad, h,
74 data.industry.getCurrentName(), data.market.getName());
75 }
76 }
77 };
78 }
79
80
81 @Override
82 public boolean shouldShow(BaseEventIntel intel) {
83 //HAColonyDefenseData data = getDefenseData(intel);
84 return true;
85 }
86
87
88 public float getAllProgressMult(BaseEventIntel intel) {
89 HAColonyDefenseData data = getDefenseData(intel);
90 return data.mult;
91 }
92
93
94 @Override
95 public Color getProgressColor(BaseEventIntel intel) {
96 HAColonyDefenseData data = getDefenseData(intel);
97 if (data.mult < 1) {
98 return Misc.getPositiveHighlightColor();
99 } else if (data.mult > 1) {
100 return Misc.getNegativeHighlightColor();
101 }
102 return Misc.getHighlightColor(); // no text anyway
103 }
104
105 @Override
106 public String getProgressStr(BaseEventIntel intel) {
107 HAColonyDefenseData data = getDefenseData(intel);
108 if (data.mult != 1) {
109 return Strings.X + Misc.getRoundedValueMaxOneAfterDecimal(data.mult);
110 }
111 return "";
112 }
113
114 public String getDesc(BaseEventIntel intel) {
115 HAColonyDefenseData data = getDefenseData(intel);
116 if (data.industry == null) {
117 return "Military infrastructure";
118 }
119 return data.industry.getCurrentName();
120 }
121
122 @Override
123 public Color getDescColor(BaseEventIntel intel) {
124 if (getDefenseData(intel).market == null) {
125 return Misc.getGrayColor();
126 }
127 return super.getDescColor(intel);
128 }
129
130 public HAColonyDefenseData getDefenseData(BaseEventIntel intel) {
131 HAColonyDefenseData best = new HAColonyDefenseData();
132
133 List<MarketAPI> markets = Misc.getPlayerMarkets(false);
134 for (MarketAPI market : markets) {
135 float mult = 1f;
136 Industry industry = null;
137 if (market.hasFunctionalIndustry(Industries.PATROLHQ)) {
138 mult = PATROL_HQ_MULT;
139 industry = market.getIndustry(Industries.PATROLHQ);
140 }
141 if (Misc.isMilitary(market)) {
142 if (market.hasFunctionalIndustry(Industries.HIGHCOMMAND)) {
143 mult = HIGH_COMMAND_MULT;
144 industry = market.getIndustry(Industries.HIGHCOMMAND);
145 } else {
146 mult = MILITARY_BASE_MULT;
147 industry = market.getIndustry(Industries.MILITARYBASE);
148 }
149 }
150
151 if (industry != null && mult < best.mult) {
152 best.market = market;
153 best.industry = industry;
154 best.mult = mult;
155 }
156 }
157
158 return best;
159 }
160
161}