1package com.fs.starfarer.api.impl.campaign.skills;
3import java.util.HashSet;
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.characters.PersonAPI;
9import com.fs.starfarer.api.combat.BaseEveryFrameCombatPlugin;
10import com.fs.starfarer.api.combat.BattleObjectiveAPI;
11import com.fs.starfarer.api.combat.CombatEngineAPI;
12import com.fs.starfarer.api.combat.CombatFleetManagerAPI;
13import com.fs.starfarer.api.combat.DeployedFleetMemberAPI;
14import com.fs.starfarer.api.combat.ShipAPI;
15import com.fs.starfarer.api.combat.ViewportAPI;
16import com.fs.starfarer.api.impl.campaign.ids.BattleObjectives;
17import com.fs.starfarer.api.impl.campaign.ids.Stats;
18import com.fs.starfarer.api.input.InputEventAPI;
29 public static String
PENALTY_ID =
"electronic_warfare_penalty";
41 private ShipAPI prevPlayerShip =
null;
42 private int skipFrames = 0;
43 private Set<CombatFleetManagerAPI> needsCleanup =
new HashSet<CombatFleetManagerAPI>();
44 public void advance(
float amount, List<InputEventAPI> events) {
45 if (engine ==
null)
return;
52 if (playerShip != prevPlayerShip) {
53 prevPlayerShip = playerShip;
67 if (player ==
null || enemy ==
null) {
81 float pTotal = player[0];
82 float pMax = player[1];
84 float eTotal = enemy[0];
85 float eMax = enemy[1];
108 int totalPenalty = (int) Math.round(Math.min(
BASE_MAXIMUM, pTotal + eTotal));
109 if (totalPenalty <= 0f)
return;
111 float ecmRatingToPenaltyMult = 1f;
113 float playerPenalty = (int) Math.min(eTotal * ecmRatingToPenaltyMult, eMax);
114 if (pTotal > 0 && playerPenalty > 0) {
115 float pMult = eTotal / (eTotal + pTotal);
116 playerPenalty *= pMult;
119 float enemyPenalty = (int) Math.min(pTotal * ecmRatingToPenaltyMult, pMax);
120 if (eTotal > 0 && enemyPenalty > 0) {
121 float eMult = pTotal / (eTotal + pTotal);
122 enemyPenalty *= eMult;
125 playerPenalty = Math.round(playerPenalty);
126 enemyPenalty = Math.round(enemyPenalty);
131 if (playerPenalty > 0 || eTotal > 0) {
135 if (eMax <= playerPenalty) sMax =
" (max)";
136 String title =
"Enemy ECM rating:" +
" " + (int) eTotal +
"%";
137 String data =
"-" + (int)playerPenalty +
"% weapon range" + sMax;
139 data =
"fully neutralized";
144 if (enemyPenalty > 0 || pTotal > 0) {
148 if (pMax <= enemyPenalty) sMax =
" (max)";
149 String title =
"ECM rating:" +
" " + (int) pTotal +
"%";
150 String data =
"-" + (int)enemyPenalty +
"% enemy weapon range" + sMax;
152 data =
"fully neutralized";
157 if (playerPenalty > 0 && eMax > 0 && engine.
getPlayerShip() !=
null) {
159 if (eccm > 100) eccm = 100;
160 if (eccm < 0) eccm = 0;
224 if (member.isFighterWing())
continue;
225 if (member.getShip() ==
null)
continue;
229 if (currPenalty < 0) currPenalty = 0;
232 float currMax = maxPenalty + maxMod;
233 if (currPenalty > currMax) {
234 currPenalty = currMax;
237 member.getShip().getMutableStats().getBallisticWeaponRangeBonus().modifyMult(
PENALTY_ID, 1f - currPenalty/100f);
238 member.getShip().getMutableStats().getEnergyWeaponRangeBonus().modifyMult(
PENALTY_ID, 1f - currPenalty/100f);
239 member.getShip().getMutableStats().getMissileWeaponRangeBonus().modifyMult(
PENALTY_ID, 1f - currPenalty/100f);
242 needsCleanup.add(manager);
246 if (needsCleanup.contains(manager)) {
247 needsCleanup.remove(manager);
250 if (member.isFighterWing())
continue;
251 if (member.getShip() ==
null)
continue;
253 member.getShip().getMutableStats().getBallisticWeaponRangeBonus().unmodify(
PENALTY_ID);
254 member.getShip().getMutableStats().getEnergyWeaponRangeBonus().unmodify(
PENALTY_ID);
255 member.getShip().getMutableStats().getMissileWeaponRangeBonus().unmodify(
PENALTY_ID);
275 float canCounter = 0f;
277 if (member.isFighterWing())
continue;
278 if (member.isStationModule())
continue;
286 if (obj.getOwner() == manager.
getOwner() && BattleObjectives.SENSOR_JAMMER.equals(obj.getType())) {
292 if (canCounter > 0) counter = 1;
294 return new int [] {(int) total, (
int) max, counter};
static SettingsAPI getSettings()
static final String ELECTRONIC_WARFARE_FLAT
static final String ELECTRONIC_WARFARE_MAX
static final String ELECTRONIC_WARFARE_PENALTY_MOD
static final String ELECTRONIC_WARFARE_PENALTY_MAX_FOR_SHIP_MOD
static final String SHIP_BELONGS_TO_FLEET_THAT_CAN_COUNTER_EW
static final String ELECTRONIC_WARFARE_PENALTY_MULT
void init(CombatEngineAPI engine)
static float BASE_MAXIMUM
void cleanUpIfNeeded(CombatFleetManagerAPI manager)
void renderInUICoords(ViewportAPI viewport)
static Object KEY_STATUS_ENEMY_RATING
void renderInWorldCoords(ViewportAPI viewport)
void advance(float amount, List< InputEventAPI > events)
static Object KEY_STATUS2
String getSpriteName(String category, String id)
void maintainStatusForPlayerShip(Object key, String spriteName, String title, String data, boolean isDebuff)
CombatFleetManagerAPI getFleetManager(FleetSide side)
List< BattleObjectiveAPI > getObjectives()
List< DeployedFleetMemberAPI > getDeployedCopyDFM()
List< PersonAPI > getAllFleetCommanders()
DynamicStatsAPI getDynamic()
MutableShipStatsAPI getMutableStats()
float getValue(String id)