Skip to content

Commit

Permalink
v1.16.6 fixes some unexpected queuing with Combat Extended and a pote…
Browse files Browse the repository at this point in the history
…ntial memory leak.
  • Loading branch information
pardeike committed Sep 19, 2019
1 parent 1803f2e commit 4b329b0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
Binary file modified Assemblies/ZombieLand.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions Source/ColonistSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public ColonistSettings(World world) : base(world)

public ColonistConfig ConfigFor(Pawn pawn)
{
if (pawn.IsColonist == false)
return null;
if (colonists.TryGetValue(pawn, out var config))
return config;
config = new ColonistConfig();
Expand All @@ -51,12 +53,17 @@ public override void ExposeData()
{
base.ExposeData();

if (Scribe.mode == LoadSaveMode.Saving)
_ = colonists.RemoveAll(pair => pair.Key == null || pair.Key.IsColonist == false);

Scribe_Collections.Look(ref colonists, "colonists", LookMode.Reference, LookMode.Deep, ref colonistsKeysWorkingList, ref colonistsValuesWorkingList);

if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
if (colonists == null)
colonists = new Dictionary<Pawn, ColonistConfig>();
else
_ = colonists.RemoveAll(pair => pair.Key == null || pair.Key.IsColonist == false);
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions Source/Gizmos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ static class Gizmos
public static Gizmo ZombieAvoidance(Pawn pawn)
{
var config = ColonistSettings.Values.ConfigFor(pawn);
if (config == null)
return null;

var autoAvoidZombies = config.autoAvoidZombies;
var description = autoAvoidZombies ? "AutoAvoidZombiesEnabledDescription" : "AutoAvoidZombiesDisabledDescription";

Expand All @@ -37,14 +40,17 @@ public static Gizmo ExtractSerum(Pawn pawn)
Action action = null;

var canDoctor = pawn.CanDoctor();
var config = canDoctor ? ColonistSettings.Values.ConfigFor(pawn) : null;
if (canDoctor)
{
var autoExtractZombieSerum = config.autoExtractZombieSerum;
description = autoExtractZombieSerum ? "AutoExtractAllowedDescription" : "AutoExtractForbiddenDescription";
icon = autoExtractZombieSerum ? ExtractingAllowed : ExtractingForbidden;
activateSound = autoExtractZombieSerum ? SoundDefOf.Designate_ZoneAdd : SoundDefOf.Designate_ZoneDelete;
action = config.ToggleAutoExtractZombieSerum;
var config = canDoctor ? ColonistSettings.Values.ConfigFor(pawn) : null;
if (config != null)
{
var autoExtractZombieSerum = config.autoExtractZombieSerum;
description = autoExtractZombieSerum ? "AutoExtractAllowedDescription" : "AutoExtractForbiddenDescription";
icon = autoExtractZombieSerum ? ExtractingAllowed : ExtractingForbidden;
activateSound = autoExtractZombieSerum ? SoundDefOf.Designate_ZoneAdd : SoundDefOf.Designate_ZoneDelete;
action = config.ToggleAutoExtractZombieSerum;
}
}

return new Command_Action
Expand Down
10 changes: 2 additions & 8 deletions Source/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Verse;
using Verse.AI;
using Verse.Sound;
using static Harmony.AccessTools;

namespace ZombieLand
{
Expand Down Expand Up @@ -1062,9 +1061,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
[HarmonyPatch(nameof(JobDriver.DriverTick))]
static class JobDriver_DriverTick_Patch
{
static readonly FieldRef<Pawn_JobTracker, int> jobsGivenThisTickRef = FieldRefAccess<Pawn_JobTracker, int>("jobsGivenThisTick");
static readonly FieldRef<Pawn_JobTracker, string> jobsGivenThisTickTextualRef = FieldRefAccess<Pawn_JobTracker, string>("jobsGivenThisTickTextual");

static void Postfix(JobDriver __instance, Pawn ___pawn)
{
if (___pawn is Zombie || ___pawn.IsColonist == false)
Expand Down Expand Up @@ -1117,11 +1113,9 @@ static void Postfix(JobDriver __instance, Pawn ___pawn)
var destination = safeDestinations.First();
if (destination.IsValid)
{
jobsGivenThisTickRef(___pawn.jobs) = 0;
jobsGivenThisTickTextualRef(___pawn.jobs) = string.Empty;

var flee = new Job(JobDefOf.Flee, destination) { playerForced = true };
___pawn.jobs.StartJob(flee, JobCondition.InterruptOptional, null);
___pawn.jobs.ClearQueuedJobs();
___pawn.jobs.StartJob(flee, JobCondition.Incompletable, null);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.16.5.0")]
[assembly: AssemblyFileVersion("1.16.5.0")]
[assembly: AssemblyVersion("1.16.6.0")]
[assembly: AssemblyFileVersion("1.16.6.0")]
2 changes: 1 addition & 1 deletion Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static bool IsDowned(this Pawn pawn)

public static bool ShouldAvoidZombies(Pawn pawn = null)
{
if (pawn == null)
if (pawn == null || pawn.IsColonist == false)
return ZombieSettings.Values.betterZombieAvoidance;

if (ZombieSettings.Values.betterZombieAvoidance == false) return false;
Expand Down
3 changes: 3 additions & 0 deletions Source/WorkGivers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)

public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
{
if (pawn.IsColonist == false)
return false;

var corpse = t as ZombieCorpse;
if (corpse.DestroyedOrNull() || corpse.Spawned == false)
return false;
Expand Down

0 comments on commit 4b329b0

Please sign in to comment.