Starsector API
Loading...
Searching...
No Matches
RemnantStationFleetManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen.themes;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Random;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignEventListener.FleetDespawnReason;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.LocationAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.impl.campaign.enc.EncounterManager;
14import com.fs.starfarer.api.impl.campaign.enc.EncounterPoint;
15import com.fs.starfarer.api.impl.campaign.enc.EncounterPointProvider;
16import com.fs.starfarer.api.impl.campaign.fleets.FleetFactoryV3;
17import com.fs.starfarer.api.impl.campaign.fleets.FleetParamsV3;
18import com.fs.starfarer.api.impl.campaign.fleets.SourceBasedFleetManager;
19import com.fs.starfarer.api.impl.campaign.ids.Factions;
20import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
21
22public class RemnantStationFleetManager extends SourceBasedFleetManager {
23
24 public class RemnantSystemEPGenerator implements EncounterPointProvider {
25 public List<EncounterPoint> generateEncounterPoints(LocationAPI where) {
26 if (!where.isHyperspace()) return null;
27 if (totalLost > 0 && source != null) {
28 String id = "ep_" + source.getId();
29 EncounterPoint ep = new EncounterPoint(id, where, source.getLocationInHyperspace(), EncounterManager.EP_TYPE_OUTSIDE_SYSTEM);
30 ep.custom = this;
31 List<EncounterPoint> result = new ArrayList<EncounterPoint>();
32 result.add(ep);
33 return result;//source.getContainingLocation().getName()
34 }
35 return null;
36 }
37 }
38
39 protected int minPts;
40 protected int maxPts;
41 protected int totalLost;
42 protected transient RemnantSystemEPGenerator epGen;
43
44 public RemnantStationFleetManager(SectorEntityToken source, float thresholdLY, int minFleets, int maxFleets, float respawnDelay,
45 int minPts, int maxPts) {
46 super(source, thresholdLY, minFleets, maxFleets, respawnDelay);
47 this.minPts = minPts;
48 this.maxPts = maxPts;
49 }
50
51 protected Object readResolve() {
52 return this;
53 }
54
55 protected transient boolean addedListener = false;
56 @Override
57 public void advance(float amount) {
58 if (!addedListener) {
59 //totalLost = 1;
60 /* best code ever -dgb
61 if (Global.getSector().getPlayerPerson() != null &&
62 Global.getSector().getPlayerPerson().getNameString().equals("Dave Salvage") &&
63 Global.getSector().getClock().getDay() == 15 &&
64 Global.getSector().getClock().getMonth() == 12 &&
65 Global.getSector().getClock().getCycle() == 206) {
66 totalLost = 0;
67 }*/
68 // global listener needs to be not this class since SourceBasedFleetManager
69 // adds it to all fleets as their event listener
70 // and so you'd get reportFleetDespawnedToListener() called multiple times
71 // from global listeners, and from fleet ones
73 Global.getSector().getListenerManager().addListener(epGen, true);
74 addedListener = true;
75 }
76 super.advance(amount);
77 }
78
79
80 @Override
81 protected CampaignFleetAPI spawnFleet() {
82 if (source == null) return null;
83
84 Random random = new Random();
85
86 int combatPoints = minPts + random.nextInt(maxPts - minPts + 1);
87
88 int bonus = totalLost * 4;
89 if (bonus > maxPts) bonus = maxPts;
90
91 combatPoints += bonus;
92
93 String type = FleetTypes.PATROL_SMALL;
94 if (combatPoints > 8) type = FleetTypes.PATROL_MEDIUM;
95 if (combatPoints > 16) type = FleetTypes.PATROL_LARGE;
96
97 combatPoints *= 8f;
98
99 FleetParamsV3 params = new FleetParamsV3(
100 source.getMarket(),
101 source.getLocationInHyperspace(),
102 Factions.REMNANTS,
103 1f,
104 type,
105 combatPoints, // combatPts
106 0f, // freighterPts
107 0f, // tankerPts
108 0f, // transportPts
109 0f, // linerPts
110 0f, // utilityPts
111 0f // qualityMod
112 );
113 //params.officerNumberBonus = 10;
114 params.random = random;
115
116 CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
117 if (fleet == null) return null;;
118
119
120 LocationAPI location = source.getContainingLocation();
121 location.addEntity(fleet);
122
124
125 fleet.setLocation(source.getLocation().x, source.getLocation().y);
126 fleet.setFacing(random.nextFloat() * 360f);
127
128 fleet.addScript(new RemnantAssignmentAI(fleet, (StarSystemAPI) source.getContainingLocation(), source));
129 fleet.getMemoryWithoutUpdate().set("$sourceId", source.getId());
130
131 return fleet;
132 }
133
134
135 @Override
136 public void reportFleetDespawnedToListener(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param) {
137 super.reportFleetDespawnedToListener(fleet, reason, param);
138 if (reason == FleetDespawnReason.DESTROYED_BY_BATTLE) {
139 String sid = fleet.getMemoryWithoutUpdate().getString("$sourceId");
140 if (sid != null && source != null && sid.equals(source.getId())) {
141 //if (sid != null && sid.equals(source.getId())) {
142 totalLost++;
143 }
144 }
145 }
146
147 public int getTotalLost() {
148 return totalLost;
149 }
150
151
152}
153
154
155
156
static SectorAPI getSector()
Definition Global.java:59
static void initRemnantFleetProperties(Random random, CampaignFleetAPI fleet, boolean dormant)
void reportFleetDespawnedToListener(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param)
RemnantStationFleetManager(SectorEntityToken source, float thresholdLY, int minFleets, int maxFleets, float respawnDelay, int minPts, int maxPts)