-
Notifications
You must be signed in to change notification settings - Fork 193
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
new tool: immortal-cravings #1301
base: master
Are you sure you want to change the base?
Conversation
da97995
to
a342a22
Compare
this is an awesome name : D however, I am seeing a parallel with the concept of Would it make sense to rename |
I'm not entirely sure. There obviously are parallels, but From the communication perspective, From the development perspective, every need that we satisfy using a tool requires some amount of research and discussion. And other needs may require entirely different techniques. So maybe it is good to keep this thing separate for now. Ultimately, I expect |
changelog.txt
Outdated
@@ -31,6 +31,7 @@ Template for new versions: | |||
- `idle-crafting`: allow dwarves to independently satisfy their need to craft objects | |||
- `gui/family-affairs`: (reinstated) inspect or meddle with pregnancies, marriages, or lover relationships | |||
- `notes`: manage map-specific notes | |||
- `immortal-cravings`: allow immortals to satisfy their cravings for food and drink |
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.
could you move this up into the new "Future" section?
docs/immortal-cravings.rst
Outdated
``enable immortal-cravings`` | ||
``disable immortal-cravings`` |
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.
``enable immortal-cravings`` | |
``disable immortal-cravings`` | |
:: | |
enable immortal-cravings |
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.
we don't usually individually document the disable command
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.
could you also add this tool to the control panel registry (internal/control-panel/registry.lua
)?
---@param p1 df.coord | ||
---@param p2 df.coord | ||
---@return number | ||
function distance(p1, p2) |
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 seems like a good candidate to move to utils
. no need to do it yet, but if/when another Lua tool requires this, we should remember that this is here
immortal-cravings.lua
Outdated
local x, y, z = dfhack.items.getPosition(item) | ||
local pitem = xyz2pos(x, y, z) |
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.
you can combine this into
local pitem = xyz2pos(dfhack.items.getPosition(item))
immortal-cravings.lua
Outdated
watched = {} | ||
|
||
threshold = -9000 |
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 should be local or "protected" globals (foo = foo or default_foo
). otherwise, they'll get reset whenever the player runs (probably mistakenly) immortal-cravings
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.
threshold
should definitely be local
since it's read only. watched
could be either
immortal-cravings.lua
Outdated
local kept = {} | ||
for _, unit_id in ipairs(watched) do | ||
local unit = df.unit.find(unit_id) | ||
if unit and not (unit.flags1.caged or unit.flags1.chained) then |
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.
opportunity to reduce code nesting here
if not unit or unit.flags1.caged or units.flags1.chained then
goto next_unit
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.
also, unit should be skipped if dead or not active (e.g. left map on a raid)
immortal-cravings.lua
Outdated
for _, need in ipairs(unit.status.current_soul.personality.needs) do | ||
if need.id == DrinkAlcohol and need.focus_level < threshold then | ||
goDrink(unit) | ||
goto next_unit |
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 goto
s could be replaced with break
s
immortal-cravings.lua
Outdated
|
||
---main loop: look for citizens with personality needs for food/drink but w/o physiological need | ||
local function main_loop() | ||
print('immortal-cravings watching:') |
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 prints in this function are probably too spammy. the prints for when actions are actually taken is enough
--- Handles automatic loading | ||
dfhack.onStateChange[GLOBAL_KEY] = function(sc) | ||
if sc == SC_MAP_UNLOADED then | ||
enabled = false |
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.
maybe add a comment here explaining that repeat-util will cancel the scheduled callbacks for you
It may take until the next weekend for me to get back to this. Busy at work and other plans for the upcoming weekend. |
no hurry! I have plenty of other PRs to keep me busy |
allow immortals to satisfy their cravings for food and drink