Skip to content

Commit

Permalink
Fix several functions in the Units module ignoring unit caste.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Jun 2, 2020
1 parent 2fc7fa7 commit 5d05cfc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 14 additions & 38 deletions library/modules/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5d05cfc

Please sign in to comment.