zone: added filters to search for creatures who can be trained for war/hunting

develop
Robert Heinrich 2012-04-15 17:40:39 +02:00
parent be580592ce
commit 8bbd43f2c9
2 changed files with 65 additions and 21 deletions

@ -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
-----------------------

@ -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 <string> & 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 <string> & 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 <string> & 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;