Skip to content

Commit

Permalink
Split stingy recoveries to separate derelicts and combat recoveries.
Browse files Browse the repository at this point in the history
  • Loading branch information
frakern committed May 24, 2023
1 parent cd9fd77 commit 6e6bef9
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 21 deletions.
10 changes: 6 additions & 4 deletions assets/starpocalypse.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"format": "prettier --write src/"
},
"dependencies": {
"prettier": "*",
"prettier-plugin-java": "*"
},
"devDependencies": {
"prettier": "2.8.8"
}
}
18 changes: 13 additions & 5 deletions src/starpocalypse/StarpocalypseMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void onGameLoad(boolean newGame) {
industryChanges();
combatAdjustedReputation();
hostilityForSpecialItemRaid();
stingyRecoveries();
stingyDerelictRecoveries();
stingyCombatRecoveries();
salvageMultiplier();
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/starpocalypse/helper/ConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/starpocalypse/helper/DropTableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions src/starpocalypse/salvage/DerelictModifyingScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ 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);
}
}

private List<SectorEntityToken> 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);
Expand Down
21 changes: 18 additions & 3 deletions src/starpocalypse/salvage/StarpocalypseFleetEncounterContext.java
Original file line number Diff line number Diff line change
@@ -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<FleetMemberAPI> recoverableShips = new LinkedList<>();
private final List<FleetMemberAPI> playerShips = new LinkedList<>();
private final List<FleetMemberAPI> storyRecoverableShips = new LinkedList<>();

@Override
Expand All @@ -23,7 +26,19 @@ public List<FleetMemberAPI> 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<FleetMemberAPI> playerFleet = Global.getSector().getPlayerFleet().getFleetData().getSnapshot();
for (FleetMemberAPI ship: recoverableShips) {
if (playerFleet.contains(ship)) {
playerShips.add(ship);
recoverableShips.remove(ship);
}
}
}
return playerShips;
}

@Override
Expand All @@ -34,4 +49,4 @@ public List<FleetMemberAPI> getStoryRecoverableShips() {
int cutOff = Math.min(23, allShips.size());
return allShips.subList(0, cutOff);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<FleetMemberAPI> recoverableShips = new LinkedList<>();
private final List<FleetMemberAPI> playerShips = new LinkedList<>();
private final List<FleetMemberAPI> storyRecoverableShips = new LinkedList<>();

@Override
Expand All @@ -24,7 +26,19 @@ public List<FleetMemberAPI> 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<FleetMemberAPI> playerFleet = Global.getSector().getPlayerFleet().getFleetData().getSnapshot();
for (FleetMemberAPI ship: recoverableShips) {
if (playerFleet.contains(ship)) {
playerShips.add(ship);
recoverableShips.remove(ship);
}
}
}
return playerShips;
}

@Override
Expand Down

0 comments on commit 6e6bef9

Please sign in to comment.