Skip to content

Commit

Permalink
Merge branch 'develop' into adv-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Aug 10, 2024
2 parents 0370d43 + 60a4543 commit eab62a3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)``

Expand Down
2 changes: 2 additions & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions library/include/modules/Units.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
37 changes: 26 additions & 11 deletions library/modules/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/lua/sort/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/lua/zone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts

0 comments on commit eab62a3

Please sign in to comment.