From 1321a0c4ec878ec1e59e77b945143749cfa39ed3 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 9 Aug 2024 21:31:14 -0700 Subject: [PATCH 1/2] don't assume all undead are dangerous add and use isWildlife and isAgitated property checks --- docs/changelog.txt | 4 ++++ docs/dev/Lua API.rst | 16 ++++++++++---- library/LuaApi.cpp | 2 ++ library/include/modules/Units.h | 7 ++++--- library/modules/Units.cpp | 37 +++++++++++++++++++++++---------- plugins/lua/sort/info.lua | 2 +- plugins/lua/zone.lua | 2 +- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 27ae3f37b6..095750dcc4 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -59,14 +59,18 @@ Template for new versions: - prevent hang when buildings in zones are destroyed in the case where the buildings were not added to the zone in the same order that they were created (uncommon) - `buildingplan`: improved performance in forts with large numbers of items - System clipboard: when pasting single lines from the system clipboard, replace newlines with spaces so they don't show up as strange CP437 glyphs in-game +- `exterminate`: don't kill friendly undead (unless ``--include-friendly`` is passed) when specifying ``undead`` as the target ## Misc Improvements ## Documentation ## API +- ``Units``: new ``isWildlife`` and ``isAgitated`` property checks ## Lua +- ``dfhack.units``: ``isWildlife`` and ``isAgitated`` property checks +- ``dfhack.units.isDanger``: no longer returns true for intelligent undead ## Removed diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 6857be24f6..b875666e72 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -1569,6 +1569,14 @@ Units module The unit is a regular visitor with no special purpose (e.g., merchant). +* ``dfhack.units.isWildlife(unit)`` + + The unit is surface or cavern wildlife. + +* ``dfhack.units.isAgitated(unit)`` + + The unit is an agitated creature. + * ``dfhack.units.isInvader(unit)`` The unit is an active invader or marauder. @@ -1587,11 +1595,11 @@ Units module Simple enemy type checks. -* ``dfhack.units.isDanger(unit[,hiding_curse])`` +* ``dfhack.units.isDanger(unit)`` - The unit is dangerous and probably hostile. This includes undead - (optionally those hiding curse), night creatures, semi-megabeasts, - invaders, agitated wildlife, crazed units, and Great Dangers (see below). + The unit is dangerous and probably hostile. This includes night creatures, + semi-megabeasts, invaders, agitated wildlife, crazed units, and Great Dangers + (see below). * ``dfhack.units.isGreatDanger(unit)`` diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 177d0b74e2..beb765eb02 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -2045,6 +2045,8 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = { WRAPM(Units, isMerchant), WRAPM(Units, isDiplomat), WRAPM(Units, isVisitor), + WRAPM(Units, isWildlife), + WRAPM(Units, isAgitated), WRAPM(Units, isInvader), WRAPM(Units, isUndead), WRAPM(Units, isNightCreature), diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h index a703705106..7eaa61ec62 100644 --- a/library/include/modules/Units.h +++ b/library/include/modules/Units.h @@ -158,6 +158,8 @@ DFHACK_EXPORT bool isAnimal(df::unit *unit); DFHACK_EXPORT bool isMerchant(df::unit *unit); DFHACK_EXPORT bool isDiplomat(df::unit *unit); DFHACK_EXPORT bool isVisitor(df::unit *unit); +DFHACK_EXPORT bool isWildlife(df::unit *unit); +DFHACK_EXPORT bool isAgitated(df::unit *unit); DFHACK_EXPORT bool isInvader(df::unit *unit); // Ignores units hiding curse by default to avoid spoiling vampires. DFHACK_EXPORT bool isUndead(df::unit *unit, bool hiding_curse = false); @@ -167,9 +169,8 @@ DFHACK_EXPORT bool isMegabeast(df::unit *unit); DFHACK_EXPORT bool isTitan(df::unit *unit); DFHACK_EXPORT bool isForgottenBeast(df::unit *unit); DFHACK_EXPORT bool isDemon(df::unit *unit); -/// Probably hostile. Includes undead (optionally those hiding curse), night creatures, -/// semi-megabeasts, invaders, agitated wildlife, crazed units, and Great Dangers. -DFHACK_EXPORT bool isDanger(df::unit *unit, bool hiding_curse = false); +/// Probably hostile. +DFHACK_EXPORT bool isDanger(df::unit *unit); // Megabeasts, titans, forgotten beasts, and demons. DFHACK_EXPORT bool isGreatDanger(df::unit *unit); diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 72585635d2..5df096cd11 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -171,8 +171,7 @@ bool Units::isFortControlled(df::unit *unit) return false; else if (unit->flags1.bits.tame) return true; - else if (unit->flags2.whole & exclude_flags2 || - unit->flags4.bits.agitated_wilderness_creature) + else if (unit->flags2.whole & exclude_flags2 || isAgitated(unit)) return false; return isOwnCiv(unit); } @@ -577,6 +576,19 @@ bool Units::isVisitor(df::unit *unit) { return unit->flags2.bits.visitor || unit->flags2.bits.visitor_uninvited; } +bool Units::isWildlife(df::unit *unit) { + CHECK_NULL_POINTER(unit); + return unit->animal.population.population_idx >= 0 + && !isMerchant(unit) + && !isForest(unit) + && !isFortControlled(unit); +} + +bool Units::isAgitated(df::unit *unit) { + CHECK_NULL_POINTER(unit); + return unit->flags4.bits.agitated_wilderness_creature; +} + bool Units::isInvader(df::unit *unit) { CHECK_NULL_POINTER(unit); return (unit->flags1.bits.marauder || @@ -624,15 +636,18 @@ bool Units::isDemon(df::unit *unit) { || cf.is_set(caste_raw_flags::UNIQUE_DEMON); } -bool Units::isDanger(df::unit *unit, bool hiding_curse) { +bool Units::isDanger(df::unit *unit) { CHECK_NULL_POINTER(unit); - return isCrazed(unit) || - isInvader(unit) || - isUndead(unit, hiding_curse) || - unit->flags4.bits.agitated_wilderness_creature || - isSemiMegabeast(unit) || - isNightCreature(unit) || - isGreatDanger(unit); + if (isTame(unit) || isOwnGroup(unit)) + return false; + + return isCrazed(unit) + || isInvader(unit) + || isOpposedToLife(unit) + || isAgitated(unit) + || isSemiMegabeast(unit) + || isNightCreature(unit) + || isGreatDanger(unit); } bool Units::isGreatDanger(df::unit *unit) { @@ -1747,7 +1762,7 @@ string Units::getProfessionName(df::unit *unit, bool ignore_noble, bool plural, return prof; } prof = getCasteProfessionName(unit->race, unit->caste, getProfession(unit), plural); - return unit->flags4.bits.agitated_wilderness_creature ? "Agitated " + prof : prof; + return isAgitated(unit) ? "Agitated " + prof : prof; } string Units::getCasteProfessionName(int race, int casteid, df::profession pid, bool plural) { diff --git a/plugins/lua/sort/info.lua b/plugins/lua/sort/info.lua index ebfc32b41b..0ad7b38cf4 100644 --- a/plugins/lua/sort/info.lua +++ b/plugins/lua/sort/info.lua @@ -749,7 +749,7 @@ local function filter_matches(unit, subset) elseif dfhack.units.isDead(unit) or not dfhack.units.isActive(unit) then return subset == 'deceased' elseif dfhack.units.isInvader(unit) or dfhack.units.isOpposedToLife(unit) - or unit.flags2.visitor_uninvited or unit.flags4.agitated_wilderness_creature + or unit.flags2.visitor_uninvited or dfhack.units.isAgitated(unit) then return subset == 'others' elseif dfhack.units.isVisiting(unit) then diff --git a/plugins/lua/zone.lua b/plugins/lua/zone.lua index 218972e2a3..94db5236c0 100644 --- a/plugins/lua/zone.lua +++ b/plugins/lua/zone.lua @@ -552,7 +552,7 @@ end local function get_unit_disposition(unit) local disposition = DISPOSITION.NONE - if dfhack.units.isInvader(unit) or dfhack.units.isOpposedToLife(unit) then + if dfhack.units.isDanger(unit) then disposition = DISPOSITION.HOSTILE elseif dfhack.units.isPet(unit) then disposition = DISPOSITION.PET From 60a454370937ed44f538ad01ecbeff0fe87648af Mon Sep 17 00:00:00 2001 From: DFHack-Urist via GitHub Actions <63161697+DFHack-Urist@users.noreply.github.com> Date: Sat, 10 Aug 2024 04:54:04 +0000 Subject: [PATCH 2/2] Auto-update submodules scripts: master --- scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts b/scripts index a787a35bda..1ab9c17d9c 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit a787a35bda45ca12a1377ed2f33576e18902d0d6 +Subproject commit 1ab9c17d9c7f3e20723f7a73d69444bd996240f8