#"Prioritize by Haulers" Improved

119 messages · Page 1 of 1 (latest)

slim carbon
#

[WIP-RC]
A code-only mod made using @frozen crypt 's TBMPL.
BepInEx config-type mod with TAPI compat.
It patches "Prioritize by Haulers" logic to give a make the boost it gives & its threshold configurable. It also gives unmanned production buildings an extra boost in priority.
Config file generated at BepInEx/config/Hauling2RecipeFix.cfg . For use as depency: TAPI/BepInEx GUID Hauling2RecipeFix

Main version 1.0.9.8 'Just Works' & is fully configurable. Next release will likely have the 2 functionalities ("Prioritize by hauler" config, Workerless Building Haul Priority Tweak) split as separate mods.
Added a simpler v0.0.2-lite that just makes workerless manufactories always have a priority/weight of 2.0, and makes the priority/weight added with "Prioritize by haulers" to be 1.0 (no threshold)

IMPORTANT NOTE: Saves won't be loadable after un/installing this if any Gatherable Prioritization is set. If any of your saves break for this reason (or possibly similar ones from, eg. scavenger/tapper if used with @calm mica 's MapMaker Reader (AKA More Crops, i think))... they can be edited & recovered - you can even send 'em to me to fix, if you would like.

Note: using BepInEx config, can potentially use BepInEx.ConfigurationManager to tweak settings ingame. But inputs do leak down into the game, so gotta take caution if used.

https://mod.io/g/timberborn/m/prioritize-by-haulers-improved

mod.io

[WIP] improves the effect of "Prioritize this building by haulers"

midnight lichen
#

feels like loading first time or second time around was quite similar, forgot to note the time when closing last time

slim carbon
#

did you make a new save? apparently that had helped @marsh mural

midnight lichen
#

i'm running the same one

marsh mural
#

If autosaves is enabled, game will make an autosave on exit

midnight lichen
#

yeah, so autosave i guess, not same exact save

marsh mural
#

Then, I start game and choose continue

slim carbon
#

hmm, hopefully I'll have enough time this week to also test it out
@midnight lichen let me know if the long loading time issue persists after making a new save

marsh mural
marsh mural
#

Now, with mod removed, all autosaves are corrupted. The same crash on loading 🤯

slim carbon
#

How the hell was gathering priority affected again? Heck, All the autosaves? Sh**

#

I gotta test this now, before I run out of time for today

midnight lichen
slim carbon
#

@marsh mural just to be extra sure, the save in question doesn't happen to be from around when you had that previous crash, right?

Could you perhaps send me crash Report & savefile? Thanks

midnight lichen
slim carbon
# midnight lichen and crashed again ...

did you update WBO to 3.2.6? from the logs, it seems you're still on 3.2.4
also TBMPL Core seems to want BepInEx v5.4.22.0, could you update bepinex too, just in case? no clue what else it could be (seems something is trying to handle/use a Need that doesn't belong with the faction)

midnight lichen
#

i'm on WB 3.2.5 still, forgot to update

#

gonna update all that later game time is up for now

midnight lichen
slim carbon
# midnight lichen BepinEx i'm on 5.4.22.1, so actually i'm a version ahead

wait, the logs say otherwise ThinkingF

[Message: BepInEx] BepInEx 5.4.21.0 - Timberborn (2023-12-19 5:10:28 PM)

it's also time for me to go ... couldn't quite figure out what's going wrong with @marsh mural ... as for your issue @midnight lichen , it's a bit unlikely to be caused by my mod - but who knows ...

i guess i should try making an even simpler version of the mod, with no extra prioritization for workerless buildings, just in case

GN

midnight lichen
#

GN

marsh mural
#

[Message: BepInEx] BepInEx 5.4.21.0 - Timberborn (2023-12-19 5:10:28 PM) is from BeepinEX where the plugins folder is located. I updated the BeepinEX to 5.4.22 and removed all BeepinEX folders inside the plugins folder

frozen crypt
#

there is no problem in the BepInEx version. the differences between the versions are not significant enough to create this error.. but of course using 5.4.22 is appropriate

#

I see the problem rather in a bad impl. patches... if each save saves the current values, then on the next load it modifies the already modified ones = it can cause a crash and break save
when modifying, you must not start from the current values, but from the initialization values... you can change the current values only if they are not serialized at that point.. otherwise you always have to start from the init value and calculate the current one with your own modifier

frozen crypt
#

try patch this HaulingCenter and Awake
where you re-initialize the entire collection _districtBuilding with your own modified data with Postfix.. but there must be no calculation, only fixed data, for example from the configuration

slim carbon
#

@frozen crypt you're talking about the current version, right? Didn't quite fully understand yours last message...
Anyhow, it should probably fix the issue if I move the extra bit of logic/prioritization for workerless buildings to where it's also toggled with the "Prioritize by haulers" ... If not I'll just get rid of that bit

Guess I'll also have look at that class, just in case

#

Thanks for claririfying the issue!

frozen crypt
#

yes, about the latest version... in the way you have it now, the problem could be that the method can be called multiple times (I didn't check) or that the data is simply serialized... but in both cases it means , that your modifier will be done more than once and in the worst case the data will be saved in Save... so either always start from the init data so that even when loading everything works even after loading the map or change the data only on the output, which is not serialized

slim carbon
#

Managed to reproduce @marsh mural 's Crash & started work on it. Gotta sleep soon though.
Joy having to find another way to not let hauling prioritization drop oh-so sharply.
Patching "Prioritize by haulers" seems not to work - not without issues like @marsh mural 's (why couldn't the threshold for it also have been a field, rather than an hard-coded number? SadF )
Well, I better get some more testing in of what i currently got (increased prioritization strength, but unchanged threshold for "Prioritize by haulers") before bed
This going to take a while, unfortunately

@frozen crypt any hidea what assembly DistrictBuilding is in? also, fixed data for hauling priorities doesn't seem feasible ... unless high hauling priority somehow gets ignored if there are no goods to carry?

frozen crypt
#

@slim carbon if you describe to me the fastest way to test it, then I can fix it (I don't want to play with it all day)
and this high hauling priority somehow gets ignored if there are no goods to carry is possible

slim carbon
#

@frozen crypt
It did work, but won't load saves where it wasn't present (Gatherer prioritization crash) ... Perhaps even removing It could cause the issue too. Strangely, i had to remove It & clear BepInEx/cache, then start a new game to make a fresh save & load that one to get the crash - none of my older saves from before i even made It where getting that crash.
Btw, It crashes Before any calculations ... I Guess i should try clearing the BepInEx cache again, just in case

Testing the logic itself was simply checking the HaulBeahviour values ingame in dev mode ...

Thanks for offering some help, though i should probably narrow down on the issue

frozen crypt
#

@slim carbon where can i find HaulBehavior in game in dev?

slim carbon
#

@frozen crypt
Towards the bottom of a building's info window.... iirr "HaulCandidate" (doesn't show up if the building needs no hauling.
The main issue with It is @marsh mural 's crashes after (un)installing It, with a save with a Gatherer set to Prioritize something. This i did confirm to be a reproducible issue...

midnight lichen
#

not sure if it has to do with your priority mod but farmers pick up instead of planting even if planting is prioritized 🤔

#

might have just never noticed before but just in case

calm mica
midnight lichen
#

that's a bit dumb...

slim carbon
#

@midnight lichen @marsh mural @calm mica @frozen crypt
Just uploaded a new version (v1.0.9.4, not live, TBMPL-autoupdate disabled), for testing
Should be a bit cleaner ...
Loading time is still up, but seems playable (don't have a large settlement to fully test).
Cleaned up the config & code ... added an option to automatically set all potentially-workerless manufactories to lowest workplace/job priority, let me know if that would actually have an use

midnight lichen
#

[Info : Unity Log] Load time: 255012ms not that big of an increase

calm mica
#

the actual pipe is a separate element from the house

calm mica
#

oh, wrong thread

slim carbon
#

Hey @steady sundial @frozen crypt @calm mica ,
I should probably split this into 2 mods:
*) A TBMPL mod to tweak the strength & threshold of "Prioritize by haulers" - with no extra logic/calculations
*) A TAPI mod to replace Manufactory with an extented class/component with a few added Properties to cache wethever there is

  • a ProductionIncreaser
  • a Workshop
  • zero assigned workers (updates on an event?)
    The HaulBeahviourProviders could then have GetWeighedBehavior patched to check those Properties for applying extra prioritization for workerless buildings ... or perhaps just replace the 2 HaulBeahviourProviders for prefabs with ProductionIncreaser (still gotta cache if there is no Workshop or zero workers)

Would it be a good idea? If so, It might take me a while to setup for it... so any help would be apprecciated

Btw, i think the main performance issue with my mod was ... It running on very hauler-ready object, always re-checking if the ProductionIncreaser component is there - pretty much very Tick, I think?

#

Btw, I'm in way over my head by now ... Yeah, it works but... ... ...

frozen crypt
#

I guess I don't understand what the goal is... what the ProductionIncreaser, Workshop and zero assigned workers will do? 🤔

slim carbon
#

This started because haulers tend to stop before fully filling/emptying, which Kinda kills workerless buildings (Manufactory+NeedIncreaser, no/optional Workshop)
Tweaking "Prioritize by haulers" helps a bit, as did the previous iterations of the mod (patched InventoryFillCalculator at 1st but was buggy, then tried patching the HaulBeahviourProviders which was slightly better but still laggy) but checking for ProductionIncreaser (pretty much a ghost worker) - which is needed to apply increased haul Priority for workerless buildings...still seems to add a tad too much overhead

#

So, if I could "cache" those tree values (of which the last is not fixed), that would reduce compute time needed very Tick ... Right?

frozen crypt
#

I don't know, but generally the fewer calculations in Tick, the faster it will be

#

I just wonder how this modification will behave on a map where there are at least 500 beavers

#

by that I mean that if it will behave like 1000 with 500 beavers, I personally would not even use the mod.. so if the calculation and adjustments must be in Tick, I would be careful about complex adjustments... if you use cache, then it will probably have to be threadsafe, which in itself is more demanding than a classic cache

#

I then recommend testing it on a map where there is a large population

steady sundial
#

Regarding the caching. It never hurts to cache stuff. The question is how big the win is? GetComponentFast seems to be pretty efficient already. It's not as good as a cached instance, though.

#

If the idea is to improve the performance, I'd start thinking about the algo itself. E.g. there is not much sense in recalculating priorities in every tick (every 300ms). The buildings don't consume goods that fast. So, you can break down the "whole list of haulers" into buckets and process them in different ticks.

Another way is to offload the calculations into parallel ticks. But here thread safety will be playing a role.

calm mica
slim carbon
#

@steady sundial @frozen crypt I'm actually not too sure how often the HaulBeahviourProviders calculate those Priorities ... I didn't touch that

#

@calm mica yeah, i think custom HaulBeahviourProviders should be doable (no other way without extra overhead, i believe)... Just gotta manually replace the one(s) already attached ...

#

Gotta sleep now ... cya

frozen crypt
#

priorities are not stored on buildings, but stored on each entity in the map. So, in theory, it would be possible to define it, but more complicated. When constructing the building, the priority value would have to be loaded and added to the current value, which I think is 0.5f. So only problem here is that if you manually change the priority, the value is overwritten. Which is correct. So setting priorities after creating an entity would not require the use of Tick either

#

Tick is done quite often here, so some optimization would be in order. But you would like to test it first on a larger map with a larger population if this is a problem and optimization is necessary or not

slim carbon
frozen crypt
#

rather, I was responding to lapantouflemagic that it would be possible to set a custom priority for each building, it would just be more complicated

#

I only ever play with one district, so I've never dealt with this hauling problem 🙂

slim carbon
frozen crypt
#

I didn't notice or care because it somehow worked when they had the ingredients. I might have to see on video when this situation occurs, I probably can't imagine it... but if it's a problem in the game, that it doesn't work well with hauling, then it would be appropriate to write it to the devs

slim carbon
#

Well, aside from @calm mica 's WBO there are almost no workerless Manufactories, so ... Edgde-case?

frozen crypt
#

I don't use WBO and I don't want to, so maybe that's why I didn't run into the hauling problem

slim carbon
#

I really should keep this mod as just a "Prioritize by haulers" configuration
and make something separate for the workerless buildings hauling - just gotta figure how exactly ...
Well, it'll keep me occupied, at least.

Since the current version seems to work well enough, I can probably take some time - not rushing this again...

midnight lichen
#

Just curious, the thing that prioritize the "workerless" buildings, can the "empty buildings" part be less prioritized unless there is like 50%inventory ready for pick up? otherwise haulers run there to pick one as soon as it's there ( having clockwork farms in mind mainly)

slim carbon
#

hmm, that should probably be doable ... not in any of the currently available versions though
thanks for the suggestion

slim carbon
#

Urgh, can't seem to replace any of those components (Manufactory / ManufactoryHaulBehaviourProvider / FillInputHaulBehaviourProvider ) without crashing ... if I understand correctly, because of the Decoration step ... any idea @steady sundial @frozen crypt ?

Seems I'll have to try again with just plain HarmonyPatching ... unless I could somehow patch WorkshopsTemplateModuleProvider 's TemplateModule Get(), where it looks like the Decorations are set ?

Well, I'm gonna sleep on it for now

steady sundial
slim carbon
steady sundial
#

No idea about netstandard. Never used it tbh.

frozen crypt
midnight lichen
calm mica
# slim carbon That's what I tried ... dunno if I somehow did it wrong, it crashed on InGame wi...

If it's too clunky / tedious / time consuming, don't sweat it.

At the end of the day this is not vital, I don't have to have worker-less buildings, I liked the idea but I can arrange things without.

Plus to be honest, I wouldn't be upset about removing a couple dependencies, I don't want people to have to install 200 things for the WBO mod to work. Especially if tbmpl presence cannot be enforced.

slim carbon
calm mica
slim carbon
calm mica
#

.cs

#

i'll send you an example in PM of a script i've already added in

#

(made by Battery smooth

midnight lichen
#

not sure if it's due to that mod but a lot of my buildings are switching to lower priority when beeing completed or ( i think) also when loading the game

slim carbon
#

as i recall, there is a toggle for that in the config file

#

ah, sorry I had set that to on by default ... my mistake

midnight lichen
#

at least it's simple, not a bugged out thing

#

how do i change that tho cauz it's quite annoying i must admit ?

slim carbon
#

it should only affect the buildings that can do without workers
the config file is at BepInEx/config/Hauling2RecipeFix.properties ... just set Workplace_deprioritize to false in there

midnight lichen
#

it affects mostly my food stuff ( with workers) 🤔

#

mush grower, mechanized coockhouse and (maybe) coocking tent

slim carbon
#

yeah. i should fix that 'wrong' default soon
it only affects buildings with the ProductionIncreaser script, but some of those only use it to keep production going when the beavers are off work ... so kinda weird have them all run unstaffed, you're right

midnight lichen
#

so just setting this to "false" should solve it?

#

or it's the one under i have to swap?

slim carbon
#

the one below

midnight lichen
#

ok, let's see if i can do the simplest things without cauzing a crash ! 😅

#

now the 6~8 minnutes of loading... that save is getting a bit big

slim carbon
#

still gotta change the workplace priorities manually, at least now they won't default to lowest on load

midnight lichen
#

had them all swapped back before closing so hope it keeps them like that when reoppening

slim carbon
#

yeah, it should keep them

midnight lichen
#

looks all good, thanks !

midnight lichen
#

How are med beds ranking in the priorities with that mod on? asking for a friend 😉

#

(like is there a dumb 2 line thing to drop in to be sure they are always 100% priority?)

slim carbon
midnight lichen
#

🤞

slim carbon
#

hmm, may just have to add an extra haulbehaviorprovider script onto those if they are GoodConsumingBuilding, since I can't seem to get the decorated-on FillInputHaulBehaviorProvider replaced ... will try to figure something out anyhow

calm mica
slim carbon
#

@calm mica @midnight lichen Hotfix is online - fixed both config and hauling priority on GoodConsuming buildings (medical beds etcetera).
Changed dependency from TBMPL (no more TBMPL auto-update) to TAPI. Config will be at BepInEx/config/Hauling2RecipeFix.cfg

slim carbon
#

Next (split) version will take a few more weeks (perhaps a bit over a month) to be ready ... this one works decently enough, right?

In the meantime I found https://github.com/BepInEx/BepInEx.ConfigurationManager, that enables ingame BepInEx-configuration editing - so that could be useful for checking/fine-tuning the settings of my Haul mod(s) ... yes, I used BepInEx rather than TAPI for the config - I don't like putting config files right in the mod-dir

tulip haven
#

U6 update?

slim carbon
#

Not yet working on it. Will likely get it ready for the official U6 release though.

calm mica
#

Thanks 😊

slim carbon
# calm mica Thanks 😊

Well, I haven't gotten around to updating this for U6 yet (should be entry-point & UI fixes mostly) ... I haven't even been keeping up with all the news in experimental.
TimberAPI got a ui-builder again, right? If so, I should be able to fix this up next weekend.
When I end up having some time on my hands in the future, I'll probably redesign the config structure for ease of use ... it was not intuitive at all in the current (U5) version

calm mica
#

Thank you!
As far as I understand if you rely on TAPI it should work the same