Starsector API
Loading...
Searching...
No Matches
HegemonyInspectionManager.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.inspection;
2
3import java.util.Random;
4
5import com.fs.starfarer.api.EveryFrameScript;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.econ.Industry;
8import com.fs.starfarer.api.campaign.econ.MarketAPI;
9import com.fs.starfarer.api.impl.campaign.DebugFlags;
10import com.fs.starfarer.api.impl.campaign.ids.Commodities;
11import com.fs.starfarer.api.impl.campaign.ids.Factions;
12import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
13import com.fs.starfarer.api.util.IntervalUtil;
14import com.fs.starfarer.api.util.Misc;
15import com.fs.starfarer.api.util.WeightedRandomPicker;
16
18
19 public static final String KEY = "$core_hegemonyInspectionManager";
20
21 public static final float MAX_THRESHOLD = 1000f;
22 public static final float FREQ_MULT = Global.getSettings().getFloat("aiInspectionFrequencyMult");
23
25 Object test = Global.getSector().getMemoryWithoutUpdate().get(KEY);
26 return (HegemonyInspectionManager) test;
27 }
28
30 super();
31 Global.getSector().getMemoryWithoutUpdate().set(KEY, this);
32 }
33
34 protected Object readResolve() {
35 if (inspectionChecker == null) {
36 inspectionChecker = new IntervalUtil(20f, 40f);
37 }
38 return this;
39 }
40
41 protected IntervalUtil inspectionChecker = new IntervalUtil(20f, 40f);
42
43 protected float suspicion = 0f;
44 protected float threshold = 250f;
45 protected float inspectionDelay = 0f;;
46 protected int numAttempts = 0;
47
48 public void advance(float amount) {
49 if (true) return; // replaced with colony crisis sending inspection
50
51 float days = Misc.getDays(amount);
52 if (intel != null) {
53 if (intel.isEnded()) {
54 intel = null;
55 inspectionDelay = 100f + 100f * random.nextFloat();
56 }
57 } else {
58 inspectionDelay -= days;
59 if (inspectionDelay <= 0) inspectionDelay = 0;
60 }
61
63 days *= 1000f;
64 inspectionDelay = 0f;
65 suspicion = 1000f;
66 }
67
68 inspectionChecker.advance(days * FREQ_MULT);
69 if (inspectionChecker.intervalElapsed() && intel == null && inspectionDelay <= 0) {
71 }
72 }
73
74 protected void checkInspection() {
75 float total = 0f;
76 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
77 if (market.isPlayerOwned()) {
78 if (market.isInHyperspace()) continue;
79 total += getAICoreUseValue(market);
80 }
81 }
82
83 //suspicion += total;
84 suspicion += total * (0.25f + random.nextFloat() * 0.75f);
85
86 //suspicion += 100000;
87
88 if (suspicion >= threshold) {
90 }
91 }
92
93 protected Random random = new Random();
95 public void createInspection() {
96 createInspection(null);
97 }
98 public void createInspection(Integer fpOverride) {
99
100 MarketAPI target = null;
101 float max = 0f;
102 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
103 if (market.isPlayerOwned()) {
104 if (market.isInHyperspace()) continue;
105 float curr = getAICoreUseValue(market);
106 if (curr > max) {
107 target = market;
108 max = curr;
109 }
110 }
111 }
112
113 if (target != null && max > 0) {
114 WeightedRandomPicker<MarketAPI> picker = new WeightedRandomPicker<MarketAPI>(random);
115 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
116 if (market.getFactionId().equals(Factions.HEGEMONY)) {
117 if (market.getMemoryWithoutUpdate().getBoolean(MemFlags.MARKET_MILITARY)) {
118 picker.add(market, market.getSize());
119 }
120 }
121 }
122 MarketAPI from = picker.pick();
123 if (from == null) return;
124
125 float fp = 50 + threshold * 0.5f;
126 //fp = 500;
127 if (fpOverride != null) {
128 fp = fpOverride;
129 }
130 intel = new HegemonyInspectionIntel(from, target, fp);
131 if (intel.isDone()) {
132 intel = null;
133 return;
134 }
135 } else {
136 return;
137 }
138
139 numAttempts++;
140 suspicion = 0f;
141 threshold *= 2f;
142 if (threshold > MAX_THRESHOLD) {
144 }
145 }
146
147 public int getNumAttempts() {
148 return numAttempts;
149 }
150
151 public static float getAICoreUseValue(MarketAPI market) {
152 float total = 0f;
153
154 String aiCoreId = market.getAdmin().getAICoreId();
155 if (aiCoreId != null) {
156 total += 10f;
157 }
158
159 for (Industry ind : market.getIndustries()) {
160 String id = ind.getAICoreId();
161 float w = 0f;
162 if (Commodities.ALPHA_CORE.equals(id)) {
163 w = 4f;
164 } else if (Commodities.BETA_CORE.equals(id)) {
165 w = 2f;
166 } else if (Commodities.GAMMA_CORE.equals(id)) {
167 w = 1f;
168 }
169 total += w;
170 }
171
172 return total;
173 }
174
175 public boolean isDone() {
176 return false;
177 }
178
179 public boolean runWhilePaused() {
180 return false;
181 }
182
183 public float getThreshold() {
184 return threshold;
185 }
186
187
188}
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59