From 8bbd43f2c955ac812000f75443997bcf3d65e36f Mon Sep 17 00:00:00 2001 From: Robert Heinrich Date: Sun, 15 Apr 2012 17:40:39 +0200 Subject: [PATCH] zone: added filters to search for creatures who can be trained for war/hunting --- README.rst | 44 +++++++++++++++++++++++--------------------- plugins/zone.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/README.rst b/README.rst index a563f7bb8..d8f8398c0 100644 --- a/README.rst +++ b/README.rst @@ -817,27 +817,29 @@ Options: Filters: -------- -:all: Process all units (to be used with additional filters). -:count: Must be followed by a number. Process only n units (to be used with additional filters). -:race: Must be followed by a race raw id (e.g. BIRD_TURKEY, ALPACA etc). -:unassigned: Not assigned to zone, chain or built cage. -:caged: In a built cage. -:uncaged: Not in a cage (in case you want your stockpiles to be left alone). -:foreign: Not of own civilization. -:own: From own civilization. -: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. -:tamed: Creature is tame. -:trained: Creature is trained. -:untrained: Creature is untrained. -:male: Creature is male. -:female: Creature is female. -:egglayer: Race lays eggs. -:grazer: Race is a grazer. -:nograzer: Race is not a grazer. -:milkable: Race is milkable. -:minage: Minimum age. Must be followed by number. -:maxage: Maximum age. Must be followed by number. +:all: Process all units (to be used with additional filters). +:count: Must be followed by a number. Process only n units (to be used with additional filters). +:race: Must be followed by a race raw id (e.g. BIRD_TURKEY, ALPACA etc). +:unassigned: Not assigned to zone, chain or built cage. +:caged: In a built cage. +:uncaged: Not in a cage (in case you want your stockpiles to be left alone). +:foreign: Not of own civilization. +:own: From own civilization. +: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. +:tamed: Creature is tame. +:trained: Creature is trained. +:untrained: Creature is untrained. +:trainablewar: Creature can be trained for war (and is not already trained for war/hunt). +:trainablehunt: Creature can be trained for hunting (and is not already trained for war/hunt). +:male: Creature is male. +:female: Creature is female. +:egglayer: Race lays eggs. +:grazer: Race is a grazer. +:nograzer: Race is not a grazer. +:milkable: Race is milkable. +:minage: Minimum age. Must be followed by number. +:maxage: Maximum age. Must be followed by number. Usage with single units ----------------------- diff --git a/plugins/zone.cpp b/plugins/zone.cpp index 7694ad00d..55a150691 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -116,6 +116,8 @@ const string zone_help_filters = " (could have weird effects during trading, be careful)\n" " trained - obvious\n" " untrained - obvious\n" + " trainablewar - can be trained for war (and is not already trained)\n" + " trainablehunt- can be trained for hunting (and is not already trained)\n" " male - obvious\n" " female - obvious\n" " egglayer - race lays eggs (use together with 'female')\n" @@ -563,6 +565,32 @@ bool isMilkable(df::unit* unit) return false; } +bool isTrainableWar(df::unit* unit) +{ + df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race]; + size_t sizecas = raw->caste.size(); + for (size_t j = 0; j < sizecas;j++) + { + df::caste_raw *caste = raw->caste[j]; + if(caste->flags.is_set(caste_raw_flags::TRAINABLE_WAR)) + return true; + } + return false; +} + +bool isTrainableHunting(df::unit* unit) +{ + df::creature_raw *raw = df::global::world->raws.creatures.all[unit->race]; + size_t sizecas = raw->caste.size(); + for (size_t j = 0; j < sizecas;j++) + { + df::caste_raw *caste = raw->caste[j]; + if(caste->flags.is_set(caste_raw_flags::TRAINABLE_HUNTING)) + return true; + } + return false; +} + bool isMale(df::unit* unit) { return unit->sex == 1; @@ -1459,6 +1487,8 @@ command_result df_zone (color_ostream &out, vector & parameters) bool find_uncaged = false; bool find_foreign = false; bool find_untrained = false; + bool find_trainable_war = false; + bool find_trainable_hunting = false; //bool find_trained = false; bool find_war = false; bool find_own = false; @@ -1593,6 +1623,16 @@ command_result df_zone (color_ostream &out, vector & parameters) out << "Filter by 'untrained'." << endl; find_untrained = true; } + else if(p == "trainablewar") + { + out << "Filter by 'trainable for war'." << endl; + find_trainable_war = true; + } + else if(p == "trainablehunt") + { + out << "Filter by 'trainable for hunting'." << endl; + find_trainable_hunting = true; + } else if(p == "war") { out << "Filter by 'trained war creature'." << endl; @@ -1896,6 +1936,8 @@ command_result df_zone (color_ostream &out, vector & parameters) || (find_male && !isMale(unit)) || (find_female && !isFemale(unit)) || (find_named && !unit->name.has_name) + || (find_trainable_war && (isWar(unit) || isHunter(unit) || !isTrainableWar(unit))) + || (find_trainable_hunting && (isWar(unit) || isHunter(unit) || !isTrainableHunting(unit))) ) continue;