1package com.fs.starfarer.api.impl.hullmods;
3import java.util.ArrayList;
8import com.fs.starfarer.api.GameState;
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.CampaignFleetAPI;
11import com.fs.starfarer.api.combat.BaseHullMod;
12import com.fs.starfarer.api.combat.HullModFleetEffect;
13import com.fs.starfarer.api.combat.MutableShipStatsAPI;
14import com.fs.starfarer.api.combat.ShipAPI;
15import com.fs.starfarer.api.combat.ShipAPI.HullSize;
16import com.fs.starfarer.api.fleet.FleetMemberAPI;
17import com.fs.starfarer.api.impl.campaign.ids.HullMods;
18import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
19import com.fs.starfarer.api.impl.campaign.ids.Strings;
20import com.fs.starfarer.api.ui.LabelAPI;
21import com.fs.starfarer.api.ui.TooltipMakerAPI;
22import com.fs.starfarer.api.util.Misc;
24@SuppressWarnings(
"unchecked")
35 public static float MIN_CR = 0.1f;
36 public static String MOD_KEY =
"core_PhaseField";
38 public static float PROFILE_MULT = 0.5f;
40 public static float MIN_FIELD_MULT = 0.25f;
48 if (index == 0)
return "" + (int) ((1f - PROFILE_MULT) * 100f) +
"%";
54 String key =
"$updatedPhaseFieldModifier";
71 float mult = getPhaseFieldMultBaseProfileAndTotal(fleet,
null, 0f, 0f)[0];
93 tooltip.
addPara(
"In addition, the fleet's detected-at range is reduced by a multiplier based on the total "
94 +
"sensor profile of the %s highest-profile ships in the fleet, and the total sensor strength of the %s "
95 +
"phase ships with the highest sensor strength values. This effect only applies when the "
96 +
"fleet's transponder is turned off.", opad,
98 "" + numProfileShips,
"" + numProfileShips);
100 tooltip.
addPara(
"Fleetwide sensor strength increases - such as from High Resolution Sensors - do not factor into "
101 +
"this calculation.", opad);
103 if (isForModSpec || ship ==
null)
return;
108 float [] data = getPhaseFieldMultBaseProfileAndTotal(fleet,
null, 0f, 0f);
109 float [] dataWithOneMore = getPhaseFieldMultBaseProfileAndTotal(fleet,
null,
112 float [] dataWithOneLess = getPhaseFieldMultBaseProfileAndTotal(fleet, ship.
getFleetMemberId(), 0f, 0f);
114 float mult = data[0];
115 float profile = data[1];
116 float sensors = data[2];
118 tooltip.
addPara(
"The sensor profile of the %s top ships in your fleet is %s. The sensor strength of the top %s phase ships "
120 "" + numProfileShips,
121 "" + (
int)Math.round(profile),
122 "" + numProfileShips,
123 "" + (
int)Math.round(sensors)
126 tooltip.
addPara(
"The detected-at range multiplier for your fleet is %s. The fleet's transponder must be off "
127 +
"for the multiplier to be applied.",
130 "transponder must be off");
135 cr = member.getRepairTracker().getCR();
140 LabelAPI label = tooltip.
addPara(
"This ship's combat readiness is below %s " +
141 "and the phase field's fleetwide effect can not be utilized. Bringing this ship into readiness " +
142 "would improve the multiplier to %s.",
144 "" + (
int) Math.round(MIN_CR * 100f) +
"%",
149 tooltip.
addPara(
"Removing this ship would change the multiplier to %s. Adding another ship with the same sensor strength " +
150 "would improve it to %s.", opad, h,
191 List<FleetMemberAPI> members =
new ArrayList<FleetMemberAPI>();
192 List<FleetMemberAPI> phase =
new ArrayList<FleetMemberAPI>();
194 if (member.getId().equals(skipId)) {
199 if (member.isMothballed())
continue;
200 if (member.getRepairTracker().getCR() < MIN_CR)
continue;
206 float [] profiles =
new float [members.size()];
207 if (addProfile <= 0) {
208 profiles =
new float [members.size()];
210 profiles =
new float [members.size() + 1];
212 float [] phaseSensors;
213 if (addSensor <= 0) {
214 phaseSensors =
new float [phase.size()];
216 phaseSensors =
new float [phase.size() + 1];
221 profiles[i] = member.getStats().getSensorProfile().getModifiedValue();
224 if (addProfile > 0) profiles[i] = addProfile;
227 phaseSensors[i] = member.getStats().getSensorStrength().getModifiedValue();
230 if (addSensor > 0) phaseSensors[i] = addSensor;
233 int numPhaseShips = numProfileShips;
235 float totalProfile = getTopKValuesSum(profiles, numProfileShips);
236 float totalPhaseSensors = getTopKValuesSum(phaseSensors, numPhaseShips);
238 float total = Math.max(totalProfile + totalPhaseSensors, 1f);
240 float mult = totalProfile / total;
241 if (totalPhaseSensors <= 0f) mult = 1f;
243 if (mult < MIN_FIELD_MULT) mult = MIN_FIELD_MULT;
244 if (mult > 1f) mult = 1f;
246 return new float[] {mult, totalProfile, totalPhaseSensors};
251 k = Math.min(k, arr.length);
256 for (
int i = 0; i < arr.length; i++) {
263 total += (k - found) * kVal;
static SettingsAPI getSettings()
static SectorAPI getSector()
void modifyMult(String source, float value)
void modifyMult(String source, float value)
void unmodifyMult(String source)
static final String PHASE_FIELD
static final String JUST_TOGGLED_TRANSPONDER
static float[] getPhaseFieldMultBaseProfileAndTotal(CampaignFleetAPI fleet, String skipId, float addProfile, float addSensor)
void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec)
static float getTopKValuesSum(float[] arr, int k)
void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id)
boolean withOnFleetSync()
boolean withAdvanceInCampaign()
void advanceInCampaign(CampaignFleetAPI fleet)
void onFleetSync(CampaignFleetAPI fleet)
boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec)
String getDescriptionParam(int index, HullSize hullSize)
static Color getNegativeHighlightColor()
static float getRoundedValueFloat(float value)
static float findKth(float[] arr, int k)
static Color getHighlightColor()
GameState getCurrentState()
FleetDataAPI getFleetData()
List< FleetMemberAPI > getMembersListCopy()
CampaignFleetAPI getPlayerFleet()
StatBonus getDetectedRangeMod()
MemoryAPI getMemoryWithoutUpdate()
boolean isTransponderOn()
void set(String key, Object value)
boolean getBoolean(String key)
MutableStat getSensorStrength()
MutableStat getSensorProfile()
MutableShipStatsAPI getMutableStats()
String getFleetMemberId()
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)