diff --git a/docs/changelog.txt b/docs/changelog.txt index 1aa7f916e..90492cdfc 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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 diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index c4b9e60fa..422060803 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -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)