Starsector API
Loading...
Searching...
No Matches
OrbitalStation.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ.impl;
2
3import java.awt.Color;
4
5import org.json.JSONException;
6import org.json.JSONObject;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.AICoreOfficerPlugin;
10import com.fs.starfarer.api.campaign.BattleAPI;
11import com.fs.starfarer.api.campaign.CampaignEventListener.FleetDespawnReason;
12import com.fs.starfarer.api.campaign.CampaignFleetAPI;
13import com.fs.starfarer.api.campaign.CustomCampaignEntityAPI;
14import com.fs.starfarer.api.campaign.FleetInflater;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
17import com.fs.starfarer.api.campaign.econ.Industry;
18import com.fs.starfarer.api.campaign.econ.MarketAPI.MarketInteractionMode;
19import com.fs.starfarer.api.campaign.listeners.FleetEventListener;
20import com.fs.starfarer.api.characters.PersonAPI;
21import com.fs.starfarer.api.combat.ShipVariantAPI;
22import com.fs.starfarer.api.fleet.FleetMemberAPI;
23import com.fs.starfarer.api.fleet.FleetMemberType;
24import com.fs.starfarer.api.impl.campaign.events.OfficerManagerEvent;
25import com.fs.starfarer.api.impl.campaign.fleets.DefaultFleetInflater;
26import com.fs.starfarer.api.impl.campaign.fleets.DefaultFleetInflaterParams;
27import com.fs.starfarer.api.impl.campaign.fleets.FleetFactoryV3;
28import com.fs.starfarer.api.impl.campaign.fleets.FleetParamsV3;
29import com.fs.starfarer.api.impl.campaign.ids.Abilities;
30import com.fs.starfarer.api.impl.campaign.ids.Commodities;
31import com.fs.starfarer.api.impl.campaign.ids.Entities;
32import com.fs.starfarer.api.impl.campaign.ids.Factions;
33import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
34import com.fs.starfarer.api.impl.campaign.ids.HullMods;
35import com.fs.starfarer.api.impl.campaign.ids.Industries;
36import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
37import com.fs.starfarer.api.impl.campaign.ids.Stats;
38import com.fs.starfarer.api.impl.campaign.ids.Tags;
39import com.fs.starfarer.api.impl.campaign.procgen.themes.RemnantOfficerGeneratorPlugin;
40import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.RaidDangerLevel;
41import com.fs.starfarer.api.ui.TooltipMakerAPI;
42import com.fs.starfarer.api.util.Misc;
43import com.fs.starfarer.api.util.Pair;
44
45
46
47public class OrbitalStation extends BaseIndustry implements FleetEventListener {
48
49 public static float DEFENSE_BONUS_BASE = 0.5f;
50 public static float DEFENSE_BONUS_BATTLESTATION = 1f;
51 public static float DEFENSE_BONUS_FORTRESS = 2f;
52
53 public static float IMPROVE_STABILITY_BONUS = 1f;
54
55 public void apply() {
56 super.apply(false);
57
58 int size = 3;
59
60 boolean battlestation = getSpec().hasTag(Industries.TAG_BATTLESTATION);
61 boolean starfortress = getSpec().hasTag(Industries.TAG_STARFORTRESS);
62 if (battlestation) {
63 size = 5;
64 } else if (starfortress) {
65 size = 7;
66 }
67
69
71
72 demand(Commodities.CREW, size);
73 demand(Commodities.SUPPLIES, size);
74
75 float bonus = DEFENSE_BONUS_BASE;
76 if (battlestation) bonus = DEFENSE_BONUS_BATTLESTATION;
77 else if (starfortress) bonus = DEFENSE_BONUS_FORTRESS;
78 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD)
79 .modifyMult(getModId(), 1f + bonus, getNameForModifier());
80
82
83 if (!isFunctional()) {
84 supply.clear();
85 unapply();
86 } else {
88 }
89 }
90
91 @Override
92 public void unapply() {
93 super.unapply();
94
96
98
99 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).unmodifyMult(getModId());
100 }
101
102 protected void applyCRToStation() {
103 if (stationFleet != null) {
104 float cr = getCR();
105 for (FleetMemberAPI member : stationFleet.getFleetData().getMembersListCopy()) {
106 member.getRepairTracker().setCR(cr);
107 }
108 FleetInflater inflater = stationFleet.getInflater();
109 if (inflater != null) {
110 if (stationFleet.isInflated()) {
111 stationFleet.deflate();
112 }
113 inflater.setQuality(Misc.getShipQuality(market));
114 if (inflater instanceof DefaultFleetInflater) {
115 DefaultFleetInflater dfi = (DefaultFleetInflater) inflater;
116 ((DefaultFleetInflaterParams)dfi.getParams()).allWeapons = true;
117 }
118 }
119 }
120 }
121
122 protected float getCR() {
123 float deficit = getMaxDeficit(Commodities.CREW, Commodities.SUPPLIES).two;
124 float demand = Math.max(getDemand(Commodities.CREW).getQuantity().getModifiedInt(),
125 getDemand(Commodities.SUPPLIES).getQuantity().getModifiedInt());
126
127 if (deficit < 0) deficit = 0f;
128 if (demand < 1) {
129 demand = 1;
130 deficit = 0f;
131 }
132
133
134 float q = Misc.getShipQuality(market);
135 if (q < 0) q = 0;
136 if (q > 1) q = 1;
137
138 float d = (demand - deficit) / demand;
139 if (d < 0) d = 0;
140 if (d > 1) d = 1;
141
142 //float cr = 0.2f + 0.4f * d + 0.4f * q;
143 //float cr = 0.2f + 0.8f * Math.min(d, q);
144 float cr = 0.5f + 0.5f * Math.min(d, q);
145 if (cr > 1) cr = 1;
146
147 return cr;
148 }
149
150
151 protected boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode) {
152 //return mode == IndustryTooltipMode.NORMAL && isFunctional();
153 return mode != IndustryTooltipMode.NORMAL || isFunctional();
154 }
155
156 @Override
157 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
158 //if (mode == IndustryTooltipMode.NORMAL && isFunctional()) {
159 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
160 Color h = Misc.getHighlightColor();
161 float opad = 10f;
162
163 float cr = getCR();
164 tooltip.addPara("Station combat readiness: %s", opad, h, "" + Math.round(cr * 100f) + "%");
165
166 addStabilityPostDemandSection(tooltip, hasDemand, mode);
167
168 boolean battlestation = getSpec().hasTag(Industries.TAG_BATTLESTATION);
169 boolean starfortress = getSpec().hasTag(Industries.TAG_STARFORTRESS);
170 float bonus = DEFENSE_BONUS_BASE;
171 if (battlestation) bonus = DEFENSE_BONUS_BATTLESTATION;
172 else if (starfortress) bonus = DEFENSE_BONUS_FORTRESS;
173 addGroundDefensesImpactSection(tooltip, bonus, Commodities.SUPPLIES);
174 }
175 }
176
177 @Override
178 protected Object readResolve() {
179 super.readResolve();
180// if (tracker == null) {
181// tracker = new IntervalUtil(0.7f, 1.3f);
182// }
183 return this;
184 }
185
186
187
188
189
190 protected CampaignFleetAPI stationFleet = null;
191 protected boolean usingExistingStation = false;
192 protected SectorEntityToken stationEntity = null;
193
194 //protected IntervalUtil tracker = new IntervalUtil(0.7f, 1.3f);
195
196 @Override
197 public void advance(float amount) {
198 super.advance(amount);
199
200 if (Global.getSector().getEconomy().isSimMode()) return;
201
202
203 if (stationEntity == null) {
204 spawnStation();
205 }
206
207 if (stationFleet != null) {
208 stationFleet.setAI(null);
209 if (stationFleet.getOrbit() == null && stationEntity != null) {
210 stationFleet.setCircularOrbit(stationEntity, 0, 0, 100);
211 }
212 }
213
214// if (stationFleet != null) {
215// if (stationFleet.getAI() != null) {
216// System.out.println("wefwefew");
217// }
218// System.out.println("Station orbit: "+ stationFleet.getAI());
220// if (stationFleet.getOrbitFocus() == null) {
221// System.out.println("wefwefe");
222// }
223// }
224
225// if (stationEntity != null && stationFleet != null) {
226// stationFleet.setFacing(stationEntity.getFacing());
227// }
228
229// if (isFunctional()) {
230// if (stationEntity == null) {
231// spawnStation(false);
232// }
233// } else {
234// if (stationEntity != null) {
235// removeStationEntityAndFleetIfNeeded();
236// }
237// }
238
239// if (stationFleet != null) {
240// //stationFleet.advance(amount);
241// if (stationEntity != null) {
242// stationFleet.setOrbit(null);
243// stationFleet.setLocation(stationEntity.getLocation().x, stationEntity.getLocation().y);
244// stationFleet.setContainingLocation(stationEntity.getContainingLocation());
245// }
246// }
247// if (stationFleet != null && stationFleet.isInCurrentLocation()) {
248// System.out.println("inf: " + stationFleet.getInflater());
249// }
250
251// float days = Global.getSector().getClock().convertToDays(amount);
252// tracker.advance(days);
253// if (tracker.intervalElapsed()) {
254// if (stationFleet != null) {
255// stationFleet.deflate();
256// }
257// }
258 }
259
260
261 @Override
262 protected void buildingFinished() {
263 super.buildingFinished();
264
265 if (stationEntity != null && stationFleet != null) {
267 } else {
268 spawnStation();
269 }
270 }
271
272 @Override
273 public void notifyBeingRemoved(MarketInteractionMode mode, boolean forUpgrade) {
274 super.notifyBeingRemoved(mode, forUpgrade);
275
276 if (!forUpgrade) {
278 }
279 }
280
281 @Override
282 protected void upgradeFinished(Industry previous) {
283 super.upgradeFinished(previous);
284
285 if (previous instanceof OrbitalStation) {
286 OrbitalStation prev = (OrbitalStation) previous;
290
291 if (stationFleet != null) {
292 stationFleet.removeEventListener(prev);
293 stationFleet.addEventListener(this);
294 }
295
296 if (stationEntity != null && stationFleet != null) {
298 } else {
299 spawnStation();
300 }
301 }
302 }
303
305 if (stationEntity != null) {
306 stationEntity.getMemoryWithoutUpdate().unset(MemFlags.STATION_FLEET);
307 stationEntity.getMemoryWithoutUpdate().unset(MemFlags.STATION_BASE_FLEET);
308
309 stationEntity.getContainingLocation().removeEntity(stationFleet);
310
311 if (stationEntity.getContainingLocation() != null && !usingExistingStation) {
312 stationEntity.getContainingLocation().removeEntity(stationEntity);
313 market.getConnectedEntities().remove(stationEntity);
314
315 // commented out so that MarketCMD doesn't NPE if you destroy a market through bombardment of a station
316 //stationEntity.setMarket(null);
317
318 } else if (stationEntity.hasTag(Tags.USE_STATION_VISUAL)) {
319 ((CustomCampaignEntityAPI)stationEntity).setFleetForVisual(null);
320 float origRadius = ((CustomCampaignEntityAPI)stationEntity).getCustomEntitySpec().getDefaultRadius();
321 ((CustomCampaignEntityAPI)stationEntity).setRadius(origRadius);
322 }
323
324 if (stationFleet != null) {
325 stationFleet.getMemoryWithoutUpdate().unset(MemFlags.STATION_MARKET);
326 stationFleet.removeEventListener(this);
327 }
328
329 stationEntity = null;
330 stationFleet = null;
331 }
332 }
333
334
335 @Override
336 public void notifyColonyRenamed() {
337 super.notifyColonyRenamed();
338 if (!usingExistingStation && stationFleet != null && stationEntity != null) {
339 stationFleet.setName(market.getName() + " Station");
340 stationEntity.setName(market.getName() + " Station");
341 }
342 }
343
344
345
346 protected void spawnStation() {
347 FleetParamsV3 fParams = new FleetParamsV3(null, null,
348 market.getFactionId(),
349 1f,
350 FleetTypes.PATROL_SMALL,
351 0,
352 0, 0, 0, 0, 0, 0);
353 fParams.allWeapons = true;
354
356
357// if (market.getId().equals("jangala")) {
358// System.out.println("wefwefew");
359// }
360
361 stationFleet = FleetFactoryV3.createFleet(fParams);
362 //stationFleet.setName(getCurrentName());
363 stationFleet.setNoFactionInName(true);
364
365
366 stationFleet.setStationMode(true);
367
368 //stationFleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_MAKE_ALLOW_DISENGAGE, true);
369
370 // needed for AI fleets to engage it, as they engage the hidden station fleet, unlike
371 // the player that interacts with the stationEntity
372 stationFleet.clearAbilities();
373 stationFleet.addAbility(Abilities.TRANSPONDER);
374 stationFleet.getAbility(Abilities.TRANSPONDER).activate();
375 stationFleet.getDetectedRangeMod().modifyFlat("gen", 10000f);
376
377 stationFleet.setAI(null);
378 stationFleet.addEventListener(this);
379
380
382
383 if (stationEntity instanceof CustomCampaignEntityAPI) {
384 if (!usingExistingStation || stationEntity.hasTag(Tags.USE_STATION_VISUAL)) {
385 ((CustomCampaignEntityAPI)stationEntity).setFleetForVisual(stationFleet);
386 }
387 }
388
389 stationFleet.setCircularOrbit(stationEntity, 0, 0, 100);
390 stationFleet.getMemoryWithoutUpdate().set(MemFlags.STATION_MARKET, market);
391 stationFleet.setHidden(true);
392
393
395 }
396
397
399 if (stationEntity == null) {
400 for (SectorEntityToken entity : market.getConnectedEntities()) {
401 if (entity.hasTag(Tags.STATION) && !entity.hasTag("NO_ORBITAL_STATION")) { // added NO_ORBITAL_STATION per modder request
402 stationEntity = entity;
404 break;
405 }
406 }
407 }
408
409 if (stationEntity == null) {
410 stationEntity = market.getContainingLocation().addCustomEntity(
411 null, market.getName() + " Station", Entities.STATION_BUILT_FROM_INDUSTRY, market.getFactionId());
412 SectorEntityToken primary = market.getPrimaryEntity();
413 float orbitRadius = primary.getRadius() + 150f;
414 stationEntity.setCircularOrbitWithSpin(primary, (float) Math.random() * 360f, orbitRadius, orbitRadius / 10f, 5f, 5f);
415 market.getConnectedEntities().add(stationEntity);
416 stationEntity.setMarket(market);
417 }
418 }
419
420
422 stationFleet.getFleetData().clear();
423
424 String fleetName = null;
425 String variantId = null;
426 float radius = 60f;
427
428 try {
429 JSONObject json = new JSONObject(getSpec().getData());
430 variantId = json.getString("variant");
431 radius = (float) json.getDouble("radius");
432 fleetName = json.getString("fleetName");
433 } catch (JSONException e) {
434 throw new RuntimeException(e);
435 }
436
437 if (stationEntity != null) {
438 fleetName = stationEntity.getName();
439 }
440
441
442 stationFleet.setName(fleetName);
443
444// try {
445// FleetMemberAPI member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, variantId);
446// } catch (Throwable t) {
447// throw new RuntimeException("Market: " + market.getId() + ", variantId: " + variantId + ", " +
448// "message: [" + t.getMessage() + "]");
449// }
450
451 FleetMemberAPI member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, variantId);
452 //String name = stationFleet.getFleetData().pickShipName(member, null);
453 String name = fleetName;
454 member.setShipName(name);
455
456 stationFleet.getFleetData().addFleetMember(member);
457
458// int level = 20;
459// PersonAPI commander = OfficerManagerEvent.createOfficer(
460// Global.getSector().getFaction(market.getFactionId()), level, true);
461// commander.getStats().setSkillLevel(Skills.GUNNERY_IMPLANTS, 3);
462// stationFleet.setCommander(commander);
463// stationFleet.getFlagship().setCaptain(commander);
464
465 //stationFleet.getFlagship().getRepairTracker().setCR(stationFleet.getFlagship().getRepairTracker().getMaxCR());
467
468 //stationFleet.setMarket(market);
469
470 //JSONObject
471
472 if (!usingExistingStation && stationEntity instanceof CustomCampaignEntityAPI) {
473 ((CustomCampaignEntityAPI)stationEntity).setRadius(radius);
474 } else if (stationEntity.hasTag(Tags.USE_STATION_VISUAL)) {
475 ((CustomCampaignEntityAPI)stationEntity).setRadius(radius);
476 }
477
478 boolean skeletonMode = !isFunctional();
479
480 if (skeletonMode) {
481 stationEntity.getMemoryWithoutUpdate().unset(MemFlags.STATION_FLEET);
482 stationEntity.getMemoryWithoutUpdate().set(MemFlags.STATION_BASE_FLEET, stationFleet);
483 stationEntity.getContainingLocation().removeEntity(stationFleet);
484
485 for (int i = 1; i < member.getStatus().getNumStatuses(); i++) {
486 ShipVariantAPI variant = member.getVariant();
487 if (i > 0) {
488 String slotId = member.getVariant().getModuleSlots().get(i - 1);
489 variant = variant.getModuleVariant(slotId);
490 } else {
491 continue;
492 }
493
494 if (!variant.hasHullMod(HullMods.VASTBULK)) {
495 member.getStatus().setDetached(i, true);
496 member.getStatus().setPermaDetached(i, true);
497 member.getStatus().setHullFraction(i, 0f);
498 }
499 }
500
501 } else {
502 stationEntity.getMemoryWithoutUpdate().unset(MemFlags.STATION_BASE_FLEET);
503 stationEntity.getMemoryWithoutUpdate().set(MemFlags.STATION_FLEET, stationFleet);
504// stationFleet.setBattle(null);
505// stationFleet.setNoEngaging(0);
506 stationEntity.getContainingLocation().removeEntity(stationFleet);
507 stationFleet.setExpired(false);
508 stationEntity.getContainingLocation().addEntity(stationFleet);
509 }
510 }
511
512 protected int getHumanCommanderLevel() {
513 boolean battlestation = getSpec().hasTag(Industries.TAG_BATTLESTATION);
514 boolean starfortress = getSpec().hasTag(Industries.TAG_STARFORTRESS);
515
516 if (starfortress) {
517 return Global.getSettings().getInt("tier3StationOfficerLevel");
518 } else if (battlestation) {
519 return Global.getSettings().getInt("tier2StationOfficerLevel");
520 }
521 return Global.getSettings().getInt("tier1StationOfficerLevel");
522 }
523
524 protected void matchCommanderToAICore(String aiCore) {
525 if (stationFleet == null) return;
526
527// if (market.isPlayerOwned()) {
528// System.out.println("wefwefew");
529// }
530
531 PersonAPI commander = null;
532 if (Commodities.ALPHA_CORE.equals(aiCore)) {
533// commander = OfficerManagerEvent.createOfficer(
534// Global.getSector().getFaction(Factions.REMNANTS), level, SkillPickPreference.NON_CARRIER);
535// commander.getStats().setSkillLevel(Skills.GUNNERY_IMPLANTS, 3);
536
537 AICoreOfficerPlugin plugin = Misc.getAICoreOfficerPlugin(Commodities.ALPHA_CORE);
538 commander = plugin.createPerson(Commodities.ALPHA_CORE, Factions.REMNANTS, null);
539 if (stationFleet.getFlagship() != null) {
540 RemnantOfficerGeneratorPlugin.integrateAndAdaptCoreForAIFleet(stationFleet.getFlagship());
541 }
542 } else {
543 //if (stationFleet.getCommander() == null || !stationFleet.getCommander().isDefault()) {
544// if (stationFleet.getFlagship() == null || stationFleet.getFlagship().getCaptain() == null ||
545// !stationFleet.getFlagship().getCaptain().isDefault()) {
546// commander = Global.getFactory().createPerson();
547// }
548
549 if (stationFleet.getFlagship() != null) {
550 int level = getHumanCommanderLevel();
551 PersonAPI current = stationFleet.getFlagship().getCaptain();
552 if (level > 0) {
553 if (current.isAICore() || current.getStats().getLevel() != level) {
554 commander = OfficerManagerEvent.createOfficer(
555 Global.getSector().getFaction(market.getFactionId()), level, true);
556 }
557 } else {
558 if (stationFleet.getFlagship() == null || stationFleet.getFlagship().getCaptain() == null ||
559 !stationFleet.getFlagship().getCaptain().isDefault()) {
560 commander = Global.getFactory().createPerson();
561 }
562 }
563 }
564
565 }
566
567// if (commander != null) {
568// PersonAPI current = stationFleet.getFlagship().getCaptain();
569// if (current.isAICore() == commander.isAICore() &&
570// current.isDefault() == commander.isDefault() &&
571// current.getStats().getLevel() == commander.getStats().getLevel()) {
572// commander = null;
573// }
574// }
575
576 if (commander != null) {
577 //stationFleet.setCommander(commander); // don't want a "this is a flagship" star showing in the fleet list
578 if (stationFleet.getFlagship() != null) {
579 stationFleet.getFlagship().setCaptain(commander);
580 stationFleet.getFlagship().setFlagship(false);
581 }
582 }
583 }
584
585
586 public void reportBattleOccurred(CampaignFleetAPI fleet, CampaignFleetAPI primaryWinner, BattleAPI battle) {
587
588 }
589
590
591 @Override
592 protected void disruptionFinished() {
593 super.disruptionFinished();
594
596 }
597
598 @Override
599 protected void notifyDisrupted() {
600 super.notifyDisrupted();
601
603 }
604
605 public void reportFleetDespawnedToListener(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param) {
606 if (fleet != stationFleet) return; // shouldn't happen...
607
608 disrupt(this);
609
610 // bug where somehow a station fleet can become empty as a result of combat
611 // then its despawn() gets called every frame
612 if (stationFleet.getMembersWithFightersCopy().isEmpty()) {
614 }
615 stationFleet.setAbortDespawn(true);
616 }
617
618 public static void disrupt(Industry station) {
619 station.setDisrupted(station.getSpec().getBuildTime() * 0.5f, true);
620 }
621
622 public boolean isAvailableToBuild() {
623 //if (getSpec().hasTag(Industries.TAG_PARENT)) return true;
624
625 boolean canBuild = false;
626 for (Industry ind : market.getIndustries()) {
627 if (ind == this) continue;
628 if (!ind.isFunctional()) continue;
629 if (ind.getSpec().hasTag(Industries.TAG_SPACEPORT)) {
630 canBuild = true;
631 break;
632 }
633 }
634 return canBuild;
635 }
636
637 public String getUnavailableReason() {
638 return "Requires a functional spaceport";
639 }
640
641
642 @Override
643 protected int getBaseStabilityMod() {
644 boolean battlestation = getSpec().hasTag(Industries.TAG_BATTLESTATION);
645 boolean starfortress = getSpec().hasTag(Industries.TAG_STARFORTRESS);
646 int stabilityMod = 1;
647 if (battlestation) {
648 stabilityMod = 2;
649 } else if (starfortress) {
650 stabilityMod = 3;
651 }
652 return stabilityMod;
653 }
654
655 @Override
656 protected Pair<String, Integer> getStabilityAffectingDeficit() {
657 return getMaxDeficit(Commodities.SUPPLIES, Commodities.CREW);
658 }
659
660
661 @Override
662 protected void applyAlphaCoreModifiers() {
663 }
664
665 @Override
666 protected void applyNoAICoreModifiers() {
667 }
668
669 @Override
671 demandReduction.modifyFlat(getModId(0), DEMAND_REDUCTION, "Alpha core");
672 }
673
674 protected void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode) {
675 float opad = 10f;
676 Color highlight = Misc.getHighlightColor();
677
678 String pre = "Alpha-level AI core currently assigned. ";
679 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
680 pre = "Alpha-level AI core. ";
681 }
682 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
683 CommoditySpecAPI coreSpec = Global.getSettings().getCommoditySpec(aiCoreId);
684 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
685 text.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
686 "Increases station combat effectiveness.", 0f, highlight,
687 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION);
688 tooltip.addImageWithText(opad);
689 return;
690 }
691
692 tooltip.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
693 "Increases station combat effectiveness.", opad, highlight,
694 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION);
695
696 }
697
698 @Override
699 public boolean canImprove() {
700 return true;
701 }
702
703 protected void applyImproveModifiers() {
704 if (isImproved()) {
705 market.getStability().modifyFlat("orbital_station_improve", IMPROVE_STABILITY_BONUS,
707 } else {
708 market.getStability().unmodifyFlat("orbital_station_improve");
709 }
710 }
711
712 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
713 float opad = 10f;
714 Color highlight = Misc.getHighlightColor();
715
716
717 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
718 info.addPara("Stability increased by %s.", 0f, highlight, "" + (int) IMPROVE_STABILITY_BONUS);
719 } else {
720 info.addPara("Increases stability by %s.", 0f, highlight, "" + (int) IMPROVE_STABILITY_BONUS);
721 }
722
723 info.addSpacer(opad);
724 super.addImproveDesc(info, mode);
725 }
726
727
728 protected boolean isMiltiarized() {
729 boolean battlestation = getSpec().hasTag(Industries.TAG_BATTLESTATION);
730 boolean starfortress = getSpec().hasTag(Industries.TAG_STARFORTRESS);
731 return battlestation || starfortress;
732 }
733
734 @Override
735 public RaidDangerLevel adjustCommodityDangerLevel(String commodityId, RaidDangerLevel level) {
736 if (!isMiltiarized()) return level;
737 return level.next();
738 }
739
740 @Override
741 public RaidDangerLevel adjustItemDangerLevel(String itemId, String data, RaidDangerLevel level) {
742 if (!isMiltiarized()) return level;
743 return level.next();
744 }
745
746}
747
748
749
750
751
static SettingsAPI getSettings()
Definition Global.java:51
static FactoryAPI getFactory()
Definition Global.java:35
static SectorAPI getSector()
Definition Global.java:59
Map< String, MutableCommodityQuantity > supply
void addStabilityPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void addGroundDefensesImpactSection(TooltipMakerAPI tooltip, float bonus, String ...commodities)
Map< String, MutableCommodityQuantity > demand
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
void reportFleetDespawnedToListener(CampaignFleetAPI fleet, FleetDespawnReason reason, Object param)
boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode)
RaidDangerLevel adjustCommodityDangerLevel(String commodityId, RaidDangerLevel level)
RaidDangerLevel adjustItemDangerLevel(String itemId, String data, RaidDangerLevel level)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void reportBattleOccurred(CampaignFleetAPI fleet, CampaignFleetAPI primaryWinner, BattleAPI battle)
void notifyBeingRemoved(MarketInteractionMode mode, boolean forUpgrade)
FleetMemberAPI createFleetMember(FleetMemberType type, String variantOrWingId)
CommoditySpecAPI getCommoditySpec(String commodityId)