From 01a372181967fe0cd2d8b736c6a5b8a0543b8869 Mon Sep 17 00:00:00 2001 From: lilwhitemouse Date: Sun, 12 Apr 2020 16:09:13 -0400 Subject: [PATCH] Add compatibility with LWM's Deep Storage --- .../StoreUtility_NoStorageBlockersIn.cs | 64 +++++++++++++++++- v1.1/Assemblies/IHoldMultipleThings.dll | Bin 0 -> 4608 bytes 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 v1.1/Assemblies/IHoldMultipleThings.dll diff --git a/Source/RSA/Patches/Storage/StoreUtility_NoStorageBlockersIn.cs b/Source/RSA/Patches/Storage/StoreUtility_NoStorageBlockersIn.cs index 505b70c..565ac34 100644 --- a/Source/RSA/Patches/Storage/StoreUtility_NoStorageBlockersIn.cs +++ b/Source/RSA/Patches/Storage/StoreUtility_NoStorageBlockersIn.cs @@ -11,15 +11,73 @@ namespace RSA [HarmonyPatch(typeof(StoreUtility), "NoStorageBlockersIn")] internal class StoreUtility_NoStorageBlockersIn { + // Some storage mods allow more than one thing in a cell. If they do, we need to do + // more of a check to see if the threshold has been met; we only check if we need to: + public static bool checkIHoldMultipleThings=false; + public static bool Prepare() { + if (ModLister.GetActiveModWithIdentifier("LWM.DeepStorage")!=null) { + checkIHoldMultipleThings=true; + Log.Message("RSA activating compatibility for LWM.DeepStorage"); + } + // If other storage mods don't work, add further tests for them here: + return true; + } [HarmonyPostfix] public static void FilledEnough(ref bool __result, IntVec3 c, Map map, Thing thing) { // if base implementation waves of, then don't need to care if (__result) { float num = 100f; - bool flag = c.GetSlotGroup(map) != null && c.GetSlotGroup(map).Settings != null; - if (flag) { - num = StorageSettings_Mapping.Get(c.GetSlotGroup(map).Settings).FillPercent; + SlotGroup slotGroup=c.GetSlotGroup(map); + + bool flag = slotGroup != null && slotGroup.Settings != null; + if (flag) + { + num = StorageSettings_Mapping.Get(slotGroup.Settings).FillPercent; + } + + //LWM.DeepStorage + if (checkIHoldMultipleThings) { + // NOTE: Other storage mods may not be comp-based. If one ever starts causing + // problems with this mod, the logic here can be updated to include checking + // whether the storage building itself is IHoldMultipleThings + foreach(Thing thisthing in map.thingGrid.ThingsListAt(c)) + { + ThingWithComps th = thisthing as ThingWithComps; + if (th == null) continue; + var allComps = th.AllComps; + + if (allComps != null) + { + foreach (var comp in allComps) + { + if (comp is IHoldMultipleThings.IHoldMultipleThings) + { + int capacity = 0; + IHoldMultipleThings.IHoldMultipleThings thiscomp = (IHoldMultipleThings.IHoldMultipleThings)comp; + + thiscomp.CapacityAt(thing, c, map, out capacity); + // if total capacity is larger than the stackLimit (full stack available) + // Allow hauling (other choices are valid) + // if (capacity > thing.def.stackLimit) return true; + // only haul if count is below threshold + // which is equivalent to availability being above threshold: + // Log.Message("capacity = " + capacity); + // Log.Message("thing.def.stackLimit = " +thing.def.stackLimit); + float var = (100f * (float)capacity / thing.def.stackLimit); + + //100 - num is necessary because capacity gives empty space not full space + __result = var > (100 - num); + // if (__result == false){ + // Log.Message("ITS TOO FULL stop"); + // } + return; + } + } + } + + } + } __result &= !map.thingGrid.ThingsListAt(c).Any(t => t.def.EverStorable(false) && t.stackCount >= thing.def.stackLimit*(num/100f)); diff --git a/v1.1/Assemblies/IHoldMultipleThings.dll b/v1.1/Assemblies/IHoldMultipleThings.dll new file mode 100644 index 0000000000000000000000000000000000000000..bccd46a0a5047f5c82cce6f823dff0a099f2c700 GIT binary patch literal 4608 zcmeHK+iw(A82@H_p%kf<`=!wXMGb0)ZM$3=QCoHkt+1uCrQi*iojtodGCMQQ%mV9! z5{)JhAH?_%=o^VKJ{Tn?#6%781>b!!eel6IeKbnI-*;wayS>DqkA!b~esj)uJKy)6 zGjmS!FMmjFMAVLU_b$k|Nh zHi|~HM)gxs+|1}?V7i0`K2sZ=eUDZ7Z~hq%nFadsaiU|~86`TvMOaK{i5^s}2s`T_ z8+aSe``;p}BF2x=`U|0NIhBAlZetC28TwBYSY4&ifB3{?4!kuOSK0QU?G{-X1as~1 z2BMWb_)8n6jZy4tBbh1#m$)ZxoEL0BpJ`E!o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