Fix several functions in the Units module ignoring unit caste.

Fixes #1583.
develop
Ben Lubar 2020-06-02 01:15:33 -05:00
parent 2fc7fa7ac2
commit 5d05cfc7cc
No known key found for this signature in database
GPG Key ID: 92939677AB59EDA4
2 changed files with 15 additions and 38 deletions

@ -42,6 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes
- Fixed a segfault when attempting to start a headless session with a graphical PRINT_MODE setting
- `labormanager`: fixed handling of new jobs in 0.47
- Fixed ``Units::isEggLayer``, ``Units::isGrazer``, ``Units::isMilkable``, ``Units::isTrainableHunting``, ``Units::isTrainableWar``, and ``Units::isTamable`` ignoring the unit's caste
## Ruby
- Updated ``item_find`` and ``building_find`` to use centralized logic that works on more screens

@ -636,74 +636,50 @@ bool Units::isEggLayer(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto caste = raw->caste.begin(); caste != raw->caste.end(); ++caste)
{
if ((*caste)->flags.is_set(caste_raw_flags::LAYS_EGGS)
|| (*caste)->flags.is_set(caste_raw_flags::LAYS_UNUSUAL_EGGS))
return true;
}
return false;
df::caste_raw *caste = raw->caste.at(unit->caste);
return caste->flags.is_set(caste_raw_flags::LAYS_EGGS)
|| caste->flags.is_set(caste_raw_flags::LAYS_UNUSUAL_EGGS);
}
bool Units::isGrazer(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto caste = raw->caste.begin(); caste != raw->caste.end(); ++caste)
{
if((*caste)->flags.is_set(caste_raw_flags::GRAZER))
return true;
}
return false;
df::caste_raw *caste = raw->caste.at(unit->caste);
return caste->flags.is_set(caste_raw_flags::GRAZER);
}
bool Units::isMilkable(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto caste = raw->caste.begin(); caste != raw->caste.end(); ++caste)
{
if((*caste)->flags.is_set(caste_raw_flags::MILKABLE))
return true;
}
return false;
df::caste_raw *caste = raw->caste.at(unit->caste);
return caste->flags.is_set(caste_raw_flags::MILKABLE);
}
bool Units::isTrainableWar(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto caste = raw->caste.begin(); caste != raw->caste.end(); ++caste)
{
if((*caste)->flags.is_set(caste_raw_flags::TRAINABLE_WAR))
return true;
}
return false;
df::caste_raw *caste = raw->caste.at(unit->caste);
return caste->flags.is_set(caste_raw_flags::TRAINABLE_WAR);
}
bool Units::isTrainableHunting(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto caste = raw->caste.begin(); caste != raw->caste.end(); ++caste)
{
if((*caste)->flags.is_set(caste_raw_flags::TRAINABLE_HUNTING))
return true;
}
return false;
df::caste_raw *caste = raw->caste.at(unit->caste);
return caste->flags.is_set(caste_raw_flags::TRAINABLE_HUNTING);
}
bool Units::isTamable(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
df::creature_raw *raw = world->raws.creatures.all[unit->race];
for (auto caste = raw->caste.begin(); caste != raw->caste.end(); ++caste)
{
if((*caste)->flags.is_set(caste_raw_flags::PET) ||
(*caste)->flags.is_set(caste_raw_flags::PET_EXOTIC))
return true;
}
return false;
df::caste_raw *caste = raw->caste.at(unit->caste);
return caste->flags.is_set(caste_raw_flags::PET)
|| caste->flags.is_set(caste_raw_flags::PET_EXOTIC);
}
bool Units::isMale(df::unit* unit)