Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
Fixed null reference exception when the game passed a null blueprint/frame.
  • Loading branch information
DingoDjango committed Nov 21, 2017
1 parent 6bc0561 commit 8be0fae
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 43 deletions.
Binary file modified Assemblies/Hand Me That Brick.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,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("2.5.18.0")]
[assembly: AssemblyFileVersion("2.5.18.0")]
[assembly: AssemblyVersion("2.6.18.0")]
[assembly: AssemblyFileVersion("2.6.18.0")]
44 changes: 19 additions & 25 deletions Source/Tools/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using Verse;
using Verse;

namespace HMTB
{
[StaticConstructorOnStartup]
public static class Utilities
{
public static IEnumerable<Thing> WorkThingsOpportunistic(Pawn pawn, ThingRequest request)
public static bool AllowedHaulDistance(Pawn pawn, Thing t)
{
IEnumerable<Thing> allMatchingThings = pawn.Map.listerThings.ThingsMatching(request);
OpportunityDistance distance = Controller.OpportunisticMode.Value;

if (Controller.OpportunisticMode.Value == OpportunityDistance.HMTB_Unrestricted)
if (distance == OpportunityDistance.HMTB_Unrestricted)
{
return allMatchingThings;
return true;
}

else
{
float maxSearchDistance;

switch (Controller.OpportunisticMode.Value)
{
case OpportunityDistance.HMTB_Close:
maxSearchDistance = 15f;
break;
case OpportunityDistance.HMTB_Medium:
maxSearchDistance = 45f;
break;
default:
maxSearchDistance = 100f; //(Long)
break;
}
float maxSearchDistance;

return allMatchingThings.Where(t => t.Position.DistanceTo(pawn.Position) < maxSearchDistance);
switch (distance)
{
case OpportunityDistance.HMTB_Close:
maxSearchDistance = 15f; //Close
break;
case OpportunityDistance.HMTB_Medium:
maxSearchDistance = 45f; //Medium
break;
default:
maxSearchDistance = 100f; //Long
break;
}

return t.Position.DistanceTo(pawn.Position) <= maxSearchDistance;
}
}
}
14 changes: 5 additions & 9 deletions Source/Work/WorkGiver_HaulDeliverResourcesToBlueprints.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using RimWorld;
using RimWorld;
using Verse;

namespace HMTB
Expand All @@ -15,17 +14,14 @@ public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
{
Blueprint blueprint = t as Blueprint;

if (blueprint is Blueprint_Install)
if (blueprint == null)
{
return base.HasJobOnThing(pawn, t, forced);
return false;
}

return !blueprint.MaterialsNeeded().NullOrEmpty() && base.HasJobOnThing(pawn, t, forced);
}
bool materialsAllowed = blueprint is Blueprint_Install ? true : !blueprint.MaterialsNeeded().NullOrEmpty();

public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
{
return Utilities.WorkThingsOpportunistic(pawn, this.PotentialWorkThingRequest);
return materialsAllowed && Utilities.AllowedHaulDistance(pawn, blueprint) && base.HasJobOnThing(pawn, t, forced);
}
}
}
13 changes: 6 additions & 7 deletions Source/Work/WorkGiver_HaulDeliverResourcesToFrames.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using RimWorld;
using RimWorld;
using Verse;

namespace HMTB
Expand All @@ -15,12 +14,12 @@ public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
{
Frame frame = t as Frame;

return !frame.MaterialsNeeded().NullOrEmpty() && base.HasJobOnThing(pawn, t, forced);
}
if (frame == null)
{
return false;
}

public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
{
return Utilities.WorkThingsOpportunistic(pawn, this.PotentialWorkThingRequest);
return !frame.MaterialsNeeded().NullOrEmpty() && Utilities.AllowedHaulDistance(pawn, frame) && base.HasJobOnThing(pawn, t, forced);
}
}
}

0 comments on commit 8be0fae

Please sign in to comment.