[1.3] [KV] RimFridge [ModSync RW]

Started by Kiame, May 28, 2017, 01:47:11 AM

Previous topic - Next topic

Kiame

Update:
Fridges can hold body parts again

Rivo

So, I'm trying to have meal production orders go straight to the fridges. I've placed the fridge, renamed the stockpile, but I can't pick that stockpile in the "Look Everywhere" option or the "Take to best stockpile" option - they never show up (from the meal order).

Is that expected behavior?

LWM

RimFridges are glorified shelves.  Super useful shelves, but glorified shelves.  Bills cannot select shelves, only stockpiles, ergo...

There is a lot of interest in making this happen, if someone can make it happen for shelves (perhaps based on Label?), it could work.

Kiame

It's a limitation of the game's code where only stockpiles and not storage buildings can be selected. I've considered adding support for it to this mod but it's a large undertaking and I like the fact this mod is small and compatible with everything due to that.

My hope was a mod like better workbench management would add support but that has not happened

LWM

Honestly, I think it could stand to be a stand-alone mod - several of us storage-ppl have players who would love it.

Kiame

Lol I have too many mods already  :-[

It's been a while since I last looked into it, I'll see if I can get it working as a stand alone

Kiame

After a few more hours on this i remember now why this is no longer possible. In B19 iirc they re-wrote the entire bill system to have everything based of Zone_Stockpile as opposed to IHaulDestination. Due to that it's really impossible even with transpilation to have this work. Bills themselves have a method to set location which is a Zone_Stockpile. Anyone that wants this to work would have to rewrite the structure of bills which i doubt is possible.

LWM

Actually, a Transpiler might be able to make that happen.

I may look into it the next time I need a challenge ;p

Kiame

#233
I am not a transpiler god  :-\

Barely a transpiler novice!  ;D

If it helps this is the code i started to write (in rimfridge to save time prototyping)

        [HarmonyPatch(typeof(Dialog_BillConfig), "DoWindowContents", new Type[] {typeof(Rect)})]
        public static class Patch_Dialog_BillConfig_DoWindowContents
        {
            public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
            {
                List<CodeInstruction> instructionList = instructions.ToList();
                FieldInfo billFI = typeof(Dialog_BillConfig).GetField("bill", BindingFlags.NonPublic | BindingFlags.Instance);

                bool found = false;
                for (int i = 0; i < instructionList.Count; ++i)
                {
                    if (instructionList[i].opcode == OpCodes.Ldsfld &&
                        instructionList[i].operand?.ToString() == "RimWorld.BillStoreModeDef SpecificStockpile")
                    {
                        found = true;

                        yield return new CodeInstruction(OpCodes.Ldfld, billFI);
                        yield return new CodeInstruction(OpCodes.Ldloc_S, 15);
                        yield return new CodeInstruction(OpCodes.Ldloc_S, 13);
                        yield return new CodeInstruction(
                            OpCodes.Call,
                            typeof(Patch_Dialog_BillConfig_DoWindowContents).GetMethod(
                                nameof(Patch_Dialog_BillConfig_DoWindowContents.AddStorageBuildings), BindingFlags.Static | BindingFlags.NonPublic));
                    }
                    yield return instructionList[i];
                }

                if (!found)
                {
                    Log.Error("NOT FOUND!!!");
                }
            }

            private static bool CanPossiblyStoreInBuildingStorage(Bill_Production bill, Building_Storage s)
            {
                var recipe = bill.recipe;
                if (!recipe.WorkerCounter.CanCountProducts(bill))
                {
                    return true;
                }
                return s.GetStoreSettings().AllowedToAccept(recipe.products[0].thingDef);
            }

            private static void AddStorageBuildings(Bill_Production bill, BillStoreModeDef item, List<FloatMenuOption> list)
            {
                List<SlotGroup> allGroupsListInPriorityOrder = bill.billStack.billGiver.Map.haulDestinationManager.AllGroupsListInPriorityOrder;
                int count = allGroupsListInPriorityOrder.Count;
                for (int i = 0; i < count; i++)
                {
                    SlotGroup group = allGroupsListInPriorityOrder[i];

                    if (group.parent is Building_Storage s)
                    {
                        if (!CanPossiblyStoreInBuildingStorage(bill, s))
                        {
                            list.Add(new FloatMenuOption(string.Format("{0} ({1})", string.Format(item.LabelCap, group.parent.SlotYielderLabel()), "IncompatibleLower".Translate()), null));
                        }
                        else
                        {
                            list.Add(new FloatMenuOption(string.Format(item.LabelCap, group.parent.SlotYielderLabel()), delegate
                            {
                                bill.SetStoreMode(BillStoreModeDefOf.SpecificStockpile, s);
                            }));
                        }
                    }
                }
            }
        }


The part that breaks is at the end with the call to bill.SetStoreMode(BillStoreModeDefOf.SpecificStockpile, s);


My basic thinking was add a method call to add storage buildings along with populating the drop down with stockpiles. In AddStorageBuildings it'd iterate over the same storage objects and just pull out storage buildings and add them the same way.

wwWraith

ModSync RW tells for some time that RimFridge was updated to 1.1.0.5, but I still can see only 1.1.0.4 in your download link, and I remember that with your releasing system it probably won't be a good idea to just "clone/download" from GitHub ;)
Think about it. Think around it. Perhaps you'll get some new good idea even if it would be completely different from my words.

Kiame



Kiame

Update:
Making the code more efficient. Please let me know if there are any issues with this update.

Kiame

Update 1.2.1.0:
RimFridges can now act like hoppers when placed next to Nutrient Paste Dispensers.
Only the cells adjacent to the Dispenser will work. See the fourth screen shot for more information.

(My hope is this will also apply to Deep Storage freezers, if there's any problems with those post messages here and not on the Deep Storage page)

slaveofpeon

#239
Yeah, this hopper idea is great, but its bugged the fridges in yours and deep storage to only be placeable next to structures requiring a hopper. I have two placed from before the update, but I cant place any anymore.

Figure its gotta do with how the game recognizes hoppers?

I attached two screenshots where I have tried to place a fridge, and showing where I have my previous fridges.
Don't mention the elephant in the room, since no one knows it exists if we make a rule against it and never talk about it.

Mention Rum, Get Sixxed