Starsector API
Loading...
Searching...
No Matches
PirateBaseManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.bases;
2
3import java.util.Random;
4
5import com.fs.starfarer.api.EveryFrameScript;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.FactionAPI;
8import com.fs.starfarer.api.campaign.StarSystemAPI;
9import com.fs.starfarer.api.impl.campaign.Tuning;
10import com.fs.starfarer.api.impl.campaign.ids.Factions;
11import com.fs.starfarer.api.impl.campaign.ids.Tags;
12import com.fs.starfarer.api.impl.campaign.intel.BaseEventManager;
13import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel.PirateBaseTier;
14import com.fs.starfarer.api.util.Misc;
15import com.fs.starfarer.api.util.WeightedRandomPicker;
16
17public class PirateBaseManager extends BaseEventManager {
18
19 public static final String KEY = "$core_pirateBaseManager";
20
21 public static final float CHECK_DAYS = 10f;
22 public static final float CHECK_PROB = 0.5f;
23
24
26 Object test = Global.getSector().getMemoryWithoutUpdate().get(KEY);
27 return (PirateBaseManager) test;
28 }
29
30 protected long start = 0;
31 protected float extraDays = 0;
32
33 protected int numDestroyed = 0;
34 protected int numSpawnChecksToSkip = 0;
35
37 super();
38 Global.getSector().getMemoryWithoutUpdate().set(KEY, this);
39 start = Global.getSector().getClock().getTimestamp();
40 }
41
42 @Override
43 protected int getMinConcurrent() {
44 return Global.getSettings().getInt("minPirateBases");
45 }
46 @Override
47 protected int getMaxConcurrent() {
48 return Global.getSettings().getInt("maxPirateBases");
49 }
50
51 @Override
52 protected float getBaseInterval() {
53 return CHECK_DAYS;
54 }
55
56
57 @Override
58 public void advance(float amount) {
59 super.advance(amount);
60 }
61
62
63
64
65
66 protected Random random = new Random();
67 @Override
69 if (numSpawnChecksToSkip > 0) {
71 return null;
72 }
73
74 if (random.nextFloat() < CHECK_PROB) return null;
75
76 StarSystemAPI system = pickSystemForPirateBase();
77 if (system == null) return null;
78
79 //PirateBaseIntel intel = new PirateBaseIntel(system, Factions.PIRATES, PirateBaseTier.TIER_5_3MODULE);
80 //PirateBaseIntel intel = new PirateBaseIntel(system, Factions.PIRATES, PirateBaseTier.TIER_3_2MODULE);
81 PirateBaseTier tier = pickTier();
82
83 //tier = PirateBaseTier.TIER_5_3MODULE;
84
85 String factionId = pickPirateFaction();
86 if (factionId == null) return null;
87
88 PirateBaseIntel intel = new PirateBaseIntel(system, factionId, tier);
89 if (intel.isDone()) intel = null;
90
91 return intel;
92 }
93
94 public String pickPirateFaction() {
95 WeightedRandomPicker<String> picker = new WeightedRandomPicker<String>(random);
96 for (FactionAPI faction : Global.getSector().getAllFactions()) {
97 if (faction.getCustomBoolean(Factions.CUSTOM_MAKES_PIRATE_BASES)) {
98 picker.add(faction.getId(), 1f);
99 }
100 }
101 return picker.pick();
102 }
103
105 float days = Global.getSector().getClock().getElapsedDaysSince(start);
106 return days;
107 }
108
109 public float getDaysSinceStart() {
110 float days = Global.getSector().getClock().getElapsedDaysSince(start) + extraDays;
111 if (Misc.isFastStartExplorer()) {
112 days += Tuning.FAST_START_EXTRA_DAYS - 30f;
113 } else if (Misc.isFastStart()) {
114 days += Tuning.FAST_START_EXTRA_DAYS + 60f;
115 }
116 return days;
117 }
118
123 public float getStandardTimeFactor() {
125 if (timeFactor < 0) timeFactor = 0;
126 if (timeFactor > 1) timeFactor = 1;
127 return timeFactor;
128 }
129
130 public float getExtraDays() {
131 return extraDays;
132 }
133
134 public void setExtraDays(float extraDays) {
135 this.extraDays = extraDays;
136 }
137
138 protected PirateBaseTier pickTier() {
139 float days = getDaysSinceStart();
140
141 days += numDestroyed * 200;
142
143 WeightedRandomPicker<PirateBaseTier> picker = new WeightedRandomPicker<PirateBaseTier>();
144
145 if (days < 360) {
146 picker.add(PirateBaseTier.TIER_1_1MODULE, 10f);
147 picker.add(PirateBaseTier.TIER_2_1MODULE, 10f);
148 } else if (days < 720f) {
149 picker.add(PirateBaseTier.TIER_2_1MODULE, 10f);
150 picker.add(PirateBaseTier.TIER_3_2MODULE, 10f);
151 } else if (days < 1080f) {
152 picker.add(PirateBaseTier.TIER_3_2MODULE, 10f);
153 picker.add(PirateBaseTier.TIER_4_3MODULE, 10f);
154 } else {
155 picker.add(PirateBaseTier.TIER_3_2MODULE, 10f);
156 picker.add(PirateBaseTier.TIER_4_3MODULE, 10f);
157 picker.add(PirateBaseTier.TIER_5_3MODULE, 10f);
158 }
159
160
161// if (true) {
162// picker.clear();
163// picker.add(PirateBaseTier.TIER_1_1MODULE, 10f);
164// picker.add(PirateBaseTier.TIER_2_1MODULE, 10f);
165// picker.add(PirateBaseTier.TIER_3_2MODULE, 10f);
166// picker.add(PirateBaseTier.TIER_4_3MODULE, 10f);
167// picker.add(PirateBaseTier.TIER_5_3MODULE, 10f);
168// }
169
170
171 return picker.pick();
172 }
173
174 public static String RECENTLY_USED_FOR_BASE = "$core_recentlyUsedForBase";
175 public static float genBaseUseTimeout() {
176 return 120f + 60f * (float) Math.random();
177 }
178 public static void markRecentlyUsedForBase(StarSystemAPI system) {
179 if (system != null && system.getCenter() != null) {
180 system.getCenter().getMemoryWithoutUpdate().set(RECENTLY_USED_FOR_BASE, true, genBaseUseTimeout());
181 }
182 }
183
184 protected StarSystemAPI pickSystemForPirateBase() {
185 WeightedRandomPicker<StarSystemAPI> far = new WeightedRandomPicker<StarSystemAPI>(random);
186 WeightedRandomPicker<StarSystemAPI> picker = new WeightedRandomPicker<StarSystemAPI>(random);
187
188 for (StarSystemAPI system : Global.getSector().getStarSystems()) {
189 if (system.hasPulsar()) continue;
190 if (system.hasTag(Tags.THEME_SPECIAL)) continue;
191 if (system.hasTag(Tags.THEME_HIDDEN)) continue;
192
193 float days = Global.getSector().getClock().getElapsedDaysSince(system.getLastPlayerVisitTimestamp());
194 if (days < 45f) continue;
195 if (system.getCenter().getMemoryWithoutUpdate().contains(RECENTLY_USED_FOR_BASE)) continue;
196
197 float weight = 0f;
198 if (system.hasTag(Tags.THEME_MISC_SKIP)) {
199 weight = 1f;
200 } else if (system.hasTag(Tags.THEME_MISC)) {
201 weight = 3f;
202 } else if (system.hasTag(Tags.THEME_REMNANT_NO_FLEETS)) {
203 weight = 3f;
204 } else if (system.hasTag(Tags.THEME_REMNANT_DESTROYED)) {
205 weight = 3f;
206 } else if (system.hasTag(Tags.THEME_RUINS)) {
207 weight = 5f;
208 } else if (system.hasTag(Tags.THEME_CORE_UNPOPULATED)) {
209 //weight = 1f;
210 weight = 0f;
211 }
212 if (weight <= 0f) continue;
213
214 float usefulStuff = system.getCustomEntitiesWithTag(Tags.OBJECTIVE).size() +
215 system.getCustomEntitiesWithTag(Tags.STABLE_LOCATION).size();
216 if (usefulStuff <= 0) continue;
217
218 if (Misc.hasPulsar(system)) continue;
219 if (Misc.getMarketsInLocation(system).size() > 0) continue;
220
221 float dist = system.getLocation().length();
222
223
224
225// float distMult = 1f - dist / 20000f;
226// if (distMult > 1f) distMult = 1f;
227// if (distMult < 0.1f) distMult = 0.1f;
228
229 float distMult = 1f;
230
231 if (dist > 36000f) {
232 far.add(system, weight * usefulStuff * distMult);
233 } else {
234 picker.add(system, weight * usefulStuff * distMult);
235 }
236 }
237
238 if (picker.isEmpty()) {
239 picker.addAll(far);
240 }
241
242 return picker.pick();
243 }
244
245 public int getNumDestroyed() {
246 return numDestroyed;
247 }
248
249 public void setNumDestroyed(int numDestroyed) {
250 this.numDestroyed = numDestroyed;
251 }
252
253 public void incrDestroyed() {
254 numDestroyed++;
257 * 3); // checks happen every 10 days on average, *3 to get months
258 }
259
260}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59