Starsector API
Loading...
Searching...
No Matches
LuddicPathFleetManager.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.ids.Factions;
13import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
14import com.fs.starfarer.api.impl.campaign.ids.Tags;
15import com.fs.starfarer.api.util.Misc;
16import com.fs.starfarer.api.util.WeightedRandomPicker;
17
19
20 @Override
21 protected int getMaxFleets() {
22 int count = 0;
23 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
24 String fid = market.getFactionId();
25 if (fid.equals(Factions.LUDDIC_CHURCH) ||
26 fid.equals(Factions.LUDDIC_PATH) ||
27 fid.equals(Factions.KOL)) {
28 count += market.getSize();
29 }
30 }
31 return count;
32 }
33
34 @Override
35 protected CampaignFleetAPI spawnFleet() {
36 StarSystemAPI target = pickTargetSystem();
37 if (true) return null;
38 if (target == null) return null;
39
40 String fleetType = FleetTypes.PATROL_SMALL;
41
42 float combat = 1;
43 for (int i = 0; i < 3; i++) {
44 if ((float) Math.random() > 0.5f) {
45 combat++;
46 }
47 }
48
49 combat *= 5f;
50
51// CampaignFleetAPI fleet = FleetFactoryV2.createFleet(new FleetParams(
52// target.getLocation(), // location
53// null, // market
54// Factions.LUDDIC_CHURCH, // pick a luddic church market to spawn from
55// Factions.LUDDIC_PATH, // fleet's faction, if different from above, which is also used for source market picking
56// fleetType,
57// combat, // combatPts
58// 0, // freighterPts
59// 0, // tankerPts
60// 0f, // transportPts
61// 0f, // linerPts
62// 0f, // civilianPts
63// 0f, // utilityPts
64// 0f, // qualityBonus
65// -1f, // qualityOverride
66// 1f, // officer num mult
67// 0 // officer level bonus
68// ));
69// if (fleet == null) return null;
70
71 FleetParamsV3 params = new FleetParamsV3(
72 null, // source market
73 target.getLocation(),
74 Factions.LUDDIC_PATH,
75 null,
76 fleetType,
77 combat, // combatPts
78 0, // freighterPts
79 0, // tankerPts
80 0f, // transportPts
81 0f, // linerPts
82 0f, // utilityPts
83 0f // qualityMod
84 );
85 //params.random = random;
86 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
87 if (fleet == null || fleet.isEmpty()) return null;
88
89 // setting the below means: transponder off and more "go dark" use when traveling
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_PASSIVE, 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 "orbiting " + source.getName());
134
135 return fleet;
136 }
137
138
139 protected StarSystemAPI pickTargetSystem() {
140 WeightedRandomPicker<StarSystemAPI> picker = new WeightedRandomPicker<StarSystemAPI>();
141 for (StarSystemAPI system : Global.getSector().getStarSystems()) {
142 if (system.hasTag(Tags.SYSTEM_CUT_OFF_FROM_HYPER)) {
143 continue;
144 }
145
146 float mult = Misc.getSpawnChanceMult(system.getLocation());
147
148
149 // want: large, unstable
150 float weight = 0f;
151 for (MarketAPI market : Misc.getMarketsInLocation(system)) {
152 if (market.getFactionId().equals(Factions.LUDDIC_CHURCH)) continue;
153 if (market.getFactionId().equals(Factions.LUDDIC_PATH)) continue;
154 if (market.getFactionId().equals(Factions.KOL)) continue;
155
156 float w = 11f - market.getStabilityValue() + market.getSize();
157 if (w > weight) weight = w;
158 }
159 weight *= mult;
160
161 picker.add(system, weight);
162 //System.out.println("System: " + system.getBaseName() + ", weight: " + weight);
163 }
164 return picker.pick();
165 }
166
167
168}
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
static CampaignFleetAPI createFleet(FleetParamsV3 params)