Starsector API
Loading...
Searching...
No Matches
CommodityGroundRaidObjectivePluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.graid;
2
3import java.awt.Color;
4import java.util.Random;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CargoAPI;
8import com.fs.starfarer.api.campaign.CargoAPI.CargoItemType;
9import com.fs.starfarer.api.campaign.CargoStackAPI;
10import com.fs.starfarer.api.campaign.TextPanelAPI;
11import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
12import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
13import com.fs.starfarer.api.campaign.econ.Industry;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.impl.campaign.econ.CommodityIconCounts;
16import com.fs.starfarer.api.impl.campaign.econ.ShippingDisruption;
17import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.RaidDangerLevel;
18import com.fs.starfarer.api.loading.Description;
19import com.fs.starfarer.api.loading.Description.Type;
20import com.fs.starfarer.api.ui.IconGroupAPI;
21import com.fs.starfarer.api.ui.IconRenderMode;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24
26 // for causing deficit; higher value means less units need to be raided to cause same deficit
27 public static float ECON_IMPACT_MULT = 1f;
28
29 public static float QUANTITY_MULT_NORMAL = 0.1f;
30 //public static float QUANTITY_MULT_NORMAL_FOR_DEFICIT = 0.5f;
31 public static float QUANTITY_MULT_NORMAL_FOR_DEFICIT = 1f;
32 public static float QUANTITY_MULT_EXCESS = 1f;
33 public static float QUANTITY_MULT_DEFICIT = -0.1f;
34 public static float QUANTITY_MULT_OVERALL = 0.1f;
35
37 private int deficitActuallyCaused;
38
40 super(market, commodityId);
41 com = market.getCommodityData(commodityId);
43 }
44
45 public void addIcons(IconGroupAPI iconGroup) {
47 if (spec == null) return;
48
51
52 int deficit = counts.deficit;
53 int available = Math.max(0, counts.available - counts.extra);
54 int extra = counts.extra;
55
56 if (available > 0) {
57 if (counts.production >= counts.available) {
59 iconGroup.addIconGroup(id, IconRenderMode.OUTLINE_CUSTOM, available, c);
60 } else {
61 iconGroup.addIconGroup(id, IconRenderMode.NORMAL, available, null);
62 }
63 }
64 if (deficit > 0) {
65 iconGroup.addIconGroup(id, IconRenderMode.RED, deficit, null);
66 }
67 if (extra > 0) {
68 iconGroup.addIconGroup(id, IconRenderMode.GREEN, extra, null);
69 }
70 }
71
72 public int getCargoSpaceNeeded() {
74 if (!spec.isFuel() && !spec.isPersonnel()) {
75 return (int) (spec.getCargoSpace() * getQuantity(getMarinesAssigned()));
76 }
77 return 0;
78 }
79
80 public int getFuelSpaceNeeded() {
82 if (spec.isFuel()) {
83 return (int) (spec.getCargoSpace() * getQuantity(getMarinesAssigned()));
84 }
85 return 0;
86 }
87
90 return (int) (spec.getBasePrice() * getQuantity(getMarinesAssigned()));
91 }
92
93 public int getDeficitCaused() {
94 float quantity = getQuantity(getMarinesAssigned(), true);
95 quantity *= ECON_IMPACT_MULT;
96 int diff = Misc.computeEconUnitChangeFromTradeModChange(com, -(int)quantity);
97 diff = -diff;
98 if (diff < 0) diff = 0;
99 if (diff == 0 && getProjectedCreditsValue() > 1000) diff = 1;
100 return diff;
101 }
102
104 return com.getCommodity();
105 }
106
107 public RaidDangerLevel getDangerLevel() {
108// if (id.equals(Commodities.HAND_WEAPONS)) {
109// System.out.println("wefwefwe");
110// }
111 RaidDangerLevel danger = com.getCommodity().getBaseDanger();
113 if (counts.production >= counts.available) {
114 danger = danger.prev();
115 }
116 if (counts.deficit > 0) {
117 danger = danger.next();
118 }
119 if (counts.extra > 0) {
120 danger = danger.prev();
121 }
122 if (source != null) {
123 danger = source.adjustCommodityDangerLevel(id, danger);
124 }
125 return danger;
126 }
127
128 public float getQuantitySortValue() {
130 }
131
132 public float getQuantity(int marines) {
133 return getQuantity(marines, false);
134 }
135
136 public float getQuantity(int marines, boolean forDeficit) {
137 float base = getBaseRaidQuantity(forDeficit);
138 return base * marines;
139 }
140
141 public int getValue(int marines) {
142 return (int) (getQuantity(marines) * getCommoditySpec().getBasePrice());
143 }
144
145
146 public float getBaseRaidQuantity(boolean forDeficit) {
147 //CommodityOnMarketAPI com = market.getCommodityData(id);
148 float unit = com.getCommodity().getEconUnit();
149
151
152 float result = 0f;
153
154 if (forDeficit) {
155 result += Math.max(0, counts.available - counts.extra) * unit * QUANTITY_MULT_NORMAL_FOR_DEFICIT;
156 } else {
157 result += Math.max(0, counts.available - counts.extra) * unit * QUANTITY_MULT_NORMAL;
158 }
159 result += counts.extra * unit * QUANTITY_MULT_EXCESS;
160 result += counts.deficit * unit * QUANTITY_MULT_DEFICIT;
161
162 result *= QUANTITY_MULT_OVERALL;
163
164 if (result < 0) result = 0;
165
166 return result;
167 }
168
170 Industry best = null;
171 int score = 0;
172 int available = com.getAvailable();
173 RaidDangerLevel base = com.getCommodity().getBaseDanger();
174 for (Industry ind : market.getIndustries()) {
175 int supply = ind.getSupply(com.getId()).getQuantity().getModifiedInt();
176 int metDemand = Math.min(available, ind.getDemand(com.getId()).getQuantity().getModifiedInt());
177 int currScore = Math.max(supply, metDemand) * 1000;
178 RaidDangerLevel danger = ind.adjustCommodityDangerLevel(com.getId(), base);
179 currScore += 1000 - danger.ordinal();
180 if (currScore > score) {
181 score = currScore;
182 best = ind;
183 }
184 }
185 return best;
186 }
187
188 public String getName() {
189 return com.getCommodity().getName();
190 }
191
193 CargoStackAPI stack = Global.getFactory().createCargoStack(CargoItemType.RESOURCES, getId(), null);
194 return stack;
195 }
196
198 return com.getId();
199 }
200
201
202 public int performRaid(CargoAPI loot, Random random, float lootMult, TextPanelAPI text) {
203 if (marinesAssigned <= 0) return 0;
204
205 float base = getQuantity(marinesAssigned);
206 base *= lootMult;
207
208 float mult = 0.9f + random.nextFloat() * 0.2f;
209 base *= mult;
210
211 quantityLooted = (int) base;
212 if (quantityLooted < 1) quantityLooted = 1;
213
215
216 deficitActuallyCaused = getDeficitCaused();
217 if (deficitActuallyCaused > 0) {
220 Misc.genUID(), "Recent raid", -deficitActuallyCaused);
221 }
222
223 xpGained = (int) (quantityLooted * getCommoditySpec().getBasePrice() * XP_GAIN_VALUE_MULT);
224 return xpGained;
225 }
226
228 return deficitActuallyCaused;
229 }
230
231 public void setDeficitActuallyCaused(int deficitActuallyCaused) {
232 this.deficitActuallyCaused = deficitActuallyCaused;
233 }
234
235 @Override
236 public boolean hasTooltip() {
237 return true;
238 }
239
240 @Override
241 public void createTooltip(TooltipMakerAPI t, boolean expanded) {
242 float opad = 10f;
243 float pad = 3f;
244 Color h = Misc.getHighlightColor();
245 Color bad = Misc.getNegativeHighlightColor();
246 Color good = Misc.getPositiveHighlightColor();
247
248 Description desc = Global.getSettings().getDescription(id, Type.RESOURCE);
249
250 t.addPara(desc.getText1FirstPara(), 0f);
251
252 t.addPara("Base value: %s per unit", opad, h, Misc.getDGSCredits(com.getCommodity().getBasePrice()));
253 }
254
255}
256
257
258
259
260
261
262
263
static SettingsAPI getSettings()
Definition Global.java:57
static FactoryAPI getFactory()
Definition Global.java:41
void addTemporaryModFlat(float durInDays, String source, String desc, float value)
static String getDGSCredits(float num)
Definition Misc.java:1390
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getHighlightColor()
Definition Misc.java:792
static Color interpolateColor(Color from, Color to, float progress)
Definition Misc.java:1261
static int computeEconUnitChangeFromTradeModChange(CommodityOnMarketAPI com, int quantity)
Definition Misc.java:5826
static Color getPositiveHighlightColor()
Definition Misc.java:822
CargoStackAPI createCargoStack(CargoItemType type, Object data, CargoAPI cargo)
Description getDescription(String id, Type type)
void addCommodity(String commodityId, float quantity)
RaidDangerLevel adjustCommodityDangerLevel(String commodityId, RaidDangerLevel level)
CommodityOnMarketAPI getCommodityData(String commodityId)
void addIconGroup(String commodityId, IconRenderMode mode, int count, Object custom)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)