Starsector API
Loading...
Searching...
No Matches
BaseEventIntel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.List;
7import java.util.Random;
8import java.util.Set;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.InteractionDialogAPI;
12import com.fs.starfarer.api.campaign.TextPanelAPI;
13import com.fs.starfarer.api.campaign.listeners.EconomyTickListener;
14import com.fs.starfarer.api.impl.campaign.ids.Tags;
15import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
16import com.fs.starfarer.api.ui.Alignment;
17import com.fs.starfarer.api.ui.CustomPanelAPI;
18import com.fs.starfarer.api.ui.EventProgressBarAPI;
19import com.fs.starfarer.api.ui.SectorMapAPI;
20import com.fs.starfarer.api.ui.TooltipMakerAPI;
21import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
22import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipLocation;
23import com.fs.starfarer.api.ui.UIComponentAPI;
24import com.fs.starfarer.api.util.Misc;
25
35public class BaseEventIntel extends BaseIntelPlugin implements EconomyTickListener {
36
40 public static final String RANDOM_EVENT_NONE = "random_event_none";
41
42 public static enum StageIconSize {
43 SMALL,
44 MEDIUM,
45 LARGE,
46 }
47 public static enum RandomizedStageType {
48 GOOD,
49 BAD,
50 NEUTRAL,
51 }
52
56 public static class EventStageDisplayData {
57 public float size;
58 public float downLineLength;
59 public String icon;
60 public Color color;
61 public Color iconColor = Color.white;
62 public String label;
63 public Color labelColor;
64 public int importance = 0;
65 }
66
67 public static class EventStageData {
68 public Object id;
69 public int progress;
70 public boolean isOneOffEvent;
71 public boolean wasEverReached = false;
72 public boolean isRepeatable = true;
73 public boolean sendIntelUpdateOnReaching = true;
74 public boolean hideIconWhenPastStageUnlessLastActive = false;
75 public boolean keepIconBrightWhenLaterStageReached = false;
76 public StageIconSize iconSize = StageIconSize.MEDIUM;
77
78 public boolean randomized = false;
79 public RandomizedStageType randomType = RandomizedStageType.NEUTRAL;
80 public int progressToResetAt;
81 public int progressToRollAt;
82 public Object rollData;
83
84 public EventStageData(Object id, int progress, boolean isOneOffEvent) {
85 this(id, progress, isOneOffEvent, StageIconSize.MEDIUM);
86 }
87 public EventStageData(Object id, int progress, boolean isOneOffEvent, StageIconSize iconSize) {
88 this.id = id;
89 this.progress = progress;
90 this.isOneOffEvent = isOneOffEvent;
91 this.iconSize = iconSize;
92 }
93
94 public void addProgressReq(TooltipMakerAPI tooltip, float pad) {
95 tooltip.addPara("Requires %s points of event progress.",
96 pad, Misc.getHighlightColor(), "" + progress);
97 }
98 public void addResetReq(TooltipMakerAPI tooltip, float pad) {
99 addResetReq(tooltip, false, pad);
100 }
101 public void beginResetReqList(TooltipMakerAPI tooltip, boolean withAvertInfo, float initPad) {
102 beginResetReqList(tooltip, withAvertInfo, "outcome", initPad);
103 }
104 public void beginResetReqList(TooltipMakerAPI tooltip, boolean withAvertInfo, String outcome, float initPad) {
105 float opad = 10f;
106 float pad = 3f;
107 tooltip.addPara("This " + outcome + " will be averted if:", initPad);
108 tooltip.setBulletedListMode(BaseIntelPlugin.BULLET);
109 if (withAvertInfo) {
110 tooltip.addPara("Event progress is reduced to %s points or below",
111 pad, Misc.getHighlightColor(), "" + progressToResetAt);
112 }
113
114 }
115 public void endResetReqList(TooltipMakerAPI tooltip, boolean withTriggeredResetInfo) {
116 endResetReqList(tooltip, withTriggeredResetInfo, "outcome", -1, -1);
117 }
118 public void endResetReqList(TooltipMakerAPI tooltip, boolean withTriggeredResetInfo, String outcome, int min, int max) {
119 tooltip.setBulletedListMode(null);
120 if (withTriggeredResetInfo) {
121 float opad = 10f;
122 if (min < 0 || max < 0) {
123 tooltip.addPara("If this " + outcome + " is triggered, event progress will be reset to a much lower value afterwards.",
124 opad);
125 } else {
126 tooltip.addPara("If this " + outcome + " is triggered, event progress will be reset to between %s and %s points.",
127 opad, Misc.getHighlightColor(), "" + min, "" + max);
128 }
129 }
130 }
131
132 public void addResetReq(TooltipMakerAPI tooltip, boolean withResetIfTriggered, float pad) {
133 addResetReq(tooltip, withResetIfTriggered, "outcome", -1, -1, pad);
134 }
135 public void addResetReq(TooltipMakerAPI tooltip, boolean withResetIfTriggered, String outcome, int min, int max, float pad) {
136 if (withResetIfTriggered) {
137 if (min < 0 || max < 0) {
138 tooltip.addPara("This " + outcome + " will be averted if event progress is reduced to %s points or below. "
139 + "If this " + outcome + " is triggered, event progress will be reset to a lower value afterwards.",
140 pad, Misc.getHighlightColor(), "" + progressToResetAt);
141 } else {
142 tooltip.addPara("This " + outcome + " will be averted if event progress is reduced to %s points or below. "
143 + "If this " + outcome + " is triggered, event progress will be reset to between %s and %s points.",
144 pad, Misc.getHighlightColor(), "" + progressToResetAt, "" + min, "" + max);
145 }
146 } else {
147 tooltip.addPara("This " + outcome + " will be averted if event progress is reduced to %s points or below.",
148 pad, Misc.getHighlightColor(), "" + progressToResetAt);
149 }
150 }
151 }
152
153 protected int progress = 0;
154 protected int maxProgress = 1000;
155
156 //protected Object startingStage;
157 protected List<EventStageData> stages = new ArrayList<EventStageData>();
158 protected IntelSortTier sortTier;
159
160 protected List<EventFactor> factors = new ArrayList<EventFactor>();
161 protected Random random = new Random();
162
163 protected float progressDeltaRemainder = 0f;
164 protected transient float uiWidth;
165
166 public BaseEventIntel() {
167 setSortTier(IntelSortTier.TIER_2);
168
169 Global.getSector().addScript(this);
170 // this needs to be done in sub-classes since it sends out an intel update
171 // and that won't have the right data because the event isn't finished
172 // being constructed here - it needs stages etc added to it
173 //Global.getSector().getIntelManager().addIntel(this);
174 Global.getSector().getListenerManager().addListener(this);
175 }
176
177 @Override
178 protected void advanceImpl(float amount) {
179 super.advanceImpl(amount);
180
181 List<EventFactor> remove = new ArrayList<EventFactor>();
182 for (EventFactor curr : factors) {
183 if (curr.isExpired()) {
184 remove.add(curr);
185 continue;
186 }
187
188 curr.advance(amount);
189
190 if (curr.isExpired()) {
191 remove.add(curr);
192 }
193 }
194 factors.removeAll(remove);
195 for (EventFactor factor : remove) {
196 factor.notifyFactorRemoved();
197 }
198 }
199
200
201
202 @Override
203 public void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode) {
204 Color c = getTitleColor(mode);
205 boolean large = true;
206 if (large) info.setParaSmallInsignia();
207 info.addPara(getName(), c, 0f);
208 //info.addPara("Hostile Activity", c, 0f);
209 if (large) info.setParaFontDefault();
210 addBulletPoints(info, mode);
211 }
212
213 protected boolean addEventFactorBulletPoints(TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate,
214 Color tc, float initPad) {
215 if (isUpdate && getListInfoParam() instanceof EventFactor) {
217 if (factor.isOneTime()) {
218 factor.addBulletPointForOneTimeFactor(this, info, tc, initPad);
219 }
220 return true;
221 }
222 return false;
223 }
224
225
226 @Override
227 public void createLargeDescription(CustomPanelAPI panel, float width, float height) {
228
229 float opad = 10f;
230 uiWidth = width;
231
232 // TODO DEBUG
233 //setProgress(900);
234 //setProgress((int) (0 + (float) Math.random() * 400));
235 //setProgress(900);
236 //setProgress(499);
237 //setProgress(200);
238 //setProgress(0);
239
240 TooltipMakerAPI main = panel.createUIElement(width, height, true);
241
242 main.setTitleOrbitronVeryLarge();
243 main.addTitle(getName(), Misc.getBasePlayerColor());
244
245 EventProgressBarAPI bar = main.addEventProgressBar(this, 100f);
246 TooltipCreator barTC = getBarTooltip();
247 if (barTC != null) {
248 main.addTooltipToPrevious(barTC, TooltipLocation.BELOW, false);
249 }
250
251 for (EventStageData curr : stages) {
252 if (curr.progress <= 0) continue; // no icon for "starting" stage
253 //if (curr.rollData == null || curr.rollData.equals(RANDOM_EVENT_NONE)) continue;
254 if (RANDOM_EVENT_NONE.equals(curr.rollData)) continue;
255 if (curr.wasEverReached && curr.isOneOffEvent && !curr.isRepeatable) continue;
256
257 if (curr.hideIconWhenPastStageUnlessLastActive &&
258 curr.progress <= progress &&
259 getLastActiveStage(true) != curr) {
260 continue;
261 }
262
263 EventStageDisplayData data = createDisplayData(curr.id);
264 UIComponentAPI marker = main.addEventStageMarker(data);
265 float xOff = bar.getXCoordinateForProgress(curr.progress) - bar.getPosition().getX();
266 marker.getPosition().aboveLeft(bar, data.downLineLength).setXAlignOffset(xOff - data.size / 2f - 1);
267
268 TooltipCreator tc = getStageTooltip(curr.id);
269 if (tc != null) {
270 main.addTooltipTo(tc, marker, TooltipLocation.LEFT, false);
271 }
272 }
273
274 // progress indicator
275 {
276 UIComponentAPI marker = main.addEventProgressMarker(this);
277 float xOff = bar.getXCoordinateForProgress(progress) - bar.getPosition().getX();
278 marker.getPosition().belowLeft(bar, -getBarProgressIndicatorHeight() * 0.5f - 2)
279 .setXAlignOffset(xOff - getBarProgressIndicatorWidth() / 2 - 1);
280 }
281
282 main.addSpacer(opad);
283 main.addSpacer(opad);
284 for (EventStageData curr : stages) {
285 if (curr.wasEverReached && curr.isOneOffEvent && !curr.isRepeatable) continue;
286 addStageDescriptionWithImage(main, curr.id);
287 }
288
289
290
291 float barW = getBarWidth();
292 float factorWidth = (barW - opad) / 2f;
293
295 //factorWidth = barW;
296 factorWidth = (int) (barW * 0.6f);
297 }
298
299 TooltipMakerAPI mFac = main.beginSubTooltip(factorWidth);
300
301 Color c = getFactionForUIColors().getBaseUIColor();
302 Color bg = getFactionForUIColors().getDarkUIColor();
303 mFac.addSectionHeading("Monthly factors", c, bg, Alignment.MID, opad).getPosition().setXAlignOffset(0);
304
305 float strW = 40f;
306 float rh = 20f;
307 //rh = 15f;
308 mFac.beginTable2(getFactionForUIColors(), rh, false, false,
309 "Monthly factors", factorWidth - strW - 3,
310 "Progress", strW
311 );
312
313 for (EventFactor factor : factors) {
314 if (factor.isOneTime()) continue;
315 if (!factor.shouldShow(this)) continue;
316
317 String desc = factor.getDesc(this);
318 if (desc != null) {
319 mFac.addRowWithGlow(Alignment.LMID, factor.getDescColor(this), desc,
320 Alignment.RMID, factor.getProgressColor(this), factor.getProgressStr(this));
321 TooltipCreator t = factor.getMainRowTooltip(this);
322 if (t != null) {
323 mFac.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
324 }
325 }
326 factor.addExtraRows(mFac, this);
327 }
328
329 //mFac.addButton("TEST", new String(), factorWidth, 20f, opad);
330 mFac.addTable("None", -1, opad);
331 mFac.getPrev().getPosition().setXAlignOffset(-5);
332
333 main.endSubTooltip();
334
335 TooltipMakerAPI oFac = main.beginSubTooltip(factorWidth);
336
337 oFac.addSectionHeading("Recent one-time factors", c, bg, Alignment.MID, opad).getPosition().setXAlignOffset(0);
338
339 oFac.beginTable2(getFactionForUIColors(), 20f, false, false,
340 "One-time factors", factorWidth - strW - 3,
341 "Progress", strW
342 );
343
344 List<EventFactor> reversed = new ArrayList<EventFactor>(factors);
345 Collections.reverse(reversed);
346 for (EventFactor factor : reversed) {
347 if (!factor.isOneTime()) continue;
348 if (!factor.shouldShow(this)) continue;
349
350 String desc = factor.getDesc(this);
351 if (desc != null) {
352 oFac.addRowWithGlow(Alignment.LMID, factor.getDescColor(this), desc,
353 Alignment.RMID, factor.getProgressColor(this), factor.getProgressStr(this));
354 TooltipCreator t = factor.getMainRowTooltip(this);
355 if (t != null) {
356 oFac.addTooltipToAddedRow(t, TooltipLocation.LEFT);
357 }
358 }
359 factor.addExtraRows(oFac, this);
360 }
361
362 oFac.addTable("None", -1, opad);
363 oFac.getPrev().getPosition().setXAlignOffset(-5);
364 main.endSubTooltip();
365
366
367 float factorHeight = Math.max(mFac.getHeightSoFar(), oFac.getHeightSoFar());
368 mFac.setHeightSoFar(factorHeight);
369 oFac.setHeightSoFar(factorHeight);
370
371
373 main.addCustom(mFac, opad * 2f);
374 main.addCustomDoNotSetPosition(oFac).getPosition().rightOfTop(mFac, opad);
375 } else if (withMonthlyFactors()) {
376 main.addCustom(mFac, opad * 2f);
377 } else if (withOneTimeFactors()) {
378 main.addCustom(oFac, opad * 2f);
379 }
380
381 //main.addButton("TEST", new String(), factorWidth, 20f, opad);
382
383 panel.addUIElement(main).inTL(0, 0);
384 }
385
386 public TooltipCreator getBarTooltip() {
387 return new TooltipCreator() {
388 public boolean isTooltipExpandable(Object tooltipParam) {
389 return false;
390 }
391 public float getTooltipWidth(Object tooltipParam) {
392 return 450;
393 }
394
395 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
396 float opad = 10f;
397 Color h = Misc.getHighlightColor();
398
399 tooltip.addPara("Event progress: %s out of %s points.", 0f, h, "" + progress, "" + maxProgress);
400 int p = getMonthlyProgress();
401 String pStr = "" + p;
402 if (p > 0) pStr = "+" + p;
403 tooltip.addPara("Projected monthly progress: %s points.", opad, getProgressColor(p), pStr);
404
405 tooltip.addPara("Event progress is influenced by various factors. Some of these apply over time, "
406 + "and some only apply once. As the event progresses, "
407 + "different stages and outcomes may unfold.", opad);
408 }
409 };
410 }
411 public TooltipCreator getStageTooltip(Object stageId) {
412 final EventStageData esd = getDataFor(stageId);
413 if (esd == null || (esd.randomized && (esd.rollData == null || RANDOM_EVENT_NONE.equals(esd.rollData)))) {
414 return new TooltipCreator() {
415 public boolean isTooltipExpandable(Object tooltipParam) {
416 return false;
417 }
418 public float getTooltipWidth(Object tooltipParam) {
420 }
421
422 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
423 float opad = 10f;
424 Color h = Misc.getHighlightColor();
425
426 tooltip.addPara("Something might occur when event progress reaches %s points. "
427 + "What that is, if anything, will be determined when event progress reaches "
428 + "%s points.", 0f,
429 h, "" + esd.progress, "" + esd.progressToRollAt);
430
431 if (esd.isRepeatable) {
432 tooltip.addPara("This event is repeatable.", opad);
433 } else {
434 tooltip.addPara("This event is not repeatable.", opad);
435 }
436 }
437 };
438 }
439 return getStageTooltipImpl(stageId);
440 }
441 public TooltipCreator getStageTooltipImpl(Object stageId) {
442 return null;
443 }
444
445 public float getImageSizeForStageDesc(Object stageId) {
446 return 64f;
447 }
448 public float getImageIndentForStageDesc(Object stageId) {
449 return 0f;
450 }
451
452 public void addStageDescriptionWithImage(TooltipMakerAPI main, Object stageId) {
453 EventStageDisplayData data = createDisplayData(stageId);
454 String icon;
455 if (data != null) {
456 icon = data.icon;
457 } else {
458 icon = getIcon();
459 }
460 float imageSize = getImageSizeForStageDesc(stageId);
461 float opad = 10f;
462 float indent = 0;
463 indent = 10f;
465 float width = getBarWidth() - indent * 2f;
466
467
468 TooltipMakerAPI info = main.beginImageWithText(icon, imageSize, width, true);
469 //TooltipMakerAPI info = main.beginImageWithText("graphics/icons/missions/ga_intro.png", 64);
470 addStageDescriptionText(info, width - imageSize - opad, stageId);
471 if (info.getHeightSoFar() > 0) {
472 main.addImageWithText(opad).getPosition().setXAlignOffset(indent);
473 main.addSpacer(0).getPosition().setXAlignOffset(-indent);
474 }
475 }
476
477 public void addStageDescriptionText(TooltipMakerAPI info, float width, Object stageId) {
478
479 }
480
481
482 public EventStageDisplayData createDisplayData(Object stageId) {
483 EventStageDisplayData data = new EventStageDisplayData();
484 data.size = getStageIconSize(stageId);
485 data.downLineLength = getStageDownLineLength(stageId);
486 data.color = getStageColor(stageId);
487 data.icon = getStageIcon(stageId);
488 data.iconColor = getStageIconColor(stageId);
489 data.importance = getStageImportance(stageId);
490 data.label = getStageLabel(stageId);
491 data.labelColor = getStageLabelColor(stageId);
492 return data;
493 }
494
495 protected String getStageIcon(Object stageId) {
496 EventStageData esd = getDataFor(stageId);
497 if (esd == null || (esd.randomized && (esd.rollData == null || RANDOM_EVENT_NONE.equals(esd.rollData)))) {
498 if (esd.randomType == RandomizedStageType.GOOD) {
499 return Global.getSettings().getSpriteName("events", "stage_unknown_good");
500 } else if (esd.randomType == RandomizedStageType.BAD) {
501 return Global.getSettings().getSpriteName("events", "stage_unknown_bad");
502 }
503 return Global.getSettings().getSpriteName("events", "stage_unknown_neutral");
504 }
505 return getStageIconImpl(stageId);
506
507 }
508 protected String getStageIconImpl(Object stageId) {
509 return Global.getSettings().getSpriteName("events", "stage_unknown");
510 }
511
512 protected float getStageIconSize(Object stageId) {
513 EventStageData esd = getDataFor(stageId);
514 if (esd != null && esd.iconSize == StageIconSize.SMALL) return 32;
515 if (esd != null && esd.iconSize == StageIconSize.LARGE) return 48;
516 return 40;
517 //return 32;
518 }
519
520 protected float getStageDownLineLength(Object stageId) {
521 EventStageData esd = getDataFor(stageId);
522 //if (esd != null && esd.iconSize == StageIconSize.SMALL) return 24;
523 //if (esd != null && esd.iconSize == StageIconSize.SMALL) return 56; // level with top of LARGE
524 if (esd != null && esd.iconSize == StageIconSize.SMALL) return 48; // level with middle of LARGE
525 if (esd != null && esd.iconSize == StageIconSize.LARGE) return 40;
526 return 32;
527 }
528
529
530 public float getBarWidth() {
531 //return uiWidth - 200f;
532 return 750f;
533 }
534 public float getBarHeight() {
535 return 20f;
536 }
537
539 float test = (float)progress / (float)maxProgress * getBarWidth();
540 return test < 50;
541 }
542
544 return 20f;
545 }
547 return 20f;
548 }
550 return Misc.getHighlightColor();
551 }
553 return getBarColor();
554 }
555 public Color getBarBracketColor() {
556 if (true) return Misc.getBasePlayerColor();
557 return getBarColor();
558 }
559
560 public Color getBarColor() {
561 Color color = Misc.getBasePlayerColor();
562 color = Misc.interpolateColor(color, Color.black, 0.25f);
563 return color;
564 }
565
566 protected Color getBaseStageColor(Object stageId) {
567 return getBarColor();
568 }
569 protected Color getDarkStageColor(Object stageId) {
570 Color color = getBarColor();
571 color = Misc.interpolateColor(color, Color.black, 0.5f);
572 return color;
573 }
574 protected Color getStageColor(Object stageId) {
575 int req = getRequiredProgress(stageId);
576
577 EventStageData last = getLastActiveStage(false);
578 EventStageData esd = getDataFor(stageId);
579 boolean grayItOut = false;
580 if (last != null && esd != null && last != esd && !esd.isOneOffEvent &&
581 !esd.keepIconBrightWhenLaterStageReached &&
582 esd.progress < last.progress) {
583 grayItOut = true;
584 }
585
586 if (esd != null && esd.randomized && esd.rollData != null) {
587 return getBaseStageColor(stageId);
588 }
589
590 if (req > progress || grayItOut) {
591 return getDarkStageColor(stageId);
592 }
593 return getBaseStageColor(stageId);
594 }
595 protected Color getStageIconColor(Object stageId) {
596 int req = getRequiredProgress(stageId);
597
598 EventStageData last = getLastActiveStage(false);
599 EventStageData esd = getDataFor(stageId);
600 boolean grayItOut = false;
601 if (last != null && esd != null && last != esd && !esd.isOneOffEvent &&
602 !esd.keepIconBrightWhenLaterStageReached &&
603 esd.progress < last.progress) {
604 grayItOut = true;
605 }
606
607 if (esd != null && esd.randomized && esd.rollData != null) {
608 return Color.white;
609 }
610
611 if (req > progress || grayItOut) {
612 return new Color(255,255,255,155);
613 }
614 return Color.white;
615 }
616 protected int getStageImportance(Object stageId) {
617 return 0;
618 }
619 protected String getStageLabel(Object stageId) {
620 Object least = null;
621 int min = Integer.MAX_VALUE;
622 for (EventStageData curr : stages) {
623 int req = curr.progress;
624 if (req > progress && req < min) {
625 min = req;
626 least = curr.id;
627 }
628 }
629 if (stageId.equals(least)) {
630 return "" + getRequiredProgress(least);
631 }
632 return null;
633 }
634 protected Color getStageLabelColor(Object stageId) {
635 return Misc.getHighlightColor();
636 }
637
638 @Override
639 public Set<String> getIntelTags(SectorMapAPI map) {
640 Set<String> tags = super.getIntelTags(map);
641 tags.add(Tags.INTEL_MAJOR_EVENT);
642 return tags;
643 }
644
645 @Override
646 public boolean hasSmallDescription() {
647 return false;
648 }
649
650 @Override
651 public boolean hasLargeDescription() {
652 return true;
653 }
654
655 public int getMaxProgress() {
656 return maxProgress;
657 }
658
659 public void setMaxProgress(int maxProgress) {
660 this.maxProgress = maxProgress;
661 }
662
663 public List<EventStageData> getStages() {
664 return stages;
665 }
666
667
668 public boolean isStageOrOneOffEventReached(Object stageId) {
669 return progress >= getRequiredProgress(stageId);
670 }
671
672 public boolean isStageActiveAndLast(Object stageId) {
673 return isStageActiveAndLast(stageId, false);
674 }
675 public boolean isStageActiveAndLast(Object stageId, boolean includeOneOffEvents) {
676 EventStageData data = getLastActiveStage(includeOneOffEvents);
677 //if (data == null) return startingStage == stageId;
678 if (data == null) return false;
679 return data.id == stageId; // assuming stageId will be enums, so == check is ok
680 }
681
682// public boolean isStageActive(Object stageId) {
683// EventStageData data = getDataFor(stageId);
684// if (data == null) return false;
685// return data.progress <= getProgress();
686// }
687
688
689// public Object getStartingStage() {
690// return startingStage;
691// }
692// public void setStartingStage(Object startingStage) {
693// this.startingStage = startingStage;
694// }
695
696 public void addStage(Object id, int progress) {
697 addStage(id, progress, StageIconSize.MEDIUM);
698 }
699 public void addStage(Object id, int progress, StageIconSize iconSize) {
700 addStage(id, progress, false, iconSize);
701 }
702 public void addStage(Object id, int progress, boolean isOneOffEvent) {
703 addStage(id, progress, isOneOffEvent, StageIconSize.MEDIUM);
704 }
705 public void addStage(Object id, int progress, boolean isOneOffEvent, StageIconSize iconSize) {
706 stages.add(new EventStageData(id, progress, isOneOffEvent, iconSize));
707 }
708
709 public boolean isStageActive(Object stageId) {
710 EventStageData data = getDataFor(stageId);
711 if (data == null) return false;
712 return data.progress <= getProgress();
713
714 }
715 public EventStageData getLastActiveStage(boolean includeOneOffEvents) {
716 EventStageData last = null;
717 int max = Integer.MIN_VALUE;
718 for (EventStageData curr : stages) {
719 if (!includeOneOffEvents && curr.isOneOffEvent) continue;
720
721 int req = curr.progress;
722 if (progress >= req && req > max) {
723 max = req;
724 last = curr;
725 }
726 }
727 return last;
728 }
729
730 public EventStageData getDataFor(Object stageId) {
731 for (EventStageData curr : stages) {
732 if (stageId.equals(curr.id)) return curr;
733 }
734 return null;
735 }
736
737 public int getRequiredProgress(Object stageId) {
738 //if (stageId == startingStage) return 0;
739 EventStageData data = getDataFor(stageId);
740 return data == null ? 0 : data.progress;
741 }
742
743 public void setSortTier(IntelSortTier sortTier) {
744 this.sortTier = sortTier;
745 }
746
747 @Override
748 public IntelSortTier getSortTier() {
749 if (sortTier == null || isEnding() || isEnded()) return super.getSortTier();
750 return sortTier;
751 }
752
753
754 @Override
755 protected void notifyEnded() {
756 super.notifyEnded();
757 Global.getSector().removeScript(this);
758 for (EventFactor factor : factors) {
759 factor.notifyEventEnded();
760 }
761 }
762
763
764 @Override
765 protected void notifyEnding() {
766 super.notifyEnding();
767// for (MarketAPI curr : getAffectedMarkets()) {
768// if (curr.hasCondition(Conditions.HOSTILE_ACTIVITY)) {
769// curr.removeCondition(Conditions.HOSTILE_ACTIVITY);
770// }
771// }
772 Global.getSector().getListenerManager().removeListener(this);
773 for (EventFactor factor : factors) {
774 factor.notifyEventEnding();
775 }
776 }
777
778 public void addFactor(EventFactor factor) {
779 addFactor(factor, null);
780 }
787 protected transient InteractionDialogAPI addingFactorDialog = null;
788 public void addFactor(EventFactor factor, InteractionDialogAPI dialog) {
789 addingFactorDialog = dialog;
790 factors.add(factor);
791 if (factor.isOneTime()) {
792 if (factor.getProgress(this) != 0) {
793 TextPanelAPI textPanel = dialog == null ? null : dialog.getTextPanel();
794 sendUpdateIfPlayerHasIntel(factor, textPanel);
795 }
796 setProgress(getProgress() + factor.getProgress(this));
797 }
798 addingFactorDialog = null;
799 }
800 public TextPanelAPI getTextPanelForStageChange() {
801 if (addingFactorDialog == null) return null;
802 return addingFactorDialog.getTextPanel();
803 }
804
805 public List<EventFactor> getFactors() {
806 return factors;
807 }
808
810 for (EventFactor f : getFactors()) {
811 if (f.getClass() == c) {
812 return f;
813 }
814 }
815 return null;
816 }
817
818 public void removeFactor(EventFactor factor) {
819 factors.remove(factor);
820 factor.notifyFactorRemoved();
821 }
822
823 public void removeFactorOfClass(Class<EventFactor> c) {
824 List<EventFactor> remove = new ArrayList<EventFactor>();
825 for (EventFactor curr : factors) {
826 if (c.isInstance(curr)) {
827 remove.add(curr);
828 }
829 }
830 factors.removeAll(remove);
831 for (EventFactor factor : remove) {
832 factor.notifyFactorRemoved();
833 }
834 }
835
837 return false;
838 }
839
840
842 return 1000000;
843 }
844
845 public int getMonthlyProgress() {
846 int total = 0;
847 float mult = 1f;
848 for (EventFactor factor : factors) {
849 if (factor.isOneTime()) continue;
850 total += factor.getProgress(this);
851 mult *= factor.getAllProgressMult(this);
852 }
853
854 if (total != 0) {
855 float sign = Math.signum(total);
856 total = Math.round(sign * Math.abs(total) * mult);
857 if (total == 0) total = (int) Math.round(1f * sign);
858 }
859
860 total = Math.min(total, getMaxMonthlyProgress());
861
862 return total;
863 }
864
865
866 public void reportEconomyTick(int iterIndex) {
867 float delta = getMonthlyProgress();
868
869 if (delta <= 0 && this instanceof HostileActivityEventIntel) {
870 setProgress(0);
871 return;
872 }
873
874 float numIter = Global.getSettings().getFloat("economyIterPerMonth");
875 float f = 1f / numIter;
876
877 delta *= f;
878 delta += progressDeltaRemainder;
879
880 int apply = (int) delta;
881
882 progressDeltaRemainder = delta - (float) apply;
883
884 setProgress(progress + apply);
885
886 }
887
888 public int getProgress() {
889 return progress;
890 }
891
892 protected transient boolean prevProgressDeltaWasPositive = false;
893 public void setProgress(int progress) {
894 if (this.progress == progress) return;
895
896 if (progress < 0) progress = 0;
898
899 EventStageData prev = getLastActiveStage(true);
900 prevProgressDeltaWasPositive = this.progress < progress;
901
902 //progress += 30;
903 //progress = 40;
904 //progress = 40;
905 //progress = 499;
906
907 this.progress = progress;
908
909
910 if (progress < 0) {
911 progress = 0;
912 }
913 if (progress > getMaxProgress()) {
915 }
916
917 // Check to see if randomized events need to be rolled/reset
918 for (EventStageData esd : getStages()) {
919 if (esd.wasEverReached && esd.isOneOffEvent && !esd.isRepeatable) continue;
920
921 if (esd.randomized) {
922 if ((esd.rollData != null && !esd.rollData.equals(RANDOM_EVENT_NONE)) && progress <= esd.progressToResetAt) {
924 }
925 if ((esd.rollData == null || esd.rollData.equals(RANDOM_EVENT_NONE)) && progress >= esd.progressToRollAt) {
927 if (esd.rollData == null) {
928 esd.rollData = RANDOM_EVENT_NONE;
929 }
930 }
931 }
932 }
933
934 // go through all of the stages made active by the new progress value
935 // generally this'd just be one stage, but possible to have multiple for a large
936 // progress increase
937 for (EventStageData curr : getStages()) {
938 if (curr.progress <= prev.progress && !prev.wasEverReached &&
939 (prev.rollData == null || prev.rollData.equals(RANDOM_EVENT_NONE))) continue;
940 //if (curr.progress > progress) continue;
941
942 // reached
943 if (curr.progress <= progress) {
944 boolean laterThanPrev = prev == null || ((Enum)prev.id).ordinal() < ((Enum)curr.id).ordinal();
945 if (curr != null && (laterThanPrev || !prev.wasEverReached)) {
946 if (curr.sendIntelUpdateOnReaching && curr.progress > 0 && (prev == null || prev.progress < curr.progress)) {
948 }
949 notifyStageReached(curr);
950 curr.rollData = null;
951 curr.wasEverReached = true;
952
953 progress = getProgress(); // in case it was changed by notifyStageReached()
954 }
955 }
956 }
957 }
958
959 protected String getSoundForStageReachedUpdate(Object stageId) {
960 return getSoundMajorPosting();
961 }
963 return null;
964 }
965 protected String getSoundForOtherUpdate(Object param) {
966 return null;
967 }
968
969 public String getCommMessageSound() {
970 if (isSendingUpdate()) {
971 if (getListInfoParam() instanceof EventStageData) {
972 EventStageData esd = (EventStageData) getListInfoParam();
973 String sound = getSoundForStageReachedUpdate(esd.id);
974 if (sound != null) {
975 return sound;
976 }
977 } else if (getListInfoParam() instanceof EventFactor) {
979 if (sound != null) {
980 return sound;
981 }
982 } else if (getListInfoParam() != null) {
984 if (sound != null) {
985 return sound;
986 }
987 }
988 return getSoundStandardUpdate();
989 }
991 }
992
993 protected void notifyStageReached(EventStageData stage) {
994
995 }
996
997 public void reportEconomyMonthEnd() {
998
999 }
1000
1001 public Color getProgressColor(int delta) {
1003 if (delta < 0) {
1004 return Misc.getPositiveHighlightColor();
1005 }
1006 } else {
1007 if (delta < 0) {
1008 return Misc.getNegativeHighlightColor();
1009 }
1010 }
1011 return Misc.getHighlightColor();
1012 }
1013
1014 public void setHideStageWhenPastIt(Object stageId) {
1015 EventStageData esd = getDataFor(stageId);
1016 if (esd == null) return;
1017 esd.hideIconWhenPastStageUnlessLastActive = true;
1018 }
1019
1020 public void setRandomized(Object stageId, RandomizedStageType type, int resetAt, int rollAt, boolean sendUpdateWhenReached) {
1021 setRandomized(stageId, type, resetAt, rollAt, sendUpdateWhenReached, true);
1022 }
1023 public void setRandomized(Object stageId, RandomizedStageType type, int resetAt, int rollAt, boolean sendUpdateWhenReached, boolean repeatable) {
1024 EventStageData esd = getDataFor(stageId);
1025 if (esd == null) return;
1026 esd.sendIntelUpdateOnReaching = sendUpdateWhenReached;
1027 esd.isRepeatable = repeatable;
1028 esd.isOneOffEvent = true;
1029 esd.randomized = true;
1030 esd.rollData = null;
1031 esd.progressToResetAt = resetAt;
1032 esd.progressToRollAt = rollAt;
1033 esd.randomType = type;
1034 }
1035
1036 public Random getRandom() {
1037 return random;
1038 }
1039
1040 public void setRandom(Random random) {
1041 this.random = random;
1042 }
1043
1044 public void resetRandomizedStage(EventStageData stage) {
1045 stage.rollData = null;
1046 }
1047
1048 public void rollRandomizedStage(EventStageData stage) {
1049
1050 }
1051
1052
1053 public float getProgressFraction() {
1054 float p = (float) progress / (float) maxProgress;
1055 if (p < 0) p = 0;
1056 if (p > 1) p = 1;
1057 return p;
1058 }
1059
1060 public boolean withMonthlyFactors() {
1061 return true;
1062 }
1063 public boolean withOneTimeFactors() {
1064 return true;
1065 }
1066}
1067
1068
1069
1070
1071
1072
1073
1074
1075
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void addBulletPoints(TooltipMakerAPI info, ListInfoMode mode)
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
void addStageDescriptionText(TooltipMakerAPI info, float width, Object stageId)
EventStageData getLastActiveStage(boolean includeOneOffEvents)
void createLargeDescription(CustomPanelAPI panel, float width, float height)
void addStageDescriptionWithImage(TooltipMakerAPI main, Object stageId)
void createIntelInfo(TooltipMakerAPI info, ListInfoMode mode)
void addFactor(EventFactor factor, InteractionDialogAPI dialog)
void setRandomized(Object stageId, RandomizedStageType type, int resetAt, int rollAt, boolean sendUpdateWhenReached, boolean repeatable)
void addStage(Object id, int progress, StageIconSize iconSize)
void setRandomized(Object stageId, RandomizedStageType type, int resetAt, int rollAt, boolean sendUpdateWhenReached)
void addStage(Object id, int progress, boolean isOneOffEvent, StageIconSize iconSize)
boolean addEventFactorBulletPoints(TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
boolean isStageActiveAndLast(Object stageId, boolean includeOneOffEvents)
void addStage(Object id, int progress, boolean isOneOffEvent)
String getSpriteName(String category, String id)
void addBulletPointForOneTimeFactor(BaseEventIntel intel, TooltipMakerAPI info, Color tc, float initPad)