Starsector API
Loading...
Searching...
No Matches
TriTachyonDeal.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.EconomyAPI.EconomyUpdateListener;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Conditions;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
17import com.fs.starfarer.api.impl.campaign.ids.Tags;
18import com.fs.starfarer.api.ui.ButtonAPI;
19import com.fs.starfarer.api.ui.IntelUIAPI;
20import com.fs.starfarer.api.ui.LabelAPI;
21import com.fs.starfarer.api.ui.SectorMapAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24
25public class TriTachyonDeal extends BaseIntelPlugin implements EconomyUpdateListener {
26
27 public static enum AgreementEndingType {
28 BROKEN,
29 }
30
31 // in $player memory
32 public static final String HAS_TRI_TACH_DEAL = "$hasTriTachDeal";
33 public static final String BROKE_TRI_TACH_DEAL = "$brokeTriTachDeal";
34
35 public static float REP_FOR_BREAKING_DEAL = 0.5f;
36
37 public static float MARKET_SIZE_TO_ACCESSIBILITY = 0.01f;
38
39 public static boolean hasDeal() {
41 }
42 public static void setHasDeal(boolean deal) {
44 }
48 public static void setBrokeDeal(boolean broke) {
50 }
51
52
53 public static String KEY = "$triTachDeal_ref";
54 public static TriTachyonDeal get() {
56 }
57
58 public static String BUTTON_END = "End";
59
60 public static String UPDATE_PARAM_ACCEPTED = "update_param_accepted";
61
62 protected FactionAPI faction = null;
63 protected AgreementEndingType endType = null;
64
67
68 setImportant(true);
69 setHasDeal(true);
70
71 TextPanelAPI text = null;
72 if (dialog != null) text = dialog.getTextPanel();
73
74 //Global.getSector().getListenerManager().addListener(this);
77
79
80 economyUpdated(); // apply the modifier right away
81
83 }
84
85 @Override
86 protected void notifyEnding() {
87 super.notifyEnding();
88
89 setHasDeal(false);
90
92 //Global.getSector().getListenerManager().removeListener(this);
94
96 }
97
98 @Override
99 protected void notifyEnded() {
100 super.notifyEnded();
101 }
102
103 protected Object readResolve() {
104 return this;
105 }
106
107 public String getBaseName() {
108 return "Tri-Tachyon Strategic Partnership";
109 }
110
111 public String getAcceptedPostfix() {
112 return "Accepted";
113 }
114
115 public String getBrokenPostfix() {
116 return "Dissolved";
117
118 }
119
120 public String getName() {
121 String postfix = "";
122 if (isEnding() && endType != null) {
123 switch (endType) {
124 case BROKEN:
125 postfix = " - " + getBrokenPostfix();
126 break;
127 }
128 }
130 postfix = " - " + getAcceptedPostfix();
131 }
132 return getBaseName() + postfix;
133 }
134
135 @Override
137 return faction;
138 }
139
140 public String getSmallDescriptionTitle() {
141 return getName();
142 }
143
144 protected float computeColonySize(String factionId) {
145 float size = 0f;
147 if (factionId.equals(curr.getFactionId())) {
148 if (curr.hasCondition(Conditions.DECIVILIZED)) continue;
149 size += curr.getSize();
150 }
151 }
152 return size;
153 }
154
157 return size * MARKET_SIZE_TO_ACCESSIBILITY;
158 }
160 float size = computeColonySize(Factions.PLAYER);
161 return size * MARKET_SIZE_TO_ACCESSIBILITY;
162 }
163
164 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
165 Color h = Misc.getHighlightColor();
166 Color g = Misc.getGrayColor();
167 float pad = 3f;
168 float opad = 10f;
169
170 float initPad = pad;
171 if (mode == ListInfoMode.IN_DESC) initPad = opad;
172
173 Color tc = getBulletColorForMode(mode);
174
175 bullet(info);
176 boolean isUpdate = getListInfoParam() != null;
177
178// if (getListInfoParam() == UPDATE_PARAM_ACCEPTED) {
179// return;
180// }
181
182 int accessPlayer = (int)Math.round(computeAccessibilityBonusPlayer() * 100f);
183 int accessTriTach = (int)Math.round(computeAccessibilityBonusTriTach() * 100f);
184
185 if (!isEnded() && !isEnding()) {
186 String fName = Global.getSector().getPlayerFaction().getDisplayName();
187 LabelAPI label;
188 label = info.addPara(fName + " colonies receive %s accessibility", initPad, tc, h, "+" + accessPlayer + "%");
189 label.setHighlight(fName, "+" + accessPlayer + "%");
191 initPad = 0f;
192
193 fName = faction.getDisplayName();
194 label = info.addPara(fName + " colonies receive %s accessibility", initPad, tc, h, "+" + accessTriTach + "%");
195 label.setHighlight(fName, "+" + accessTriTach + "%");
197 }
198
199 unindent(info);
200 }
201
202
203 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
204 Color h = Misc.getHighlightColor();
205 Color g = Misc.getGrayColor();
206 Color tc = Misc.getTextColor();
207 float pad = 3f;
208 float opad = 10f;
209
210 info.addImage(getFaction().getLogo(), width, 128, opad);
211
212 if (isEnding() || isEnded()) {
213 info.addPara("Your agreement with the Tri-Tachyon Corporation is no longer in force.", opad);
214 return;
215 }
216
217 info.addPara("A partnership with the %s that allows you to leverage your combined market power "
218 + "for mutual benefit.", opad, faction.getBaseUIColor(), faction.getDisplayNameLong());
219
220 addBulletPoints(info, ListInfoMode.IN_DESC);
221
222 info.addPara("Each partner's accessibility bonus is based "
223 + "on the total size of the colonies of the other partner.", opad);
224
225 info.addPara("The contract is carefully worded to survive even in the face of open hostilities, and is, "
226 + "from a legal perspective, perpetually binding.", opad);
227
228 info.addPara("You can of course decide to end this partnership unilaterally, but there "
229 + "would be no possibility of re-negotiating a similar deal after displaying such a lack of respect "
230 + "for your contractual obligations.", opad);
231
232 ButtonAPI button = info.addButton("End the partnership", BUTTON_END,
233 getFactionForUIColors().getBaseUIColor(), getFactionForUIColors().getDarkUIColor(),
234 (int)(width), 20f, opad * 1f);
235 button.setShortcut(Keyboard.KEY_U, true);
236
237 }
238
239
240 public String getIcon() {
241 return faction.getCrest();
242 }
243
244 public Set<String> getIntelTags(SectorMapAPI map) {
245 Set<String> tags = super.getIntelTags(map);
246 tags.add(Tags.INTEL_AGREEMENTS);
247 tags.add(faction.getId());
248 return tags;
249 }
250
251 @Override
252 public String getImportantIcon() {
253 return Global.getSettings().getSpriteName("intel", "important_accepted_mission");
254 }
255
256 @Override
258 return null;
259 }
260
261
263 return faction;
264 }
265
266 public void endAgreement(AgreementEndingType type, InteractionDialogAPI dialog) {
267 if (!isEnded() && !isEnding()) {
268 endType = type;
269 setImportant(false);
270 //endAfterDelay();
272
273 if (dialog != null) {
274 sendUpdate(new Object(), dialog.getTextPanel());
275 }
276
277 if (type == AgreementEndingType.BROKEN) {
278 setBrokeDeal(true);
280 TextPanelAPI text = dialog == null ? null : dialog.getTextPanel();
282 }
283 }
284 }
285
286
287 @Override
288 public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
289 if (buttonId == BUTTON_END) {
290 endAgreement(AgreementEndingType.BROKEN, null);
291 }
292 super.buttonPressConfirmed(buttonId, ui);
293 }
294
295
296 @Override
297 public void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt) {
298 if (buttonId == BUTTON_END) {
299 prompt.addPara("You can decide to end this partnership unilaterally, but taking this action would "
300 + "hurt your standing with %s, and there "
301 + "would be no possibility of re-negotiating a similar deal after displaying such a lack of respect "
302 + "for your contractual obligations.", 0f,
304 }
305
306 }
307
308 @Override
309 public boolean doesButtonHaveConfirmDialog(Object buttonId) {
310 if (buttonId == BUTTON_END) {
311 return true;
312 }
313 return super.doesButtonHaveConfirmDialog(buttonId);
314 }
315
316 public void commodityUpdated(String commodityId) {
317 }
318
319 public static String ACCESS_MOD_ID = "ttDeal_access";
320 public void economyUpdated() {
321 float player = computeAccessibilityBonusPlayer();
322 float triTach = computeAccessibilityBonusTriTach();
323 String descPlayer = "Strategic partnership with " + faction.getDisplayName();
324 String descTriTach = "Strategic partnership with " + Global.getSector().getPlayerFaction().getDisplayName();
326 float mod = 0f;
327 String desc = null;
328 if (Factions.TRITACHYON.equals(curr.getFactionId())) {
329 mod = triTach;
330 desc = descTriTach;
331 } else if (Factions.PLAYER.equals(curr.getFactionId())) {
332 mod = player;
333 desc = descPlayer;
334 }
335 if (mod != 0) {
336 curr.getAccessibilityMod().modifyFlat(ACCESS_MOD_ID, mod, desc);
337 } else {
338 curr.getAccessibilityMod().unmodifyFlat(ACCESS_MOD_ID);
339 }
340 }
341 }
342
343 public void unapplyAccessModifier() {
345 curr.getAccessibilityMod().unmodifyFlat(ACCESS_MOD_ID);
346 }
347 }
348
349 public boolean isEconomyListenerExpired() {
350 return isEnding() || isEnded();
351 }
352
353
354}
355
356
357
358
359
360
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
void sendUpdate(Object listInfoParam, TextPanelAPI textPanel)
void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt)
void buttonPressConfirmed(Object buttonId, IntelUIAPI ui)
void endAgreement(AgreementEndingType type, InteractionDialogAPI dialog)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode)
static Color getTextColor()
Definition Misc.java:839
static void incrUntrustwortyCount()
Definition Misc.java:6622
static Color getBasePlayerColor()
Definition Misc.java:833
static Color getGrayColor()
Definition Misc.java:826
static void adjustRep(float repChangeFaction, RepLevel limit, String factionId, float repChangePerson, RepLevel personLimit, PersonAPI person, TextPanelAPI text)
Definition Misc.java:3884
static Color getHighlightColor()
Definition Misc.java:792
String getSpriteName(String category, String id)
FactionAPI getFaction(String factionId)
void addUpdateListener(EconomyUpdateListener listener)
void removeUpdateListener(EconomyUpdateListener listener)
void set(String key, Object value)
void setShortcut(int key, boolean putLast)
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)
void addImage(String spriteName, float pad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
ButtonAPI addButton(String text, Object data, float width, float height, float pad)