Starsector API
Loading...
Searching...
No Matches
SindrianDiktatFuelDeal.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel;
2
3import java.awt.Color;
4import java.util.Set;
5
6import org.lwjgl.input.Keyboard;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.FactionAPI;
10import com.fs.starfarer.api.campaign.InteractionDialogAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.TextPanelAPI;
13import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
14import com.fs.starfarer.api.campaign.econ.MonthlyReport;
15import com.fs.starfarer.api.campaign.econ.MonthlyReport.FDNode;
16import com.fs.starfarer.api.campaign.listeners.EconomyTickListener;
17import com.fs.starfarer.api.impl.campaign.ids.Factions;
18import com.fs.starfarer.api.impl.campaign.ids.Tags;
19import com.fs.starfarer.api.impl.campaign.intel.events.SindrianDiktatHostileActivityFactor;
20import com.fs.starfarer.api.impl.campaign.rulecmd.HA_CMD;
21import com.fs.starfarer.api.impl.campaign.shared.SharedData;
22import com.fs.starfarer.api.ui.ButtonAPI;
23import com.fs.starfarer.api.ui.IntelUIAPI;
24import com.fs.starfarer.api.ui.LabelAPI;
25import com.fs.starfarer.api.ui.SectorMapAPI;
26import com.fs.starfarer.api.ui.TooltipMakerAPI;
27import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
28import com.fs.starfarer.api.util.Misc;
29
30public class SindrianDiktatFuelDeal extends BaseIntelPlugin implements EconomyTickListener {
31
32 public static enum AgreementEndingType {
33 BROKEN,
34 }
35
36 public static float REP_FOR_BREAKING_DEAL = 0.5f;
37
38 public static String KEY = "$sindrianDiktatDeal_ref";
39 public static SindrianDiktatFuelDeal get() {
40 return (SindrianDiktatFuelDeal) Global.getSector().getMemoryWithoutUpdate().get(KEY);
41 }
42
43 public static String BUTTON_END = "End";
44
45 public static String UPDATE_PARAM_ACCEPTED = "update_param_accepted";
46
47 protected FactionAPI faction = null;
48 protected AgreementEndingType endType = null;
49
50 public SindrianDiktatFuelDeal(InteractionDialogAPI dialog) {
51 this.faction = Global.getSector().getFaction(Factions.DIKTAT);
52
53 setImportant(true);
54 SindrianDiktatHostileActivityFactor.setMadeDeal(true);
55
56 TextPanelAPI text = null;
57 if (dialog != null) text = dialog.getTextPanel();
58
59 Global.getSector().getListenerManager().addListener(this);
60 Global.getSector().getMemoryWithoutUpdate().set(KEY, this);
61
62 Global.getSector().getIntelManager().addIntel(this, true);
63
65
66 HA_CMD.avertOrEndDiktatAttackAsNecessary();
67 }
68
69 @Override
70 protected void notifyEnding() {
71 super.notifyEnding();
72
73 SindrianDiktatHostileActivityFactor.setMadeDeal(false);
74 Global.getSector().getListenerManager().removeListener(this);
75 Global.getSector().getMemoryWithoutUpdate().unset(KEY);
76 }
77
78 @Override
79 protected void notifyEnded() {
80 super.notifyEnded();
81 }
82
83 protected Object readResolve() {
84 return this;
85 }
86
87 public String getBaseName() {
88 return "Sindrian Diktat Fuel Accord";
89 }
90
91 public String getAcceptedPostfix() {
92 return "Accepted";
93 }
94
95 public String getBrokenPostfix() {
96 return "Ended";
97
98 }
99
100 public String getName() {
101 String postfix = "";
102 if (isEnding() && endType != null) {
103 switch (endType) {
104 case BROKEN:
105 postfix = " - " + getBrokenPostfix();
106 break;
107 }
108 }
110 postfix = " - " + getAcceptedPostfix();
111 }
112 return getBaseName() + postfix;
113 }
114
115 @Override
116 public FactionAPI getFactionForUIColors() {
117 return faction;
118 }
119
120 public String getSmallDescriptionTitle() {
121 return getName();
122 }
123
124 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
125 Color h = Misc.getHighlightColor();
126 Color g = Misc.getGrayColor();
127 float pad = 3f;
128 float opad = 10f;
129
130 float initPad = pad;
131 if (mode == ListInfoMode.IN_DESC) initPad = opad;
132
133 Color tc = getBulletColorForMode(mode);
134
135 bullet(info);
136 boolean isUpdate = getListInfoParam() != null;
137
138// if (getListInfoParam() == UPDATE_PARAM_ACCEPTED) {
139// return;
140// }
141
142
143
144 unindent(info);
145 }
146
147
148 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
149 Color h = Misc.getHighlightColor();
150 Color g = Misc.getGrayColor();
151 Color tc = Misc.getTextColor();
152 float pad = 3f;
153 float opad = 10f;
154
155 info.addImage(getFaction().getLogo(), width, 128, opad);
156
157 if (isEnding() || isEnded()) {
158 info.addPara("You are no longer abiding by your agreement with the Sindrian Diktat.", opad);
159 return;
160 }
161
162 float feeFraction = Global.getSettings().getFloat("diktatFuelFeeFraction");
163
164 LabelAPI label = info.addPara("You've made an agreement with the Sindrian Diktat, paying a sizeable "
165 + "fee, %s of your gross fuel exports, in exchange for them not bombarding "
166 + "your fuel production facilities from orbit.",
167 opad, h, "" + (int) Math.round(feeFraction * 100f) + "%");
168 label.setHighlight("Sindrian Diktat", "" + (int) Math.round(feeFraction * 100f) + "%");
169 label.setHighlightColors(faction.getBaseUIColor(), h);
170
171 info.addPara("You can end this agreement, but there "
172 + "would be no possibility of re-negotiating a similar one in the future.", opad);
173
174 ButtonAPI button = info.addButton("End the agreement", BUTTON_END,
175 getFactionForUIColors().getBaseUIColor(), getFactionForUIColors().getDarkUIColor(),
176 (int)(width), 20f, opad * 1f);
177 button.setShortcut(Keyboard.KEY_U, true);
178
179 }
180
181
182 public String getIcon() {
183 return faction.getCrest();
184 }
185
186 public Set<String> getIntelTags(SectorMapAPI map) {
187 Set<String> tags = super.getIntelTags(map);
188 tags.add(Tags.INTEL_AGREEMENTS);
189 tags.add(faction.getId());
190 return tags;
191 }
192
193 @Override
194 public String getImportantIcon() {
195 return Global.getSettings().getSpriteName("intel", "important_accepted_mission");
196 }
197
198 @Override
199 public SectorEntityToken getMapLocation(SectorMapAPI map) {
200 return null;
201 }
202
203
204 public FactionAPI getFaction() {
205 return faction;
206 }
207
208 public void endAgreement(AgreementEndingType type, InteractionDialogAPI dialog) {
209 if (!isEnded() && !isEnding()) {
210 endType = type;
211 setImportant(false);
213
214 if (dialog != null) {
215 sendUpdate(new Object(), dialog.getTextPanel());
216 }
217
218 if (type == AgreementEndingType.BROKEN) {
219 SindrianDiktatHostileActivityFactor.setBrokeDeal(true);
220
221 //Misc.incrUntrustwortyCount();
222
223 TextPanelAPI text = dialog == null ? null : dialog.getTextPanel();
224 Misc.adjustRep(Factions.DIKTAT, -REP_FOR_BREAKING_DEAL, text);
225 }
226 }
227 }
228
229
230 @Override
231 public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
232 if (buttonId == BUTTON_END) {
233 endAgreement(AgreementEndingType.BROKEN, null);
234 }
235 super.buttonPressConfirmed(buttonId, ui);
236 }
237
238
239 @Override
240 public void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt) {
241 if (buttonId == BUTTON_END) {
242 prompt.addPara("The terms of the agreement are so onerous that your reputation at large "
243 + "would not suffer for unilaterally breaking it, "
244 + "though your standing with the Sindrian Diktat specifically "
245 + "would of course be affected.", 0f,
246 faction.getBaseUIColor(), faction.getDisplayName());
247 }
248
249 }
250
251 @Override
252 public boolean doesButtonHaveConfirmDialog(Object buttonId) {
253 if (buttonId == BUTTON_END) {
254 return true;
255 }
256 return super.doesButtonHaveConfirmDialog(buttonId);
257 }
258
259 public void reportEconomyMonthEnd() {
260
261 }
262
263 public void reportEconomyTick(int iterIndex) {
264 int numIter = Global.getSettings().getInt("economyIterPerMonth");
265 if (iterIndex != numIter - 1) return;
266
267 float feeFraction = Global.getSettings().getFloat("diktatFuelFeeFraction");
268
269 MonthlyReport report = SharedData.getData().getCurrentReport();
270 FDNode marketsNode = report.getNode(MonthlyReport.OUTPOSTS);
271 if (marketsNode == null) return;
272
273 float exportIncome = computeFuelExportIncome(marketsNode);
274 int credits = (int) (exportIncome * feeFraction);
275
276 if (credits <= 0) return;
277
278 FDNode node = getMonthlyReportNode();
279 node.upkeep += credits;
280 }
281
282 public float computeFuelExportIncome(FDNode curr) {
283 float total = 0f;
284 if (curr.custom instanceof CommodityOnMarketAPI) {
285 CommodityOnMarketAPI com = (CommodityOnMarketAPI) curr.custom;
286 if (com.isFuel()) {
287 total += curr.income;
288 }
289 }
290 for (FDNode child : curr.getChildren().values()) {
291 total += computeFuelExportIncome(child);
292 }
293 return total;
294
295 }
296
297 public FDNode getMonthlyReportNode() {
298 MonthlyReport report = SharedData.getData().getCurrentReport();
299 FDNode marketsNode = report.getNode(MonthlyReport.OUTPOSTS);
300 if (marketsNode.name == null) {
301 marketsNode.name = "Colonies";
302 marketsNode.custom = MonthlyReport.OUTPOSTS;
303 marketsNode.tooltipCreator = report.getMonthlyReportTooltip();
304 }
305
306 FDNode paymentNode = report.getNode(marketsNode, "diktat_fuel_fees");
307 paymentNode.name = "Sindrian Diktat fuel accord fees";
308 paymentNode.icon = faction.getCrest();
309
310 if (paymentNode.tooltipCreator == null) {
311 paymentNode.tooltipCreator = new TooltipCreator() {
312 public boolean isTooltipExpandable(Object tooltipParam) {
313 return false;
314 }
315 public float getTooltipWidth(Object tooltipParam) {
316 return 450;
317 }
318 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
319 tooltip.addPara("Fees paid to the Sindrian Diktat in exchange for their refraining "
320 + "from interfering in your fuel production business. From orbit.", 0f);
321 }
322 };
323 }
324
325 return paymentNode;
326 }
327
328
329}
330
331
332
333
334
335
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void sendUpdate(Object listInfoParam, TextPanelAPI textPanel)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt)
void endAgreement(AgreementEndingType type, InteractionDialogAPI dialog)
String getSpriteName(String category, String id)