1package com.fs.starfarer.api.impl.campaign.intel.events;
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.Comparator;
7import java.util.Random;
11import org.lwjgl.util.vector.Vector2f;
13import com.fs.starfarer.api.Global;
14import com.fs.starfarer.api.campaign.CampaignFleetAPI;
15import com.fs.starfarer.api.campaign.StarSystemAPI;
16import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
17import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
18import com.fs.starfarer.api.campaign.econ.MarketAPI;
19import com.fs.starfarer.api.impl.campaign.econ.PiracyRespite;
20import com.fs.starfarer.api.impl.campaign.ids.Factions;
21import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel;
22import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
23import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
24import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.Stage;
25import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel;
26import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel.FGIEventListener;
27import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI;
28import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI.GenericRaidParams;
29import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
30import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission.FleetStyle;
31import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator;
32import com.fs.starfarer.api.impl.campaign.rulecmd.KantaCMD;
33import com.fs.starfarer.api.ui.TooltipMakerAPI;
34import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
35import com.fs.starfarer.api.util.Misc;
36import com.fs.starfarer.api.util.WeightedRandomPicker;
45 public static String
RAID_KEY =
"$PirateRaid_ref";
72 return super.getProgress(
intel);
76 return "Pirate activity";
80 if (first)
return "Pirates";
94 public void createTooltip(
TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
96 tooltip.
addPara(
"Piracy follows interstellar civilization almost without exception.", 0f);
98 tooltip.
addPara(
"However, you have %s, which is enough dissuade most pirates from attacking your interests.",
102 tooltip.
addPara(
"You've %s, and it's not the sort of thing you can do over.",
105 tooltip.
addPara(
"Having %s, however, should be enough dissuade most pirates from attacking your interests.",
134 return super.getMaxNumFleets(system);
145 difficulty += (int) Math.round(f * 7f);
160 if (difficulty < minDiff) difficulty = minDiff;
162 difficulty += random.nextInt(4);
184 ListInfoMode mode,
boolean isUpdate, Color tc,
float initPad) {
185 info.
addPara(
"Rumors of pirate raid", tc, initPad);
191 ListInfoMode mode,
boolean isUpdate, Color tc,
float initPad) {
192 info.
addPara(
"Pirate raid averted", tc, initPad);
210 info.
addPara(
"There are rumors that a pirate raid targeting your colonies "
211 +
"may be organized in the near future. If the raid is successful, the targeted colonies will "
212 +
"suffer from reduced stability.", small,
215 if (stage.id == Stage.HA_EVENT) {
217 info.
addPara(
"If the raid is defeated, your colonies will suffer less shipping disruptions from "
218 +
"piracy for the foreseeable future.",
222 info.
addPara(
"If the raid is defeated, your colonies will "
223 +
"permanently gain increased accessibility.",
226 info.
addPara(
"If the raid is defeated, your colonies will gain "
227 +
"increased accessibility for several cycles.",
234 stage.addResetReq(info,
false,
"crisis", -1, -1, opad);
260 if (stage.id == Stage.HA_EVENT || stage.id == Stage.MINOR_EVENT) {
261 if (stage.id == Stage.MINOR_EVENT) {
264 public void createTooltip(
TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
267 tooltip.
addPara(
"A pirate raid will be launched against one of your "
268 +
"star systems.", opad);
296 if (stage.id == Stage.HA_EVENT || stage.id == Stage.MINOR_EVENT) {
299 if (target !=
null && source !=
null) {
313 HAERandomEventData data =
new HAERandomEventData(
this, stage);
314 stage.rollData = data;
321 if (source ==
null || target ==
null) {
325 stage.rollData =
null;
334 if (mag < 0.1f && stage.id != Stage.MINOR_EVENT) {
338 picker.
add(system, mag * mag);
341 return picker.
pick();
345 if (target ==
null)
return null;
347 List<MarketAPI> list =
new ArrayList<MarketAPI>();
355 if (dist > maxDist)
continue;
363 if (other == market)
continue;
364 if (!other.getFaction().isHostileTo(market.getFaction()))
continue;
365 if (other.getSize() <= market.getSize() - 2)
continue;
367 float dist =
Misc.
getDistance(market.getPrimaryEntity().getLocation(), other.getPrimaryEntity().getLocation());
368 if (dist < 8000)
continue;
375 Collections.sort(list,
new Comparator<MarketAPI>() {
379 return (
int) Math.signum(d1 - d2);
384 for (
int i = 0; i < list.size() && i < 4; i++) {
387 float w = 100000f / (dist * dist);
388 picker.
add(market, w);
391 return picker.
pick();
404 if (
intel ==
null)
return;
414 GenericRaidParams params =
new GenericRaidParams(
new Random(random.nextLong()),
true);
416 params.source = source;
418 params.prepDays = 7f + random.nextFloat() * 14f;
419 params.payloadDays = 27f + 7f * random.nextFloat();
421 params.raidParams.where = target;
423 if (market.getFaction().isHostileTo(source.
getFaction()) || market.getFaction().isPlayerFaction()) {
424 params.raidParams.allowedTargets.add(market);
427 if (params.raidParams.allowedTargets.isEmpty())
return false;
428 params.raidParams.allowNonHostileTargets =
true;
430 params.style = FleetStyle.STANDARD;
432 if (stage.id == Stage.MINOR_EVENT) {
433 params.fleetSizes.add(5);
434 params.fleetSizes.add(3);
440 if (mag1 > 1f) mag1 = 1f;
442 float totalDifficulty = (0.25f + mag1 * 0.25f + mag2 * 0.5f) * 100f;
445 if (r.nextFloat() < 0.33f) {
446 params.style = FleetStyle.QUANTITY;
449 while (totalDifficulty > 0) {
450 float max = Math.min(10f, totalDifficulty * 0.5f);
451 float min = Math.max(2, max - 2);
452 if (max < min) max = min;
456 params.fleetSizes.add(diff);
457 totalDifficulty -= diff;
470 if (stage.id == Stage.HA_EVENT) {
485 public static void main(String[] args) {
486 Random r =
new Random();
487 int [] counts =
new int[11];
488 for (
int i = 0; i < 10000; i++) {
492 for (
int i = 0; i < counts.length; i++) {
493 System.out.println(i +
": " + counts[i]);
498 double r = random.nextGaussian();
507 return min + (float) r * (max - min);
static SettingsAPI getSettings()
static SectorAPI getSector()
static final String PIRATES
boolean isPlayerVisible()
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
static Object DISCOVERED_PARAM
static PirateBaseIntel getIntelFor(StarSystemAPI system)
boolean playerHasDealWithBaseCommander()
void addBorder(TooltipMakerAPI info, Color c)
float getEffectMagnitude(StarSystemAPI system)
Random getRandomizedStageRandom()
TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage)
HostileActivityEventIntel intel
HAERandomEventData getRollDataForEvent()
static HostileActivityEventIntel get()
float getMarketPresenceFactor(StarSystemAPI system)
static PiracyRespiteScript get()
int getMaxNumFleets(StarSystemAPI system)
float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage)
Color getDescColor(BaseEventIntel intel)
boolean shouldShow(BaseEventIntel intel)
TooltipCreator getMainRowTooltip(BaseEventIntel intel)
boolean startRaid(MarketAPI source, StarSystemAPI target, EventStageData stage, Random random)
static String SMALL_RAID_KEY
static void main(String[] args)
static final String DEFEATED_LARGE_PIRATE_RAID
boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage)
static boolean isDefeatedLargePirateRaid()
Color getNameColor(float mag)
Color getNameColorForThreatList()
void rollEvent(HostileActivityEventIntel intel, EventStageData stage)
String getNameForThreatList(boolean first)
static void setDefeatedLargePirateRaid(boolean value)
String getDesc(BaseEventIntel intel)
PirateHostileActivityFactor(HostileActivityEventIntel intel)
MarketAPI findRaidSource(HostileActivityEventIntel intel, EventStageData stage, final StarSystemAPI target)
CampaignFleetAPI createFleet(StarSystemAPI system, Random random)
String getProgressStr(BaseEventIntel intel)
StarSystemAPI findRaidTarget(HostileActivityEventIntel intel, EventStageData stage)
String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage)
int getProgress(BaseEventIntel intel)
static float getNormalRandom(Random random, float min, float max)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
static void avertOrAbortRaid()
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
void reportFGIAborted(FleetGroupIntel intel)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)
void finish(boolean isAbort)
void setListener(FGIEventListener listener)
static GenericRaidFGI get(String key)
CampaignFleetAPI createFleet()
void createStandardFleet(int difficulty, String factionId, Vector2f locInHyper)
void triggerMakeLowRepImpact()
void triggerSetPirateFleet()
static float getNormalRandom(float min, float max)
static boolean playerHasProtection()
static boolean playerEverHadProtection()
static boolean isHiddenBase(MarketAPI market)
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
static Color getNegativeHighlightColor()
static List< StarSystemAPI > getPlayerSystems(boolean includeNonPlayerFaction)
static Color getGrayColor()
static float getDistance(SectorEntityToken from, SectorEntityToken to)
static Color getHighlightColor()
static Color getPositiveHighlightColor()
float getFloat(String key)
MemoryAPI getPlayerMemoryWithoutUpdate()
IntelManagerAPI getIntelManager()
FactionAPI getFaction(String factionId)
void addIntel(IntelInfoPlugin plugin)
List< IntelInfoPlugin > getIntel()
List< MarketAPI > getMarketsCopy()
Vector2f getLocationInHyperspace()
void set(String key, Object value)
boolean getBoolean(String key)