Starsector API
Loading...
Searching...
No Matches
GateCMD.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd.missions;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6import java.util.Map;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.BaseCampaignEntityPickerListener;
10import com.fs.starfarer.api.campaign.CampaignFleetAPI;
11import com.fs.starfarer.api.campaign.CargoAPI;
12import com.fs.starfarer.api.campaign.InteractionDialogAPI;
13import com.fs.starfarer.api.campaign.JumpPointAPI.JumpDestination;
14import com.fs.starfarer.api.campaign.LocationAPI;
15import com.fs.starfarer.api.campaign.OptionPanelAPI;
16import com.fs.starfarer.api.campaign.SectorEntityToken;
17import com.fs.starfarer.api.campaign.StarSystemAPI;
18import com.fs.starfarer.api.campaign.TextPanelAPI;
19import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
20import com.fs.starfarer.api.campaign.rules.MemoryAPI;
21import com.fs.starfarer.api.impl.campaign.GateEntityPlugin;
22import com.fs.starfarer.api.impl.campaign.GateExplosionScript;
23import com.fs.starfarer.api.impl.campaign.ids.Tags;
24import com.fs.starfarer.api.impl.campaign.rulecmd.BaseCommandPlugin;
25import com.fs.starfarer.api.ui.TooltipMakerAPI;
26import com.fs.starfarer.api.util.Misc;
27import com.fs.starfarer.api.util.Misc.Token;
28
33public class GateCMD extends BaseCommandPlugin {
34
37 protected TextPanelAPI text;
40 protected MemoryAPI memory;
42 protected Map<String, MemoryAPI> memoryMap;
43
44 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
45
46 this.dialog = dialog;
47 this.memoryMap = memoryMap;
48
49 String command = params.get(0).getString(memoryMap);
50 if (command == null) return false;
51
53
57
60
61 if (command.equals("selectDestination")) {
63 } else if (command.equals("notifyScanned")) {
65 } else if (command.equals("explode")) {
67 } else if (command.equals("isPopulated")) {
68 return isPopulated(entity);
69 }
70 return true;
71 }
72
73 public static boolean isPopulated(SectorEntityToken targetGate) {
74 if (targetGate.getContainingLocation() == null) return false;
75
76 LocationAPI loc = targetGate.getContainingLocation();
77 if (loc.hasTag(Tags.THEME_CORE_POPULATED)) return true;
78
79 return !Misc.getMarketsInLocation(loc).isEmpty();
80 }
81
82 public static int computeFuelCost(SectorEntityToken targetGate) {
83 float dist = Misc.getDistanceToPlayerLY(targetGate);
85
86 return (int) Math.ceil(dist * fuelPerLY * Misc.GATE_FUEL_COST_MULT);
87 }
88
89 protected void selectDestination() {
90 final ArrayList<SectorEntityToken> gates =
91 new ArrayList<SectorEntityToken>(GateEntityPlugin.getGateData().scanned);
92 gates.remove(entity);
93 dialog.showCampaignEntityPicker("Select destination", "Destination:", "Initiate transit",
96 public void pickedEntity(SectorEntityToken entity) {
97 int cost = computeFuelCost(entity);
99
100 dialog.dismiss();
101 Global.getSector().setPaused(false);
102 JumpDestination dest = new JumpDestination(entity, null);
104
105 float distLY = Misc.getDistanceLY(entity, GateCMD.this.entity);
106 if (entity.getCustomPlugin() instanceof GateEntityPlugin) {
108 plugin.showBeingUsed(distLY);
109 }
110 if (GateCMD.this.entity.getCustomPlugin() instanceof GateEntityPlugin) {
112 plugin.showBeingUsed(distLY);
113 }
114
116 GateCMD.this.entity, entity);
117 }
118 public void cancelledEntityPicking() {
119
120 }
121 public String getMenuItemNameOverrideFor(SectorEntityToken entity) {
122 return null;
123 }
124 public String getSelectedTextOverrideFor(SectorEntityToken entity) {
126 }
127 public void createInfoText(TooltipMakerAPI info, SectorEntityToken entity) {
128
129 int cost = computeFuelCost(entity);
130 int available = (int) Global.getSector().getPlayerFleet().getCargo().getFuel();
131
132 Color reqColor = Misc.getHighlightColor();
133 Color availableColor = Misc.getHighlightColor();
134 if (cost > available) {
135 reqColor = Misc.getNegativeHighlightColor();
136 }
137
139// LabelAPI label = info.addPara("Transit requires %s fuel. "
140// + "You have %s units of fuel available.", 0f,
141// Misc.getTextColor(),
142// //Misc.getGrayColor(),
143// availColor, Misc.getWithDGS(cost), Misc.getWithDGS(available));
144// label.setHighlightColors(reqColor, availColor);
145
146 info.beginGrid(200f, 2, Misc.getGrayColor());
148 info.addToGrid(0, 0, " Fuel required:", Misc.getWithDGS(cost), reqColor);
149 info.addToGrid(1, 0, " Fuel available:", Misc.getWithDGS(available), availableColor);
150 info.addGrid(0);;
151 }
152 public boolean canConfirmSelection(SectorEntityToken entity) {
153 int cost = computeFuelCost(entity);
154 int available = (int) Global.getSector().getPlayerFleet().getCargo().getFuel();
155 return cost <= available;
156 }
157 public float getFuelColorAlphaMult() {
158 return 0.5f;
159 }
160 public float getFuelRangeMult() { // just for showing it on the map when picking destination
161 if (true) return 0f;
162 if (Misc.GATE_FUEL_COST_MULT <= 0) return 0f;
163 return 1f / Misc.GATE_FUEL_COST_MULT;
164 }
165 });
166 }
167
168 public static void notifyScanned(SectorEntityToken gate) {
169 GateEntityPlugin.getGateData().scanned.add(gate);
170 gate.getCustomPlugin().advance(0f); // makes gate activate if already did quest
171 }
172
173
174
175
176 public static void explode(SectorEntityToken gate) {
178
179 // If the player blew up the Gate at a responsible distance from the core worlds, take note.
180 // Askonia is near the center of the core worlds, so use distance to there to gauge.
181
182 if(Global.getSector().getMemoryWithoutUpdate().contains("$gaATG_useJanusPrototype") &&
183 !Global.getSector().getMemoryWithoutUpdate().contains("$ggaATG_firstJanusResults")) {
184 StarSystemAPI askonia = Global.getSector().getStarSystem("askonia");
185 if(askonia != null) {
186 float dist = Misc.getDistance(gate.getLocationInHyperspace(), askonia.getLocation());
187 System.out.print("dist = " + dist);
188 if(dist > 12000.0f) {
189 Global.getSector().getMemoryWithoutUpdate().set("$gaATG_didRemoteFirstJanusTest", true );
190 }
191 }
192 }
193
194 }
195}
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
static SectorAPI getSector()
Definition Global.java:65
static void reportFleetTransitingGate(CampaignFleetAPI fleet, SectorEntityToken gateFrom, SectorEntityToken gateTo)
static MemoryAPI getEntityMemory(Map< String, MemoryAPI > memoryMap)
static void notifyScanned(SectorEntityToken gate)
Definition GateCMD.java:168
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
Definition GateCMD.java:44
static boolean isPopulated(SectorEntityToken targetGate)
Definition GateCMD.java:73
static int computeFuelCost(SectorEntityToken targetGate)
Definition GateCMD.java:82
static String getWithDGS(float num)
Definition Misc.java:1381
static float getDistanceLY(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:602
static float GATE_FUEL_COST_MULT
Definition Misc.java:220
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
Definition Misc.java:936
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static float getDistanceToPlayerLY(Vector2f locInHyper)
Definition Misc.java:626
static Color getHighlightColor()
Definition Misc.java:792
void showCampaignEntityPicker(String title, String selectedText, String okText, FactionAPI factionForUIColors, List< SectorEntityToken > entities, CampaignEntityPickerListener listener)
void addScript(EveryFrameScript script)
void doHyperspaceTransition(CampaignFleetAPI fleet, SectorEntityToken jumpLocation, JumpDestination dest)
StarSystemAPI getStarSystem(String name)
CustomCampaignEntityPlugin getCustomPlugin()
void set(String key, Object value)
Object addToGrid(int x, int y, String label, String value)
void beginGrid(float itemWidth, int cols)