Skip to content
This repository was archived by the owner on May 6, 2023. It is now read-only.

Commit ea40c5f

Browse files
authored
Nex integration and bugfixing (#29)
- Fix Nexerlin alliance state (commission check in Military Market). - Fix game crash in ship damager when minDmods is equal maxDmods.
1 parent 0fbae0c commit ea40c5f

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

assets/mod_info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": " Starpocalypse",
44
"author": "Jaghaimo",
55
"utility": true,
6-
"version": "2.2.2",
6+
"version": "2.2.3",
77
"description": "More apocalyptic settings",
88
"gameVersion": "0.95.1a-RC6",
99
"modPlugin": "starpocalypse.StarpocalypseMod",

assets/starpocalypse.version

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"modVersion": {
66
"major": 2,
77
"minor": 2,
8-
"patch": 2
8+
"patch": 3
99
},
10-
"directDownloadURL": "https://github.com/jaghaimo/starpocalypse/releases/download/2.2.2/starpocalypse-2.2.2.zip"
10+
"directDownloadURL": "https://github.com/jaghaimo/starpocalypse/releases/download/2.2.3/starpocalypse-2.2.3.zip"
1111
}

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ repositories {
1515
artifact()
1616
}
1717
}
18+
ivy {
19+
url 'https://github.com/'
20+
patternLayout {
21+
artifact '/[organization]/[module]/raw/master/jars/[revision]'
22+
}
23+
metadataSources {
24+
artifact()
25+
}
26+
}
1827
}
1928

2029
// project level config
@@ -40,6 +49,7 @@ build {
4049
// compile time dependencies
4150
dependencies {
4251
implementation "jaghaimo:starsector-api:[email protected]"
52+
implementation "Histidine91:Nexerelin:ExerelinCore.jar"
4353

4454
// game dependencies
4555
implementation group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.10'

src/starpocalypse/helper/CargoUtils.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void damageShip(String location, FleetMemberAPI ship, int minDmods
2222
Random random = new Random();
2323
if (DModManager.setDHull(variant)) {
2424
log.info(location + ": Damaging " + hullName);
25-
int numberOfDmods = random.nextInt(maxDmods - minDmods) + minDmods;
25+
int numberOfDmods = getNumberOfDmods(random, minDmods, maxDmods);
2626
DModManager.addDMods(variant, true, numberOfDmods, random);
2727
}
2828
}
@@ -41,4 +41,12 @@ public static int getTier(CargoStackAPI stack) {
4141
}
4242
return tier;
4343
}
44+
45+
private static int getNumberOfDmods(Random random, int minDmods, int maxDmods) {
46+
int numDmods = minDmods;
47+
if (maxDmods > minDmods) {
48+
numDmods += random.nextInt(maxDmods - minDmods);
49+
}
50+
return numDmods;
51+
}
4452
}

src/starpocalypse/submarket/RegulatedMilitaryMarket.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package starpocalypse.submarket;
22

3+
import com.fs.starfarer.api.Global;
34
import com.fs.starfarer.api.campaign.CargoAPI;
45
import com.fs.starfarer.api.campaign.CargoStackAPI;
56
import com.fs.starfarer.api.campaign.FleetDataAPI;
@@ -8,6 +9,9 @@
89
import com.fs.starfarer.api.campaign.econ.SubmarketAPI;
910
import com.fs.starfarer.api.fleet.FleetMemberAPI;
1011
import com.fs.starfarer.api.impl.campaign.submarkets.MilitarySubmarketPlugin;
12+
import exerelin.campaign.AllianceManager;
13+
import exerelin.campaign.PlayerFactionStore;
14+
import exerelin.utilities.NexUtilsFaction;
1115
import lombok.extern.log4j.Log4j;
1216
import starpocalypse.config.SimpleMap;
1317
import starpocalypse.helper.CargoUtils;
@@ -65,6 +69,32 @@ public void updateCargoPrePlayerInteraction() {
6569
}
6670
}
6771

72+
@Override
73+
protected boolean hasCommission() {
74+
if (Global.getSettings().getModManager().isModEnabled("nexerelin")) {
75+
return hasCommissionNex();
76+
}
77+
return super.hasCommission();
78+
}
79+
80+
private boolean hasCommissionNex() {
81+
String commissionFaction = NexUtilsFaction.getCommissionFactionId();
82+
if (hasCommissionNex(commissionFaction)) {
83+
return true;
84+
}
85+
if (hasCommissionNex(PlayerFactionStore.getPlayerFactionId())) {
86+
return true;
87+
}
88+
return submarket.getFaction().getId().equals(commissionFaction);
89+
}
90+
91+
private boolean hasCommissionNex(String factionId) {
92+
if (factionId == null) {
93+
return false;
94+
}
95+
return AllianceManager.areFactionsAllied(factionId, submarket.getFaction().getId());
96+
}
97+
6898
private boolean isStabilityLegal(SimpleMap stabilityMap, float baseValue) {
6999
if (!ConfigHelper.wantsRegulation(market.getFactionId())) {
70100
return false;

src/starpocalypse/submarket/ShipDamager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void reportSubmarketCargoAndShipsUpdated(SubmarketAPI submarket) {
3333
apply(location, submarket.getCargo().getMothballedShips().getMembersListCopy());
3434
}
3535

36-
private static boolean canDamageShips(SubmarketAPI submarket) {
36+
private boolean canDamageShips(SubmarketAPI submarket) {
3737
boolean hasSubmarket = ConfigHelper.getShipDamageSubmarket().has(submarket.getSpecId());
3838
boolean hasFaction = ConfigHelper.getShipDamageFaction().has(submarket.getMarket().getFactionId());
3939
return hasSubmarket && hasFaction;

0 commit comments

Comments
 (0)