Starsector API
Loading...
Searching...
No Matches
Objectives.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.salvage;
2
3import java.util.List;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.CargoAPI;
9import com.fs.starfarer.api.campaign.CargoAPI.CargoItemType;
10import com.fs.starfarer.api.campaign.CargoPickerListener;
11import com.fs.starfarer.api.campaign.CargoStackAPI;
12import com.fs.starfarer.api.campaign.CoreInteractionListener;
13import com.fs.starfarer.api.campaign.CustomCampaignEntityPlugin;
14import com.fs.starfarer.api.campaign.CustomEntitySpecAPI;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.campaign.InteractionDialogAPI;
17import com.fs.starfarer.api.campaign.LocationAPI;
18import com.fs.starfarer.api.campaign.OptionPanelAPI;
19import com.fs.starfarer.api.campaign.RuleBasedDialog;
20import com.fs.starfarer.api.campaign.SectorEntityToken;
21import com.fs.starfarer.api.campaign.TextPanelAPI;
22import com.fs.starfarer.api.campaign.econ.MarketAPI;
23import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
24import com.fs.starfarer.api.campaign.rules.MemoryAPI;
25import com.fs.starfarer.api.impl.campaign.CampaignObjective;
26import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActionEnvelope;
27import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActions;
28import com.fs.starfarer.api.impl.campaign.DebugFlags;
29import com.fs.starfarer.api.impl.campaign.ids.Commodities;
30import com.fs.starfarer.api.impl.campaign.ids.Entities;
31import com.fs.starfarer.api.impl.campaign.ids.Factions;
32import com.fs.starfarer.api.impl.campaign.ids.Items;
33import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
34import com.fs.starfarer.api.impl.campaign.ids.Tags;
35import com.fs.starfarer.api.impl.campaign.intel.events.ht.HTNeutrinoBurstFactor;
36import com.fs.starfarer.api.impl.campaign.intel.events.ht.HTPoints;
37import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel;
38import com.fs.starfarer.api.impl.campaign.intel.misc.CommSnifferIntel;
39import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
40import com.fs.starfarer.api.impl.campaign.rulecmd.BaseCommandPlugin;
41import com.fs.starfarer.api.impl.campaign.rulecmd.FireBest;
42import com.fs.starfarer.api.impl.campaign.shared.WormholeManager;
43import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamVisibilityManager;
44import com.fs.starfarer.api.loading.Description;
45import com.fs.starfarer.api.loading.Description.Type;
46import com.fs.starfarer.api.ui.LabelAPI;
47import com.fs.starfarer.api.ui.TooltipMakerAPI;
48import com.fs.starfarer.api.util.Misc;
49import com.fs.starfarer.api.util.Misc.Token;
50
55public class Objectives extends BaseCommandPlugin {
56
57 public static String BURST_RANGE = "$COB_burstRange";
58
59 public static int WORMHOLE_FUEL = 100;
60 public static String WORMHOLE_TYPE_STR = "wormhole";
61
62 public static float BURST_RANGE_MAKESHIFT = 10;
63 public static float BURST_RANGE_DOMAIN = 15;
64 public static float BURST_RANGE_SCAVENGER_MIN = 5; // used by HT_CMD
65 public static float BURST_RANGE_SCAVENGER_MAX = 10; // used by HT_CMD
66
67 public static float SALVAGE_FRACTION = 0.5f;
68
69 protected CampaignFleetAPI playerFleet;
70 protected SectorEntityToken entity;
71 protected FactionAPI playerFaction;
72 protected FactionAPI entityFaction;
73 protected TextPanelAPI text;
74 protected OptionPanelAPI options;
75 protected CargoAPI playerCargo;
76 protected MemoryAPI memory;
77 protected InteractionDialogAPI dialog;
78 protected Map<String, MemoryAPI> memoryMap;
79 protected FactionAPI faction;
80
81 public Objectives() {
82
83 }
84
85 public Objectives(SectorEntityToken entity) {
86 init(entity);
87 }
88
89 protected void init(SectorEntityToken entity) {
90 memory = entity.getMemoryWithoutUpdate();
91 this.entity = entity;
92 playerFleet = Global.getSector().getPlayerFleet();
93 playerCargo = playerFleet.getCargo();
94
95 playerFaction = Global.getSector().getPlayerFaction();
96 entityFaction = entity.getFaction();
97
98 faction = entity.getFaction();
99
100 if (entity.hasTag(Tags.MAKESHIFT)) {
102 } else {
104 }
105
106// DebugFlags.OBJECTIVES_DEBUG = false;
107// DebugFlags.OBJECTIVES_DEBUG = true;
108 }
109
110 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
111
112 this.dialog = dialog;
113 this.memoryMap = memoryMap;
114
115 String command = params.get(0).getString(memoryMap);
116 if (command == null) return false;
117
118 entity = dialog.getInteractionTarget();
119 init(entity);
120
122
123 text = dialog.getTextPanel();
124 options = dialog.getOptionPanel();
125
126 if (command.equals("printCost")) {
127 String type = params.get(1).getString(memoryMap);
128 printCost(type);
129 } else if (command.equals("showSalvage")) {
130 printSalvage();
131 } else if (command.equals("selectWormholeAnchor")) {
133 } else if (command.equals("hasWormholeAnchor")) {
134 return hasWormholeAnchor();
135 } else if (command.equals("hasRepImpact")) {
136 return hasRepImpact();
137 } else if (command.equals("showRepairCost")) {
138 printRepairCost(true);
139 } else if (command.equals("showBurstCost")) {
140 boolean hasRecent = HyperspaceTopographyEventIntel.hasRecentReadingsNearPlayer();
141 printBurstCost(canBurst() && !hasRecent);
142 } else if (command.equals("showRepairCostNoPrompt")) {
143 printRepairCost(false);
144 } else if (command.equals("printHackDesc")) {
146 } else if (command.equals("canBuild")) {
147 String type = params.get(1).getString(memoryMap);
148 return canBuild(type);
149 } else if (command.equals("canActivate")) {
150 return canActivate(entity.getCustomEntityType());
151 } else if (command.equals("canBurst")) {
152 return canBurst();
153 } else if (command.equals("build")) {
154 String type = params.get(1).getString(memoryMap);
155 build(type, Factions.PLAYER);
156 } else if (command.equals("printDescription")) {
157 updateMemory();
158 String type = entity.getCustomEntityType();
159 printDescription(type);
160 } else if (command.equals("isHacked")) {
161 return isHacked();
162 } else if (command.equals("doAction")) {
163 String action = params.get(1).getString(memoryMap);
164 if (action.equals("hack")) {
165 hack();
166 } else if (action.equals("reset")) {
167 reset();
168 } else if (action.equals("unhack")) {
169 unhack();
170 } else if (action.equals("control")) {
171 control(Factions.PLAYER);
172 } else if (action.equals("salvage")) {
173 salvage(Factions.PLAYER);
174 } else if (action.equals("burst")) {
175 doBurst();
176 }
177 }
178 return true;
179 }
180
181 protected void doBurst() {
182 CargoAPI cargo = playerCargo;
183 String [] res = getBurstResources();
184 int [] quantities = getBurstQuantities();
185 for (int i = 0; i < res.length; i++) {
186 String commodityId = res[i];
187 int quantity = quantities[i];
188 cargo.removeCommodity(commodityId, quantity);
189 AddRemoveCommodity.addCommodityLossText(commodityId, quantity, text);
190 }
191
192 float range = memory.getFloat(BURST_RANGE);
193 SlipstreamVisibilityManager.updateSlipstreamVisibility(entity.getLocationInHyperspace(), range);
194
195 int points = 0;
196 if (entity.hasTag(Tags.MAKESHIFT)) {
197 points = HTPoints.NEUTRINO_BURST_MAKESHIFT;
198 } else {
199 points = HTPoints.NEUTRINO_BURST_DOMAIN;
200 }
201
202
203 boolean hasRecent = HyperspaceTopographyEventIntel.hasRecentReadingsNearPlayer();
204 if (!hasRecent && points > 0) {
205 HyperspaceTopographyEventIntel.addFactorCreateIfNecessary(new HTNeutrinoBurstFactor(points), dialog);
206 if (HyperspaceTopographyEventIntel.get() != null) {
207 HyperspaceTopographyEventIntel.get().addRecentReadings(entity.getLocationInHyperspace());
208 }
209 }
210 }
211
212 protected boolean hasRepImpact() {
213 for (MarketAPI curr : Global.getSector().getEconomy().getMarkets(entity.getContainingLocation())) {
214 if (curr.getFaction() == entity.getFaction() &&
215 !curr.getFaction().isNeutralFaction() &&
216 !curr.getFaction().isPlayerFaction()) {
217 return true;
218 }
219 }
220 return false;
221 }
222
223 public void salvage(final String factionId) {
224
225 CargoAPI salvage = Global.getFactory().createCargo(true);
226 String [] r = getResources();
227 int [] q = getSalvageQuantities();
228
229 for (int i = 0; i < r.length; i++) {
230 salvage.addCommodity(r[i], q[i]);
231 }
232
233 dialog.getVisualPanel().showLoot("Salvaged", salvage, false, true, true, new CoreInteractionListener() {
234 public void coreUIDismissed() {
235 dialog.dismiss();
236 dialog.hideTextPanel();
237 dialog.hideVisualPanel();
238
239 LocationAPI loc = entity.getContainingLocation();
240 SectorEntityToken built = loc.addCustomEntity(null,
241 null,
242 Entities.STABLE_LOCATION, // type of object, defined in custom_entities.json
243 Factions.NEUTRAL); // faction
244 if (entity.getOrbit() != null) {
245 built.setOrbit(entity.getOrbit().makeCopy());
246 }
247 loc.removeEntity(entity);
248 updateOrbitingEntities(loc, entity, built);
249
250 built.getMemoryWithoutUpdate().set(MemFlags.RECENTLY_SALVAGED, true, 30f);
251
252 if (Factions.PLAYER.equals(factionId) && hasRepImpact() &&
253 !entity.getFaction().isPlayerFaction() &&
254 !entity.getFaction().isNeutralFaction()) {
255 RepActions action = RepActions.COMBAT_AGGRESSIVE;
256 if (entity.hasTag(Tags.MAKESHIFT)) {
257 action = RepActions.COMBAT_AGGRESSIVE_TOFF;
258 }
259 Global.getSector().adjustPlayerReputation(
260 new RepActionEnvelope(action, null, null, null, false, true, "Change caused by destruction of " + entity.getCustomEntitySpec().getDefaultName().toLowerCase()),
261 faction.getId());
262 }
263
264 ListenerUtil.reportObjectiveDestroyed(entity, built, Global.getSector().getFaction(factionId));
265 }
266 });
267 options.clearOptions();
268 dialog.setPromptText("");
269
270 }
271
272 public void updateOrbitingEntities(LocationAPI loc, SectorEntityToken prev, SectorEntityToken built) {
273 if (loc == null) return;
274 for (SectorEntityToken other : loc.getAllEntities()) {
275 if (other == prev) continue;
276 if (other.getOrbit() == null) continue;
277 if (other.getOrbitFocus() == prev) {
278 other.setOrbitFocus(built);
279 }
280 }
281 }
282
283 public boolean isNonFunctional() {
284 return entity.getMemoryWithoutUpdate().getBoolean(MemFlags.OBJECTIVE_NON_FUNCTIONAL);
285 }
286
287 public void control(String factionId) {
288 if (dialog != null) {
289 if (Factions.PLAYER.equals(factionId) && isNonFunctional()) {
291 }
292 if (Factions.PLAYER.equals(factionId) && hasRepImpact() &&
293 !entity.getFaction().isPlayerFaction() && !entity.getFaction().isNeutralFaction()) {
294 RepActions action = RepActions.COMBAT_AGGRESSIVE;
295 //action = RepActions.COMBAT_AGGRESSIVE_TOFF;
296 Global.getSector().adjustPlayerReputation(
297 new RepActionEnvelope(action, null, null, text, false, true),
298 faction.getId());
299 }
300 }
301 FactionAPI prev = entity.getFaction();
302 entity.setFaction(factionId);
303 faction = entity.getFaction();
304
305 if (!entity.hasTag(Tags.COMM_RELAY) && faction.isPlayerFaction()) {
306 unhack();
307 }
308
309 entity.getMemoryWithoutUpdate().unset(MemFlags.OBJECTIVE_NON_FUNCTIONAL);
310
311 if (dialog != null) {
312 ((RuleBasedDialog) dialog.getPlugin()).updateMemory();
313 updateMemory();
314
315 printOwner();
316 }
317
318
319 ListenerUtil.reportObjectiveChangedHands(entity, prev, faction);
320 }
321
322 public void unhack() {
323 CommSnifferIntel intel = CommSnifferIntel.getExistingSnifferIntelForRelay(entity);
324 if (intel != null) {
325 intel.uninstall();
326 updateMemory();
327 } else {
328 CustomCampaignEntityPlugin plugin = entity.getCustomPlugin();
329 if (plugin instanceof CampaignObjective) {
331 o.setHacked(false);
332 }
333 updateMemory();
334 }
335 }
336
337 public void hack() {
338 CustomCampaignEntityPlugin plugin = entity.getCustomPlugin();
339 if (plugin instanceof CampaignObjective) {
341 o.setHacked(true);
342 }
343 updateMemory();
344 }
345
346 public void reset() {
347 CustomCampaignEntityPlugin plugin = entity.getCustomPlugin();
348 if (plugin instanceof CampaignObjective) {
350 o.setReset(true);
351 }
352 // so that a false sensor reading doesn't spawn immediately after "introducing false readings"
353 Global.getSector().getPlayerFleet().getMemoryWithoutUpdate().set(MemFlags.FLEET_NOT_CHASING_GHOST, true,
354 0.5f + Misc.random.nextFloat() * 1f);
355 updateMemory();
356 }
357
358 public boolean isHacked() {
359 CustomCampaignEntityPlugin plugin = entity.getCustomPlugin();
360 if (plugin instanceof CampaignObjective) {
362 return o.isHacked();
363 }
364 return false;
365 }
366
367 public void build(String type, String factionId) {
368 if (entity.hasTag(Tags.NON_CLICKABLE)) return;
369 if (entity.hasTag(Tags.FADING_OUT_AND_EXPIRING)) return;
370
371 LocationAPI loc = entity.getContainingLocation();
372 SectorEntityToken built = loc.addCustomEntity(null,
373 null,
374 type, // type of object, defined in custom_entities.json
375 factionId); // faction
376 if (entity.getOrbit() != null) {
377 built.setOrbit(entity.getOrbit().makeCopy());
378 }
379 built.setLocation(entity.getLocation().x, entity.getLocation().y);
380 loc.removeEntity(entity);
381 updateOrbitingEntities(loc, entity, built);
382
383 //entity.setContainingLocation(null);
384 built.getMemoryWithoutUpdate().set("$originalStableLocation", entity);
385
386 if (text != null) {
388 Global.getSoundPlayer().playUISound("ui_objective_constructed", 1f, 1f);
389 }
390 }
391
392
393 public boolean canBuild(String type) {
395 return true;
396 }
397
398
399 CargoAPI cargo = playerCargo;
400 String [] res = getResources();
401 int [] quantities = getQuantities();
402
403 if (type.equals(WORMHOLE_TYPE_STR)) {
404 res = getWormholeResources();
405 quantities = getWormholeQuantities();
406 }
407
408 for (int i = 0; i < res.length; i++) {
409 String commodityId = res[i];
410 int quantity = quantities[i];
411 if (quantity > cargo.getQuantity(CargoItemType.RESOURCES, commodityId)) {
412 return false;
413 }
414 }
415 return true;
416 }
417
418 public void removeBuildCosts() {
420 return;
421 }
422
423 CargoAPI cargo = playerCargo;
424 String [] res = getResources();
425 int [] quantities = getQuantities();
426 for (int i = 0; i < res.length; i++) {
427 String commodityId = res[i];
428 int quantity = quantities[i];
429 cargo.removeCommodity(commodityId, quantity);
430 }
431 }
432
433 public void removeRepairCosts(TextPanelAPI text) {
435 return;
436 }
437
438 CargoAPI cargo = playerCargo;
439 String [] res = getRepairResources();
440 int [] quantities = getRepairQuantities();
441 for (int i = 0; i < res.length; i++) {
442 String commodityId = res[i];
443 int quantity = quantities[i];
444 cargo.removeCommodity(commodityId, quantity);
445 AddRemoveCommodity.addCommodityLossText(commodityId, quantity, text);
446 }
447 }
448
449 public boolean canActivate(String type) {
451 return true;
452 }
453
454 CargoAPI cargo = playerCargo;
455 String [] res = getRepairResources();
456 int [] quantities = getRepairQuantities();
457 for (int i = 0; i < res.length; i++) {
458 String commodityId = res[i];
459 int quantity = quantities[i];
460 if (quantity > cargo.getQuantity(CargoItemType.RESOURCES, commodityId)) {
461 return false;
462 }
463 }
464 return true;
465 }
466
467 public boolean canBurst() {
469 return true;
470 }
471
472 CargoAPI cargo = playerCargo;
473 String [] res = getBurstResources();
474 int [] quantities = getBurstQuantities();
475 for (int i = 0; i < res.length; i++) {
476 String commodityId = res[i];
477 int quantity = quantities[i];
478 if (quantity > cargo.getQuantity(CargoItemType.RESOURCES, commodityId)) {
479 return false;
480 }
481 }
482 return true;
483 }
484
485
486 public void updateMemory() {
487 //memory.set("$cob_hacked", isHacked(), 0f);
488 //memory.set(BaseCampaignObjectivePlugin.HACKED, isHacked(), 0f);
489 }
490
491 public void printDescription(String type) {
492 Description desc = Global.getSettings().getDescription(type, Type.CUSTOM);
493 if (desc != null) {
494 text.addParagraph(desc.getText1());
495 }
496
497 CustomEntitySpecAPI spec = Global.getSettings().getCustomEntitySpec(type);
498 CustomCampaignEntityPlugin plugin = spec.getPlugin();
499 SectorEntityToken temp = entity.getContainingLocation().createToken(0, 0);
500 for (String tag : spec.getTags()) {
501 temp.addTag(tag);
502 }
503 plugin.init(temp, null);
504
505 boolean objective = entity.hasTag(Tags.OBJECTIVE);
506 if (objective) {
507 plugin = entity.getCustomPlugin();
508 }
509
510 Class c = null;
511 if (plugin instanceof CampaignObjective) {
513 c = o.getClass();
514
515 TooltipMakerAPI info = text.beginTooltip();
516 o.printEffect(info, 0f);
517 text.addTooltip();
518
520 }
521
522 printOwner();
523
524 for (SectorEntityToken curr : entity.getContainingLocation().getEntitiesWithTag(Tags.OBJECTIVE)) {
525 if (curr.hasTag(Tags.OBJECTIVE)) {
526 if (curr.getFaction() == null || !curr.getFaction().isPlayerFaction() ||
527 curr.getCustomEntitySpec() == null) {
528 continue;
529 }
530
531 CustomCampaignEntityPlugin ccep = curr.getCustomPlugin();
532 if (ccep instanceof CampaignObjective) {
534 if (c == o.getClass()) {
535 if (entity == curr) {
536 text.addPara("Another one in this star system would have no effect " +
537 "beyond providing redundancy in case this one is lost.");
538 } else {
539 text.addPara("There's already " +
540 curr.getCustomEntitySpec().getAOrAn() + " " +
541 curr.getCustomEntitySpec().getNameInText() + " under your control " +
542 "in this star system. Another one would have no effect " +
543 "beyond providing redundancy if one is lost.");
544 }
545 break;
546 }
547 }
548 }
549 }
550
551 }
552
553 public void printOwner() {
554 boolean objective = entity.hasTag(Tags.OBJECTIVE);
555 if (objective) {
556 if (!faction.isNeutralFaction()) {
557 if (entity.getFaction().isPlayerFaction() && !Misc.isPlayerFactionSetUp()) {
558 text.addPara("This " + entity.getCustomEntitySpec().getShortName() + " is under your control.",
559 entity.getFaction().getBaseUIColor(), "your");
560 } else {
561 text.addPara("This " + entity.getCustomEntitySpec().getShortName() + " is under %s control.",
562 entity.getFaction().getBaseUIColor(), entity.getFaction().getPersonNamePrefix());
563 }
564 } else {
565 text.addPara("This " + entity.getCustomEntitySpec().getShortName() + " is not claimed by any faction.");
566 }
567 }
568 }
569
570
571
572 public void printHackDesc() {
573// if (entity.hasTag(Tags.COMM_RELAY)) {
574// text.addPara("The comm sniffer will remain active until it is detected and cleared out by the " +
575// "maintenance subroutines. The odds of this happening increase drastically when " +
576// "multiple comm sniffers are installed on different relays in the comm network.");
577// } else {
578// text.addPara("The hack will eventually be picked up and cleared out by the maintenance subroutines, but should " +
579// "remain effective for at least three months.");
580// }
581 }
582
583 public void printRepairCost(boolean withPrompt) {
584 Misc.showCost(text, null, null, getRepairResources(), getRepairQuantities());
585 if (withPrompt) {
586 text.addPara("Proceed with reactivation?");
587 }
588 }
589
590 public void printBurstCost(boolean withPrompt) {
591 Misc.showCost(text, null, null, getBurstResources(), getBurstQuantities());
592 boolean hasRecent = HyperspaceTopographyEventIntel.hasRecentReadingsNearPlayer();
593 if (hasRecent) {
594 LabelAPI label = text.addPara("You've recently acquired topographic data within %s light-years of your current location,"
595 + " and a neutrino burst here "
596 + "will not meaningfully contribute to your understanding of "
597 + "hyperspace topology. It will, however, still "
598 + "reveal all nearby slipstreams.", Misc.getHighlightColor(),
599 "" + (int)HyperspaceTopographyEventIntel.RECENT_READINGS_RANGE_LY);
600 label.setHighlightColors(Misc.getHighlightColor(), Misc.getNegativeHighlightColor(), Misc.getNegativeHighlightColor());
601 label.setHighlight("" + (int)HyperspaceTopographyEventIntel.RECENT_READINGS_RANGE_LY,
602 "will not meaningfully contribute", "hyperspace topology");
603 }
604 //RECENT_READINGS_RANGE_LY
605 if (withPrompt) {
606 text.addPara("Proceed with neutrino burst?");
607 }
608 }
609
610 public void printSalvage() {
611 Misc.showCost(text, "Potential salvage", false, null, null, getResources(), getSalvageQuantities());
612
613 text.addPara("Proceed with salvage operation?");
614 }
615
616 public void printCost(String type) {
617 if (type.equals(WORMHOLE_TYPE_STR)) {
618 Misc.showCost(text, null, null, getWormholeResources(), getWormholeQuantities());
619 return;
620 }
621 printDescription(type);
622
623 Misc.showCost(text, null, null, getResources(), getQuantities());
624
625 if (canBuild(type)) {
626 text.addPara("Proceed with construction?");
627 } else {
628 text.addPara("You do not have the necessary resources to build this structure.");
629 }
630 }
631
632 public String [] getWormholeResources() {
633 return new String[] {Commodities.FUEL};
634 }
635
636 public int [] getWormholeQuantities() {
637 return new int[] {WORMHOLE_FUEL};
638 }
639
640 public String [] getResources() {
641 if (entity.hasTag(Tags.MAKESHIFT) || entity.hasTag(Tags.STABLE_LOCATION)) {
642 return new String[] {Commodities.HEAVY_MACHINERY, Commodities.METALS, Commodities.RARE_METALS};
643 }
644 return new String[] {Commodities.HEAVY_MACHINERY, Commodities.METALS, Commodities.RARE_METALS, Commodities.VOLATILES};
645 }
646
647
648 public int [] getSalvageQuantities() {
649 int [] q = getQuantities();
650 int [] result = new int [q.length];
651
652 for (int i = 0; i < result.length; i++) {
653 result[i] = (int) (q[i] * SALVAGE_FRACTION);
654 }
655 return result;
656 }
657 public int [] getQuantities() {
658 if (entity.hasTag(Tags.MAKESHIFT) || entity.hasTag(Tags.STABLE_LOCATION)) {
659 return new int[] {15, 30, 5};
660 }
661 return new int[] {50, 200, 20, 20};
662 }
663
664 public String [] getRepairResources() {
665 return new String[] {Commodities.HEAVY_MACHINERY };
666 }
667
668
669 public int [] getRepairQuantities() {
670 return new int[] {5};
671 }
672
673
674 public int [] getBurstQuantities() {
675 return new int[] {HTPoints.NEUTRINO_BURST_VOLATILES_COST};
676 }
677
678 public String [] getBurstResources() {
679 return new String[] {Commodities.VOLATILES};
680 }
681
682 public boolean hasWormholeAnchor() {
683 return !getWormholeAnchors().isEmpty();
684 }
685 public CargoAPI getWormholeAnchors() {
686 CargoAPI copy = Global.getFactory().createCargo(false);
687 for (CargoStackAPI stack : playerCargo.getStacksCopy()) {
688 if (stack.isSpecialStack() && Items.WORMHOLE_ANCHOR.equals(stack.getSpecialDataIfSpecial().getId())) {
689 copy.addFromStack(stack);
690 }
691 }
692 copy.sort();
693 return copy;
694 }
695
696 public void selectWormholeAnchor() {
697 CargoAPI copy = getWormholeAnchors();
698
699 final float width = 310f;
700 dialog.showCargoPickerDialog("Select wormhole anchor to deploy", "Deploy", "Cancel", true, width, copy,
701 new CargoPickerListener() {
702 public void pickedCargo(CargoAPI cargo) {
703 if (cargo.isEmpty()) {
704 cancelledCargoSelection();
705 return;
706 }
707
708 cargo.sort();
709 for (CargoStackAPI stack : cargo.getStacksCopy()) {
710 if (stack.isSpecialStack()) {
711 WormholeManager.get().addWormhole(stack.getSpecialDataIfSpecial(), entity, dialog);
712
714 playerCargo.removeCommodity(Commodities.FUEL, WORMHOLE_FUEL);
716 }
717
718 FireBest.fire(null, dialog, memoryMap, "WormholeDeploymentFinished");
719 break;
720 }
721 }
722 }
723 public void cancelledCargoSelection() {
724 }
725 public void recreateTextPanel(TooltipMakerAPI panel, CargoAPI cargo, CargoStackAPI pickedUp, boolean pickedUpFromSource, CargoAPI combined) {
726 panel.addPara("Deploying and activating a wormhole anchor, turning it into an active terminus, "
727 + "will consume %s fuel. Your fleet is carrying %s fuel.",
728 0f, Misc.getHighlightColor(),
729 "" + WORMHOLE_FUEL,
730 "" + (int)playerCargo.getFuel());
731
732 boolean makeUnstable = WormholeManager.willWormholeBecomeUnstable(entity);
733 if (makeUnstable) {
734 panel.addPara("Once the operation is completed, the wormhole will take about a cycle to stablize,"
735 + "before it can be used.", 10f, Misc.getHighlightColor(), "cycle");
736 } else {
737 panel.addPara("Usually, the wormhole will take about a cycle to stablize, but you have "
738 + "calibration data that will allow it to be used immediately.", 10f);
739 }
740 }
741 });
742 }
743}
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
static SettingsAPI getSettings()
Definition Global.java:51
static SoundPlayerAPI getSoundPlayer()
Definition Global.java:43
static FactoryAPI getFactory()
Definition Global.java:35
static SectorAPI getSector()
Definition Global.java:59
static void addCommodityLossText(String commodityId, int quantity, TextPanelAPI text)
static MemoryAPI getEntityMemory(Map< String, MemoryAPI > memoryMap)
static boolean fire(String ruleId, InteractionDialogAPI dialog, Map< String, MemoryAPI > memoryMap, String params)
Definition FireBest.java:56
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
void updateOrbitingEntities(LocationAPI loc, SectorEntityToken prev, SectorEntityToken built)
CargoAPI createCargo(boolean unlimitedStacks)
Description getDescription(String id, Type type)
CustomEntitySpecAPI getCustomEntitySpec(String id)
SoundAPI playUISound(String id, float pitch, float volume)
void printNonFunctionalAndHackDescription(TextPanelAPI text)
void printEffect(TooltipMakerAPI text, float pad)