expose and use casteFlagSet

develop
Myk Taylor 2023-08-13 00:20:08 -07:00
parent 93ed45d6e7
commit 296a34834c
No known key found for this signature in database
3 changed files with 24 additions and 5 deletions

@ -1525,6 +1525,11 @@ Units module
Computes the effective attribute value, including curse effect.
* ``dfhack.units.casteFlagSet(race, caste, flag)``
Returns whether the given ``df.caste_raw_flags`` flag is set for the given
race and caste.
* ``dfhack.units.getMiscTrait(unit, type[, create])``
Finds (or creates if requested) a misc trait object with the given id.

@ -1816,6 +1816,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, getNemesis),
WRAPM(Units, getPhysicalAttrValue),
WRAPM(Units, getMentalAttrValue),
WRAPM(Units, casteFlagSet),
WRAPM(Units, getMiscTrait),
WRAPM(Units, getAge),
WRAPM(Units, getKillCount),

@ -450,7 +450,9 @@ end
local function get_unit_disposition(unit)
local disposition = DISPOSITION.NONE
if dfhack.units.isPet(unit) then
if dfhack.units.isInvader(unit) or dfhack.units.isOpposedToLife(unit) then
disposition = DISPOSITION.HOSTILE
elseif dfhack.units.isPet(unit) then
disposition = DISPOSITION.PET
elseif dfhack.units.isDomesticated(unit) then
disposition = DISPOSITION.TAME
@ -458,8 +460,6 @@ local function get_unit_disposition(unit)
disposition = DISPOSITION.TRAINED
elseif dfhack.units.isTamable(unit) then
disposition = DISPOSITION.WILD_TRAINABLE
elseif dfhack.units.isInvader(unit) or dfhack.units.isOpposedToLife(unit) then
disposition = DISPOSITION.HOSTILE
else
disposition = DISPOSITION.WILD_UNTRAINABLE
end
@ -467,8 +467,21 @@ local function get_unit_disposition(unit)
end
local function get_item_disposition(item)
-- TODO
return DISPOSITION.TAME.value
local disposition = DISPOSITION.NONE
if dfhack.units.casteFlagSet(item.race, item.caste, df.caste_raw_flags.OPPOSED_TO_LIFE) then
disposition = DISPOSITION.HOSTILE
-- elseif dfhack.units.isPet(unit) then
-- disposition = DISPOSITION.PET
-- elseif dfhack.units.isDomesticated(unit) then
-- disposition = DISPOSITION.TAME
elseif dfhack.units.casteFlagSet(item.race, item.caste, df.caste_raw_flags.PET) or
dfhack.units.casteFlagSet(item.race, item.caste, df.caste_raw_flags.PET_EXOTIC)
then
disposition = DISPOSITION.WILD_TRAINABLE
else
disposition = DISPOSITION.WILD_UNTRAINABLE
end
return disposition.value
end
local function is_assignable_unit(unit)