Starsector API
Loading...
Searching...
No Matches
RepairGantry.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
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.BaseHullMod;
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
20public class RepairGantry extends BaseHullMod {
21
22 private static Map mag = new HashMap();
23 static {
24 mag.put(HullSize.FRIGATE, 10f);
25 mag.put(HullSize.DESTROYER, 25f);
26 mag.put(HullSize.CRUISER, 30f);
27 mag.put(HullSize.CAPITAL_SHIP, 40f);
28 }
29
30 public static final float BATTLE_SALVAGE_MULT = .2f;
31 public static final float MIN_CR = 0.1f;
32
33 public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
34 //stats.getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).modifyFlat(id, SALVAGE_MODIFIER);
35 stats.getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).modifyFlat(id, (Float) mag.get(hullSize) * 0.01f);
36 //stats.getDynamic().getMod(Stats.BATTLE_SALVAGE_VALUE_MULT_MOD).modifyFlat(id, (Float) mag.get(hullSize) * 0.01f * (Float) mag.get(hullSize) * 0.01f);
37 }
38
39 public String getDescriptionParam(int index, HullSize hullSize) {
40 //if (index == 0) return "" + (int) (SALVAGE_MODIFIER * 100f);
41 //if (index == 1) return "" + (int) (BATTLE_SALVAGE_MODIFIER * 100f);
42
43 if (index == 0) return "" + ((Float) mag.get(HullSize.FRIGATE)).intValue() + "%";
44 if (index == 1) return "" + ((Float) mag.get(HullSize.DESTROYER)).intValue() + "%";
45 if (index == 2) return "" + ((Float) mag.get(HullSize.CRUISER)).intValue() + "%";
46 if (index == 3) return "" + ((Float) mag.get(HullSize.CAPITAL_SHIP)).intValue() + "%";
47 if (index == 4) return "" + (int)Math.round(BATTLE_SALVAGE_MULT * 100f) + "%";
48
49 return null;
50 }
51
52 @Override
53 public void advanceInCombat(ShipAPI ship, float amount) {
54
55 }
56
57
58 @Override
59 public boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
60 return true;
61 }
62
63 @Override
64 public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
65 float pad = 3f;
66 float opad = 10f;
67 Color h = Misc.getHighlightColor();
68 Color bad = Misc.getNegativeHighlightColor();
69
70 tooltip.addPara("Each additional ship with a salvage gantry provides diminishing returns. " +
71 "The higher the highest recovery bonus from a single ship in the fleet, the later diminishing returns kick in.", opad);
72
73 if (isForModSpec || ship == null) return;
75
76 CampaignFleetAPI fleet = Global.getSector().getPlayerFleet();
77 float fleetMod = getAdjustedGantryModifier(fleet, null, 0f);
78 float currShipMod = (Float) mag.get(hullSize) * 0.01f;
79
80 float fleetModWithOneMore = getAdjustedGantryModifier(fleet, null, currShipMod);
81 float fleetModWithoutThisShip = getAdjustedGantryModifier(fleet, ship.getFleetMemberId(), 0f);
82
83 tooltip.addPara("The total resource recovery bonus for your fleet is %s.", opad, h,
84 "" + (int)Math.round(fleetMod * 100f) + "%");
85
86 float cr = ship.getCurrentCR();
87 for (FleetMemberAPI member : Global.getSector().getPlayerFleet().getFleetData().getMembersListCopy()) {
88 if (member.getId().equals(ship.getFleetMemberId())) {
89 cr = member.getRepairTracker().getCR();
90 }
91 }
92
93 if (cr < MIN_CR) {
94 LabelAPI label = tooltip.addPara("This ship's combat readiness is below %s " +
95 "and the gantry can not be utilized. Bringing this ship into readiness " +
96 "would increase the fleetwide bonus to %s.",
97 opad, h,
98 "" + (int) Math.round(MIN_CR * 100f) + "%",
99 "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
100 label.setHighlightColors(bad, h);
101 label.setHighlight("" + (int) Math.round(MIN_CR * 100f) + "%", "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
102
103// tooltip.addPara("Bringing this ship into readiness " +
104// "would increase the fleet's bonus to %s.", opad, h,
105// "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
106 } else {
107 if (fleetMod > currShipMod) {
108 tooltip.addPara("Removing this ship would decrease it to %s. Adding another ship of the same type " +
109 "would increase it to %s.", opad, h,
110 "" + (int)Math.round(fleetModWithoutThisShip * 100f) + "%",
111 "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
112 } else {
113 tooltip.addPara("Adding another ship of the same type " +
114 "would increase it to %s.", opad, h,
115 "" + (int)Math.round(fleetModWithOneMore * 100f) + "%");
116 }
117 }
118
119 tooltip.addPara("The fleetwide post-battle salvage bonus is %s.", opad, h,
120 "" + (int)Math.round(getAdjustedGantryModifierForPostCombatSalvage(fleet) * 100f) + "%");
121// "" + Misc.getRoundedValueMaxOneAfterDecimal(
122// getAdjustedGantryModifierForPostCombatSalvage(fleet) * 100f) + "%");
123
124 }
125
126
127 public static float getAdjustedGantryModifierForPostCombatSalvage(CampaignFleetAPI fleet) {
128 return getAdjustedGantryModifier(fleet, null, 0) * BATTLE_SALVAGE_MULT;
129 }
130
131 public static float getAdjustedGantryModifier(CampaignFleetAPI fleet, String skipId, float add) {
132 //List<Pair<FleetMemberAPI, Float>> values = new ArrayList<Pair<FleetMemberAPI,Float>>();
133
134 float max = 0f;
135 float total = 0f;
136 for (FleetMemberAPI member : fleet.getFleetData().getMembersListCopy()) {
137 if (member.isMothballed()) continue;
138 if (member.getRepairTracker().getCR() < MIN_CR) continue;
139
140 if (member.getId().equals(skipId)) {
141 continue;
142 }
143 float v = member.getStats().getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).computeEffective(0f);
144 if (v <= 0) continue;
145
146// Pair<FleetMemberAPI, Float> p = new Pair<FleetMemberAPI, Float>(member, v);
147// values.add(p);
148 if (v > max) max = v;
149 total += v;
150 }
151 if (add > max) max = add;
152 total += add;
153
154 if (max <= 0) return 0f;
155 float units = total / max;
156 if (units <= 1) return max;
157 float mult = Misc.logOfBase(2.5f, units) + 1f;
158 float result = total * mult / units;
159 if (result <= 0) {
160 result = 0;
161 } else {
162 result = Math.round(result * 100f) / 100f;
163 result = Math.max(result, 0.01f);
164 }
165 return result;
166 }
167
168
169}
170
171
172
173
174
175
176
177
178
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
static float getAdjustedGantryModifier(CampaignFleetAPI fleet, String skipId, float add)
void advanceInCombat(ShipAPI ship, float amount)
boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec)
String getDescriptionParam(int index, HullSize hullSize)
void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id)
static float getAdjustedGantryModifierForPostCombatSalvage(CampaignFleetAPI fleet)
void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec)