Starsector API
Loading...
Searching...
No Matches
DisposablePirateFleetManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.fleets;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.campaign.CampaignFleetAPI;
5import com.fs.starfarer.api.campaign.StarSystemAPI;
6import com.fs.starfarer.api.campaign.econ.MarketAPI;
7import com.fs.starfarer.api.campaign.econ.MarketConditionAPI;
8import com.fs.starfarer.api.impl.campaign.fleets.FleetFactory.MercType;
9import com.fs.starfarer.api.impl.campaign.ids.Conditions;
10import com.fs.starfarer.api.impl.campaign.ids.Factions;
11import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
12import com.fs.starfarer.api.impl.campaign.intel.SystemBountyManager;
13import com.fs.starfarer.api.impl.campaign.intel.bases.PirateActivity;
14import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel.PirateBaseTier;
15import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseManager;
16import com.fs.starfarer.api.util.Misc;
17
29
30 protected Object readResolve() {
31 super.readResolve();
32 return this;
33 }
34
35 @Override
36 protected String getSpawnId() {
37 return "pirates";
38 }
39
40
41 @Override
42 public void advance(float amount) {
43 super.advance(amount);
44 }
45
46 @Override
48 PirateBaseTier tier = getPirateActivityTier();
49 MarketAPI largestBounty = getLargestMarketIfSystemHasBounty();
50
51 float tierMult = getMultForTier(tier);
52 float bountyMult = largestBounty == null ? 0 : largestBounty.getSize();
53
54 float desiredNumFleets = 1f;
55
56 desiredNumFleets += tierMult > 0 ? 3f + tierMult : 0;
57 desiredNumFleets += bountyMult;
58
59 return (int) Math.round(desiredNumFleets);
60 }
61
62 protected float getMultForTier(PirateBaseTier tier) {
63 if (tier == null) return 0f;
64 return tier.ordinal() + 1f;
65 }
66
67 protected PirateBaseTier getPirateActivityTier() {
68 if (currSpawnLoc == null) return null;
69 for (MarketAPI market : Global.getSector().getEconomy().getMarkets(currSpawnLoc)) {
70 if (market.isHidden()) continue;
71 if (market.getFactionId().equals(Factions.PIRATES)) continue;
72 MarketConditionAPI mc = market.getCondition(Conditions.PIRATE_ACTIVITY);
73 if (mc != null && mc.getPlugin() instanceof PirateActivity) {
74 PirateActivity pa = (PirateActivity) mc.getPlugin();
75 return pa.getIntel() == null ? null : pa.getIntel().getTier();
76 }
77 }
78 return null;
79 }
80 protected boolean hasPirateActivity() {
81 return getPirateActivityTier() != null;
82 }
83
84 protected MarketAPI getLargestMarketIfSystemHasBounty() {
85 if (currSpawnLoc == null) return null;
86 MarketAPI largest = null;
87 boolean bounty = false;
88 int maxSize = 0;
89 for (MarketAPI market : Global.getSector().getEconomy().getMarkets(currSpawnLoc)) {
90 if (market.isHidden()) continue;
91 if (market.getFactionId().equals(Factions.PIRATES)) continue;
92
93 if (SystemBountyManager.getInstance().isActive(market)) bounty = true;
94
95 if (market.getSize() > maxSize) {
96 maxSize = market.getSize();
97 largest = market;
98 }
99 }
100 if (!bounty) largest = null;
101 return largest;
102 }
103
104 protected CampaignFleetAPI spawnFleetImpl() {
105 StarSystemAPI system = currSpawnLoc;
106 if (system == null) return null;
107
108 CampaignFleetAPI player = Global.getSector().getPlayerFleet();
109 if (player == null) return null;
110
111 int num = Misc.getMarketsInLocation(system).size();
112 if (Misc.getMarketsInLocation(system, Factions.PLAYER).size() == num && num > 0) {
113 return null; // handled by HostileActivityIntel, DisposableHostileActivityFleetManager, etc
114 }
115
116// float distToPlayerLY = Misc.getDistanceLY(player.getLocationInHyperspace(), system.getLocation());
117// if (distToPlayerLY > 1f) return null;
118
119 PirateBaseTier tier = getPirateActivityTier();
120 MarketAPI largestBounty = getLargestMarketIfSystemHasBounty();
121 float tierMult = getMultForTier(tier);
122 float bountyMult = 0f;
123 if (largestBounty != null) {
124 bountyMult = largestBounty.getSize();
125 }
126 //float recentSpawns = getRecentSpawnsForSystem(currSpawnLoc);
127
128 // up to 5 for tier and 8 for market, so max is 13; reasonable avg/high value maybe 10
129 float bonus = tierMult + bountyMult;
130
131
132 float timeFactor = (PirateBaseManager.getInstance().getDaysSinceStart() - 180f) / (365f * 2f);
133 if (timeFactor < 0) timeFactor = 0;
134 if (timeFactor > 1) timeFactor = 1;
135
136 float earlyTimeFactor = (PirateBaseManager.getInstance().getDaysSinceStart() - 60f) / 120f;
137 if (earlyTimeFactor < 0) earlyTimeFactor = 0;
138 if (earlyTimeFactor > 1) earlyTimeFactor = 1;
139
140 //timeFactor = 1f;
141
142 float r = (float) Math.random();
143 //r = (float) Math.sqrt(r);
144
145 //float fp = 15f + 30f * (float) Math.random() + bonus * 15f * r * timeFactor;
146
147 float fp = (10f + bonus) * earlyTimeFactor +
148 (5f + bonus) * (0.5f + 0.5f * (float) Math.random()) +
149 50f * (0.5f + 0.5f * r) * timeFactor;
150
151 // larger fleets if more fleets
152 float desired = getDesiredNumFleetsForSpawnLocation();
153 if (desired > 2) {
154 fp += ((desired - 2) * (0.5f + (float) Math.random() * 0.5f)) * 2f * timeFactor;
155 }
156
157 if (fp < 10) fp = 10;
158
159 MercType type;
160 if (fp < 25) {
161 type = MercType.SCOUT;
162 } else if (fp < 75) {
163 type = MercType.PRIVATEER;
164 } else if (fp < 125) {
165 type = MercType.PATROL;
166 } else {
167 type = MercType.ARMADA;
168 }
169
170 String fleetType = type.fleetType;
171
172 float combat = fp;
173 float tanker = 0f;
174
175 if (type == MercType.PATROL || type == MercType.ARMADA) {
176 tanker = combat * 0.1f;
177 }
178
179 combat = Math.round(combat);
180 tanker = Math.round(tanker);
181
182 FleetParamsV3 params = new FleetParamsV3(
183 null,
184 system.getLocation(), // location
185 Factions.PIRATES,
186 null, // quality override
187 fleetType,
188 combat, // combatPts
189 0f, // freighterPts
190 tanker, // tankerPts
191 0f, // transportPts
192 0f, // linerPts
193 0f, // utilityPts
194 0f // qualityMod
195 );
196 params.ignoreMarketFleetSizeMult = true;
197 if (timeFactor <= 0) {
198 params.maxShipSize = 1;
199 }
200 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
201
202 if (fleet == null || fleet.isEmpty()) return null;
203
204 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PIRATE, true);
205 fleet.getMemoryWithoutUpdate().set(MemFlags.FLEET_NO_MILITARY_RESPONSE, true);
206
207 setLocationAndOrders(fleet, 0.25f, 0.25f);
208
209 return fleet;
210 }
211
212}
213
214
215
216
217
218
219
220
static SectorAPI getSector()
Definition Global.java:59
void setLocationAndOrders(CampaignFleetAPI fleet, float probStartInHyper, float probStayInHyper)
static CampaignFleetAPI createFleet(FleetParamsV3 params)