Extends Units module

Adds unit check functions for
- animals
- demons
- titans
- megabeasts
- semimegabeasts
- night creatures
develop
Josh Cooper 2022-11-09 11:44:28 -08:00
parent ccd43f1710
commit beee445f6f
3 changed files with 44 additions and 0 deletions

@ -72,6 +72,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## API
- ``Lua::PushInterfaceKeys()``: transforms viewscreen ``feed()`` keys into something that can be interpreted by lua-based widgets
- ``Lua::Push()``: now handles maps with otherwise supported keys and values
- Units module: added ``isAnimal()``, ``isDemon()``, ``isTitan()``, ``isMegabeast()``, ``isSemiMegabeast()``, and ``isNightCreature()``
- Constructions module: added ``insert()`` to insert constructions into the game's sorted list.
- MiscUtils: moved the following string transformation functions from ``uicommon.h``: ``int_to_string``, ``ltrim``, ``rtrim``, and ``trim``

@ -141,6 +141,7 @@ DFHACK_EXPORT std::string getRaceChildName(df::unit* unit);
DFHACK_EXPORT bool isBaby(df::unit* unit);
DFHACK_EXPORT bool isChild(df::unit* unit);
DFHACK_EXPORT bool isAdult(df::unit* unit);
DFHACK_EXPORT bool isAnimal(df::unit* unit);
DFHACK_EXPORT bool isEggLayer(df::unit* unit);
DFHACK_EXPORT bool isGrazer(df::unit* unit);
DFHACK_EXPORT bool isMilkable(df::unit* unit);
@ -163,6 +164,11 @@ DFHACK_EXPORT bool isActive(df::unit *unit);
DFHACK_EXPORT bool isKilled(df::unit *unit);
DFHACK_EXPORT bool isGelded(df::unit* unit);
DFHACK_EXPORT bool isDomesticated(df::unit* unit);
DFHACK_EXPORT bool isDemon(df::unit* unit);
DFHACK_EXPORT bool isTitan(df::unit* unit);
DFHACK_EXPORT bool isMegabeast(df::unit* unit);
DFHACK_EXPORT bool isSemiMegabeast(df::unit* unit);
DFHACK_EXPORT bool isNightCreature(df::unit* unit);
DFHACK_EXPORT double getAge(df::unit *unit, bool true_age = false);
DFHACK_EXPORT int getKillCount(df::unit *unit);

@ -770,6 +770,12 @@ bool Units::isAdult(df::unit* unit)
return !isBaby(unit) && !isChild(unit);
}
bool Units::isAnimal(df::unit* unit)
{
CHECK_NULL_POINTER(unit)
return unit->enemy.caste_flags.is_set(df::enums::caste_raw_flags::NATURAL_ANIMAL);
}
bool Units::isEggLayer(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
@ -1824,6 +1830,37 @@ bool Units::isDomesticated(df::unit* unit)
return tame;
}
bool Units::isDemon(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
return unit->enemy.caste_flags.is_set(df::enums::caste_raw_flags::DEMON);
}
bool Units::isTitan(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
return unit->enemy.caste_flags.is_set(df::enums::caste_raw_flags::TITAN);
}
bool Units::isMegabeast(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
return unit->enemy.caste_flags.is_set(df::enums::caste_raw_flags::MEGABEAST);
}
bool Units::isSemiMegabeast(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
return unit->enemy.caste_flags.is_set(df::enums::caste_raw_flags::SEMIMEGABEAST);
}
bool Units::isNightCreature(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
return unit->enemy.caste_flags.is_set(df::enums::caste_raw_flags::NIGHT_CREATURE);
}
// 50000 and up is level 0, 25000 and up is level 1, etc.
const vector<int32_t> Units::stress_cutoffs {50000, 25000, 10000, -10000, -25000, -50000, -100000};