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
36 if (target == null || true) return null;
37
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;
87 if (fleet == null || fleet.isEmpty()) return null;
88
89
91
92 MarketAPI source = Misc.getSourceMarket(fleet);
93 if (source == null) return null;
94
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) {
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 {
112 fleet.setLocation(loc.x, loc.y);
113 }
114
115
116 Vector2f dest = Misc.getPointAtRadius(target.getLocation(), 1500);
118 SectorEntityToken token = hyper.createToken(dest.x, dest.y);
119
121 "traveling to the " + target.getBaseName() + " star system");
122
123 if ((float) Math.random() > 0.75f) {
125 "raiding around the " + target.getBaseName() + " star system");
126 } else {
128 "raiding the " + target.getBaseName() + " star system");
129 }
131 "returning to " + source.getName());
132 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source.getPrimaryEntity(), 2f + 2f * (float) Math.random(),
133 "offloading ill-gotten goods");
135
136 return fleet;
137 }
138
139
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;
210
211 if (fleet == null || fleet.isEmpty()) return null;
212
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:57
static SectorAPI getSector()
Definition Global.java:65
static CampaignFleetAPI createFleet(FleetParamsV3 params)
static CampaignFleetAPI createPirateFleet(int combatPoints, RouteData route, Vector2f locInHyper)
static final String SYSTEM_CUT_OFF_FROM_HYPER
Definition Tags.java:133
static MarketAPI getSourceMarket(CampaignFleetAPI fleet)
Definition Misc.java:2162
static float getSpawnChanceMult(Vector2f locInHyper)
Definition Misc.java:2180
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
Definition Misc.java:936
static Vector2f pickHyperLocationNotNearPlayer(Vector2f from, float minDist)
Definition Misc.java:2193
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static Vector2f getPointAtRadius(Vector2f from, float r)
Definition Misc.java:697
void addAssignment(FleetAssignment assignment, SectorEntityToken target, float maxDurationInDays)
void addEntity(SectorEntityToken entity)
SectorEntityToken createToken(float x, float y)
List< StarSystemAPI > getStarSystems()
void set(String key, Object value)