Starsector API
Loading...
Searching...
No Matches
HighResSensors.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.hullmods;
2
3import java.awt.Color;
4import java.util.HashMap;
5import java.util.Map;
6
7import com.fs.starfarer.api.GameState;
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.combat.HullModFleetEffect;
11import com.fs.starfarer.api.combat.MutableShipStatsAPI;
12import com.fs.starfarer.api.combat.ShipAPI;
13import com.fs.starfarer.api.combat.ShipAPI.HullSize;
14import com.fs.starfarer.api.fleet.FleetMemberAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Stats;
16import com.fs.starfarer.api.ui.LabelAPI;
17import com.fs.starfarer.api.ui.TooltipMakerAPI;
18import com.fs.starfarer.api.util.Misc;
19
20@SuppressWarnings("unchecked")
21public class HighResSensors extends BaseLogisticsHullMod implements HullModFleetEffect {
22
23// public static float BONUS = 60;
24// public static float CAPITAL_BONUS = 100;
25
26 public static float MIN_CR = 0.1f;
27 public static String MOD_KEY = "core_HighResSensors";
28
29 private static Map combatMag = new HashMap();
30 private static Map mag = new HashMap();
31// static {
32// mag.put(HullSize.FRIGATE, Global.getSettings().getFloat("baseSensorFrigate"));
33// mag.put(HullSize.DESTROYER, Global.getSettings().getFloat("baseSensorDestroyer"));
34// mag.put(HullSize.CRUISER, Global.getSettings().getFloat("baseSensorCruiser"));
35// mag.put(HullSize.CAPITAL_SHIP, Global.getSettings().getFloat("baseSensorCapital"));
36// }
37 static {
38 mag.put(HullSize.FRIGATE, 50f);
39 mag.put(HullSize.DESTROYER, 75f);
40 mag.put(HullSize.CRUISER, 100f);
41 mag.put(HullSize.CAPITAL_SHIP, 150f);
42
43 combatMag.put(HullSize.FRIGATE, 1000f);
44 combatMag.put(HullSize.DESTROYER, 1500f);
45 combatMag.put(HullSize.CRUISER, 2000f);
46 combatMag.put(HullSize.CAPITAL_SHIP, 2500f);
47 }
48
49 public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
50 //stats.getSensorStrength().modifyPercent(id, ((Float) mag.get(hullSize)).intValue());
51// float bonus = BONUS;
52// if (hullSize == HullSize.CAPITAL_SHIP) bonus = CAPITAL_BONUS;
53// stats.getSensorStrength().modifyFlat(id, bonus);
54
55 stats.getDynamic().getMod(Stats.HRS_SENSOR_RANGE_MOD).modifyFlat(id, (Float) mag.get(hullSize));
56
57 boolean sMod = isSMod(stats);
58 if (sMod) {
59 float mag = ((Float) combatMag.get(hullSize)).intValue();
60 stats.getSightRadiusMod().modifyFlat(id, mag);
61 }
62 }
63
64 public String getSModDescriptionParam(int index, HullSize hullSize) {
65 if (index == 0) return "" + ((Float) combatMag.get(HullSize.FRIGATE)).intValue();
66 if (index == 1) return "" + ((Float) combatMag.get(HullSize.DESTROYER)).intValue();
67 if (index == 2) return "" + ((Float) combatMag.get(HullSize.CRUISER)).intValue();
68 if (index == 3) return "" + ((Float) combatMag.get(HullSize.CAPITAL_SHIP)).intValue();
69 return null;
70 }
71 public String getDescriptionParam(int index, HullSize hullSize) {
72// if (index == 0) return "" + (int) BONUS;
73// if (index == 1) return "" + (int) CAPITAL_BONUS;
74// if (index == 0) return "" + ((Float) mag.get(HullSize.FRIGATE)).intValue();
75// if (index == 1) return "" + ((Float) mag.get(HullSize.DESTROYER)).intValue();
76// if (index == 2) return "" + ((Float) mag.get(HullSize.CRUISER)).intValue();
77 //if (index == 3) return "" + ((Float) mag.get(HullSize.CAPITAL_SHIP)).intValue();
78 return null;
79 }
80
81 public void advanceInCampaign(CampaignFleetAPI fleet) {
82 }
83 public boolean withAdvanceInCampaign() {
84 return false;
85 }
86 public boolean withOnFleetSync() {
87 return true;
88 }
89
90 public void onFleetSync(CampaignFleetAPI fleet) {
91 float modifier = getAdjustedHRSModifier(fleet, null, 0f);
92 if (modifier <= 0) {
93 fleet.getSensorRangeMod().unmodifyFlat(MOD_KEY);
94 } else {
95 fleet.getSensorRangeMod().modifyFlat(MOD_KEY, modifier, "Ships with high resolution sensors");
96 }
97 }
98
99 @Override
100 public boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
101 return false; // no description from the csv
102 }
103
104 @Override
105 public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
106 float pad = 3f;
107 float opad = 10f;
108 Color h = Misc.getHighlightColor();
109 Color bad = Misc.getNegativeHighlightColor();
110
111 tooltip.addPara("A ship with high resolution sensors increases the fleet's sensor range by %s/%s/%s/%s," +
112 " depending on hull size. " +
113 "Each additional ship with high resolution sensors provides diminishing returns. " +
114 "The higher the highest sensor range increase from a single ship in the fleet, the later diminishing returns kick in.",
115 opad, h,
116 "" + ((Float) mag.get(HullSize.FRIGATE)).intValue(),
117 "" + ((Float) mag.get(HullSize.DESTROYER)).intValue(),
118 "" + ((Float) mag.get(HullSize.CRUISER)).intValue(),
119 "" + ((Float) mag.get(HullSize.CAPITAL_SHIP)).intValue()
120 );
121
122 if (isForModSpec || ship == null) return;
124
125 CampaignFleetAPI fleet = Global.getSector().getPlayerFleet();
126 float fleetMod = getAdjustedHRSModifier(fleet, null, 0f);
127 float currShipMod = (Float) mag.get(hullSize);
128
129 float fleetModWithOneMore = getAdjustedHRSModifier(fleet, null, currShipMod);
130 float fleetModWithoutThisShip = getAdjustedHRSModifier(fleet, ship.getFleetMemberId(), 0f);
131
132 tooltip.addPara("The total sensor strength increase for your fleet is %s.", opad, h,
133 "" + (int)Math.round(fleetMod));
134
135 float cr = ship.getCurrentCR();
136 for (FleetMemberAPI member : Global.getSector().getPlayerFleet().getFleetData().getMembersListCopy()) {
137 if (member.getId().equals(ship.getFleetMemberId())) {
138 cr = member.getRepairTracker().getCR();
139 }
140 }
141
142 if (cr < MIN_CR) {
143 LabelAPI label = tooltip.addPara("This ship's combat readiness is below %s " +
144 "and its high resolution sensors can not be utilized. Bringing this ship into readiness " +
145 "would increase the fleetwide bonus to %s.",
146 opad, h,
147 "" + (int) Math.round(MIN_CR * 100f) + "%",
148 "" + (int)Math.round(fleetModWithOneMore));
149 label.setHighlightColors(bad, h);
150 label.setHighlight("" + (int) Math.round(MIN_CR * 100f) + "%", "" + (int)Math.round(fleetModWithOneMore));
151 } else {
152 if (fleetMod > currShipMod) {
153 tooltip.addPara("Removing this ship would decrease it to %s. Adding another ship of the same type " +
154 "would increase it to %s.", opad, h,
155 "" + (int)Math.round(fleetModWithoutThisShip),
156 "" + (int)Math.round(fleetModWithOneMore));
157 } else {
158 tooltip.addPara("Adding another ship of the same type " +
159 "would increase it to %s.", opad, h,
160 "" + (int)Math.round(fleetModWithOneMore));
161 }
162 }
163 }
164
165 public static float getAdjustedHRSModifier(CampaignFleetAPI fleet, String skipId, float add) {
166 float max = 0f;
167 float total = 0f;
168 for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
169 if (member.isMothballed()) continue;
170 if (member.getRepairTracker().getCR() < MIN_CR) continue;
171
172 if (member.getId().equals(skipId)) {
173 continue;
174 }
175 float v = member.getStats().getDynamic().getMod(Stats.HRS_SENSOR_RANGE_MOD).computeEffective(0f);
176 if (v <= 0) continue;
177
178 if (v > max) max = v;
179 total += v;
180 }
181 if (add > max) max = add;
182 total += add;
183
184 if (max <= 0) return 0f;
185 float units = total / max;
186 if (units <= 1) return max;
187 float mult = Misc.logOfBase(2.5f, units) + 1f;
188 float result = total * mult / units;
189 if (result <= 0) {
190 result = 0;
191 } else {
192 result = Math.round(result * 100f) / 100f;
193 result = Math.max(result, 1f);
194 }
195 return result;
196 }
197
198
199}
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id)
String getDescriptionParam(int index, HullSize hullSize)
void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec)
static float getAdjustedHRSModifier(CampaignFleetAPI fleet, String skipId, float add)
String getSModDescriptionParam(int index, HullSize hullSize)
boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec)