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
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) {
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()) {
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
75
76 @Override
77 public boolean isTransient() {
78 return false;
79 }
80
89
91 incoming.add(Factions.PIRATES, 5f);
92 incoming.add(Factions.POOR, 5f);
93 incoming.add(Factions.INDEPENDENT, 5f);
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
129 tooltip.addPara("Requires a spaceport to have any effect", Misc.getNegativeHighlightColor(), 10f);
130 return;
131 }
132
134 tooltip.addPara("Reduced stability (maximum of %s, reached after %s days)",
135 10f, Misc.getHighlightColor(),
136 "-" + (int) (MAX_STABILITY_PENALTY),
137 "" + (int) MAX_DAYS);
138 tooltip.addPara("Increased population growth (maximum of %s, reached after %s days)",
139 10f, Misc.getHighlightColor(),
140 "+" + (int) (MAX_GROWTH),
141 "" + (int) MAX_DAYS);
142
143 tooltip.addPara("Increased accessibility (maximum of %s, reached after %s days)",
144 10f, Misc.getHighlightColor(),
145 "+" + (int) Math.round(MAX_ACCESS_BONUS * 100f) + "%",
146 "" + (int) MAX_DAYS);
147 } else {
148 tooltip.addPara("%s stability (maximum of %s, reached after %s days)",
149 10f, Misc.getHighlightColor(),
150 "-" + (int)getStabilityPenalty(),
151 "-" + (int) (MAX_STABILITY_PENALTY),
152 "" + (int) MAX_DAYS);
153 tooltip.addPara("%s population growth (maximum of %s, reached after %s days)",
154
155 10f, Misc.getHighlightColor(),
156 "+" + (int) getImmigrationBonus(),
157 "+" + (int) (MAX_GROWTH),
158 "" + (int) MAX_DAYS);
159
160 tooltip.addPara("%s accessibility (maximum of %s, reached after %s days)",
161 10f, Misc.getHighlightColor(),
162 "+" + (int) Math.round(getAccessBonus() * 100f) + "%",
163 "+" + (int) Math.round(MAX_ACCESS_BONUS * 100f) + "%",
164 "" + (int) MAX_DAYS);
165 }
166
167 tooltip.addPara("Colony does not require the transponder to be turned on for open trade. " +
168 "All commodities are legal to trade.", 10f);
169
170 tooltip.addPara("Colony gets income from smuggled exports.", 10f);
171 }
172}
173
174
175
176
177
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
void modifyFlat(String source, float value)
void modifyFlat(String source, float value)
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
static final String OFFICER_IS_MERC_PROB_MOD
Definition Stats.java:40
static String ucFirst(String str)
Definition Misc.java:559
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getHighlightColor()
Definition Misc.java:792
void addTransientImmigrationModifier(MarketImmigrationModifier mod)
MarketConditionAPI getCondition(String id)
MutableStatWithTempMods getStability()
void removeTransientImmigrationModifier(MarketImmigrationModifier mod)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)