-
Notifications
You must be signed in to change notification settings - Fork 221
Update emigration.lua #736
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
Conversation
Fix for emigration.lua not working since the citizenship logic was changed.
|
I'm having a hard time following the changes in this PR. it looks like you've overwritten all the improvements made since 0.47, such as compliance with the enabled API needed for autostart. could you integrate your changes into the existing code instead? |
Integrated the changes to existing code.
Removed some excess whitespace.
|
Yeah, I did the integration and it also seems to passes the checks. |
|
Of course there's still the fact that I haven't tested if it works in 50.* as well as in 0.47.*. |
emigration.lua
Outdated
| @@ -1,4 +1,5 @@ | |||
| --Allow stressed dwarves to emigrate from the fortress | |||
| -- Updated for 0.47.05 and potentially for 50.08 by wsfsbvchr | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I encourage you to add your name to https://github.com/DFHack/dfhack/blob/develop/docs/about/Authors.rst but it's not really appropriate to add it here. Your name will already be recorded in the git history and be visible here: https://github.com/DFHack/scripts/graphs/contributors
|
code looks reasonable (and professional, I might add). could you tell us when you've had a chance to do some testing in v50 to make sure it actually works as advertised? In particular, I'm not confident I understand the long-term implications of assigning a unit to another site. |
|
I'd imagine they live their lives like any of the other histfigs in those non-player site entities. I got the idea for that while experiencing the bug where the dwarves just immediately return after leaving the map; I figured if they're members in another place, they surely will go there. It's admittedly bit cheaty though. I'm also not sure what happens without any new entity links. I suppose they might settle somewhere anyway. Oh, and, I just tried v50 in wine, and apparently in v50 |
Adjusted to use of df.global.plotinfo.
|
Apparently it's df.global.plotinfo. v50 feels so clunky and complicated, but looks like there are no errors now, and two dwarves succesfully left my newly started fortress in search for better life. |
| --@module = true | ||
| --@enable = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two lines are required for the enabled API to function. see https://docs.dfhack.org/en/latest/docs/dev/Lua%20API.html#script-enable-api for details.
emigration.lua
Outdated
| -- old version: http://dffd.bay12games.com/file.php?id=8404 | ||
| --@module = true | ||
| --@enable = true | ||
| --[====[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs have moved to separate .rst files. If you made any changes to the docs, they should go in https://github.com/DFHack/scripts/blob/master/docs/emigration.rst
script files shouldn't have duplicate docs since they just get out of date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anything relevant to the docs has changed.
Though I don't know if the part in bold is technically true: "Dwarves who can leave in friendly company (e.g. a dwarven merchant caravan) will choose to do so, but extremely stressed dwarves can choose to leave alone, or even in the company of a visiting elven bard!", but I suppose it hasn't been true in many years.
Perhaps it's not intended literally, but as a description of how despaired some of the emigrating dwarves must be?
| local json = require('json') | ||
| local persist = require('persist-table') | ||
| A happy dwarf (ie with negative stress) will never emigrate. | ||
| local GLOBAL_KEY = 'emigration' -- used for state change hooks and persistence | ||
| Usage:: | ||
| enabled = enabled or false | ||
| emigration enable|disable | ||
| ]====] | ||
|
|
||
| function isEnabled() | ||
| return enabled | ||
| end | ||
| enabled = enabled or false | ||
|
|
||
| local function persist_state() | ||
| persist.GlobalTable[GLOBAL_KEY] = json.encode({enabled=enabled}) | ||
| local args = {...} | ||
| if args[1] == "enable" then | ||
| enabled = true | ||
| elseif args[1] == "disable" then | ||
| enabled = false | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part looks like it was accidentally copied from an earlier version. Could you fix the merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I must've uploaded the wrong file or something. Now the correct file should be there.
| dfhack.onStateChange[GLOBAL_KEY] = function(sc) | ||
| if sc == SC_MAP_UNLOADED then | ||
| enabled = false | ||
| return | ||
| end | ||
|
|
||
| if sc ~= SC_MAP_LOADED or df.global.gamemode ~= df.game_mode.DWARF then | ||
| return | ||
| dfhack.onStateChange.loadEmigration = function(code) | ||
| if code==SC_MAP_LOADED then | ||
| if enabled then | ||
| print("Emigration enabled.") | ||
| event_loop() | ||
| else | ||
| print("Emigration disabled.") | ||
| end | ||
| end | ||
|
|
||
| local persisted_data = json.decode(persist.GlobalTable[GLOBAL_KEY] or '') | ||
| enabled = (persisted_data or {enabled=false})['enabled'] | ||
| event_loop() | ||
| end | ||
|
|
||
| if dfhack_flags.module then | ||
| return | ||
| end | ||
|
|
||
| if df.global.gamemode ~= df.game_mode.DWARF or not dfhack.isMapLoaded() then | ||
| dfhack.printerr('emigration needs a loaded fortress map to work') | ||
| return | ||
| if dfhack.isMapLoaded() then | ||
| dfhack.onStateChange.loadEmigration(SC_MAP_LOADED) | ||
| end | ||
|
|
||
| local args = {...} | ||
| if dfhack_flags and dfhack_flags.enable then | ||
| args = {dfhack_flags.enable_state and 'enable' or 'disable'} | ||
| end | ||
|
|
||
| if args[1] == "enable" then | ||
| enabled = true | ||
| elseif args[1] == "disable" then | ||
| enabled = false | ||
| else | ||
| return | ||
| end | ||
|
|
||
| event_loop() | ||
| persist_state() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part also looks like it was overwritten with old code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry!
Proper fix for stuff, hopefully.
One more fix, maybe now...
|
I think it should now have the v50 base with my updated emigration solutions, but I can't focus at the moment so here's to hoping. |
Removed excess whitespace
myk002
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. thanks!
Followup to DFHack/dfhack#1784 (comment)
Fix for emigration.lua not working since the citizenship logic was changed.
It works at least in 0.47.05, based on some testing by myself. It can be tested relatively easy with stress-inducing scripts, such as this one I created while testing this: https://github.com/wsfsbvchr/dfhack-utils/blob/main/stress-tests.lua
The 50.* version seems to have some different things in the plugin part of the script, so at least adding those might be necessary. Also the exact location of unit's stress has apparently changed?