From c99d449c9dd4719e1334ebeca7f414464cbb4d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Torres?= Date: Sun, 19 Jan 2020 00:50:01 -0300 Subject: [PATCH] - Fixed fuel waste when forced-refuelling a non-empty building. --- Assemblies/BurnItForFuel.dll | Bin 14336 -> 14848 bytes Source/CompSelectFuel.cs | 1 + Source/HarmonyPatch.cs | 20 +++++++++++++++++++- Source/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Assemblies/BurnItForFuel.dll b/Assemblies/BurnItForFuel.dll index 1322ab3a974248ff5ab6834e03cbf2d83eaef2ed..b0ba48231c081c47bff46dc9220ad2a54cd62afd 100644 GIT binary patch delta 4307 zcma)AdvH|M8UM~XckjJ>@9vV#hCm)b9wclwAuJ>y(C{)uUO@sRXn+bK1Wbw9kcS8{ z-9#J&gw~ylK*SkD&>0Xa7zGi=4y_|~tQK+XU`sP(uytq=@zshl(BC;5U;V2$bAR{y zecyM!?>mos&fRo2b+$gSIqP=XmT##4xT;jI)&u^=%dqm*duO7dyw<2sYm7Wmze^(Mn!3 zadUDJjf9*{#GGT{J9;Yk3MO3C?YtsJvSR157&Gui>CJxX zm;(3aR|GXBB?YHIPWmNB(al$+re&&BM5Y0AL(XaAb3RgYj+$lh#}FsUJ&ol!i`-$B z>pbR;4gVJ^^%D78MxatMl6IHdulZdW zdp9vk58eX}>Fo&=g>$~89ghC{^s<{#Y17S`D=pPF9 z6OY`BSUge_`cMBqA?wmx+emDjLGuWr`m% z7TG*GUWJt(NN!0-WK3u~-VCinf*u;mgIKnDD2oS|JA=JNo;qa7XUTEJJ>H_)?-Ua? z-Y#b@IkE~a@xE*HI%){WzKh6es8fRX10(eSE7=~u6;{%X$S=S>yj?C6GqMK6>n>;@ zuI9>&G&rAl2W33~b-?9!6-@cw&3daM-4pd#ob{Ckp6F6;&04LmQJs5iR~y_r&S_g_~<6v@3rW8 zmGZBMX3-wR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SkaV%EeqvLnpq+xa_um|x)k&<5I1&rk^~<%hY|MYm!`KYXgpVgFvTR1_Hl4U@xt zc=^}QE4X>|b%0yNG|gt?%Fy>t>@83Cmx^U-MtWp$Rr*{p_{YpuT;*jgQ`@uDU}g3j z)?i@LubA4KKSN#0|Lx%Gkt0G~D!wAVw|GxQ+@{sD_t%fiYP@rCg{q$Xc`%ICvmnQJ zP%s=056&vt#yn|WZ(^2u>x!CWE`yHOO6>Y|qRSKKB7S1`95uD{YG;9uSVGr8LiZxI zrF2NGFMG*$P=K CompGetGizmosExtra() } yield break; } + } } \ No newline at end of file diff --git a/Source/HarmonyPatch.cs b/Source/HarmonyPatch.cs index 93b817e..b36e637 100644 --- a/Source/HarmonyPatch.cs +++ b/Source/HarmonyPatch.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using UnityEngine; using Verse; using Verse.AI; @@ -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) @@ -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().fuelSettings.filter; Predicate predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && filter.Allows(x); @@ -107,7 +113,8 @@ public static void FindAllFuel_Postfix(Pawn pawn, Thing refuelable, ref List FindAllFuel(Pawn pawn, Thing refuelable) { - int quantity = refuelable.TryGetComp().GetFuelCountToFullyRefuel(); + CompRefuelable comp = refuelable.TryGetComp(); + int quantity = GetFuelCountToFullyRefuel(comp); ThingFilter filter = new ThingFilter(); filter = refuelable.TryGetComp().fuelSettings.filter; Predicate validator = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && filter.Allows(x); @@ -148,5 +155,16 @@ private static List 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); + } } } \ No newline at end of file diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs index e6d1f99..6fa7aac 100644 --- a/Source/Properties/AssemblyInfo.cs +++ b/Source/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0")] -[assembly: AssemblyFileVersion("1.2.2")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.3")] \ No newline at end of file