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