Starsector API
Loading...
Searching...
No Matches
FreeMarket.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.campaign.econ.MarketImmigrationModifier;
7import com.fs.starfarer.api.impl.campaign.ids.Conditions;
8import com.fs.starfarer.api.impl.campaign.ids.Factions;
9import com.fs.starfarer.api.impl.campaign.ids.Stats;
10import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
11import com.fs.starfarer.api.ui.TooltipMakerAPI;
12import com.fs.starfarer.api.util.Misc;
13
14
15
16public class FreeMarket extends BaseMarketConditionPlugin implements MarketImmigrationModifier {
17
18 public static float OFFICER_MERC_PROB_MOD = 0.25f;
19
20 public static float MIN_STABILITY_PENALTY = 1f;
21 public static float MAX_STABILITY_PENALTY = 3f;
22 //public static float STABILITY_PENALTY = 3f;
23
24 public static float MIN_ACCESS_BONUS = 0.05f;
25 public static float MAX_ACCESS_BONUS = 0.25f;
26
27 public static float MIN_GROWTH = 3f;
28 public static float MAX_GROWTH = 10f;
29 public static float MAX_DAYS = 365f;
30
31 public static FreeMarket get(MarketAPI market) {
32 MarketConditionAPI mc = market.getCondition(Conditions.FREE_PORT);
33 if (mc != null && mc.getPlugin() instanceof FreeMarket) {
34 return (FreeMarket) mc.getPlugin();
35 }
36 return null;
37 }
38
39 private float daysActive = 0f;
40 @Override
41 public void advance(float amount) {
42 if (!market.hasSpaceport()) {
43 market.removeSpecificCondition(condition.getIdForPluginModifications());
44 market.setFreePort(false);
45 return;
46 }
47 if (amount <= 0) return;
48
49 super.advance(amount);
50
51 float days = Global.getSector().getClock().convertToDays(amount);
52 daysActive += days;
53 }
54
55 public boolean runWhilePaused() {
56 return true;
57 }
58
59 public float getDaysActive() {
60 return daysActive;
61 }
62
63 public void setDaysActive(float daysActive) {
64 this.daysActive = daysActive;
65 }
66
67 public void apply(String id) {
68 market.addTransientImmigrationModifier(this);
69
70 market.getAccessibilityMod().modifyFlat(id, getAccessBonus(), "Free port");
71 market.getStability().modifyFlat(id, -getStabilityPenalty(), "Free port");
72
73 market.getStats().getDynamic().getMod(Stats.OFFICER_IS_MERC_PROB_MOD).modifyFlat(id, OFFICER_MERC_PROB_MOD);
74 }
75
76 @Override
77 public boolean isTransient() {
78 return false;
79 }
80
81 public void unapply(String id) {
82 market.removeTransientImmigrationModifier(this);
83
84 market.getStability().unmodifyFlat(id);
85 market.getAccessibilityMod().unmodifyFlat(id);
86
87 market.getStats().getDynamic().getMod(Stats.OFFICER_IS_MERC_PROB_MOD).unmodifyFlat(id);
88 }
89
90 public void modifyIncoming(MarketAPI market, PopulationComposition incoming) {
91 incoming.add(Factions.PIRATES, 5f);
92 incoming.add(Factions.POOR, 5f);
93 incoming.add(Factions.INDEPENDENT, 5f);
94 incoming.getWeight().modifyFlat(getModId(), getImmigrationBonus(), Misc.ucFirst(condition.getName().toLowerCase()));
95 }
96
97 protected float getImmigrationBonus() {
98 //float growth = Math.min(1f, daysActive / 10f) * MAX_GROWTH;
99 float growth = MIN_GROWTH + daysActive / MAX_DAYS * (MAX_GROWTH - MIN_GROWTH);
100 growth = Math.round(growth);
101 if (growth > MAX_GROWTH) growth = MAX_GROWTH;
102 if (growth < 1) growth = 1;
103 return growth;
104 }
105
106 protected float getAccessBonus() {
107 //float growth = Math.min(1f, daysActive / 10f) * MAX_GROWTH;
108 float access = MIN_ACCESS_BONUS + daysActive / MAX_DAYS * (MAX_ACCESS_BONUS - MIN_ACCESS_BONUS);
109 access = Math.round(access * 100f) / 100f;
110 if (access > MAX_ACCESS_BONUS) access = MAX_ACCESS_BONUS;
111 if (access < 0.01f) access = 0.01f;
112 return access;
113 }
114
115 protected float getStabilityPenalty() {
116 //float growth = Math.min(1f, daysActive / 10f) * MAX_GROWTH;
118 s = Math.round(s);
120 if (s < 1f) s = 1f;
121 return s;
122 }
123
124
125 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
126 super.createTooltipAfterDescription(tooltip, expanded);
127
128 if (!market.hasSpaceport()) {
129 tooltip.addPara("Requires a spaceport to have any effect", Misc.getNegativeHighlightColor(), 10f);
130 return;
131 }
132
133// tooltip.addPara("%s stability",
134// 10f, Misc.getHighlightColor(),
135// "-" + (int)STABILITY_PENALTY);
136 tooltip.addPara("%s stability (maximum of %s, reached after %s days)",
137 10f, Misc.getHighlightColor(),
138 "-" + (int)getStabilityPenalty(),
139 "-" + (int) (MAX_STABILITY_PENALTY),
140 "" + (int) MAX_DAYS);
141 tooltip.addPara("%s population growth (maximum of %s, reached after %s days)",
142
143 10f, Misc.getHighlightColor(),
144 "+" + (int) getImmigrationBonus(),
145 "+" + (int) (MAX_GROWTH),
146 "" + (int) MAX_DAYS);
147
148 tooltip.addPara("%s accessibility (maximum of %s, reached after %s days)",
149 10f, Misc.getHighlightColor(),
150 "+" + (int) Math.round(getAccessBonus() * 100f) + "%",
151 "+" + (int) Math.round(MAX_ACCESS_BONUS * 100f) + "%",
152 "" + (int) MAX_DAYS);
153
154 tooltip.addPara("Colony does not require the transponder to be turned on for open trade. " +
155 "All commodities are legal to trade.", 10f);
156
157 tooltip.addPara("Colony gets income from smuggled exports.", 10f);
158 }
159}
160
161
162
163
164
static SectorAPI getSector()
Definition Global.java:59
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
void modifyIncoming(MarketAPI market, PopulationComposition incoming)