[1.0] Bulk Recipe Generator

Started by Lowlofir, May 28, 2019, 01:25:24 PM

Previous topic - Next topic

Lowlofir

Bulk recipe generator

Description
Generates bulk recipes for what crafts too fast.

Scans recipes on game launch and makes copies for those with a short crafting time, multiplying ingredients count, products count, and work amount.
Right click original recipe in "Add bill" list to see corresponding bulk ones.

Compatibility

  • Safe to add to saves.
  • To safely remove it remove bills on work tables that uses this mod's recipes first (can be done automatically by using button on mod settings page).
  • Should work with recipes from other mods, however it is not properly tested yet.

Download

FalkrimWright

What about optional x10 x25 x50 x75 recipies?

Lowlofir

#2
I added such option. But recipes list in game become more multiplier list than item to craft list, so it is disabled by default until I find better solution. Also meaning of that numeric value in option changed, so it should be like 5 times larger than before for similar behavior.

Canute

Maybe create a mod option, to flag what kind of recipes should show up at the bench.
At last that option should work for existing colonies, ok maybe they need to reload the safegame so these recipes should show up/disappear.

Lowlofir

Updated. Now added recipes are in context menu (right click) of original ones.

Tenshi~Akari

Probably should include a small warning for existing saves. I lost several pawns, production benches and animals (both modded & vanilla) due to a few exception errors. Here's the red one that popped up on the initial load:


Could not execute post-long-event action. Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Ad2mod.Ad2 ---> System.NullReferenceException: original
  at Harmony.PatchProcessor.Patch () [0x00000] in <filename unknown>:0
  at Harmony.HarmonyInstance.Patch (System.Reflection.MethodBase original, Harmony.HarmonyMethod prefix, Harmony.HarmonyMethod postfix, Harmony.HarmonyMethod transpiler) [0x00000] in <filename unknown>:0
  at Ad2mod.Ad2+<>c__DisplayClass14_0.<RecipeIconsCompatibility>b__0 () [0x00000] in <filename unknown>:0
  at Ad2mod.Ad2.RecipeIconsCompatibility (Harmony.HarmonyInstance harmony) [0x00000] in <filename unknown>:0
  at Ad2mod.Ad2..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (intptr) <0x00065>
at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (System.RuntimeTypeHandle) <0x00047>
at StartupImpact.Patch.StaticConstructorOnStartupUtilityCallAll.Prefix () <0x00142>
at (wrapper dynamic-method) Verse.StaticConstructorOnStartupUtility.CallAll_Patch1 () <0x00021>
at Verse.PlayDataLoader.<DoPlayLoad>m__2 () <0x00014>
at Verse.LongEventHandler.ExecuteToExecuteWhenFinished () <0x00093>


And this one for one of the pawns that disappeared upon loading w/ the mod:

Exception spawning loaded thing Kai: System.TypeInitializationException: An exception was thrown by the type initializer for Ad2mod.Ad2 ---> System.NullReferenceException: original
  at Harmony.PatchProcessor.Patch () [0x00000] in <filename unknown>:0
  at Harmony.HarmonyInstance.Patch (System.Reflection.MethodBase original, Harmony.HarmonyMethod prefix, Harmony.HarmonyMethod postfix, Harmony.HarmonyMethod transpiler) [0x00000] in <filename unknown>:0
  at Ad2mod.Ad2+<>c__DisplayClass14_0.<RecipeIconsCompatibility>b__0 () [0x00000] in <filename unknown>:0
  at Ad2mod.Ad2.RecipeIconsCompatibility (Harmony.HarmonyInstance harmony) [0x00000] in <filename unknown>:0
  at Ad2mod.Ad2..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (intptr)
  at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor (RuntimeTypeHandle type) [0x00000] in <filename unknown>:0
  at StartupImpact.Patch.StaticConstructorOnStartupUtilityCallAll.Prefix () [0x00000] in <filename unknown>:0
  at (wrapper dynamic-method) Verse.StaticConstructorOnStartupUtility:CallAll_Patch1 ()
  at Verse.PlayDataLoader.<DoPlayLoad>m__2 () [0x00000] in <filename unknown>:0
  at Verse.LongEventHandler.ExecuteToExecuteWhenFinished () [0x00000] in <filename unknown>:0


Outside of that, it seems to work in new games alright from the little bit I tested, but it was only just that little bit.

Lowlofir

#6
Wow, I don't know now how this could happen. Thanks for report. I'll try to figure this out. I tested adding and removing it to/from saves few times with different other mods combinations, and the only problem I found happens when loading save that have bills made by this mod while it is disabled, and even in this case nothing was lost.
Exceptions are from method for patching RecipeIcons mod for compatibility, maybe I overlooked something stupid in that code.

Edit: Ok, I found a way to cause same error message. It is a special case when Recipe icons mod present and enabled, but it's dlls are missing. Still not clear for me how this can cause mentioned loss of pawns etc. but I made this part more failsafe in new update, so at least errors will be more informative next time.

Tenshi~Akari

#7
Cool, just updated to the most recent version, all seems to be well despite the initial error log pop-up (not copying it over since you said it was a fail-safe... also the disabling of right-click on ambiguous recipe labels, etc.). All pawns & benches accounted for & working.  Will be sure to report back if I find anything else. Thanks for the fix! :D

EDIT: Coming back with an unfortunate report, it seems whatever temporary fix was put in place disables the ability to direct drafted pawns to where you need them to be w/ right-click. (At first I thought it was my own mouse, but everything else that requires a right-click on this PC works just fine...) Definitely might want to check on this bug. I don't have any error pop-ups to provide, but there's definitely no response when right-clicking anywhere on the ground during drafting procedures.

Lowlofir

#8
It is a bug. I fixed it now. Also I changed errors and warnings in this update so now red errors mean real errors and likely should be examined.

5teVe

well, i don't have a good half of multiplier recipes
like: i can craft x5,x10,x25,x50 of %recipe_1%, but can't craft x25 for %recipe_2%, only x5,x10,x50.
or for %recipe_3%, that allows to craft only x5 etc
screens must be more speech than my banana engrish





p.s. there is no recipe browsers fault, even if i use vanilla interface, recipes doesn't shows as full

Tenshi~Akari

^^ At first I thought this was an issue as well, but then I noticed the description again: The multipliers only take affect if the crafting time is short enough. If you have recipes that take a while to complete, the number of multipliers for it will be smaller. Tested this out by adjusting the "WorkToMake" value on a piece of modded apparel to a smaller number, and upon loading, more multipliers had shown up.

Honestly, I think it's pretty reasonable to have it that way so as not to be "too cheatsy" or just having ridiculously long workloads for making multiples of items with high "WorkToMake/WorkToBuild" ticks, but I can understand why there can be confusion on that part.

(Also was coming back to report that so far everything works well since the updates. Haven't had any issues or conflicts since my last bug report. Thanks again for the fixes!)

Lowlofir

#11
I will explain how it works (or at least how I hope it works).
First, it generates all recipes on game launch.

  • Scan all recipes already exists. Those which met following conditions are passed to next step, other ignored

    • recipe work amount < 120 seconds
    • has only one product
    • has at least one ingredient
  • For each recipe selected in previous step:
    make sequence of multiplied recipes until last one have work amount > 120
So there is not more than one recipe with work amount > 120 for each source recipe.

Then mod just hide recipes that should not be shown in recipes lists.

If "Put recipes in context menu" checked (in mod settings) than all generated recipes are shown only in right click menu.
Else, if "Put recipes in context menu" unchecked, than generated recipes are shown in same list as source ones right after them, but only that which has work amount less than 1.5*[Default target time] (where "Default target time" is bad named mod setting).

So it is correct that you see different number of bulk recipes for different source recipes. However, it is not correct that sometimes multipliers are skipped and even stock recipe is not accessible (or it just didn't fit on screenshot?). I'll check why this could happen.

I make recipes generate on game launch because otherwise it will be more difficult to implement. Recipe list is not local to particular save. If I would make a option to change 120 second limit, it will not be safe to load saves after lowering this value if save uses recipes that are not available anymore. Or maybe it is possible to generate recipes with settings saved in save right on save loading (and remove recipes on unload?), or catch missing recipe errors, anyway it is much easier (at least for me) to make it like it is made now, and I don't think that longer bulk recipes really should exist.

Thanks for the feedback!

5teVe

Quote from: Lowlofir on June 06, 2019, 05:32:10 AM
I will explain how it works (or at least how I hope it works).
First, it generates all recipes on game launch.

  • Scan all recipes already exists. Those which met following conditions are passed to next step, other ignored

    • recipe work amount < 120 seconds
    • has only one product
    • has at least one ingredient
  • For each recipe selected in previous step:
    make sequence of multiplied recipes until last one have work amount > 120
So there is not more than one recipe with work amount > 120 for each source recipe.

I make recipes generate on game launch because otherwise it will be more difficult to implement. Recipe list is not local to particular save. If I would make a option to change 120 second limit, it will not be safe to load saves after lowering this value if save uses recipes that are not available anymore. Or maybe it is possible to generate recipes with settings saved in save right on save loading (and remove recipes on unload?), or catch missing recipe errors, anyway it is much easier (at least for me) to make it like it is made now, and I don't think that longer bulk recipes really should exist.

Thanks for the feedback!
np, but if i want to change this limit just for myself, can i do it? and how?

Hjkma

Hey. Bulk recipes are shown in the menu from the Dubs Mint Menus mod, can you make a compatibility patch so that such recipes can be hidden and appear only with the context menu?

Schwartz

The mod is working well here. It appears some recipes from other mods don't respect the max work amount limit and allow only very low bulk multipliers. Modded workbenches may show the bulk bills in the menu and not upon right-click. Example for both: Fertile Fields.