Starsector API
Loading...
Searching...
No Matches
TestFleetGroupIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.group;
2
3import java.util.List;
4import java.util.Random;
5
6import java.awt.Color;
7
8import org.lwjgl.util.vector.Vector2f;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.CampaignFleetAPI;
12import com.fs.starfarer.api.campaign.FactionAPI;
13import com.fs.starfarer.api.campaign.SectorEntityToken;
14import com.fs.starfarer.api.campaign.StarSystemAPI;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
17import com.fs.starfarer.api.impl.campaign.ids.Industries;
18import com.fs.starfarer.api.impl.campaign.intel.group.FGRaidAction.FGRaidParams;
19import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
20import com.fs.starfarer.api.impl.campaign.missions.hub.BaseHubMission;
21import com.fs.starfarer.api.ui.Alignment;
22import com.fs.starfarer.api.ui.TooltipMakerAPI;
23import com.fs.starfarer.api.util.Misc;
24import com.fs.starfarer.api.util.WeightedRandomPicker;
25
27
28 public static String PREPARE_ACTION = "prepare_action";
29 public static String TRAVEL_ACTION = "travel_action";
30 public static String RAID_ACTION = "raid_action";
31 public static String RETURN_ACTION = "return_action";
32
33
36
38 super();
39
40 MarketAPI garnir = Global.getSector().getEconomy().getMarket("corvus_IIIa");
41 MarketAPI jangala = Global.getSector().getEconomy().getMarket("jangala");
42 MarketAPI gilead = Global.getSector().getEconomy().getMarket("gilead");
43 MarketAPI asher = Global.getSector().getEconomy().getMarket("asher");
44
45 //gilead = Global.getSector().getEconomy().getMarket("market_system_192c:planet_1");
46
47// gilead = jangala;
48// addAction(new FGWaitAction(jangala.getPrimaryEntity(), 1f, "preparing for expedition"));
49// addAction(new FGTravelAction(jangala.getPrimaryEntity(), gilead.getPrimaryEntity().getStarSystem().getCenter()));
50// addAction(new FGTravelAction(gilead.getPrimaryEntity(), jangala.getPrimaryEntity()));
51
53 addAction(new FGWaitAction(garnir.getPrimaryEntity(), 1f, "preparing for raid"), PREPARE_ACTION);
57// addAction(new FGWaitAction(gilead.getPrimaryEntity().getStarSystem().getCenter(), 5f,
58// "preparing for raid"), POST_RAID_ACTION);
59
60
61 FGRaidParams params = new FGRaidParams();
62 params.where = gilead.getPrimaryEntity().getStarSystem();
63 params.allowedTargets.add(gilead);
64 params.allowedTargets.add(asher);
65 //params.setBombardment(BombardType.SATURATION);
66 params.setDisrupt(Industries.FARMING, Industries.MEGAPORT);
67
68 raidAction = new FGRaidAction(params, 3f);
70
74
75
76 origin = garnir.getPrimaryEntity();
77
78 createRoute(Factions.PIRATES, 30, 7, null, null);
79 }
80
81 protected void spawnFleets() {
82 MarketAPI garnir = Global.getSector().getEconomy().getMarket("corvus_IIIa");
83 Vector2f loc = garnir.getLocationInHyperspace();
84
85 Float damage = null;
86 if (route != null && route.getExtra() != null) {
87 damage = route.getExtra().damage;
88 }
89 if (damage == null) damage = 0f;
90
91 String factionId;
92 factionId = Factions.LUDDIC_CHURCH;
93 factionId = Factions.PIRATES;
94
95
97 picker.add(3);
98 picker.add(4);
99 picker.add(6);
100 picker.add(7);
101 picker.add(9);
102 picker.add(10);
103 picker.add(10);
104
105 float total = 0;
106 for (Integer i : picker.getItems()) total += i;
107
108 float spawnsToSkip = total * damage * 0.5f;
109 float skipped = 0f;
110
111
112 while (!picker.isEmpty()) {
113 Integer size = picker.pickAndRemove();
114 if (skipped < spawnsToSkip && getRandom().nextFloat() < damage) {
115 skipped += size;
116 continue;
117 }
118
119 FleetCreatorMission m = new FleetCreatorMission(new Random());
120 m.beginFleet();
121
122 m.createQualityFleet(size, factionId, loc);
123 m.setFleetSource(garnir);
124 m.setFleetDamageTaken(damage);
125 //m.triggerSetFleetFaction();
126 //m.triggerFleetAllowLongPursuit();
128 //m.triggerSetWarFleet();
130
131 CampaignFleetAPI fleet = m.createFleet();
132 if (fleet != null && route != null) {
133 setLocationAndCoordinates(fleet, route.getCurrent());
134 fleets.add(fleet);
135 }
136 }
137
138 }
139
140 protected void addNonUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad) {
141 Color h = Misc.getHighlightColor();
142 FGAction curr = getCurrentAction();
143 StarSystemAPI system = raidAction.getParams().where;
144
145 float untilDeparture = getETAUntil(TRAVEL_ACTION);
146 float untilRaid = getETAUntil(RAID_ACTION);
147 float untilReturn = getETAUntil(RETURN_ACTION, true);
148
149 if (mode == ListInfoMode.MESSAGES) { // initial notification only, not updates
150 info.addPara("Targeting the " + system.getNameWithLowercaseTypeShort(), tc, initPad);
151 initPad = 0f;
152 }
153 if (untilDeparture > 0) {
154 addETABulletPoints(null, null, false, untilDeparture, ETAType.DEPARTURE, info, tc, initPad);
155 }
156 if (untilRaid > 0 && getSource().getContainingLocation() != system) {
157 addETABulletPoints(system.getNameWithLowercaseTypeShort(), null, false, untilRaid, ETAType.ARRIVING,
158 info, tc, initPad);
159 initPad = 0f;
160 }
161 if (untilReturn > 0 && isSucceeded() && getSource().getContainingLocation() != system) {
163
164 addETABulletPoints(from.getNameWithLowercaseTypeShort(), null, false, untilReturn, ETAType.RETURNING,
165 info, tc, initPad);
166 initPad = 0f;
167 }
168 if (mode == ListInfoMode.INTEL && curr != null && curr.getId().equals(RAID_ACTION)) {
169 info.addPara("Operating in the " + system.getNameWithLowercaseTypeShort(), tc, initPad);
170 initPad = 0f;
171 }
172 if (mode != ListInfoMode.IN_DESC && isEnding()) {
173 if (!isSucceeded()) {
174 info.addPara("The raiding forces have been defeated and scatter", tc, initPad);
175 }
176 }
177 }
178
179 protected void addUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad) {
180 StarSystemAPI system = raidAction.getParams().where;
181 //Color h = Misc.getHighlightColor();
182 if (ABORT_UPDATE.equals(param)) {
183 info.addPara("The raiding forces have been defeated and scatter", tc, initPad);
184 } else if (PREPARE_ACTION.equals(param)) {
185 float untilRaid = getETAUntil(RAID_ACTION);
186 addETABulletPoints(system.getNameWithLowercaseTypeShort(), null, true, untilRaid, ETAType.ARRIVING,
187 info, tc, initPad);
188 } else if (TRAVEL_ACTION.equals(param)) {
189 addArrivedBulletPoint(system.getNameWithLowercaseTypeShort(), null, info, tc, initPad);
190 } else if (RAID_ACTION.equals(param)) {
191 if (isSucceeded()) {
192 info.addPara("The raiding forces are withdrawing", tc, initPad);
193 } else {
194 info.addPara("The raiding forces have been defeated and scatter", tc, initPad);
195 }
196 }
197 }
198
199 @Override
201 if (RETURN_ACTION.equals(action.getId())) return false;
202 if (RAID_ACTION.equals(action.getId())) {
203 // if it failed, will send an update on abort() instead
204 return isSucceeded();
205 }
206 if (TRAVEL_ACTION.equals(action.getId())) {
207 // no update for "arriving" when traveling from one planet in-system to another
209 }
210
211 return super.shouldSendIntelUpdateWhenActionFinished(action);
212 }
213
214 protected void addBasicDescription(TooltipMakerAPI info, float width, float height, float opad) {
215 info.addImage(getFaction().getLogo(), width, 128, opad);
216
217 StarSystemAPI system = raidAction.getParams().where;
218
219 info.addPara(Misc.ucFirst(faction.getPersonNamePrefixAOrAn()) + " %s raid against "
220 + "the " + system.getNameWithLowercaseTypeShort() + ".", opad,
222 }
223
224 protected void addAssessmentSection(TooltipMakerAPI info, float width, float height, float opad) {
225 Color h = Misc.getHighlightColor();
226
228
229 List<MarketAPI> targets = raidAction.getParams().allowedTargets;
230
231 if (!isEnding() && !isSucceeded()) {
232 info.addSectionHeading("Assessment",
234 if (targets.isEmpty()) {
235 info.addPara("There are no colonies for the raid to target in the system.", opad);
236 } else {
237 StarSystemAPI system = raidAction.getParams().where;
238
239 boolean potentialDanger = addStrengthDesc(info, opad, system, "raiding forces",
240 "the raid is unlikely to find success",
241 "the raid's outcome is uncertain",
242 "the raid is likely to find success");
243
244 if (potentialDanger) {
245 showMarketsInDanger(info, opad, width, system, targets,
246 "should be safe from the raid",
247 "are at risk of being raided and losing stability:",
248 "losing stability");
249 }
250 }
251 }
252 }
253
254
255 protected void addStatusSection(TooltipMakerAPI info, float width, float height, float opad) {
256 FGAction curr = getCurrentAction();
257
258 boolean showStatus = curr != null || isEnding() || isSucceeded();
259
260 if (showStatus) {
261 info.addSectionHeading("Status",
263 if (isEnding() && !isSucceeded()) {
264 info.addPara("The raiding forces have been defeated and any "
265 + "remaining ships are retreating in disarray.", opad);
266 } else if (isEnding() || isSucceeded()) {
267 info.addPara("The raid was successful and the raiding forces are withdrawing.", opad);
268 } else if (curr != null) {
269 //StarSystemAPI from = getSource().getStarSystem();
271 if (PREPARE_ACTION.equals(curr.getId())) {
272 BaseHubMission.addStandardMarketDesc("Making preparations in orbit around",
273 getSource().getMarket(), info, opad);
274 } else if (TRAVEL_ACTION.equals(curr.getId())) {
275 info.addPara("Traveling from " + getSource().getMarket().getName() + " to the " +
276 to.getNameWithLowercaseTypeShort() + ".", opad);
277 } else if (RAID_ACTION.equals(curr.getId())) {
278 info.addPara("Conducting operations in the " +
279 to.getNameWithLowercaseTypeShort() + ".", opad);
280 }
281 }
282 }
283 }
284
285
286 public String getBaseName() {
287 return Misc.ucFirst(getFaction().getPersonNamePrefix()) + " Raid";
288 }
289
290 public boolean isSucceeded() {
292 }
293
295 return origin;
296 }
297
301
302 @Override
303 protected boolean isPlayerTargeted() {
304 return true;
305 }
306}
307
308
309
310
static SectorAPI getSector()
Definition Global.java:65
void addArrivedBulletPoint(String destName, Color destHL, TooltipMakerAPI info, Color tc, float initPad)
void createRoute(String factionId, int approximateTotalDifficultyPoints, int approximateNumberOfFleets, Object custom)
void addETABulletPoints(String destName, Color destHL, boolean withDepartedText, float eta, ETAType type, TooltipMakerAPI info, Color tc, float initPad)
void showMarketsInDanger(TooltipMakerAPI info, float opad, float width, StarSystemAPI system, List< MarketAPI > targets, String safeStr, String riskStr, String riskStrHighlight)
boolean addStrengthDesc(TooltipMakerAPI info, float opad, StarSystemAPI system, String forces, String outcomeFailure, String outcomeUncertain, String outcomeSuccess)
static void setLocationAndCoordinates(CampaignFleetAPI fleet, RouteSegment current)
void addNonUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad)
void addUpdateBulletPoints(TooltipMakerAPI info, Color tc, Object param, ListInfoMode mode, float initPad)
void addBasicDescription(TooltipMakerAPI info, float width, float height, float opad)
void addStatusSection(TooltipMakerAPI info, float width, float height, float opad)
void addAssessmentSection(TooltipMakerAPI info, float width, float height, float opad)
void createQualityFleet(int difficulty, String factionId, Vector2f locInHyper)
static void addStandardMarketDesc(String prefix, MarketAPI market, TooltipMakerAPI info, float pad)
static String ucFirst(String str)
Definition Misc.java:559
static Color getHighlightColor()
Definition Misc.java:792
void addImage(String spriteName, float pad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
LabelAPI addSectionHeading(String str, Alignment align, float pad)