1package com.fs.starfarer.api.impl.campaign.intel.events;
3import java.util.Random;
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.campaign.StarSystemAPI;
8import com.fs.starfarer.api.campaign.econ.MarketAPI;
9import com.fs.starfarer.api.impl.campaign.fleets.DisposableFleetManager;
10import com.fs.starfarer.api.impl.campaign.ids.Factions;
11import com.fs.starfarer.api.util.Misc;
12import com.fs.starfarer.api.util.WeightedRandomPicker;
21 protected Random
random =
new Random();
35 return "hostile_activity";
39 if (currSpawnLoc ==
null)
return null;
46 if (intel ==
null)
return 0;
53 if (timestamp !=
null) {
54 float daysSince =
Global.
getSector().getClock().getElapsedDaysSince(timestamp);
55 if (daysSince < delay)
return 0;
58 if (currSpawnLoc !=
null) {
59 boolean longEnough =
false;
60 for (MarketAPI market : Misc.getMarketsInLocation(currSpawnLoc, Factions.PLAYER)) {
61 if (market.getDaysInExistence() >= delay) {
74 mag = Misc.interpolate(mag, mag2, 0.6f);
82 if (mag <= 0f)
return 0;
84 if (mag > 1f) mag = 1f;
86 float desiredNumFleets = 1f;
92 desiredNumFleets += (int)Math.round(mag * (max - 1f) * mult);
94 return (
int) Math.round(desiredNumFleets);
104 if (player ==
null)
return null;
105 StarSystemAPI nearest =
null;
107 float minDist = Float.MAX_VALUE;
121 for (StarSystemAPI system : Misc.getSystemsWithPlayerColonies(
false)) {
123 float distToPlayerLY = Misc.getDistanceLY(player.getLocationInHyperspace(), system.getLocation());
124 if (distToPlayerLY > MAX_RANGE_FROM_PLAYER_LY)
continue;
126 if (distToPlayerLY < minDist) {
129 minDist = distToPlayerLY;
134 if (nearest ==
null && currSpawnLoc !=
null) {
135 float distToPlayerLY = Misc.getDistanceLY(player.getLocationInHyperspace(), currSpawnLoc.getLocation());
136 if (distToPlayerLY <= DESPAWN_RANGE_LY) {
137 nearest = currSpawnLoc;
145 StarSystemAPI system = currSpawnLoc;
146 if (system ==
null)
return null;
149 if (player ==
null)
return null;
152 if (intel ==
null)
return null;
154 String idKey =
"$dhafm_ID";
156 WeightedRandomPicker<HostileActivityFactor> picker =
new WeightedRandomPicker<HostileActivityFactor>(
random);
166 for (ManagedFleetData data : active) {
167 if (data.fleet !=
null &&
168 curr.
getId().equals(data.fleet.getMemoryWithoutUpdate().getString(idKey))) {
178 if (pick ==
null)
return null;
182 if (fleet ==
null || fleet.isEmpty())
return null;
184 fleet.getMemoryWithoutUpdate().set(idKey, pick.
getId());
static SettingsAPI getSettings()
static SectorAPI getSector()
Long getPlayerVisibleTimestamp()
List< EventFactor > getFactors()
CampaignFleetAPI spawnFleetImpl()
StarSystemAPI pickNearestPopulatedSystem()
HostileActivityEventIntel getIntel()
StarSystemAPI pickCurrentSpawnLocation()
int getDesiredNumFleetsForSpawnLocation()
DisposableHostileActivityFleetManager()
float getNumFleetsMultiplier(StarSystemAPI system)
static HostileActivityEventIntel get()
float getMarketPresenceFactor(StarSystemAPI system)
float getTotalActivityMagnitude(StarSystemAPI system)
float getFloat(String key)
float getSpawnInHyperProbability(StarSystemAPI system)
float getStayInHyperProbability(StarSystemAPI system)
float getSpawnFrequency(StarSystemAPI system)
CampaignFleetAPI createFleet(StarSystemAPI system, Random random)
int getMaxNumFleets(StarSystemAPI system)