Starsector API
Loading...
Searching...
No Matches
FleetDesc.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd;
2
3import java.awt.Color;
4import java.util.List;
5import java.util.Map;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.CampaignFleetAPI;
9import com.fs.starfarer.api.campaign.FactionAPI;
10import com.fs.starfarer.api.campaign.InteractionDialogAPI;
11import com.fs.starfarer.api.campaign.TextPanelAPI;
12import com.fs.starfarer.api.campaign.rules.MemoryAPI;
13import com.fs.starfarer.api.characters.MutableCharacterStatsAPI.SkillLevelAPI;
14import com.fs.starfarer.api.impl.campaign.econ.ShippingDisruption;
15import com.fs.starfarer.api.impl.campaign.fleets.EconomyFleetAssignmentAI.EconomyRouteData;
16import com.fs.starfarer.api.impl.campaign.fleets.EconomyFleetRouteManager;
17import com.fs.starfarer.api.impl.campaign.fleets.RouteManager;
18import com.fs.starfarer.api.impl.campaign.fleets.RouteManager.RouteData;
19import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
20import com.fs.starfarer.api.ui.LabelAPI;
21import com.fs.starfarer.api.util.Misc;
22import com.fs.starfarer.api.util.Misc.Token;
23
24public class FleetDesc extends BaseCommandPlugin {
25
26 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
27 if (dialog == null) return false;
28 if (!(dialog.getInteractionTarget() instanceof CampaignFleetAPI)) return false;
29
30 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
31 CampaignFleetAPI fleet = (CampaignFleetAPI) dialog.getInteractionTarget();
32
33 FactionAPI faction = fleet.getFaction();
34 TextPanelAPI text = dialog.getTextPanel();
35
36 if (Global.getSettings().isDevMode() && !Global.getSettings().getBoolean("playtestingMode")) {
37 text.addParagraph("Admiral skills:");
38 for (SkillLevelAPI skill : fleet.getCommanderStats().getSkillsCopy()) {
39 if (skill.getSkill().isAdmiralSkill()) {
40 text.addParagraph(" " + skill.getSkill().getId());
41 }
42 }
43 }
44
45
46 MemoryAPI mem = fleet.getMemoryWithoutUpdate();
47 if (!mem.contains("$shownFleetDescAlready")) {
48 mem.set("$shownFleetDescAlready", true, 0);
49 }
50
51 boolean smuggler = mem.getBoolean(MemFlags.MEMORY_KEY_SMUGGLER);
52 boolean trader = mem.getBoolean(MemFlags.MEMORY_KEY_TRADE_FLEET);
53
54 Color hl = Misc.getHighlightColor();
55 Color red = Misc.getNegativeHighlightColor();
56
57 RouteData route = RouteManager.getInstance().getRoute(EconomyFleetRouteManager.SOURCE_ID, fleet);
58 if ((trader || smuggler) && route != null) {
59 EconomyRouteData data = (EconomyRouteData) route.getCustom();
60
61 Integer id = route.getCurrentSegmentId();
62
63 String from = data.from.getName();
64 String to = data.to.getName();
65 //int index = route.getCurrentIndex();
66 if (id >= EconomyFleetRouteManager.ROUTE_DST_LOAD) {
67 from = data.to.getName();
68 to = data.from.getName();
69 }
70 String cargo = "";
71
72 if (id <= EconomyFleetRouteManager.ROUTE_DST_UNLOAD) {
73 cargo = EconomyRouteData.getCargoList(data.cargoDeliver);
74 if (!cargo.isEmpty() && id == EconomyFleetRouteManager.ROUTE_SRC_LOAD) cargo += " (being loaded)";
75 } else {
76 cargo = EconomyRouteData.getCargoList(data.cargoReturn);
77 if (!cargo.isEmpty() && id == EconomyFleetRouteManager.ROUTE_DST_LOAD) cargo += " (being loaded)";
78 }
79
80 if (trader || smuggler) {
81 LabelAPI label = text.addParagraph("You encounter " + fleet.getFaction().getPersonNamePrefixAOrAn() + " " +
82 fleet.getFaction().getPersonNamePrefix() + " "+ fleet.getName().toLowerCase() + ".");
83 label.highlightFirst(fleet.getFaction().getPersonNamePrefix());
84 label.setHighlightColor(fleet.getFaction().getBaseUIColor());
85
86 text.setFontSmallInsignia();
87
88 text.addParagraph("--------------------------------------------------------------------------------------------------------------");
89 if (data.from.isHidden()) {
90 text.addPara("Port of origin: %s", hl, "Unknown");
91 } else {
92 text.addPara("Port of origin: %s", hl, data.from.getName());
93 }
94 text.addPara("Current destination: %s", hl, to);
95 if (from.equals(data.to.getName())) {
96 text.addPara("Returning from: %s", hl, data.to.getName());
97 }
98 if (cargo.isEmpty()) {
99 text.addPara("No cargo");
100 } else {
101 text.addPara("Cargo: %s", hl, cargo);
102 //text.addPara(cargo);
103 }
104
105 text.addParagraph("--------------------------------------------------------------------------------------------------------------");
106 text.setFontInsignia();
107
108 int penalty = Math.round(ShippingDisruption.getPenaltyForShippingLost(data.from.getSize(), data.size) * 100f);
109
110
111 if (!fleet.getFaction().isPlayerFaction()) {
112 if (data.from.isHidden()) {
113 text.addPara("If this fleet does not reach its destination safely, it will cause a shortage " +
114 "of the commodities it carries. " +
115 "In addition, its loss would reduce the accessibility of its port of origin by %s for up to three months.",
116 Misc.getTextColor(), Misc.getHighlightColor(), "" + penalty + "%");
117 } else {
118 text.addPara("If this fleet does not reach its destination safely, it will cause a shortage " +
119 "of the commodities it carries. " +
120 "In addition, its loss would reduce the accessbility of " + data.from.getName() + " by %s for up to three months.",
121 Misc.getTextColor(), Misc.getHighlightColor(), "" + penalty + "%");
122 }
123 }
124 }
125 }
126
127 if (!fleet.getFaction().isPlayerFaction() && !fleet.getFaction().isNeutralFaction()) {
128 if (fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.MEMORY_KEY_NO_REP_IMPACT)) {
129 if (Misc.isDecentralized(fleet.getFaction())) {
130// text.addPara("This fleet's behavior falls outside the accepted norms of the faction it nominally belongs to. " +
131// "Engaging it in battle will not cause any changes to your reputation.",
132// Misc.getHighlightColor(), "will not cause any changes to your reputation");
133 text.addPara("Engaging this fleet in battle will not cause any changes to your reputation with the faction it nominally belongs to.",
134 Misc.getHighlightColor(), "will not cause any changes to your reputation");
135 } else {
136 text.addPara("This fleet is operating without official sanction from the faction it nominally belongs to. " +
137 "Engaging it in battle will not cause any changes to your reputation.",
138 Misc.getHighlightColor(), "will not cause any changes to your reputation");
139 }
140 } else if (fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.MEMORY_KEY_LOW_REP_IMPACT) && fleet.knowsWhoPlayerIs()) {
141 if (Misc.isDecentralized(fleet.getFaction())) {
142// text.addPara("This fleet's behavior falls outside the accepted norms of the faction it nominally belongs to. " +
143// "Engaging it in battle will not cause immediate hostilities " +
144// "with the faction it belongs to, though it will slightly strain the relationship.",
145// Misc.getHighlightColor(), "will not cause immediate hostilities");
146 text.addPara("Engaging this fleet in battle will not cause immediate hostilities " +
147 "with the faction it nominally belongs to, though it will slightly strain the relationship.",
148 Misc.getHighlightColor(), "will not cause immediate hostilities");
149 } else {
150 text.addPara("This fleet is either operating in a legal gray area or its behavior " +
151 "falls outside accepted norms. Engaging it in battle will not cause immediate hostilities " +
152 "with the faction it nominally belongs to, though it will slightly strain the relationship.",
153 Misc.getHighlightColor(), "will not cause immediate hostilities");
154 }
155 }
156 }
157
158 return true;
159 }
160
161}
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
boolean getBoolean(String key)