Starsector API
Loading...
Searching...
No Matches
BaseHostileActivityFactor.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6import java.util.Random;
7
8import java.awt.Color;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.CampaignFleetAPI;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
14import com.fs.starfarer.api.campaign.econ.Industry;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.impl.campaign.ids.Industries;
17import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
18import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
19import com.fs.starfarer.api.ui.Alignment;
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.util.Misc;
24
32@SuppressWarnings("unused")
34
36 protected List<HostileActivityCause2> causes = new ArrayList<HostileActivityCause2>();
37
38 protected long seed;
39
40
42 this.intel = intel;
43 }
44
45 public int getProgress(BaseEventIntel intel) {
46 int total = 0;
47 for (HostileActivityCause2 cause : getCauses()) {
48 total += cause.getProgress();
49 }
50 return total;
51 }
52
53
54 public void addExtraRows(TooltipMakerAPI info, BaseEventIntel intel) {
55 for (HostileActivityCause2 cause : getCauses()) {
56 if (!cause.shouldShow()) continue;
57
58 String desc = cause.getDesc();
59 if (desc != null) {
60 info.addRowWithGlow(Alignment.LMID, cause.getDescColor(intel), " " + desc,
61 Alignment.RMID, cause.getProgressColor(intel), cause.getProgressStr());
62 TooltipCreator t = cause.getTooltip();
63 if (t != null) {
64 info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
65 }
66 }
67 cause.addExtraRows(info, intel);
68 }
69 }
70
71 public String getId() {
72 return getClass().getSimpleName();
73 }
74
75 public float getSpawnFrequency(StarSystemAPI system) {
76// if (this instanceof PerseanLeagueHostileActivityFactor) {
77// return 10000f;
78// }
79 return getEffectMagnitude(system);
80 }
81
83 return 0.25f;
84 }
85
86
88 return 0.25f;
89 }
90
91 public int getMaxNumFleets(StarSystemAPI system) {
92 return 1000;
93 }
94
95// public float getEffectMagnitudeAdjustedBySuppression(StarSystemAPI system) {
96// float mag = getEffectMagnitude(system);
97// //float s = intel.computeSuppressionAmount();
98// // currently, keep fleets the same size when suppressed, too
99// // otherwise, the fights just get less fun as you're trying to suppress more
100// return mag;
101// }
102
103 public float getEffectMagnitude(StarSystemAPI system) {//, boolean adjustByEventProgress) {
104 float mag = 0f;
105 for (HostileActivityCause2 cause : causes) {
106 mag += cause.getMagnitudeContribution(system);
107 }
108// if (adjustByEventProgress) {
109// float f = intel.getProgressFraction();
110// float add = f * 0.5f;
111// add = Math.min(add, 1f - mag); wefwefwefewfwe
112// if (mag < f) {
113// mag = Misc.interpolate(mag, f, 0.5f);
114// }
115// }
116 return mag;
117 }
118
119 public void addCause(HostileActivityCause2 cause) {
120 causes.add(cause);
121 }
122
123 public List<HostileActivityCause2> getCauses() {
124 return causes;
125 }
126
127 @SuppressWarnings("rawtypes")
128 public void removeCauseOfClass(Class c) {
129 Iterator<HostileActivityCause2> iter = causes.iterator();
130 while (iter.hasNext()) {
131 HostileActivityCause2 curr = iter.next();
132 if (curr.getClass() == c) {
133 iter.remove();
134 }
135 }
136 }
137
138 @SuppressWarnings("rawtypes")
139 public HostileActivityCause2 getCauseOfClass(Class c) {
140 Iterator<HostileActivityCause2> iter = causes.iterator();
141 while (iter.hasNext()) {
142 HostileActivityCause2 curr = iter.next();
143 if (curr.getClass() == c) {
144 return curr;
145 }
146 }
147 return null;
148 }
149
150 public CampaignFleetAPI createFleet(StarSystemAPI system, Random random) {
151 return null;
152 }
153
154 public String getNameForThreatList(boolean first) {
155 return getDesc(intel);
156 }
157
159 return getDescColor(intel);
160 }
161
162 public float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage) {
163 return 0;
164 }
165
166 public void rollEvent(HostileActivityEventIntel intel, EventStageData stage) {
167
168 }
169
170 public void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
171 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
172
173 }
174
175 public void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info) {
176
177 }
178
179 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
180 return null;
181 }
182
184 return null;
185 }
186
187 public TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage) {
188 return new BaseFactorTooltip() {
189 @Override
190 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
191 tooltip.addTitle(title);
192 stage.endResetReqList(tooltip, true, "crisis",
194 }
195 };
196 }
197
198 public void resetEvent(HostileActivityEventIntel intel, EventStageData stage) {
199 HAERandomEventData data = (HAERandomEventData) stage.rollData;
200 intel.sendUpdateIfPlayerHasIntel(data, false);
201 stage.rollData = null;
202 }
203
204 public void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
205 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
206
207 }
208
209 public boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage) {
210 return false;
211 }
212
213
214 public void setRandomizedStageSeed(long seed) {
215 this.seed = seed;
216 }
218 return seed;
219 }
220
221 public Random getRandomizedStageRandom(int level) {
222 return Misc.getRandom(seed, level);
223 }
224 public Random getRandomizedStageRandom() {
225 return new Random(seed);
226 }
227
228 public String getEventStageSound(HAERandomEventData data) {
229 return "colony_threat";
230 }
231
232 public static boolean checkFactionExists(String factionId, boolean requireMilitary) {
233 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
234 if (market.getFactionId().equals(factionId)) {
235 Industry b = market.getIndustry(Industries.MILITARYBASE);
236 if (b == null) b = market.getIndustry(Industries.HIGHCOMMAND);
237 if (b != null || !requireMilitary) {
238 return true;
239 }
240 }
241 }
242 return false;
243 }
244
245// @Override
246// public boolean canEscalate(HostileActivityEventIntel intel, EventStageData stage) {
247// return true;
248// }
249}
250
251
252
static SectorAPI getSector()
Definition Global.java:65
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage)
static boolean checkFactionExists(String factionId, boolean requireMilitary)
String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage)
float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)
void rollEvent(HostileActivityEventIntel intel, EventStageData stage)
void resetEvent(HostileActivityEventIntel intel, EventStageData stage)
TooltipCreator getStageTooltipImpl(HostileActivityEventIntel intel, EventStageData stage)
TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage)
static Random getRandom(long seed, int level)
Definition Misc.java:2973
Object addRowWithGlow(Object ... data)
void addTooltipToAddedRow(TooltipCreator tc, TooltipLocation loc)