Starsector API
Loading...
Searching...
No Matches
SurveyPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.util.LinkedHashMap;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.PlanetAPI;
9import com.fs.starfarer.api.campaign.econ.MarketConditionAPI;
10import com.fs.starfarer.api.combat.MutableStat;
11import com.fs.starfarer.api.combat.MutableStat.StatMod;
12import com.fs.starfarer.api.fleet.MutableFleetStatsAPI;
13import com.fs.starfarer.api.impl.campaign.ids.Commodities;
14import com.fs.starfarer.api.impl.campaign.ids.Conditions;
15import com.fs.starfarer.api.impl.campaign.ids.Stats;
16import com.fs.starfarer.api.impl.campaign.procgen.ConditionGenDataSpec;
17import com.fs.starfarer.api.impl.campaign.procgen.themes.DerelictThemeGenerator;
18import com.fs.starfarer.api.plugins.SurveyPlugin;
19import com.fs.starfarer.api.util.Misc;
20
21public class SurveyPluginImpl implements SurveyPlugin {
22
23 public static int FLAT_SUPPLIES = 10;
24
25 public static int BASE_MACHINERY = 10;
26 public static int BASE_CREW = 50;
27 public static int BASE_SUPPLIES = 10;
28 public static int MIN_SUPPLIES_OR_MACHINERY = 5;
29
30 public static float MIN_PLANET_RADIUS = 70;
31 public static float MAX_PLANET_RADIUS = 250;
32 public static float MULT_AT_MAX_PLANET_RADIUS = 5;
33
34
35 private CampaignFleetAPI fleet;
36 private PlanetAPI planet;
37
38 private MutableStat costMult = new MutableStat(1f);
39 private MutableStat xpMult = new MutableStat(1f);
40
41 public void init(CampaignFleetAPI fleet, PlanetAPI planet) {
42 this.fleet = fleet;
43 this.planet = planet;
44
45 float hazard = getHazardMultiplier();
46 if (hazard != 1f) {
47 costMult.modifyMult("planet_hazard", hazard, "Hazard rating");
48 }
49 float size = getSizeMultiplier();
50 if (size != 1f) {
51 costMult.modifyMult("planet_size", size, "Planet size");
52 }
53
54 xpMult.applyMods(costMult);
55
56 if (fleet != null) {
57 MutableFleetStatsAPI stats = fleet.getStats();
58 MutableStat stat = stats.getDynamic().getStat(Stats.SURVEY_COST_MULT);
59 for (StatMod mod : stat.getMultMods().values()) {
60 costMult.modifyMult(mod.source, mod.value, mod.desc);
61 }
62 }
63
64 }
65
66 protected float getHazardMultiplier() {
67 float hazard = planet.getMarket().getHazardValue();
68 return hazard;
69 }
70
71 protected float getSizeMultiplier() {
72 float radius = planet.getRadius();
74 if (range <= 0) return 1f;
75 if (radius < MIN_PLANET_RADIUS) radius = MIN_PLANET_RADIUS;
76 if (radius > MAX_PLANET_RADIUS) radius = MAX_PLANET_RADIUS;
77
78 float mult = 1f + ((radius - MIN_PLANET_RADIUS) / range) * (MULT_AT_MAX_PLANET_RADIUS - 1f);
79
80 mult = (int)(mult * 20) / 20f;
81
82 return mult;
83 }
84
85
86 public Map<String, Integer> getRequired() {
87 Map<String, Integer> result = new LinkedHashMap<String, Integer>();
88
89 float mult = getCostMult().getModifiedValue();
90
91 int machinery = (int)Math.round(BASE_MACHINERY * mult);
92 machinery -= (int) Misc.getFleetwideTotalMod(fleet, Stats.getSurveyCostReductionId(Commodities.HEAVY_MACHINERY), 0);
93 machinery = Math.round(machinery / 10f) * 10;
94 if (machinery < MIN_SUPPLIES_OR_MACHINERY) machinery = MIN_SUPPLIES_OR_MACHINERY;
95
96 result.put(Commodities.CREW, (int)Math.round((int)(BASE_CREW * mult) / 10f) * 10);
97 result.put(Commodities.HEAVY_MACHINERY, machinery);
98
99 return result;
100 }
101
102 public Map<String, Integer> getConsumed() {
103 Map<String, Integer> result = new LinkedHashMap<String, Integer>();
104
105 float mult = getCostMult().getModifiedValue();
106 int supplies = (int)Math.round(BASE_SUPPLIES * mult);
107 supplies += FLAT_SUPPLIES;
108 supplies = Math.round((int) supplies / 10f) * 10;
109 supplies -= (int) Misc.getFleetwideTotalMod(fleet, Stats.getSurveyCostReductionId(Commodities.SUPPLIES), 0);
110 if (supplies < MIN_SUPPLIES_OR_MACHINERY) supplies = MIN_SUPPLIES_OR_MACHINERY;
111 result.put(Commodities.SUPPLIES, supplies);
112
113 return result;
114 }
115
116 public MutableStat getCostMult() {
117 return costMult;
118 }
119
120 public long getXP() {
121 float xp = 0;
122
123 if (planet.getMarket() != null) {
124 for (MarketConditionAPI mc : planet.getMarket().getConditions()) {
125 xp += getBaseXPForCondition(mc.getId());
126 }
127 }
128 xp *= getXPMult().getModifiedValue();
129
130 return (long) xp;
131 }
132
133 public long getBaseXPForCondition(String conditionId) {
134 long xp = 0;
135
136 float base = Global.getSettings().getFloat("baseSurveyXP");
137 ConditionGenDataSpec data = (ConditionGenDataSpec) Global.getSettings().getSpec(ConditionGenDataSpec.class, conditionId, true);
138 if (data != null) {
139 xp += base * data.getXpMult();
140 }
141 return xp;
142 }
143
144 public MutableStat getXPMult() {
145 return xpMult;
146 }
147
148
149 public String getImageCategory() {
150 return "illustrations";
151 }
152
153 public String getImageKey() {
154 return "survey";
155 }
156
157 public String getSurveyDataType(PlanetAPI planet) {
158 if (planet.getMarket() == null) return null;
159
160 int count = 0;
161 float value = 0;
162 for (MarketConditionAPI mc : planet.getMarket().getConditions()) {
163 if (DerelictThemeGenerator.interestingConditionsWithRuins.contains(mc.getId())) {
164 count++;
165 }
166 if (mc.getGenSpec() != null) {
167 //value += mc.getGenSpec().getXpMult();
168 value += mc.getGenSpec().getRank();
169 }
170 }
171
172 if (planet.getMarket().hasCondition(Conditions.HABITABLE)) {
173 value += 4f;
174 }
175
176 float hazard = planet.getMarket().getHazardValue();
177 value -= (hazard - 1f) * 2f;
178
179 if (value <= 5) return Commodities.SURVEY_DATA_1;
180 if (value <= 8) return Commodities.SURVEY_DATA_2;
181 if (value <= 11 && count <= 1) return Commodities.SURVEY_DATA_3;
182 if (value <= 14 && count <= 2) return Commodities.SURVEY_DATA_4;
183 return Commodities.SURVEY_DATA_5;
184
185// if (value <= 10 && count <= 0) return Commodities.SURVEY_DATA_1;
186// if (value <= 20 && count <= 0) return Commodities.SURVEY_DATA_2;
187// if (value <= 30 && count <= 1) return Commodities.SURVEY_DATA_3;
188// if (value <= 40 && count <= 2) return Commodities.SURVEY_DATA_4;
189// return Commodities.SURVEY_DATA_5;
190
191// too few class V with below approach
192// if (count <= 0) return Commodities.SURVEY_DATA_1;
193// if (count <= 1) return Commodities.SURVEY_DATA_2;
194// if (count <= 2) return Commodities.SURVEY_DATA_3;
195// if (count <= 3) return Commodities.SURVEY_DATA_4;
196// return Commodities.SURVEY_DATA_5;
197 }
198
199
200 public Map<String, Integer> getOutpostConsumed() {
201 Map<String, Integer> result = new LinkedHashMap<String, Integer>();
202
203 result.put(Commodities.CREW, 1000);
204 result.put(Commodities.HEAVY_MACHINERY, 100);
205 result.put(Commodities.SUPPLIES, 200);
206
207 return result;
208 }
209
210}
211
212
213
static SettingsAPI getSettings()
Definition Global.java:51
void init(CampaignFleetAPI fleet, PlanetAPI planet)
Object getSpec(Class c, String id, boolean nullOnNotFound)