Skip to content

Commit

Permalink
- Fixed fuel waste when forced-refuelling a non-empty building.
Browse files Browse the repository at this point in the history
  • Loading branch information
João Pedro Torres committed Jan 19, 2020
1 parent 2576444 commit c99d449
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Binary file modified Assemblies/BurnItForFuel.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Source/CompSelectFuel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
}
yield break;
}

}
}
20 changes: 19 additions & 1 deletion Source/HarmonyPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using Verse;
using Verse.AI;

Expand All @@ -25,6 +26,10 @@ static HarmonyPatches()

harmonyInstance.Patch(original: AccessTools.Method(type: typeof(RefuelWorkGiverUtility), name: "FindAllFuel"),
prefix: null, postfix: new HarmonyMethod(type: patchType, name: nameof(FindAllFuel_Postfix)), transpiler: null);

harmonyInstance.Patch(original: AccessTools.Method(type: typeof(CompRefuelable), name: "GetFuelCountToFullyRefuel"),
prefix: null, postfix: new HarmonyMethod(type: patchType, name: nameof(GetFuelCountToFullyRefuel_Postfix)), transpiler: null);

}

public static void CanRefuel_Postfix(object __instance, Pawn pawn, Thing t, bool forced, ref bool __result)
Expand Down Expand Up @@ -85,6 +90,7 @@ public static void FindBestFuel_Postfix(Pawn pawn, Thing refuelable, ref Thing _

private static Thing FindBestFuel(Pawn pawn, Thing refuelable)
{
//Log.Message("FindBestFuel_Postfix for: "+refuelable);
ThingFilter filter = new ThingFilter();
filter = refuelable.TryGetComp<CompSelectFuel>().fuelSettings.filter;
Predicate<Thing> predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && filter.Allows(x);
Expand All @@ -107,7 +113,8 @@ public static void FindAllFuel_Postfix(Pawn pawn, Thing refuelable, ref List<Thi

private static List<Thing> FindAllFuel(Pawn pawn, Thing refuelable)
{
int quantity = refuelable.TryGetComp<CompRefuelable>().GetFuelCountToFullyRefuel();
CompRefuelable comp = refuelable.TryGetComp<CompRefuelable>();
int quantity = GetFuelCountToFullyRefuel(comp);
ThingFilter filter = new ThingFilter();
filter = refuelable.TryGetComp<CompSelectFuel>().fuelSettings.filter;
Predicate<Thing> validator = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && filter.Allows(x);
Expand Down Expand Up @@ -148,5 +155,16 @@ private static List<Thing> FindAllFuel(Pawn pawn, Thing refuelable)
}
return null;
}

public static void GetFuelCountToFullyRefuel_Postfix(CompRefuelable __instance, ref int __result)
{
__result = GetFuelCountToFullyRefuel(__instance);
}

public static int GetFuelCountToFullyRefuel(CompRefuelable __instance)
{
float f = (__instance.TargetFuelLevel - __instance.Fuel) / __instance.Props.FuelMultiplierCurrentDifficulty;
return Mathf.Max(Mathf.CeilToInt(f), 1);
}
}
}
2 changes: 1 addition & 1 deletion Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.2.2")]
[assembly: AssemblyFileVersion("1.3")]

0 comments on commit c99d449

Please sign in to comment.