Starsector API
Loading...
Searching...
No Matches
PerseanLeagueMembership.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel;
2
3import java.util.Set;
4
5import java.awt.Color;
6
7import org.lwjgl.input.Keyboard;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.FactionAPI;
11import com.fs.starfarer.api.campaign.InteractionDialogAPI;
12import com.fs.starfarer.api.campaign.RepLevel;
13import com.fs.starfarer.api.campaign.SectorEntityToken;
14import com.fs.starfarer.api.campaign.TextPanelAPI;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.campaign.econ.MonthlyReport;
17import com.fs.starfarer.api.campaign.econ.MonthlyReport.FDNode;
18import com.fs.starfarer.api.campaign.listeners.CommissionEndedListener;
19import com.fs.starfarer.api.campaign.listeners.EconomyTickListener;
20import com.fs.starfarer.api.characters.PersonAPI;
21import com.fs.starfarer.api.impl.campaign.econ.EstablishedPolity;
22import com.fs.starfarer.api.impl.campaign.ids.Factions;
23import com.fs.starfarer.api.impl.campaign.ids.People;
24import com.fs.starfarer.api.impl.campaign.ids.Tags;
25import com.fs.starfarer.api.impl.campaign.intel.contacts.ContactIntel;
26import com.fs.starfarer.api.impl.campaign.intel.events.EstablishedPolityScript;
27import com.fs.starfarer.api.impl.campaign.rulecmd.HA_CMD;
28import com.fs.starfarer.api.impl.campaign.shared.SharedData;
29import com.fs.starfarer.api.ui.ButtonAPI;
30import com.fs.starfarer.api.ui.IntelUIAPI;
31import com.fs.starfarer.api.ui.LabelAPI;
32import com.fs.starfarer.api.ui.SectorMapAPI;
33import com.fs.starfarer.api.ui.TooltipMakerAPI;
34import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
35import com.fs.starfarer.api.util.Misc;
36
38
39 public static enum AgreementEndingType {
40 EXPIRED,
41 BROKEN,
42 ENDED,
43 }
44
45 public static int TIMES_LEFT_LEAGUE_FOR_NO_REJOIN = 2;
46
47 // in $player memory
48 public static final String PL_MEMBERSHIP_GOOD_DEAL = "$hasGoodPLMembershipDeal";
49 public static final String PAYING_HOUSE_HANNAN = "$payingHouseHannan";
50 public static final String LEFT_LEAGUE_WHEN_GOOD_DEAL = "$leftLeagueWhenGoodDeal";
51 public static final String IS_LEAGUE_MEMBER = "$isLeagueMember";
52 public static final String NUM_TIMES_LEFT_LEAGUE = "$numTimesLeftLeague";
53
54 public static final String DEFEATED_BLOCKADE = "$defeatedLeagueBlockade";
55 public static final String DEFEATED_PUN_EX = "$defeatedLeaguePunEx";
56
60 public static void incrLeftLeagueCount() {
61 int count = getNumTimesLeftLeague();
63 }
64
69 public static void setDefeatedBlockade(boolean value) {
71 if (!value) {
73 }
74 }
75 public static void setDefeatedPunEx(boolean value) {
77 if (!value) {
79 }
80 }
84
106 public static void setLeagueMember(boolean member) {
108 }
109
110
111 public static String KEY = "$plMembership_ref";
115
116 public static String BUTTON_END = "End";
117 public static String BUTTON_RENEGE_HANNAN = "Renege Hannan";
118
119 public static String UPDATE_PARAM_ACCEPTED = "update_param_accepted";
120
121
122 protected FactionAPI faction = null;
123 protected AgreementEndingType endType = null;
124
126 this.faction = Global.getSector().getFaction(Factions.PERSEAN);
127
128 setImportant(true);
129 setLeagueMember(true);
131
134
135 TextPanelAPI text = null;
136 if (dialog != null) text = dialog.getTextPanel();
137
140
142
144 if (!level.isAtWorst(RepLevel.NEUTRAL)) {
146 }
147
149 }
150
151 @Override
152 protected void notifyEnding() {
153 super.notifyEnding();
154
155 setLeagueMember(false);
157 //setPayingHouseHannan(false);
158 stopPayingHouseHannan(false, null);
159
161
163 }
164
165 @Override
166 protected void notifyEnded() {
167 super.notifyEnded();
168 }
169
170 protected Object readResolve() {
171 return this;
172 }
173
174 public String getBaseName() {
175 return "Persean League Membership";
176 }
177
178 public String getAcceptedPostfix() {
179 return "Accepted";
180 }
181
182 public String getBrokenPostfix() {
183 return "Annulled";
184
185 }
186 public String getEndedPostfix() {
187 return "Ended";
188 }
189
190 public String getExpiredPostfix() {
191 return "Expired";
192 }
193
194 public String getName() {
195 String postfix = "";
196 if (isEnding() && endType != null) {
197 switch (endType) {
198 case BROKEN:
199 postfix = " - " + getBrokenPostfix();
200 break;
201 case ENDED:
202 postfix = " - " + getEndedPostfix();
203 break;
204 case EXPIRED:
205 postfix = " - " + getExpiredPostfix();
206 break;
207 }
208 }
210 postfix = " - " + getAcceptedPostfix();
211 }
212 return getBaseName() + postfix;
213 }
214
215 @Override
217 return faction;
218 }
219
220 public String getSmallDescriptionTitle() {
221 return getName();
222 }
223
224 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
225 Color h = Misc.getHighlightColor();
226 Color g = Misc.getGrayColor();
227 float pad = 3f;
228 float opad = 10f;
229
230 float initPad = pad;
231 if (mode == ListInfoMode.IN_DESC) initPad = opad;
232
233 Color tc = getBulletColorForMode(mode);
234
235 bullet(info);
236 boolean isUpdate = getListInfoParam() != null;
237
238// if (getListInfoParam() == UPDATE_PARAM_ACCEPTED) {
239// return;
240// }
241
242 int perMonth = computeCreditsPerMonth();
243 if (perMonth != 0 && !isEnded() && !isEnding()) {
244 Color c = perMonth > 0 ? h : Misc.getNegativeHighlightColor();
245 info.addPara("%s per month", initPad, tc, c, Misc.getDGSCredits(perMonth));
246 }
247
248 unindent(info);
249 }
250
251// @Override
252// public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
253// Color h = Misc.getHighlightColor();
254// Color g = Misc.getGrayColor();
255// Color c = getTitleColor(mode);
256// float pad = 3f;
257// float opad = 10f;
258//
259// info.addPara(getName(), c, 0f);
260//
261// addBulletPoints(info, mode);
262// }
263
264 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
265 Color h = Misc.getHighlightColor();
266 Color g = Misc.getGrayColor();
267 Color tc = Misc.getTextColor();
268 float pad = 3f;
269 float opad = 10f;
270
271 Color c = faction.getBaseUIColor();
272
273 info.addImage(getFaction().getLogo(), width, 128, opad);
274
275 if (isEnding() || isEnded()) {
276 info.addPara("Your agreement with the League is no longer in force.", opad, c, "League");
277 return;
278 }
279
280 if (isGoodDeal()) {
281 info.addPara("You've negotiated a good membership deal from a position of strength. "
282 + "The League will support you politically, which "
283 + "for example makes it untenable for the Hegemony to insist on AI inspections "
284 + "in your space.", opad, c, "League");
285
286 if (isPayingHouseHannan()) {
287 info.addPara("Part of your arrangement involves unofficial payments directly to the accounts "
288 + "of House Hannan, as payment for facilitating this agreement.", opad);
289 addBulletPoints(info, ListInfoMode.IN_DESC);
290 ButtonAPI button = info.addButton("Renege on the payments", BUTTON_RENEGE_HANNAN,
291 getFactionForUIColors().getBaseUIColor(), getFactionForUIColors().getDarkUIColor(),
292 (int)(width), 20f, opad * 1f);
293 button.setShortcut(Keyboard.KEY_G, true);
294 info.addSpacer(opad);
295 }
296 } else {
297 info.addPara("You've joined the Persean League, though it's whispered that you only did so to avoid "
298 + "harassment, and your membership dues are nothing more than protection payments. "
299 + "However, the League still supports you politically, which "
300 + "for example makes it untenable for the Hegemony to insist on AI inspections "
301 + "in your space.", opad, c, "Persean League");
302 }
303
304 info.addPara("Due to being new members of the League, your colonies enjoy an "
305 + "increased flow of trade, resulting in a %s accessibility bonus.",
306 opad, h,
307 "+" + (int)Math.round(EstablishedPolity.ACCESSIBILITY_BONUS * 100f) + "%");
308
309 info.addPara("Your League membership is contingent on maintaining an active Persean League commission. If "
310 + "you resign it, or if it is annulled for any reason, your membership will end as well.", opad);
311
313 info.addPara("You are paying membership dues to the League.", opad);
314 addBulletPoints(info, ListInfoMode.IN_DESC);
315 }
316
317
318 ButtonAPI button = info.addButton("End League membership", BUTTON_END,
319 getFactionForUIColors().getBaseUIColor(), getFactionForUIColors().getDarkUIColor(),
320 (int)(width), 20f, opad * 1f);
321 button.setShortcut(Keyboard.KEY_U, true);
322
323 }
324
325
326 public String getIcon() {
327 return faction.getCrest();
328 }
329
330 public Set<String> getIntelTags(SectorMapAPI map) {
331 Set<String> tags = super.getIntelTags(map);
332 tags.add(Tags.INTEL_AGREEMENTS);
333 tags.add(faction.getId());
334 return tags;
335 }
336
337 @Override
338 public String getImportantIcon() {
339 return Global.getSettings().getSpriteName("intel", "important_accepted_mission");
340 }
341
342 @Override
344 return null;
345 }
346
347
348 public void reportEconomyMonthEnd() {
349
350 }
351
352 public void reportEconomyTick(int iterIndex) {
353
354 int credits = computeCreditsPerTick();
355
356 if (credits != 0) {
357 FDNode node = getMonthlyReportNode();
358 if (credits > 0) {
359 node.income += credits;
360 } else if (credits < 0) {
361 node.upkeep -= credits;
362 }
363 }
364 }
365
366 public FDNode getMonthlyReportNode() {
368 FDNode marketsNode = report.getNode(MonthlyReport.OUTPOSTS);
369 if (marketsNode.name == null) {
370 marketsNode.name = "Colonies";
371 marketsNode.custom = MonthlyReport.OUTPOSTS;
372 marketsNode.tooltipCreator = report.getMonthlyReportTooltip();
373 }
374
375 FDNode paymentNode = report.getNode(marketsNode, "persean_league_membership");
376 paymentNode.name = "Persean League membership dues";
377 //paymentNode.upkeep += payment;
378 //paymentNode.icon = Global.getSettings().getSpriteName("income_report", "generic_expense");
379 paymentNode.icon = faction.getCrest();
380
381 if (paymentNode.tooltipCreator == null) {
382 paymentNode.tooltipCreator = new TooltipCreator() {
383 public boolean isTooltipExpandable(Object tooltipParam) {
384 return false;
385 }
386 public float getTooltipWidth(Object tooltipParam) {
387 return 450;
388 }
389 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
390 tooltip.addPara("Monthly dues for keeping your Persean League membership in good standing.", 0f);
391 }
392 };
393 }
394
395 return paymentNode;
396 }
397
399 int perTick = computeCreditsPerTick();
400 float numIter = Global.getSettings().getFloat("economyIterPerMonth");
401 return (int) (perTick * numIter);
402 }
403
404 public static int computeCreditsPerTick() {
405 float numIter = Global.getSettings().getFloat("economyIterPerMonth");
406 float f = 1f / numIter;
407
408 int payment = 0;
409 float feeFraction = Global.getSettings().getFloat("perseanLeagueFeeFraction");
410 if (isGoodDeal()) {
411 feeFraction = 0f;
412 }
413 if (isPayingHouseHannan()) {
414 feeFraction += Global.getSettings().getFloat("houseHannanFeeFraction");
415 }
416
417 for (MarketAPI market : Misc.getPlayerMarkets(false)) {
418 payment += (int) (market.getGrossIncome() * f) * feeFraction;
419 }
420
421 return -payment;
422 }
423
425 return faction;
426 }
427
428 public void endMembership(AgreementEndingType type, InteractionDialogAPI dialog) {
429 if (!isEnded() && !isEnding()) {
430 boolean baseMembership = !PerseanLeagueMembership.isGoodDeal();
431
432 endType = type;
433 setImportant(false);
434 //endAfterDelay();
436
438
441
442 if (dialog != null) {
443 sendUpdate(new Object(), dialog.getTextPanel());
444 }
445
446 if (baseMembership) {
448 }
449
450 }
451 }
452
453
454 public static void stopPayingHouseHannan(boolean trustBroken, InteractionDialogAPI dialog) {
455 if (isPayingHouseHannan()) {
456 TextPanelAPI text = null;
457 if (dialog != null) text = dialog.getTextPanel();
459 if (reynard != null) {
460 Misc.adjustRep(reynard, -0.5f, text);
461 ContactIntel.removeContact(reynard, dialog);
462 }
464
465 new GensHannanMachinations(dialog);
466 if (trustBroken) {
468 }
469 }
470 }
471
472 @Override
473 public void buttonPressConfirmed(Object buttonId, IntelUIAPI ui) {
474 if (buttonId == BUTTON_END) {
475 endMembership(AgreementEndingType.ENDED, null);
476 } else if (buttonId == BUTTON_RENEGE_HANNAN) {
477 stopPayingHouseHannan(true, null);
478 }
479 super.buttonPressConfirmed(buttonId, ui);
480 }
481
482
483 @Override
484 public void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt) {
486
487 if (buttonId == BUTTON_END) {
488 if (isGoodDeal()) {
489 String extra = "";
490 LabelAPI label = prompt.addPara("You've negotiated a good membership deal from a position of strength. If "
491 + "you leave, you will not be allowed to rejoin, but the " +
492 faction.getDisplayNameWithArticle() + " will likely refrain "
493 + "from harassing your interests." + extra, 0f,
497 label.setHighlight("will not be allowed to rejoin", faction.getDisplayNameWithArticleWithoutArticle());
498 if (isPayingHouseHannan()) {
499 prompt.addPara("However, Gens Hannan will not be pleased with their payments being stopped.",
500 10f, Misc.getNegativeHighlightColor(), "Gens Hannan will not be pleased");
501 }
502 } else {
503 String extra = "";
504 boolean canRejoin = getNumTimesLeftLeague() < TIMES_LEFT_LEAGUE_FOR_NO_REJOIN - 1;
505 float rejoinPad = 10f;
507 LabelAPI label = prompt.addPara(
508 "If you leave, " + faction.getDisplayNameWithArticle() + " will likely take"
509 + " drastic action against your colonies." + extra, 0f);
512 } else {
513 if (canRejoin) {
514 prompt.addPara("If you leave, " + faction.getDisplayNameWithArticle() + " will likely start "
515 + " harassing your interests in the near future.", 0f,
518 } else {
519 rejoinPad = 0f;
520 }
521 }
522 if (!canRejoin) {
523 prompt.addPara("Given your history, it is likely that you would not be allowed "
524 + "to rejoin the League at any point in the future.",
525 rejoinPad, Misc.getNegativeHighlightColor(),
526 "would not be allowed to rejoin");
527 }
528 }
529 } else if (buttonId == BUTTON_RENEGE_HANNAN) {
530 prompt.addPara("Gens Hannan will not be pleased. While they are unlikely to be unable to obtain your outright "
531 + "explulsion from the League, their influence is significant and will likely be used "
532 + "to continually undermine your standing. ", 0f,
534 "continually undermine your standing");
535
536 prompt.addPara("You will also lose Reynard Hannan as a contact.", 10f,
538 "lose Reynard Hannan");
539 }
540 }
541
542 @Override
543 public boolean doesButtonHaveConfirmDialog(Object buttonId) {
544 if (buttonId == BUTTON_END
545 || buttonId == BUTTON_RENEGE_HANNAN) {
546 return true;
547 }
548 return super.doesButtonHaveConfirmDialog(buttonId);
549 }
550
551
553 if (intel.getFaction().getId().equals(Factions.PERSEAN)) {
554 endMembership(AgreementEndingType.BROKEN, null);
555 }
556
557 }
558}
559
560
561
562
563
564
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
MonthlyReportNodeTooltipCreator getMonthlyReportTooltip()
static PersonAPI getPerson(String id)
Definition People.java:107
void sendUpdate(Object listInfoParam, TextPanelAPI textPanel)
void createConfirmationPrompt(Object buttonId, TooltipMakerAPI prompt)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
static void stopPayingHouseHannan(boolean trustBroken, InteractionDialogAPI dialog)
void endMembership(AgreementEndingType type, InteractionDialogAPI dialog)
static void removeContact(PersonAPI person, InteractionDialogAPI dialog)
static void sendPerseanLeaguePunitiveExpedition(InteractionDialogAPI dialog)
Definition HA_CMD.java:957
static Color getTextColor()
Definition Misc.java:839
static String getDGSCredits(float num)
Definition Misc.java:1390
static Color getNegativeHighlightColor()
Definition Misc.java:802
static void incrUntrustwortyCount()
Definition Misc.java:6622
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
static List< MarketAPI > getPlayerMarkets(boolean includeNonPlayerFaction)
Definition Misc.java:980
boolean isAtWorst(RepLevel level)
Definition RepLevel.java:68
String getSpriteName(String category, String id)
void setSecondaryColorOverride(Color secondaryOverride)
void setSecondaryColorSegmentsOverride(int secondaryColorSegmentsOverride)
FactionAPI getFaction(String factionId)
ListenerManagerAPI getListenerManager()
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)
UIComponentAPI addSpacer(float height)
ButtonAPI addButton(String text, Object data, float width, float height, float pad)