Starsector API
Loading...
Searching...
No Matches
RecentUnrest.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.econ.MarketAPI;
5import com.fs.starfarer.api.campaign.econ.MarketConditionAPI;
6import com.fs.starfarer.api.impl.campaign.ids.Conditions;
7import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
8import com.fs.starfarer.api.ui.TooltipMakerAPI;
9import com.fs.starfarer.api.util.Misc;
10import com.fs.starfarer.api.util.TimeoutTracker;
11
13
14 public static RecentUnrest get(MarketAPI market) {
15 return get(market, true);
16 }
17 public static RecentUnrest get(MarketAPI market, boolean addIfNeeded) {
19 if (mc == null && !addIfNeeded) return null;
20
21 if (mc == null) {
24 }
25 return (RecentUnrest) mc.getPlugin();
26 }
27
28 public static int getPenalty(MarketAPI market) {
29 RecentUnrest ru = get(market, false);
30 if (ru == null) return 0;
31 return ru.getPenalty();
32 }
33
34 public static float DECREASE_DAYS = 90f;
35
36 protected int penalty;
37 protected float untilDecrease = DECREASE_DAYS;
39
40 public RecentUnrest() {
41 }
42
43 public int getPenalty() {
44 return penalty;
45 }
46
47 public void apply(String id) {
48 market.getStability().modifyFlat(id, -1 * penalty, "Recent unrest");
49 }
50
51 public void unapply(String id) {
53 }
54
55
56 public void add(int stability, String reason) {
57 penalty += stability;
58 float dur = reasons.getRemaining(reason) + stability * DECREASE_DAYS;
59 reasons.add(reason, dur);
60 }
61
62 public void counter(int points, String reason) {
63 points = Math.min(points, penalty);
64 penalty -= points;
65 if (penalty < 0) penalty = 0;
66 float dur = reasons.getRemaining(reason) + points * DECREASE_DAYS;
67 reasons.add(reason, dur);
68 }
69
70 @Override
71 public void advance(float amount) {
72 super.advance(amount);
73
74 float days = Misc.getDays(amount);
75 //days *= 100000f;
76 reasons.advance(days);
77
78 if (penalty > 0) {
79 untilDecrease -= days;
80 if (untilDecrease <= 0) {
81 penalty--;
82 if (penalty < 0) penalty = 0;
84 }
85 }
86 if (penalty <= 0) {
88 }
89 }
90
91 @Override
92 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
93 super.createTooltip(tooltip, expanded);
94 }
95
96
97 @Override
98 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
99 super.createTooltipAfterDescription(tooltip, expanded);
100
101 float pad = 3f;
102 float opad = 10f;
103
105 tooltip.addPara("A penalty to stability that goes down by %s point every three months.",
106 opad, Misc.getHighlightColor(),
107 "1");
108 } else {
109 tooltip.addPara("%s stability. Goes down by one point every three months.",
110 opad, Misc.getHighlightColor(),
111 "-" + (int)penalty);
112
113 if (!reasons.getItems().isEmpty()) {
114 tooltip.addPara("Recent contributing factors:", opad);
115
116 float initPad = pad;
117 for (String reason : reasons.getItems()) {
118 tooltip.addPara(BaseIntelPlugin.BULLET + reason, initPad);
119 initPad = 0f;
120 }
121 }
122 }
123
124 }
125
126 @Override
127 public boolean isTransient() {
128 return false;
129 }
130
131 public void setPenalty(int penalty) {
132 this.penalty = penalty;
133 }
134
135
136}
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
void modifyFlat(String source, float value)
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded)
static float getDays(float amount)
Definition Misc.java:4663
static Color getHighlightColor()
Definition Misc.java:792
MarketConditionAPI getCondition(String id)
MutableStatWithTempMods getStability()
MarketConditionAPI getSpecificCondition(String token)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)