diff --git a/assets/starpocalypse.json b/assets/starpocalypse.json index 46a4bd5..e0b4c6f 100644 --- a/assets/starpocalypse.json +++ b/assets/starpocalypse.json @@ -61,10 +61,12 @@ # Number of s-mods available to player (without skill). "maxPermaMods": 0, # easy mode: 1, vanilla: 2 - # Remove all ships from salvageable debris fields and always require a story point to recover a ship (both derelict - # ships found across the sector, and post battle recoveries - including own ships). - # Also remove all cryopods with officers, and other "items" (like survey data). - "stingyRecoveries": true, + # Always require story points to recover ships + # (both derelict ships found across the sector, and post battle recoveries). + "stingyRecoveriesDerelicts": true, + "stingyRecoveriesCombat": true, + # Also require a story point to recover disabled player ships post battle. + "stingyRecoveriesCombatIncludePlayerShips": true, # Reduce quantity of salvaged items. "salvageMultiplier": -0.5, # vanilla: 0 diff --git a/package.json b/package.json index d93090c..c78c180 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "format": "prettier --write src/" }, "dependencies": { - "prettier": "*", "prettier-plugin-java": "*" + }, + "devDependencies": { + "prettier": "2.8.8" } } diff --git a/src/starpocalypse/StarpocalypseMod.java b/src/starpocalypse/StarpocalypseMod.java index f8753f6..14683b7 100644 --- a/src/starpocalypse/StarpocalypseMod.java +++ b/src/starpocalypse/StarpocalypseMod.java @@ -48,7 +48,8 @@ public void onGameLoad(boolean newGame) { industryChanges(); combatAdjustedReputation(); hostilityForSpecialItemRaid(); - stingyRecoveries(); + stingyDerelictRecoveries(); + stingyCombatRecoveries(); salvageMultiplier(); } @@ -159,10 +160,17 @@ private void setMaxPermaMods() { Misc.MAX_PERMA_MODS = maxPermaMods; } - private void stingyRecoveries() { - if (settings.optBoolean("stingyRecoveries", true)) { - log.info("Enabling stingy recoveries"); - DropTableUtils.makeRecoveryRequireStoryPoint(); + private void stingyDerelictRecoveries() { + if (settings.optBoolean("stingyRecoveriesDerelicts", true)) { + log.info("Enabling stingy derelict recoveries"); + DropTableUtils.makeDerelictRecoveryRequireStoryPoint(); + } + } + + private void stingyCombatRecoveries() { + if (settings.optBoolean("stingyRecoveriesCombat", true)) { + log.info("Enabling stingy combat recoveries"); + DropTableUtils.makeCombatRecoveryRequireStoryPoint(); } } diff --git a/src/starpocalypse/helper/ConfigHelper.java b/src/starpocalypse/helper/ConfigHelper.java index 7b6f239..49830e6 100644 --- a/src/starpocalypse/helper/ConfigHelper.java +++ b/src/starpocalypse/helper/ConfigHelper.java @@ -54,6 +54,15 @@ public class ConfigHelper { @Getter private static boolean shyBlackMarket = false; + @Getter + private static boolean stingyRecoveriesDerelicts = true; + + @Getter + private static boolean stingyRecoveriesCombat = true; + + @Getter + private static boolean stingyRecoveriesIncludePlayerShips = true; + @Getter private static final SimpleSet shyBlackMarketFaction = new SimpleSet("faction", "shyBlackMarketFaction.csv"); @@ -98,6 +107,9 @@ private static void loadConfig(JSONObject settings) { removeEndgameCargo = settings.optBoolean("removeMilitaryEndgameCargo", true); removeEndgameShips = settings.optBoolean("removeMilitaryEndgameShips", true); shyBlackMarket = settings.optBoolean("shyBlackMarket", true); + stingyRecoveriesDerelicts = settings.optBoolean("stingyRecoveriesDerelicts", true); + stingyRecoveriesCombat = settings.optBoolean("stingyRecoveriesCombat", true); + stingyRecoveriesIncludePlayerShips = settings.optBoolean("stingyRecoveriesIncludePlayerShips", true); } private static void transparentMarket(JSONObject settings, Logger log) { diff --git a/src/starpocalypse/helper/DropTableUtils.java b/src/starpocalypse/helper/DropTableUtils.java index 0cce2a3..b524e17 100644 --- a/src/starpocalypse/helper/DropTableUtils.java +++ b/src/starpocalypse/helper/DropTableUtils.java @@ -27,11 +27,14 @@ public static void removeBlueprintPackages() { } } - public static void makeRecoveryRequireStoryPoint() { - Global.getSector().registerPlugin(new StarpocalypseCampaignPlugin()); + public static void makeDerelictRecoveryRequireStoryPoint() { Global.getSector().addTransientScript(new DerelictModifyingScript()); } + public static void makeCombatRecoveryRequireStoryPoint() { + Global.getSector().registerPlugin(new StarpocalypseCampaignPlugin()); + } + public static void applySalvageMultiplier(float multiplier) { CampaignFleetAPI fleet = Global.getSector().getPlayerFleet(); MutableFleetStatsAPI stats = fleet.getStats(); diff --git a/src/starpocalypse/salvage/DerelictModifyingScript.java b/src/starpocalypse/salvage/DerelictModifyingScript.java index c8b2fd7..54e1427 100644 --- a/src/starpocalypse/salvage/DerelictModifyingScript.java +++ b/src/starpocalypse/salvage/DerelictModifyingScript.java @@ -24,12 +24,11 @@ public boolean runWhilePaused() { @Override public void advance(float amount) { - // Check for nearby salvageable derelicts for (SectorEntityToken entity : getEntities(Tags.DEBRIS_FIELD)) { - clearSpecialData(entity); + forceStoryPointRecovery(entity); } for (SectorEntityToken entity : getEntities(Tags.SALVAGEABLE)) { - clearSpecialData(entity); + forceStoryPointRecovery(entity); } } @@ -37,7 +36,7 @@ private List getEntities(String tag) { return Global.getSector().getPlayerFleet().getContainingLocation().getEntitiesWithTag(tag); } - private void clearSpecialData(SectorEntityToken entity) { + private void forceStoryPointRecovery(SectorEntityToken entity) { MemoryAPI memory = entity.getMemoryWithoutUpdate(); if (memory.contains(MemFlags.SALVAGE_SPECIAL_DATA)) { Object specialData = memory.get(MemFlags.SALVAGE_SPECIAL_DATA); diff --git a/src/starpocalypse/salvage/StarpocalypseFleetEncounterContext.java b/src/starpocalypse/salvage/StarpocalypseFleetEncounterContext.java index af69acd..72486a4 100644 --- a/src/starpocalypse/salvage/StarpocalypseFleetEncounterContext.java +++ b/src/starpocalypse/salvage/StarpocalypseFleetEncounterContext.java @@ -1,16 +1,19 @@ package starpocalypse.salvage; +import com.fs.starfarer.api.Global; import com.fs.starfarer.api.campaign.BattleAPI; import com.fs.starfarer.api.campaign.CampaignFleetAPI; import com.fs.starfarer.api.fleet.FleetMemberAPI; import com.fs.starfarer.api.impl.campaign.FleetEncounterContext; -import java.util.Collections; +import starpocalypse.helper.ConfigHelper; + import java.util.LinkedList; import java.util.List; public class StarpocalypseFleetEncounterContext extends FleetEncounterContext { private final List recoverableShips = new LinkedList<>(); + private final List playerShips = new LinkedList<>(); private final List storyRecoverableShips = new LinkedList<>(); @Override @@ -23,7 +26,19 @@ public List getRecoverableShips( recoverableShips.addAll(super.getRecoverableShips(battle, winningFleet, otherFleet)); storyRecoverableShips.clear(); storyRecoverableShips.addAll(super.getStoryRecoverableShips()); - return Collections.emptyList(); + // Ignore player ships. + playerShips.clear(); + if (!ConfigHelper.isStingyRecoveriesIncludePlayerShips()) { + // Fleet snapshot before battle. + List playerFleet = Global.getSector().getPlayerFleet().getFleetData().getSnapshot(); + for (FleetMemberAPI ship: recoverableShips) { + if (playerFleet.contains(ship)) { + playerShips.add(ship); + recoverableShips.remove(ship); + } + } + } + return playerShips; } @Override @@ -34,4 +49,4 @@ public List getStoryRecoverableShips() { int cutOff = Math.min(23, allShips.size()); return allShips.subList(0, cutOff); } -} +} \ No newline at end of file diff --git a/src/starpocalypse/salvage/StarpocalypseNexFleetEncounterContext.java b/src/starpocalypse/salvage/StarpocalypseNexFleetEncounterContext.java index 5e491e3..4ca7291 100644 --- a/src/starpocalypse/salvage/StarpocalypseNexFleetEncounterContext.java +++ b/src/starpocalypse/salvage/StarpocalypseNexFleetEncounterContext.java @@ -1,17 +1,19 @@ package starpocalypse.salvage; +import com.fs.starfarer.api.Global; import com.fs.starfarer.api.campaign.BattleAPI; import com.fs.starfarer.api.campaign.CampaignFleetAPI; import com.fs.starfarer.api.fleet.FleetMemberAPI; import exerelin.campaign.battle.NexFleetEncounterContext; +import starpocalypse.helper.ConfigHelper; -import java.util.Collections; import java.util.LinkedList; import java.util.List; public class StarpocalypseNexFleetEncounterContext extends NexFleetEncounterContext { private final List recoverableShips = new LinkedList<>(); + private final List playerShips = new LinkedList<>(); private final List storyRecoverableShips = new LinkedList<>(); @Override @@ -24,7 +26,19 @@ public List getRecoverableShips( recoverableShips.addAll(super.getRecoverableShips(battle, winningFleet, otherFleet)); storyRecoverableShips.clear(); storyRecoverableShips.addAll(super.getStoryRecoverableShips()); - return Collections.emptyList(); + // Ignore player ships. + playerShips.clear(); + if (!ConfigHelper.isStingyRecoveriesIncludePlayerShips()) { + // Fleet snapshot before battle. + List playerFleet = Global.getSector().getPlayerFleet().getFleetData().getSnapshot(); + for (FleetMemberAPI ship: recoverableShips) { + if (playerFleet.contains(ship)) { + playerShips.add(ship); + recoverableShips.remove(ship); + } + } + } + return playerShips; } @Override