Starsector API
Loading...
Searching...
No Matches
SurveyPlanetMissionIntel.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.PlanetAPI;
17import com.fs.starfarer.api.campaign.RepLevel;
18import com.fs.starfarer.api.campaign.ReputationActionResponsePlugin.ReputationAdjustmentResult;
19import com.fs.starfarer.api.campaign.SectorEntityToken;
20import com.fs.starfarer.api.campaign.econ.MarketAPI;
21import com.fs.starfarer.api.campaign.econ.MarketAPI.SurveyLevel;
22import com.fs.starfarer.api.campaign.listeners.SurveyPlanetListener;
23import com.fs.starfarer.api.campaign.rules.MemoryAPI;
24import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin;
25import com.fs.starfarer.api.impl.campaign.CoreReputationPlugin.MissionCompletionRep;
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.CoreReputationPlugin.RepRewards;
29import com.fs.starfarer.api.impl.campaign.ids.Factions;
30import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
31import com.fs.starfarer.api.impl.campaign.ids.Tags;
32import com.fs.starfarer.api.ui.SectorMapAPI;
33import com.fs.starfarer.api.ui.TooltipMakerAPI;
34import com.fs.starfarer.api.util.Misc;
35import com.fs.starfarer.api.util.Misc.Token;
36import com.fs.starfarer.api.util.WeightedRandomPicker;
37
38public class SurveyPlanetMissionIntel extends BaseMissionIntel implements SurveyPlanetListener {
39 public static Logger log = Global.getLogger(SurveyPlanetMissionIntel.class);
40
41 protected int reward;
42 protected FactionAPI faction;
43 protected MarketAPI market;
44
45 protected PlanetAPI planet;
46
47
48
49 public SurveyPlanetMissionIntel(PlanetAPI planet) {
50 this.planet = planet;
51
52 WeightedRandomPicker<MarketAPI> marketPicker = new WeightedRandomPicker<MarketAPI>();
53 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
54 if (market.isHidden()) continue;
55 if (market.getFaction().isPlayerFaction()) continue;
56
57 marketPicker.add(market, market.getSize());
58 }
59
60 market = marketPicker.pick();
61 if (market == null) {
63 return;
64 }
65
66 faction = market.getFaction();
67 if (!market.getFaction().isHostileTo(Factions.INDEPENDENT) && (float) Math.random() > 0.67f) {
68 faction = Global.getSector().getFaction(Factions.INDEPENDENT);
69 }
70
71 setDuration(120f);
72
73 reward = (int) Misc.getDistance(new Vector2f(), planet.getLocationInHyperspace());
74 //reward *= 1.25f;
75 reward = 20000 + (reward / 10000) * 10000;
76 if (reward < 10000) reward = 10000;
77
78
79 log.info("Created SurveyPlanetMissionIntel: " + planet.getName() + ", faction: " + faction.getDisplayName());
80
81
83 setPostingLocation(market.getPrimaryEntity());
84
85 Global.getSector().getIntelManager().queueIntel(this);
86
87 }
88
89
90 public PlanetAPI getPlanet() {
91 return planet;
92 }
93
94
95 @Override
96 protected MissionResult createAbandonedResult(boolean withPenalty) {
97 if (withPenalty) {
98 MissionCompletionRep rep = new MissionCompletionRep(RepRewards.HIGH, RepLevel.WELCOMING,
99 -RepRewards.TINY, RepLevel.INHOSPITABLE);
100 ReputationAdjustmentResult result = Global.getSector().adjustPlayerReputation(
101 new RepActionEnvelope(RepActions.MISSION_FAILURE, rep,
102 null, null, true, false),
103 faction.getId());
104 return new MissionResult(0, result);
105 }
106 return new MissionResult();
107 }
108
109
110 @Override
111 protected MissionResult createTimeRanOutFailedResult() {
112 return createAbandonedResult(true);
113 }
114
115
116 @Override
117 public void missionAccepted() {
118 planet.getMemoryWithoutUpdate().set("$spm_target", true, getDuration());
119 planet.getMemoryWithoutUpdate().set("$spm_eventRef", this, getDuration());
120 Misc.setFlagWithReason(planet.getMemoryWithoutUpdate(), MemFlags.ENTITY_MISSION_IMPORTANT,
121 "spm", true, getDuration());
122
123 Global.getSector().getListenerManager().addListener(this);
124 }
125
126
127 @Override
128 public void endMission() {
129 planet.getMemoryWithoutUpdate().unset("$spm_target");
130 planet.getMemoryWithoutUpdate().unset("$spm_eventRef");
131 Misc.setFlagWithReason(planet.getMemoryWithoutUpdate(), MemFlags.ENTITY_MISSION_IMPORTANT,
132 "spm", false, 0f);
133 Global.getSector().getListenerManager().removeListener(this);
134
136 }
137
138 @Override
139 public void advanceMission(float amount) {
140 if (planet.getMarket() != null && planet.getMarket().getSurveyLevel() == SurveyLevel.FULL) {
142 }
143 }
144
145 @Override
146 public boolean callEvent(String ruleId, final InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
147 String action = params.get(0).getString(memoryMap);
148
149 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
150 CargoAPI cargo = playerFleet.getCargo();
151
152// if (action.equals("finishedSurvey")) {
153// AddRemoveCommodity.addCreditsGainText(reward, dialog.getTextPanel());
154// cargo.getCredits().add(reward);
155//
156// MissionCompletionRep rep = new MissionCompletionRep(RepRewards.HIGH, RepLevel.WELCOMING,
157// -RepRewards.TINY, RepLevel.INHOSPITABLE);
158//
159// ReputationAdjustmentResult result = Global.getSector().adjustPlayerReputation(
160// new RepActionEnvelope(RepActions.MISSION_SUCCESS, rep,
161// null, dialog.getTextPanel(), true, false),
162// faction.getId());
163// setMissionResult(new MissionResult(reward, result));
164// setMissionState(MissionState.COMPLETED);
165// endMission();
166// }
167
168 return true;
169 }
170
171 public void reportPlayerSurveyedPlanet(PlanetAPI planet) {
172 if (planet != this.planet) return;
173
174 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
175 CargoAPI cargo = playerFleet.getCargo();
176
177 cargo.getCredits().add(reward);
178
179 MissionCompletionRep rep = new MissionCompletionRep(RepRewards.HIGH, RepLevel.WELCOMING,
180 -RepRewards.TINY, RepLevel.INHOSPITABLE);
181
182 ReputationAdjustmentResult result = Global.getSector().adjustPlayerReputation(
183 new RepActionEnvelope(RepActions.MISSION_SUCCESS, rep,
184 null, null, true, false),
185 faction.getId());
186 setMissionResult(new MissionResult(reward, result));
187 setMissionState(MissionState.COMPLETED);
188 endMission();
190 }
191
192
193
194
195
196 protected void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode) {
197
198 Color h = Misc.getHighlightColor();
199 Color g = Misc.getGrayColor();
200 float pad = 3f;
201 float opad = 10f;
202
203 float initPad = pad;
204 if (mode == ListInfoMode.IN_DESC) initPad = opad;
205
206 Color tc = getBulletColorForMode(mode);
207
208 bullet(info);
209 boolean isUpdate = getListInfoParam() != null;
210
211 if (isUpdate) {
212 // 3 possible updates: de-posted/expired, failed, completed
213 if (isFailed() || isCancelled()) {
214 return;
215 } else if (isCompleted()) {
216 if (missionResult.payment > 0) {
217 info.addPara("%s received", initPad, tc, h, Misc.getDGSCredits(missionResult.payment));
218 }
220 null, null, info, tc, isUpdate, 0f);
221 }
222 } else {
223 // either in small description, or in tooltip/intel list
224 if (missionResult != null) {
225 if (missionResult.payment > 0) {
226 info.addPara("%s received", initPad, tc, h, Misc.getDGSCredits(missionResult.payment));
227 initPad = 0f;
228 }
229
230 if (missionResult.rep1 != null) {
232 null, null, info, tc, isUpdate, initPad);
233 initPad = 0f;
234 }
235 } else {
236 float betweenPad = 0f;
237 if (mode != ListInfoMode.IN_DESC) {
238 info.addPara("Faction: " + faction.getDisplayName(), initPad, tc,
239 faction.getBaseUIColor(),
240 faction.getDisplayName());
241 initPad = betweenPad;
242 } else {
243 betweenPad = 0f;
244 }
245
246 info.addPara("%s reward", initPad, tc, h, Misc.getDGSCredits(reward));
247 addDays(info, "to complete", duration - elapsedDays, tc, betweenPad);
248 }
249 }
250
251 unindent(info);
252 }
253
254 @Override
255 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
256 Color c = getTitleColor(mode);
257 info.addPara(getName(), c, 0f);
258
259 addBulletPoints(info, mode);
260 }
261
262 public String getSortString() {
263 return "Survey";
264 }
265
266 public String getName() {
267 //String name = planet.getName();
268 String name = planet.getTypeNameWithWorld();
269 return "Survey " + name + getPostfixForState();
270 }
271
272
273 @Override
274 public FactionAPI getFactionForUIColors() {
275 return faction;
276 }
277
278 public String getSmallDescriptionTitle() {
279 return getName();
280 }
281
282
283 @Override
284 public void createSmallDescription(TooltipMakerAPI info, float width, float height) {
285 Color h = Misc.getHighlightColor();
286 Color g = Misc.getGrayColor();
287 Color tc = Misc.getTextColor();
288 float pad = 3f;
289 float opad = 10f;
290
291 info.addImage(faction.getLogo(), width, 128, opad);
292
293 String name = planet.getName();
294
295 String authorities = "authorities";
296 if (!faction.getId().equals(market.getFactionId())) {
297 authorities = "concerns";
298 }
299
300 info.addPara("%s " + authorities + " " + market.getOnOrAt() + " " + market.getName() +
301 " have posted a reward for completing a full survey of " + name + ", " +
302 planet.getSpec().getAOrAn() + " " + planet.getTypeNameWithWorld().toLowerCase() + ".",
303 opad, faction.getBaseUIColor(), Misc.ucFirst(faction.getPersonNamePrefix()));
304
305
306 if (isPosted() || isAccepted()) {
307 addBulletPoints(info, ListInfoMode.IN_DESC);
308
309 info.showFullSurveyReqs(planet, true, opad);
310
311// SurveyPlugin plugin = (SurveyPlugin) Global.getSettings().getNewPluginInstance("surveyPlugin");
312// plugin.init(Global.getSector().getPlayerFleet(), planet);
313//
314//
315// Map<String, Integer> required = plugin.getRequired();
316// Map<String, Integer> consumed = plugin.getConsumed();
317//
318// StatBonus stat = new StatBonus();
319// int id = 0;
320// for (String key : required.keySet()) {
321// CommoditySpecAPI com = Global.getSettings().getCommoditySpec(key);
322// int qty = required.get(key);
323//
324// stat.modifyFlat("" + id++, qty, Misc.ucFirst(com.getLowerCaseName()));
325// }
326// for (String key : consumed.keySet()) {
327// CommoditySpecAPI com = Global.getSettings().getCommoditySpec(key);
328// int qty = consumed.get(key);
329//
330// stat.modifyFlat("" + id++, qty, Misc.ucFirst(com.getLowerCaseName()));
331// }
332//
333// info.addPara("The following resources are required for your fleet to run a full survey of " + name + ":", opad);
334// info.setLowGridRowHeight();
335// info.addStatModGrid(200, 50f, opad, opad, stat, new StatModValueGetter() {
336// public String getPercentValue(StatMod mod) { return null; }
337// public String getMultValue(StatMod mod) { return null; }
338// public Color getModColor(StatMod mod) { return null; }
339// public String getFlatValue(StatMod mod) {
340// return "" + (int)mod.value;
341// }
342// });
343
345
346 addAcceptOrAbandonButton(info, width, "Accept", "Abandon");
347 } else {
349
350 addBulletPoints(info, ListInfoMode.IN_DESC);
351 }
352
353 }
354
355 public String getIcon() {
356 return Global.getSettings().getSpriteName("campaignMissions", "survey_planet");
357 }
358
359 public Set<String> getIntelTags(SectorMapAPI map) {
360 Set<String> tags = super.getIntelTags(map);
361 tags.add(Tags.INTEL_EXPLORATION);
362 tags.add(Tags.INTEL_MISSIONS);
363 tags.add(faction.getId());
364 return tags;
365 }
366
367 @Override
368 public SectorEntityToken getMapLocation(SectorMapAPI map) {
369 return planet;
370 }
371
372
373
374}
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)
void setPostingLocation(SectorEntityToken postingLocation)
void addDays(TooltipMakerAPI info, String after, float days)
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
void addAcceptOrAbandonButton(TooltipMakerAPI info, float width)
void createSmallDescription(TooltipMakerAPI info, float width, float height)
boolean callEvent(String ruleId, final InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)
String getSpriteName(String category, String id)