Starsector API
Loading...
Searching...
No Matches
PirateFleetManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.fleets;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.campaign.FleetAssignment;
8import com.fs.starfarer.api.campaign.LocationAPI;
9import com.fs.starfarer.api.campaign.SectorEntityToken;
10import com.fs.starfarer.api.campaign.StarSystemAPI;
11import com.fs.starfarer.api.campaign.econ.MarketAPI;
12import com.fs.starfarer.api.impl.campaign.fleets.FleetFactory.MercType;
13import com.fs.starfarer.api.impl.campaign.fleets.RouteManager.RouteData;
14import com.fs.starfarer.api.impl.campaign.ids.Factions;
15import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
16import com.fs.starfarer.api.impl.campaign.ids.Tags;
17import com.fs.starfarer.api.util.Misc;
18import com.fs.starfarer.api.util.WeightedRandomPicker;
19
27
28 @Override
29 protected int getMaxFleets() {
30 return (int) Global.getSettings().getFloat("maxPirateFleets");
31 }
32
33 @Override
34 protected CampaignFleetAPI spawnFleet() {
35 StarSystemAPI target = pickTargetSystem();
36 if (target == null || true) return null;
37
38 WeightedRandomPicker<MercType> picker = new WeightedRandomPicker<MercType>();
39 picker.add(MercType.SCOUT, 10f);
40 picker.add(MercType.BOUNTY_HUNTER, 10f);
41 picker.add(MercType.PRIVATEER, 10f);
42 picker.add(MercType.PATROL, 10f);
43 picker.add(MercType.ARMADA, 3f);
44
45 MercType type = picker.pick();
46
47
48 float combat = 0f;
49 float tanker = 0f;
50 float freighter = 0f;
51 String fleetType = type.fleetType;
52 switch (type) {
53 case SCOUT:
54 combat = Math.round(1f + (float) Math.random() * 2f);
55 break;
56 case PRIVATEER:
57 case BOUNTY_HUNTER:
58 combat = Math.round(3f + (float) Math.random() * 2f);
59 break;
60 case PATROL:
61 combat = Math.round(9f + (float) Math.random() * 3f);
62 break;
63 case ARMADA:
64 combat = Math.round(12f + (float) Math.random() * 8f);
65 break;
66 }
67
68 FleetParamsV3 params = new FleetParamsV3(
69 null,
70 target.getLocation(),
71 Factions.PIRATES, // quality will always be reduced by non-market-faction penalty, which is what we want
72 null,
73 fleetType,
74 combat, // combatPts
75 freighter, // freighterPts
76 tanker, // tankerPts
77 0f, // transportPts
78 0f, // linerPts
79 0f, // utilityPts
80 0f // qualityMod
81 );
82// if (route != null) {
83// params.timestamp = route.getTimestamp();
84// }
85 //params.random = random;
86 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
87 if (fleet == null || fleet.isEmpty()) return null;
88
89
90 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PIRATE, true);
91
92 MarketAPI source = Misc.getSourceMarket(fleet);
93 if (source == null) return null;
94
95 CampaignFleetAPI player = Global.getSector().getPlayerFleet();
96 boolean spawnAtSource = true;
97 if (player != null) {
98 float sourceToPlayer = Misc.getDistance(player.getLocation(), source.getLocationInHyperspace());
99 float targetToPlayer = Misc.getDistance(player.getLocation(), target.getLocation());
100 spawnAtSource = sourceToPlayer < targetToPlayer;
101 }
102
103 if (spawnAtSource) {
104 source.getPrimaryEntity().getContainingLocation().addEntity(fleet);
105 fleet.setLocation(source.getPrimaryEntity().getLocation().x, source.getPrimaryEntity().getLocation().y);
106
107 fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, source.getPrimaryEntity(), 2f + (float) Math.random() * 2f,
108 "orbiting " + source.getName());
109 } else {
110 Vector2f loc = Misc.pickHyperLocationNotNearPlayer(target.getLocation(), Global.getSettings().getMaxSensorRangeHyper() + 500f);
111 Global.getSector().getHyperspace().addEntity(fleet);
112 fleet.setLocation(loc.x, loc.y);
113 }
114
115
116 Vector2f dest = Misc.getPointAtRadius(target.getLocation(), 1500);
117 LocationAPI hyper = Global.getSector().getHyperspace();
118 SectorEntityToken token = hyper.createToken(dest.x, dest.y);
119
120 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, token, 1000,
121 "traveling to the " + target.getBaseName() + " star system");
122
123 if ((float) Math.random() > 0.75f) {
124 fleet.addAssignment(FleetAssignment.RAID_SYSTEM, target.getHyperspaceAnchor(), 20,
125 "raiding around the " + target.getBaseName() + " star system");
126 } else {
127 fleet.addAssignment(FleetAssignment.RAID_SYSTEM, target.getCenter(), 20,
128 "raiding the " + target.getBaseName() + " star system");
129 }
130 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, source.getPrimaryEntity(), 1000,
131 "returning to " + source.getName());
132 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source.getPrimaryEntity(), 2f + 2f * (float) Math.random(),
133 "offloading ill-gotten goods");
134 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, source.getPrimaryEntity(), 1000);
135
136 return fleet;
137 }
138
139
140 protected StarSystemAPI pickTargetSystem() {
141 WeightedRandomPicker<StarSystemAPI> picker = new WeightedRandomPicker<StarSystemAPI>();
142 for (StarSystemAPI system : Global.getSector().getStarSystems()) {
143 float mult = Misc.getSpawnChanceMult(system.getLocation());
144
145 if (system.hasTag(Tags.SYSTEM_CUT_OFF_FROM_HYPER)) {
146 continue;
147 }
148
149 // want: large, unstable
150 float weight = 0f;
151 float bounties = 0;
152 for (MarketAPI market : Misc.getMarketsInLocation(system)) {
153 if (market.getFactionId().equals(Factions.PIRATES)) continue;
154 //weight += market.getSize() * (15f - market.getStabilityValue());
155 float w = 11f - market.getStabilityValue() + market.getSize();
156 if (w > weight) weight = w;
157// if (market.hasCondition(Conditions.EVENT_SYSTEM_BOUNTY)) {
158// bounties++;
159// }
160 }
161
162 weight *= (bounties + 1);
163 weight *= mult;
164
165 picker.add(system, weight);
166 }
167 return picker.pick();
168 }
169
170
171 public static CampaignFleetAPI createPirateFleet(int combatPoints, RouteData route, Vector2f locInHyper) {
172 float combat = combatPoints;
173 float tanker = 0f;
174 float freighter = 0f;
175
176 MercType type = MercType.SCOUT;
177 if (combat >= 18f) type = MercType.ARMADA;
178 if (combat >= 12f) type = MercType.PATROL;
179 if (combat >= 6f) {
180 if ((float) Math.random() < 0.5f) {
181 type = MercType.PRIVATEER;
182 } else {
183 type = MercType.BOUNTY_HUNTER;
184 }
185 }
186
187 combat *= 5f;
188
189 String fleetType = type.fleetType;
190
191 FleetParamsV3 params = new FleetParamsV3(
192 route != null ? route.getMarket() : null,
193 locInHyper,
194 Factions.PIRATES, // quality will always be reduced by non-market-faction penalty, which is what we want
195 route != null ? route.getQualityOverride() : null,
196 fleetType,
197 combat, // combatPts
198 freighter, // freighterPts
199 tanker, // tankerPts
200 0f, // transportPts
201 0f, // linerPts
202 0f, // utilityPts
203 0f // qualityMod
204 );
205 if (route != null) {
206 params.timestamp = route.getTimestamp();
207 }
208 //params.random = random;
209 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
210
211 if (fleet == null || fleet.isEmpty()) return null;
212
213 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PIRATE, true);
214 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_ALLOW_LONG_PURSUIT, true);
215
216 MarketAPI source = Misc.getSourceMarket(fleet);
217 if (source == null) return null;
218
219 return fleet;
220 }
221}
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
static CampaignFleetAPI createFleet(FleetParamsV3 params)
static CampaignFleetAPI createPirateFleet(int combatPoints, RouteData route, Vector2f locInHyper)