Skip to content

Commit

Permalink
v3.8.7 fixes saving/loading forced work
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Oct 2, 2023
1 parent 46bbb9a commit 0311214
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
Binary file modified 1.4/Assemblies/AchtungMod.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</li>
</modDependencies>
<packageId>brrainz.achtung</packageId>
<modVersion>3.8.6.0</modVersion>
<modVersion>3.8.7.0</modVersion>
<steamAppId>730936602</steamAppId>
<url>https://github.com/pardeike/Achtung2</url>
<description>Command your colonists like a boss!
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.achtung</identifier>
<version>3.8.6.0</version>
<version>3.8.7.0</version>
<targetVersions>
<li>1.0.0</li>
<li>1.1.0</li>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ModName>Achtung</ModName>
<ModFileName>Achtung</ModFileName>
<Repository>https://github.com/pardeike/Achtung2</Repository>
<ModVersion>3.8.6.0</ModVersion>
<ModVersion>3.8.7.0</ModVersion>
<ProjectGuid>{8BD5A28F-96C4-43B4-907F-600AA0162F84}</ProjectGuid>
</PropertyGroup>

Expand Down
28 changes: 23 additions & 5 deletions Source/ForcedJob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RimWorld;
using HarmonyLib;
using RimWorld;
using System;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -12,6 +13,7 @@ namespace AchtungMod
public class ForcedJob : IExposable
{
public HashSet<ForcedTarget> targets = new();
public List<ForcedTarget> targets_temp_list = new();
public Pawn pawn = null;
public List<WorkGiverDef> workgiverDefs = new();
public List<WorkGiver_Scanner> workgiverScanners = new();
Expand All @@ -26,7 +28,6 @@ public class ForcedJob : IExposable
public bool buildSmart = Achtung.Settings.buildingSmartDefault;
public bool started = false;
public bool cancelled = false;
public Coroutine expanderThing, expanderCell, contractor;
static readonly Dictionary<BuildableDef, int> TypeScores = new()
{
{ ThingDefOf.PowerConduit, 1000 },
Expand Down Expand Up @@ -433,20 +434,37 @@ public bool IsEmpty()
return targets.Count == 0;
}

public void ExposeData()
void ScribeTargets()
{
if (Scribe.mode == LoadSaveMode.Saving)
_ = targets.RemoveWhere(target => target == null || target.item == null || target.item.IsValid == false || target.item.ThingDestroyed);
targets_temp_list = targets.ToList();

Scribe_Collections.Look(ref targets_temp_list, "targets", LookMode.Deep);

if (Scribe.mode == LoadSaveMode.Saving)
targets_temp_list.Clear();

if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
targets = new HashSet<ForcedTarget>(targets_temp_list);
targets_temp_list.Clear();
}
}

public void ExposeData()
{
Scribe_References.Look(ref pawn, "pawn");
Scribe_Collections.Look(ref workgiverDefs, "workgivers", LookMode.Def);
Scribe_Collections.Look(ref targets, "targets", LookMode.Deep);
ScribeTargets();
Scribe_Values.Look(ref isThingJob, "thingJob", false, true);
Scribe_Values.Look(ref initialized, "inited", false, true);
Scribe_Values.Look(ref cellRadius, "radius", 0, true);
Scribe_Values.Look(ref buildSmart, "buildSmart", true, true);
Scribe_References.Look(ref lastThing, "lastThing");
Scribe_Values.Look(ref lastLocation, "lastLocation", XY.Invalid, true);

if (Scribe.mode == LoadSaveMode.PostLoadInit)
workgiverScanners = workgiverDefs.Select(wgd => wgd.Worker).OfType<WorkGiver_Scanner>().ToList();
}
}
}
11 changes: 2 additions & 9 deletions Source/ForcedTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ public void ExposeData()
Scribe_Values.Look(ref materialScore, "materialScore", 0, true);
}

public bool Equals(ForcedTarget other)
{
return item == other.item;
}

public override int GetHashCode()
{
return item.GetHashCode();
}
public bool Equals(ForcedTarget other) => item == other.item;
public override int GetHashCode() => item.GetHashCode();

public bool IsValidTarget()
{
Expand Down
5 changes: 3 additions & 2 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ public static void Postfix()
else
iterations = 0;

for (var i = 0; i < iterations; i++)
it.MoveNext();
if (Scribe.mode == LoadSaveMode.Inactive)
for (var i = 0; i < iterations; i++)
it.MoveNext();
}
}

Expand Down

0 comments on commit 0311214

Please sign in to comment.