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
23
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();
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
45 int minPts, int maxPts) {
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
74 addedListener = true;
75 }
76 super.advance(amount);
77 }
78
79
80 @Override
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(
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
117 if (fleet == null) return null;;
118
119
121 location.addEntity(fleet);
122
124
126 fleet.setFacing(random.nextFloat() * 360f);
127
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:65
static CampaignFleetAPI createFleet(FleetParamsV3 params)
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)
void addEntity(SectorEntityToken entity)
ListenerManagerAPI getListenerManager()
void addScript(EveryFrameScript script)
void set(String key, Object value)