Skip to content

Commit a4aeafb

Browse files
committed
*small bugfixes
1 parent 193b4d9 commit a4aeafb

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

WarTech/WarTech/Helper.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static PlanetControlState CalculateActualAttacks(StarSystem system, Plane
9090
int randomDefence = rand.Next(maxDefence) + 1;
9191
if (randomAttack > randomDefence) {
9292
if (Fields.WarFatique[initialTarget] < 100) {
93-
Fields.WarFatique[initialTarget] = Mathf.Min(100, Fields.WarFatique[initialTarget] + Fields.settings.FatiquePerLostAttack);
93+
Fields.WarFatique[initialTarget] = Mathf.Min(100, Fields.WarFatique[initialTarget] + Fields.settings.FatiquePerLostAttack);
9494
}
9595
}
9696
else {
@@ -316,15 +316,16 @@ public static void RefreshResources(SimGameState Sim) {
316316
resources.defence = 0;
317317
}
318318
}
319-
if (Fields.factionResources.Find(x => x.faction == Faction.Locals) == null) {
320-
Fields.factionResources.Add(new FactionResources(Faction.Locals, 0, 0));
321-
}
322319
}
323-
foreach (StarSystem system in Sim.StarSystems) {
324-
FactionResources resources = Fields.factionResources.Find(x => x.faction == system.Owner);
325-
if (resources != null && !IsExcluded(resources.faction)) {
326-
resources.offence += Mathf.RoundToInt(GetOffenceValue(system) * (1 - (Fields.WarFatique[system.Owner] / 100)));
327-
resources.defence += Mathf.RoundToInt(GetDefenceValue(system) * (1 - (Fields.WarFatique[system.Owner] / 100)));
320+
if (Sim.Starmap != null) {
321+
foreach (StarSystem system in Sim.StarSystems) {
322+
FactionResources resources = Fields.factionResources.Find(x => x.faction == system.Owner);
323+
if (resources != null) {
324+
if (!IsExcluded(resources.faction)) {
325+
resources.offence += Mathf.RoundToInt(GetOffenceValue(system) * (1 - (Fields.WarFatique[system.Owner] / 100)));
326+
resources.defence += Mathf.RoundToInt(GetDefenceValue(system) * (1 - (Fields.WarFatique[system.Owner] / 100)));
327+
}
328+
}
328329
}
329330
}
330331
if (Fields.settings.debug) {

WarTech/WarTech/Patch.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,17 @@ static void Postfix(SimGameState simGame) {
234234
}
235235
}
236236
Helper.RefreshTargets(simGame);
237-
if (Fields.factionResources.Count == 0) {
238-
Helper.RefreshResources(simGame);
239-
}
240237
if (Fields.WarFatique == null || Fields.WarFatique.Count == 0) {
241238
Fields.WarFatique = new Dictionary<Faction, float>();
242239
Dictionary<Faction, FactionDef> factions = (Dictionary<Faction, FactionDef>)AccessTools.Field(typeof(SimGameState), "factions").GetValue(simGame);
243240
foreach (KeyValuePair<Faction, FactionDef> pair in factions) {
244241
Fields.WarFatique.Add(pair.Key, 0);
245242
}
246243
}
244+
if (Fields.factionResources.Count == 0) {
245+
Helper.RefreshResources(simGame);
246+
}
247+
247248
}
248249
catch (Exception e) {
249250
Logger.LogError(e);

0 commit comments

Comments
 (0)