Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fix/general-strike #836

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Template for new versions:
## New Features

## Fixes
- 'fix/general-strike: make less aggressive about trying to fix problems that don't exist yet

## Misc Improvements

Expand Down
7 changes: 6 additions & 1 deletion fix/general-strike.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ local argparse = require('argparse')
local function fix_seeds(quiet)
local count = 0
for _,v in ipairs(df.global.world.items.other.SEEDS) do
if not v.flags.in_building then
if (not v.flags.in_job) and (not v.flags.in_building) then
local bld = dfhack.items.getHolderBuilding(v)
if bld and bld:isFarmPlot() then
v.flags.in_building = true
for _,i in ipairs(bld.contained_items) do
if i.item.id == v.id then
i.use_mode = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it you discovered the seeds had the wrong use_mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in rare cases, yes

when seed planting starts, the seed is added to the building's inventory vector in use mode 0 (the same as for any workshop, and farms do act like a workshop in this regard), with in_job and in_building set. when the plant seed job completes, the in_job flag is cleared and the seed's use mode changes to 2

the problem that this tool is seeking to correct is when the plant seed job is cancelled incorrectly. normally, when the job is cancelled, the in_job flag is cleared but the use mode is unchanged. in most cases the seed is immediately removed from the building and everything is fine, but in uncommon cases the seed gets stuck in the building. i'm guessing that there's a cancellation code path in toady's code that doesn't cancel plant seed jobs properly leaving them in a limbo state where they can neither be removed nor completed, which results (i suspect) in planters spamming trying to replant the seed but not being able to do so because it's locked into that building somehow. my assumption is that toady has (as he is wont to do) cut and paste job cancellation code into diverse locations, and updated some but not all such cancellation pathways in a way that has an differential impact here

the script attempts to detect and fix this latter case by changing the seed to "planted", but the version putnam provided is both too aggressive and insufficient: it tries to change them to "planted" while they're still being planted, and it fails to change their use mode to 2, which results in the game being inconsistent about whether the seed is actually planted or not. this results in overplanting the field (i've seen them shove as many as nine seeds into a field with four spaces), and inconsistent on-screen displays it appears that the seeds in use_mode 0 actually do grow and eventually get harvested, but they don't look like they're in the farm and are not, at least for some purposes, treated as if they are in the farm, and i can understand why players feel like their seeds have disappeared because that's what it looks like on the map view

the determination that use_mode 2 was required was based both on experimenting with poking other use_modes into the inventory vector using gm-editor and by watching seeds that appeared to be planted correctly. every mode other than mode 2 yielded the "purple infinity" on the farm plot detail view, while only mode 2 resulted in the map view showing the plot as occupied, and only mode 2 prevents the dwarfs from trying to plant another seed in the same spot

i ran a test fort for two seasons with the code above, during which i saw only a very small number (but not zero) of corrections and saw none of the weirdness i was seeing with the previous version

end
end
count = count + 1
end
end
Expand Down