Repository navigation
Conversation
This script provides tools for recovering from a deceased baron/count/duke. When the landholder dies, the game selects a successor, but this successor is almost always at another site. The game is supposed to push the successor into an army that will path to the site and join it as the new landholder, but the vanilla code to do this includes a test that prevents it from working for landholders (it works for any _other_ civ-level noble position where this happens, just not for landholders. go figure.) so clearly this is what is _supposed_ to happen, it just doesn't because Toady's code is broken. This script finds the already-appointed successor, creates an army, shoves the successor into it, and emulates a unitless "makeown" so that when the successor arrives they'll (re)join the site as the new landholder automatically. Tested on a fort with a dead baron obtained from BlindIRL.
SilasD
left a comment
There was a problem hiding this comment.
nitpicky stuff, not the important stuff Quietust flagged.
I'll try to give it more attention later.
| ev.id = df.global.hist_event_next_id - 1 | ||
| ev.year = df.global.cur_year | ||
| ev.seconds = df.global.cur_year_tick | ||
| ev.hfid = hf.id | ||
| ev.state = state | ||
| ev.reason = reason or df.history_event_reason.none | ||
| ev.site = site_id | ||
| ev.region = -1 | ||
| ev.layer = -1 | ||
| if site then ev.region_pos:assign(site.pos) end | ||
| world.history.events:insert('#', ev) |
There was a problem hiding this comment.
as a style & consistency thing, I think auto-vivification would be better here, like the above functions have.
There was a problem hiding this comment.
yeah this is copying the structure in the actual code which really does do it this way - most of toady's constructors are default-only and it's up to the consumer to actually fill in the details
There was a problem hiding this comment.
also in this case autovivificaton is messier because of the conditional logic for setting site position
There was a problem hiding this comment.
you could auto-vivify most of it, and manually set only the region_pos field.
you'd have to either split up the code into a call to df.new(), an assign to the new object, manually set that field, and the :insert.
or do the autovivify :insert, then index the vector for the last element in it and adjust region_pos.
(this would be a use case for the df.new(object, assign_table) API extension I posted as a draft. )
or I think you could put something like this in the assign table:
region_pos = site and site.pos or { -1, -1 },
I've definitely done conditionals while building a table, and I think that's the syntax.
again not saying you have to do anything. this bit is fine as-is, it just stood out as different.
| end | ||
|
|
||
| local function new_remove_link_event(entity, hf, position_id) | ||
| df.global.hist_event_next_id = df.global.hist_event_next_id + 1 |
There was a problem hiding this comment.
I think, for these history events, you should increment the global after the insertion;
that way if the insertion fails, the state remains consistent.
that's a nitpick, not a big deal.
if you do change it, you will also have to change the id math below, just delete the - 1
There was a problem hiding this comment.
DF's own code tends to do it the other way around, but you do have a point
|
Verified that the updated version still works in the test fort I'm using, at least for |
Bumber64
left a comment
There was a problem hiding this comment.
Just skimmed, but noticed a few things.
| - ``recall`` for land-holder positions is limited by a native gate: the | ||
| successor-travel sweep skips any position whose definition has | ||
| ``land_holder > 0`` *before* reading the destination, so a baron, | ||
| count, or duke never gets a native travel army no matter what | ||
| ``st_id`` says. The ``st_id`` write is still correct and consumed | ||
| by the same native path -- it just needs the one native check | ||
| bypassed for the target only. A production fix should scope the | ||
| bypass (call the creation path for the single intended nemesis, or | ||
| patch for a single sweep window); a global patch makes every | ||
| stranded land-holder in the world travel at once. |
| end | ||
| if not gate(rd_i32(hf, 0x30) == -1, | ||
| if not gate(hf.died_year == -1, | ||
| ('figure+0x30 (died_year?) == -1 [=%d]'):format(rd_i32(hf, 0x30))) |
was used during investigation, no longer needed
|
Again verified that, after these changes, |
This script provides tools for recovering from a deceased baron/count/duke.
When the landholder dies, the game selects a successor, but this successor is almost always at another site. The game is supposed to push the successor into an army that will path to the site and join it as the new landholder, but the vanilla code to do this includes a test that prevents it from working for landholders (it works for any other civ-level noble position where this happens, just not for landholders. go figure.) so clearly this is what is supposed to happen, it just doesn't because Toady's code is broken.
This script finds the already-appointed successor, creates an army, shoves the successor into it, and emulates a unitless "makeown" so that when the successor arrives they'll (re)join the site as the new landholder automatically.
Tested on a fort with a dead baron obtained from BlindIRL.