diff options
| author | Robert Heinrich | 2012-04-16 21:37:48 +0200 |
|---|---|---|
| committer | Robert Heinrich | 2012-04-16 21:37:48 +0200 |
| commit | 6d180d61c483350d19f08c5cdb74edd4aaff21da (patch) | |
| tree | 191ff19a766fe40066e8948c9a5279215fba983d /plugins/zone.cpp | |
| parent | 70ebd26e6cab3cd7b40c13039016904f1ed69e0a (diff) | |
| download | dfhack-6d180d61c483350d19f08c5cdb74edd4aaff21da.tar.gz dfhack-6d180d61c483350d19f08c5cdb74edd4aaff21da.tar.bz2 dfhack-6d180d61c483350d19f08c5cdb74edd4aaff21da.tar.xz | |
autopasture: only process domesticated own units to avoid problems with wild animals forgetting their training and going on a rampage
Diffstat (limited to 'plugins/zone.cpp')
| -rw-r--r-- | plugins/zone.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/plugins/zone.cpp b/plugins/zone.cpp index 43c25972..968fda72 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -410,6 +410,7 @@ void doMarkForSlaughter(df::unit* unit) unit->flags2.bits.slaughter = 1; } +// check if creature is tame bool isTame(df::unit* creature) { bool tame = false; @@ -437,6 +438,26 @@ bool isTame(df::unit* creature) return tame; } +// check if creature is domesticated +// seems to be the only way to really tell if it's completely safe to autonestbox it (training can revert) +bool isDomesticated(df::unit* creature) +{ + bool tame = false; + if(creature->flags1.bits.tame) + { + switch (creature->training_level) + { + case df::animal_training_level::Domesticated: + tame=true; + break; + default: + tame=false; + break; + } + } + return tame; +} + // check if trained (might be useful if pasturing war dogs etc) bool isTrained(df::unit* unit) { @@ -1181,7 +1202,7 @@ bool isFreeEgglayer(df::unit * unit) { if( !isDead(unit) && !isUndead(unit) && isFemale(unit) - && isTame(unit) + && isDomesticated(unit) // better strict than sorry (medium trained wild animals can revert into wild state) && isOwnCiv(unit) && isEggLayer(unit) && !isAssigned(unit) @@ -1436,10 +1457,6 @@ command_result assignUnitsToCagezone(color_ostream& out, vector<df::unit*> units int32_t y1 = building->y1; int32_t y2 = building->y2; int32_t z = building->z; - //out << " x1:"<<x1<<" x2:"<<x2 - // << " y1:"<<y1<<" y2:"<<x2 - // << " z:"<<z<<endl; - //out << "filling vector with cages on this zone" << endl; vector <df::building_cagest*> cages; for (int32_t x = x1; x<=x2; x++) { @@ -1477,10 +1494,10 @@ command_result assignUnitsToCagezone(color_ostream& out, vector<df::unit*> units } } df::unit* unit = units.back(); + units.pop_back(); command_result result = assignUnitToCage(out, unit, (df::building*) bestcage, verbose); if(result!=CR_OK) return result; - units.pop_back(); } return CR_OK; @@ -2416,12 +2433,6 @@ command_result df_zone (color_ostream &out, vector <string> & parameters) if(cagezone_assign) { - // !!! optimize me: collect a vector of unit pointers which match the search and pass it to - // a method assignUnitsToCagezone(out, units, building) which only builds the vector of cages once - //command_result result = assignUnitToCagezone(out, unit, building, verbose); - //if(result != CR_OK) - // return result; - //continue; units_for_cagezone.push_back(unit); } else if(building_assign) @@ -2472,7 +2483,7 @@ command_result df_zone (color_ostream &out, vector <string> & parameters) } else if(unit_slaughter) { - // by default behave like the game: only allow slaughtering of named war/hunting pets + // by default behave like the game? only allow slaughtering of named war/hunting pets //if(unit->name.has_name && !find_named && !(isWar(unit)||isHunter(unit))) //{ // out << "Slaughter of named unit denied. Use the filter 'named' to override this check." << endl; @@ -3453,7 +3464,6 @@ command_result start_autonestbox(color_ostream &out) config_autonestbox = pworld->AddPersistentData("autonestbox/config"); config_autonestbox.ival(0) = enable_autonestbox; config_autonestbox.ival(1) = sleep_autonestbox; - //out << "autonestbox created persistent config object." << endl; } out << "Starting autonestbox." << endl; init_autonestbox(out); |
