From e58a46b42b99c935a4c200a557efa479165d45b4 Mon Sep 17 00:00:00 2001 From: Robert Heinrich Date: Mon, 16 Apr 2012 03:31:49 +0200 Subject: [PATCH] zone: fixed filter 'trained' so it now finds war/hunting creatures (who strangely don't have a training level) --- README.rst | 3 +- plugins/zone.cpp | 79 +++++++++++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/README.rst b/README.rst index 0849cacf5..7cd6de124 100644 --- a/README.rst +++ b/README.rst @@ -829,8 +829,9 @@ Filters: :own: From own civilization. Negatable. :merchant: Is a merchant / belongs to a merchant. Should only be used for pitting, not for stealing animals (slaughter should work). :war: Trained war creature. Negatable. +:hunting: Trained hunting creature. Negatable. :tamed: Creature is tame. Negatable. -:trained: Creature is trained. Negatable. +:trained: Creature is trained. Finds war/hunting creatures as well as creatures who have a training level greater than 'domesticated'. If you want to specifically search for war/hunting creatures use 'war' or 'hunting' Negatable. :trainablewar: Creature can be trained for war (and is not already trained for war/hunt). Negatable. :trainablehunt: Creature can be trained for hunting (and is not already trained for war/hunt). Negatable. :male: Creature is male. Negatable. diff --git a/plugins/zone.cpp b/plugins/zone.cpp index 1e1171235..ca9213128 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -336,12 +336,11 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out ) int32_t getUnitAge(df::unit* unit); bool isTame(df::unit* unit); bool isTrained(df::unit* unit); -bool isTrained(df::unit* creature); -bool isWar(df::unit* creature); -bool isHunter(df::unit* creature); -bool isOwnCiv(df::unit* creature); -bool isMerchant(df::unit* creature); -bool isForest(df::unit* creature); +bool isWar(df::unit* unit); +bool isHunter(df::unit* unit); +bool isOwnCiv(df::unit* unit); +bool isMerchant(df::unit* unit); +bool isForest(df::unit* unit); bool isActivityZone(df::building * building); bool isPenPasture(df::building * building); @@ -433,44 +432,46 @@ bool isTame(df::unit* creature) } // check if trained (might be useful if pasturing war dogs etc) -bool isTrained(df::unit* creature) +bool isTrained(df::unit* unit) { + // case a: trained for war/hunting (those don't have a training level, strangely) + if(isWar(unit) || isHunter(unit)) + return true; + + // case b: tamed and trained wild creature, gets a training level bool trained = false; - if(creature->flags1.bits.tame) - { - switch (creature->training_level) - { - case df::animal_training_level::Trained: - case df::animal_training_level::WellTrained: - case df::animal_training_level::SkilfullyTrained: - case df::animal_training_level::ExpertlyTrained: - case df::animal_training_level::ExceptionallyTrained: - case df::animal_training_level::MasterfullyTrained: - //case df::animal_training_level::Domesticated: - trained = true; - break; - default: - break; - } + switch (unit->training_level) + { + case df::animal_training_level::Trained: + case df::animal_training_level::WellTrained: + case df::animal_training_level::SkilfullyTrained: + case df::animal_training_level::ExpertlyTrained: + case df::animal_training_level::ExceptionallyTrained: + case df::animal_training_level::MasterfullyTrained: + //case df::animal_training_level::Domesticated: + trained = true; + break; + default: + break; } return trained; } // check for profession "war creature" -bool isWar(df::unit* creature) +bool isWar(df::unit* unit) { - if( creature->profession == df::profession::TRAINED_WAR - || creature->profession2 == df::profession::TRAINED_WAR) + if( unit->profession == df::profession::TRAINED_WAR + || unit->profession2 == df::profession::TRAINED_WAR) return true; else return false; } // check for profession "hunting creature" -bool isHunter(df::unit* creature) +bool isHunter(df::unit* unit) { - if( creature->profession == df::profession::TRAINED_HUNTER - || creature->profession2 == df::profession::TRAINED_HUNTER) + if( unit->profession == df::profession::TRAINED_HUNTER + || unit->profession2 == df::profession::TRAINED_HUNTER) return true; else return false; @@ -478,16 +479,16 @@ bool isHunter(df::unit* creature) // check if creature belongs to the player's civilization // (don't try to pasture/slaughter random untame animals) -bool isOwnCiv(df::unit* creature) +bool isOwnCiv(df::unit* unit) { - return creature->civ_id == ui->civ_id; + return unit->civ_id == ui->civ_id; } // check if creature belongs to the player's race // (in combination with check for civ helps to filter out own dwarves) -bool isOwnRace(df::unit* creature) +bool isOwnRace(df::unit* unit) { - return creature->race == ui->race_id; + return unit->race == ui->race_id; } string getRaceName(int32_t id) @@ -1728,7 +1729,17 @@ command_result df_zone (color_ostream &out, vector & parameters) find_not_war = true; invert_filter = false; } - else if(p == "own"&& !invert_filter) + else if(p == "hunting" && !invert_filter) + { + out << "Filter by 'trained hunting creature'." << endl; + find_hunter = true; + } + else if(p == "hunting" && invert_filter) + { + out << "Filter by 'not a trained hunting creature'." << endl; + find_not_hunter = true; + invert_filter = false; + }else if(p == "own"&& !invert_filter) { out << "Filter by 'own civilization'." << endl; find_own = true;