Starsector API
Loading...
Searching...
No Matches
EncounterTricksterGhostCreator.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.ghosts.types;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Random;
6
7import org.lwjgl.util.vector.Vector2f;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.CampaignFleetAPI;
11import com.fs.starfarer.api.campaign.LocationAPI;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.impl.campaign.enc.BaseEPEncounterCreator;
14import com.fs.starfarer.api.impl.campaign.fleets.AutoDespawnScript;
15import com.fs.starfarer.api.impl.campaign.ghosts.BaseSensorGhostCreator;
16import com.fs.starfarer.api.impl.campaign.ghosts.GhostFrequencies;
17import com.fs.starfarer.api.impl.campaign.ghosts.SensorGhost;
18import com.fs.starfarer.api.impl.campaign.ghosts.SensorGhostManager;
19import com.fs.starfarer.api.impl.campaign.ids.Factions;
20import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
21import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathBaseIntel;
22import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel;
23import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
24import com.fs.starfarer.api.impl.campaign.missions.hub.MissionFleetAutoDespawn;
25import com.fs.starfarer.api.util.WeightedRandomPicker;
26
28
29 public static enum OtherFleetType {
30 PIRATE,
31 LUDDIC_PATH,
32 MERCENARY,
33 NOTHING, // higher chance to spawn no encounter when near a base; creator has higher base probability to compensate
34 }
35
36 @Override
37 public List<SensorGhost> createGhost(SensorGhostManager manager) {
38 if (!Global.getSector().getCurrentLocation().isHyperspace()) return null;
39
40 Random random = manager.getRandom();
41 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
42 LocationAPI hyper = Global.getSector().getCurrentLocation();
43
44 Vector2f loc = findHyperspaceArea(pf.getLocation(), 3000, 4000, 1000, random, true, 3000);
45 if (loc == null) return null;
46
47 CampaignFleetAPI other = createOtherFleet(manager, pf.getLocation());
48 if (other == null) {
49 // to trigger full timeout, since this is a valid outcome for this creator
50 // i.e. it picked "nothing" due to not being near a pirate base etc
51// List<SensorGhost> result = new ArrayList<SensorGhost>();
52// result.add(new NoGhost(manager));
53// return result;
54 // actually, don't want the above, it's fine fo this ghost to trigger the short timeout and for
55 // another ghost to be picked
56 return null;
57 }
58
59 hyper.addEntity(other);
60 other.setLocation(loc.x, loc.y);
61 other.addScript(new AutoDespawnScript(other));
62
63 boolean guideToTarget = manager.getRandom().nextBoolean();
64 //guideToTarget = false;
65 List<SensorGhost> result = new ArrayList<SensorGhost>();
66 SensorGhost g = new EncounterTricksterGhost(manager, other, guideToTarget);
67 if (g.isCreationFailed()) {
68 hyper.removeEntity(other);
69 return null;
70 }
71 result.add(g);
72 return result;
73 }
74
75 @Override
76 public float getFrequency(SensorGhostManager manager) {
78 //return 100000f;
79 }
80
81
82 public CampaignFleetAPI createOtherFleet(SensorGhostManager manager, Vector2f locInHyper) {
83 Random random = manager.getRandom();
84
85
86 PirateBaseIntel intel = BaseEPEncounterCreator.getClosestPirateBase(locInHyper);
87 float f1 = BaseEPEncounterCreator.getPirateBaseProximityFactor(intel, locInHyper);
88
89 LuddicPathBaseIntel intel2 = BaseEPEncounterCreator.getClosestLuddicPathBase(locInHyper);
90 float f2 = BaseEPEncounterCreator.getLuddicPathBaseProximityFactor(intel2, locInHyper);
91
92 float result = Math.max(f1, f2);
93
94 StarSystemAPI ruins = BaseEPEncounterCreator.getClosestSystemWithRuins(locInHyper);
95 float f3 = BaseEPEncounterCreator.getRuinsProximityFactor(ruins, locInHyper);
96 f3 *= 0.25f;
97 result = Math.max(result, f3);
98
99 WeightedRandomPicker<OtherFleetType> picker = new WeightedRandomPicker<OtherFleetType>(random);
100 picker.add(OtherFleetType.PIRATE, f1 + 0.1f);
101 picker.add(OtherFleetType.LUDDIC_PATH, f2 + 0.05f);
102 picker.add(OtherFleetType.MERCENARY, (f1 + f2) * 0.25f + 0.01f);
103 picker.add(OtherFleetType.NOTHING, 1f);
104 OtherFleetType type = picker.pick();
105 if (type == null) return null;
106
107 CampaignFleetAPI fleet = null;
108 FleetCreatorMission m = new FleetCreatorMission(random);
109 m.beginFleet();
110
111 if (type == OtherFleetType.PIRATE) {
112 String factionId = Factions.PIRATES;
113 if (intel != null && intel.getMarket() != null) factionId = intel.getMarket().getFactionId();
114 int difficulty = 0;
115
116 if (intel != null) {
117 difficulty += (int) Math.round(f1 * 2f);
118 if (intel != null) {
119 switch (intel.getTier()) {
120 case TIER_1_1MODULE: difficulty += 2; break;
121 case TIER_2_1MODULE: difficulty += 2; break;
122 case TIER_3_2MODULE: difficulty += 3; break;
123 case TIER_4_3MODULE: difficulty += 4; break;
124 case TIER_5_3MODULE: difficulty += 5; break;
125 }
126 }
127 difficulty += random.nextInt(4);
128 } else {
129 difficulty += 4;
130 difficulty += random.nextInt(7);
131 }
132 Vector2f loc = locInHyper;
133 m.createStandardFleet(difficulty, factionId, loc);
134 m.triggerSetStandardAggroPirateFlags();
135 m.triggerFleetAllowLongPursuit();
136 if (intel != null && intel.getMarket() != null) {
137 m.triggerSetFleetMemoryValue(MemFlags.MEMORY_KEY_SOURCE_MARKET, intel.getMarket().getId());
138 }
139 fleet = m.createFleet();
140 } else if (type == OtherFleetType.LUDDIC_PATH) {
141 int difficulty = 0;
142 if (intel2 != null) {
143 difficulty += (int) Math.round(f2 * 2f);
144 if (intel2.isLarge()) {
145 difficulty += 5;
146 } else {
147 difficulty += 3;
148 }
149 difficulty += random.nextInt(4);
150 } else {
151 difficulty += 4;
152 difficulty += random.nextInt(7);
153 }
154
155 Vector2f loc = locInHyper;
156 m.createStandardFleet(difficulty, Factions.LUDDIC_PATH, loc);
157 m.triggerSetStandardAggroPirateFlags();
158 m.triggerFleetAllowLongPursuit();
159 m.triggerFleetPatherNoDefaultTithe();
160 if (intel2 != null && intel2.getMarket() != null) {
161 m.triggerSetFleetMemoryValue(MemFlags.MEMORY_KEY_SOURCE_MARKET, intel2.getMarket().getId());
162 }
163
164 fleet = m.createFleet();
165 } else if (type == OtherFleetType.MERCENARY) {
166 int difficulty = 3;
167 float f = Math.max(f1, f2);
168 difficulty += (int) Math.round(f * 3f);
169 difficulty += random.nextInt(5);
170
171 Vector2f loc = locInHyper;
172 m.createQualityFleet(difficulty, Factions.MERCENARY, loc);
173 m.triggerFleetAllowLongPursuit();
174 m.triggerSetFleetFaction(Factions.INDEPENDENT);
175 m.triggerMakeNoRepImpact();
176 m.triggerFleetSetAllWeapons();
177
178 fleet = m.createFleet();
179 } else if (type == OtherFleetType.NOTHING) {
180 return null;
181 }
182
183 if (fleet == null) return null;
184 fleet.removeScriptsOfClass(MissionFleetAutoDespawn.class);
185 fleet.addScript(new MissionFleetAutoDespawn(null, fleet));
186
187 return fleet;
188 }
189
190
191}
192
193
194
195
196
197
static SectorAPI getSector()
Definition Global.java:59
static Vector2f findHyperspaceArea(Vector2f from, float minRange, float maxRange, float radius, Random random, boolean clear, float noSlipstreamRange)
static float getEncounterTricksterFrequency(SensorGhostManager manager)
CampaignFleetAPI createOtherFleet(SensorGhostManager manager, Vector2f locInHyper)