Starsector API
Loading...
Searching...
No Matches
AnalyzeEntityMissionIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel;
2
3import java.awt.Color;
4import java.util.List;
5import java.util.Map;
6import java.util.Set;
7
8import org.apache.log4j.Logger;
9import org.lwjgl.util.vector.Vector2f;
10
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.CampaignFleetAPI;
13import com.fs.starfarer.api.campaign.CargoAPI;
14import com.fs.starfarer.api.campaign.FactionAPI;
15import com.fs.starfarer.api.campaign.InteractionDialogAPI;
16import com.fs.starfarer.api.campaign.RepLevel;
17import com.fs.starfarer.api.campaign.ReputationActionResponsePlugin.ReputationAdjustmentResult;
18import com.fs.starfarer.api.campaign.SectorEntityToken;
19import com.fs.starfarer.api.campaign.econ.MarketAPI;
20import com.fs.starfarer.api.campaign.rules.MemoryAPI;
21import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin;
22import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.MissionCompletionRep;
23import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActionEnvelope;
24import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepActions;
25import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.RepRewards;
26import com.fs.starfarer.api.impl.campaign.ids.Factions;
27import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
28import com.fs.starfarer.api.impl.campaign.ids.Tags;
29import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity;
30import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.BreadcrumbSpecial;
31import com.fs.starfarer.api.ui.SectorMapAPI;
32import com.fs.starfarer.api.ui.TooltipMakerAPI;
33import com.fs.starfarer.api.util.Misc;
34import com.fs.starfarer.api.util.Misc.Token;
35import com.fs.starfarer.api.util.WeightedRandomPicker;
36
38 public static Logger log = Global.getLogger(AnalyzeEntityMissionIntel.class);
39
40 protected int reward;
41 protected FactionAPI faction;
42 protected MarketAPI market;
43
44 protected SectorEntityToken entity;
45
46
47 public AnalyzeEntityMissionIntel(SectorEntityToken entity) {
48 this.entity = entity;
49
50 WeightedRandomPicker<MarketAPI> marketPicker = new WeightedRandomPicker<MarketAPI>();
51 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
52 if (market.isHidden()) continue;
53 if (market.getFaction().isPlayerFaction()) continue;
54 marketPicker.add(market, market.getSize());
55 }
56
57 market = marketPicker.pick();
58 if (market == null) {
60 return;
61 }
62
63 faction = market.getFaction();
64 if (!market.getFaction().isHostileTo(Factions.INDEPENDENT) && (float) Math.random() > 0.67f) {
65 faction = Global.getSector().getFaction(Factions.INDEPENDENT);
66 }
67
68 setDuration(120f);
69
70 reward = (int) Misc.getDistance(new Vector2f(), entity.getLocationInHyperspace());
71 //reward *= 1.25f;
72 reward = 20000 + (reward / 10000) * 10000;
73 if (reward < 10000) reward = 10000;
74
75
76 log.info("Created AnalyzeEntityMissionIntel: " + entity.getName() + ", faction: " + faction.getDisplayName());
77
78
80 setPostingLocation(market.getPrimaryEntity());
81
82 Global.getSector().getIntelManager().queueIntel(this);
83
84 }
85
86 @Override
88 if (isPosted() && (!entity.isAlive() || entity.hasTag(Tags.NON_CLICKABLE))) {
89 cancel();
90 }
91 }
92
93
94
95 public SectorEntityToken getEntity() {
96 return entity;
97 }
98
99 @Override
100 protected MissionResult createAbandonedResult(boolean withPenalty) {
101 if (withPenalty) {
102 MissionCompletionRep rep = new MissionCompletionRep(RepRewards.HIGH, RepLevel.WELCOMING,
103 -RepRewards.TINY, RepLevel.INHOSPITABLE);
104 ReputationAdjustmentResult result = Global.getSector().adjustPlayerReputation(
105 new RepActionEnvelope(RepActions.MISSION_FAILURE, rep,
106 null, null, true, false),
107 faction.getId());
108 return new MissionResult(0, result);
109 }
110 return new MissionResult();
111 }
112
113 @Override
114 protected MissionResult createTimeRanOutFailedResult() {
115 return createAbandonedResult(true);
116 }
117
118 @Override
119 public void missionAccepted() {
120 entity.getMemoryWithoutUpdate().set("$aem_target", true, getDuration());
121 entity.getMemoryWithoutUpdate().set("$aem_eventRef", this, getDuration());
122 Misc.setFlagWithReason(entity.getMemoryWithoutUpdate(), MemFlags.ENTITY_MISSION_IMPORTANT,
123 "aem", true, getDuration());
124 }
125
126
127 @Override
128 public void endMission() {
129 entity.getMemoryWithoutUpdate().unset("$aem_target");
130 entity.getMemoryWithoutUpdate().unset("$aem_eventRef");
131 Misc.setFlagWithReason(entity.getMemoryWithoutUpdate(), MemFlags.ENTITY_MISSION_IMPORTANT,
132 "aem", false, 0f);
134 }
135
136 @Override
137 public void advanceMission(float amount) {
138 }
139
140 @Override
141 public boolean callEvent(String ruleId, final InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
142 String action = params.get(0).getString(memoryMap);
143
144 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
145 CargoAPI cargo = playerFleet.getCargo();
146
147 if (action.equals("runPackage")) {
148 AddRemoveCommodity.addCreditsGainText(reward, dialog.getTextPanel());
149 cargo.getCredits().add(reward);
150
151 MissionCompletionRep rep = new MissionCompletionRep(RepRewards.HIGH, RepLevel.WELCOMING,
152 -RepRewards.TINY, RepLevel.INHOSPITABLE);
153
154 ReputationAdjustmentResult result = Global.getSector().adjustPlayerReputation(
155 new RepActionEnvelope(RepActions.MISSION_SUCCESS, rep,
156 null, dialog.getTextPanel(), true, false),
157 faction.getId());
158 setMissionResult(new MissionResult(reward, result));
159 setMissionState(MissionState.COMPLETED);
160 endMission();
161 }
162
163 return true;
164 }
165
166
167 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
168
169 Color h = Misc.getHighlightColor();
170 Color g = Misc.getGrayColor();
171 float pad = 3f;
172 float opad = 10f;
173
174 float initPad = pad;
175 if (mode == ListInfoMode.IN_DESC) initPad = opad;
176
177 Color tc = getBulletColorForMode(mode);
178
179 bullet(info);
180 boolean isUpdate = getListInfoParam() != null;
181
182 if (isUpdate) {
183 // 3 possible updates: de-posted/expired, failed, completed
184 if (isFailed() || isCancelled()) {
185 return;
186 } else if (isCompleted()) {
187 if (missionResult.payment > 0) {
188 info.addPara("%s received", initPad, tc, h, Misc.getDGSCredits(missionResult.payment));
189 }
191 null, null, info, tc, isUpdate, 0f);
192 }
193 } else {
194 // either in small description, or in tooltip/intel list
195 if (missionResult != null) {
196 if (missionResult.payment > 0) {
197 info.addPara("%s received", initPad, tc, h, Misc.getDGSCredits(missionResult.payment));
198 initPad = 0f;
199 }
200
201 if (missionResult.rep1 != null) {
203 null, null, info, tc, isUpdate, initPad);
204 initPad = 0f;
205 }
206 } else {
207 if (mode != ListInfoMode.IN_DESC) {
208 info.addPara("Faction: " + faction.getDisplayName(), initPad, tc,
209 faction.getBaseUIColor(),
210 faction.getDisplayName());
211 initPad = 0f;
212 }
213
214 info.addPara("%s reward", initPad, tc, h, Misc.getDGSCredits(reward));
215 addDays(info, "to complete", duration - elapsedDays, tc, 0f);
216 }
217 }
218
219 unindent(info);
220 }
221
222 @Override
223 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
224 Color c = getTitleColor(mode);
225 info.addPara(getName(), c, 0f);
226
227 addBulletPoints(info, mode);
228 }
229
230 public String getSortString() {
231 return "Analyze";
232 }
233
234 public String getName() {
235 String name = "";
236// if (entity.getCustomEntitySpec() != null) {
237// name = entity.getCustomEntitySpec().getNameInText();
238// } else {
239 name = entity.getName(); // we want caps on every word since this is a title, so no getNameInText()
240// }
241
242 return "Analyze " + name + getPostfixForState();
243 }
244
245
246 @Override
247 public FactionAPI getFactionForUIColors() {
248 return faction;
249 }
250
251 public String getSmallDescriptionTitle() {
252 return getName();
253 }
254
255
256 @Override
257 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
258 Color h = Misc.getHighlightColor();
259 Color g = Misc.getGrayColor();
260 //Color c = getTitleColor(mode);
261 Color tc = Misc.getTextColor();
262 float pad = 3f;
263 float opad = 10f;
264
265 info.addImage(faction.getLogo(), width, 128, opad);
266
267 String name = "";
268 String shortName = "";
269 String isOrAre = "is";
270 String aOrAn = "a";
271 if (entity.getCustomEntitySpec() != null) {
272 name = entity.getCustomEntitySpec().getNameInText();
273 shortName = entity.getCustomEntitySpec().getShortName();
274 isOrAre = entity.getCustomEntitySpec().getIsOrAre();
275 aOrAn = entity.getCustomEntitySpec().getAOrAn();
276 } else {
277 name = entity.getName();
278 shortName = entity.getName();
279 }
280
281 String authorities = "authorities";
282 if (!faction.getId().equals(market.getFactionId())) {
283 authorities = "concerns";
284 }
285 info.addPara("%s " + authorities + " " + market.getOnOrAt() + " " + market.getName() +
286 " have posted a reward for running a custom sensor package on " + aOrAn + " " + name + ".",
287 opad, faction.getBaseUIColor(), Misc.ucFirst(faction.getPersonNamePrefix()));
288
289 String loc = BreadcrumbSpecial.getLocatedString(entity, true);
290 info.addPara("The " + shortName + " " + isOrAre + " " + loc + ".", opad);
291
292 if (isPosted() || isAccepted()) {
293 addBulletPoints(info, ListInfoMode.IN_DESC);
294
296
297 addAcceptOrAbandonButton(info, width, "Accept", "Abandon");
298 } else {
300
301 addBulletPoints(info, ListInfoMode.IN_DESC);
302 }
303
304 }
305
306 public String getIcon() {
307 return Global.getSettings().getSpriteName("campaignMissions", "analyze_entity");
308 }
309
310 public Set<String> getIntelTags(SectorMapAPI map) {
311 Set<String> tags = super.getIntelTags(map);
312 tags.add(Tags.INTEL_EXPLORATION);
313 tags.add(Tags.INTEL_MISSIONS);
314 tags.add(faction.getId());
315 return tags;
316 }
317
318 @Override
319 public SectorEntityToken getMapLocation(SectorMapAPI map) {
320 if (entity != null && entity.isDiscoverable() && entity.getStarSystem() != null) {
321 return entity.getStarSystem().getCenter();
322 }
323 return entity;
324 }
325
326
327
328}
static SettingsAPI getSettings()
Definition Global.java:51
static Logger getLogger(Class c)
Definition Global.java:26
static SectorAPI getSector()
Definition Global.java:59
static void addAdjustmentMessage(float delta, FactionAPI faction, PersonAPI person, TextPanelAPI panel, TooltipMakerAPI info, Color tc, boolean withCurrent, float pad)
boolean callEvent(String ruleId, final InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
void setPostingLocation(SectorEntityToken postingLocation)
void addDays(TooltipMakerAPI info, String after, float days)
void addAcceptOrAbandonButton(TooltipMakerAPI info, float width)
String getSpriteName(String category, String id)