|
|
|
@ -172,12 +172,12 @@ const string autobutcher_help =
|
|
|
|
|
" sleep X - change timer to sleep X frames between runs.\n"
|
|
|
|
|
" watch R - start watching race(s)\n"
|
|
|
|
|
" R = valid race RAW id (ALPACA, BIRD_TURKEY, etc)\n"
|
|
|
|
|
//" or a list of RAW ids seperated by spaces\n"
|
|
|
|
|
" or a list of RAW ids seperated by spaces\n"
|
|
|
|
|
//" or the keyword 'all' which adds all races with\n"
|
|
|
|
|
//" at least one owned tame unit in your fortress\n"
|
|
|
|
|
" unwatch R - stop watching race\n"
|
|
|
|
|
" unwatch R - stop watching race(s)\n"
|
|
|
|
|
" the current target settings will be remembered\n"
|
|
|
|
|
" forget R - unwatch race and forget target settings for it\n"
|
|
|
|
|
" forget R - unwatch race(s) and forget target settings for it/them\n"
|
|
|
|
|
//" autowatch - automatically adds all new races (animals you buy\n"
|
|
|
|
|
//" from merchants, tame yourself or get from migrants)\n"
|
|
|
|
|
//" to the watch list using default target count\n"
|
|
|
|
@ -197,13 +197,13 @@ const string autobutcher_help =
|
|
|
|
|
|
|
|
|
|
const string autobutcher_help_example =
|
|
|
|
|
"Examples:\n"
|
|
|
|
|
" autobutcher target 4 3 2 1 ALPACA\n"
|
|
|
|
|
" autobutcher watch ALPACA\n"
|
|
|
|
|
" autobutcher target 4 3 2 1 ALPACA BIRD_TURKEY\n"
|
|
|
|
|
" autobutcher watch ALPACA BIRD_TURKEY\n"
|
|
|
|
|
" autobutcher start\n"
|
|
|
|
|
" This means you want to have max 7 kids (4 female, 3 male) and max 3 adults\n"
|
|
|
|
|
" (2 female, 1 male) of the race alpaca. Once the kids grow up the oldest\n"
|
|
|
|
|
" adults will get slaughtered. Excess kids will get slaughtered starting with\n"
|
|
|
|
|
" the youngest to allow that the older ones grow into adults.\n"
|
|
|
|
|
" (2 female, 1 male) of the races alpaca and turkey. Once the kids grow up the\n"
|
|
|
|
|
" oldest adults will get slaughtered. Excess kids will get slaughtered starting\n"
|
|
|
|
|
" the the youngest to allow that the older ones grow into adults.\n"
|
|
|
|
|
//" autobutcher target 0 0 0 0 all\n"
|
|
|
|
|
//" autobutcher autowatch\n"
|
|
|
|
|
//" autobutcher start\n"
|
|
|
|
@ -2058,7 +2058,9 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
bool forget_race = false;
|
|
|
|
|
bool list_watched = false;
|
|
|
|
|
bool change_target = false;
|
|
|
|
|
string target_racename = "";
|
|
|
|
|
vector <string> target_racenames;
|
|
|
|
|
vector <int> target_raceids;
|
|
|
|
|
|
|
|
|
|
int target_fk = default_fk;
|
|
|
|
|
int target_mk = default_mk;
|
|
|
|
|
int target_fa = default_fa;
|
|
|
|
@ -2066,10 +2068,15 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
|
|
|
|
|
int32_t target_raceid = -1;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < parameters.size(); i++)
|
|
|
|
|
if(!parameters.size())
|
|
|
|
|
{
|
|
|
|
|
string & p = parameters[i];
|
|
|
|
|
out << "You must specify a command!" << endl;
|
|
|
|
|
out << autobutcher_help << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse main command
|
|
|
|
|
string & p = parameters[0];
|
|
|
|
|
if (p == "help" || p == "?")
|
|
|
|
|
{
|
|
|
|
|
out << autobutcher_help << endl;
|
|
|
|
@ -2092,13 +2099,10 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
out << "Autobutcher stopped.";
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
else if(p == "verbose")
|
|
|
|
|
{
|
|
|
|
|
verbose = true;
|
|
|
|
|
}
|
|
|
|
|
else if(p == "sleep")
|
|
|
|
|
{
|
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
|
if(!parameters.size())
|
|
|
|
|
{
|
|
|
|
|
out.printerr("No duration specified!");
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
@ -2106,8 +2110,8 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
size_t ticks = 0;
|
|
|
|
|
stringstream ss(parameters[i+1]);
|
|
|
|
|
i++;
|
|
|
|
|
stringstream ss(parameters.back());
|
|
|
|
|
//i++;
|
|
|
|
|
ss >> ticks;
|
|
|
|
|
if(ticks <= 0)
|
|
|
|
|
{
|
|
|
|
@ -2121,52 +2125,19 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
}
|
|
|
|
|
else if(p == "watch")
|
|
|
|
|
{
|
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
|
{
|
|
|
|
|
out.printerr("No race specified!");
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// todo: parse more than one race
|
|
|
|
|
target_racename = parameters[i+1];
|
|
|
|
|
i++;
|
|
|
|
|
out << "Start watching race " << target_racename << endl;
|
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
|
watch_race = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(p == "unwatch")
|
|
|
|
|
{
|
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
|
{
|
|
|
|
|
out.printerr("No race specified!");
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// todo: parse more than one race
|
|
|
|
|
target_racename = parameters[i+1];
|
|
|
|
|
i++;
|
|
|
|
|
out << "Stop watching race " << target_racename << endl;
|
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
|
unwatch_race = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(p == "forget")
|
|
|
|
|
{
|
|
|
|
|
if(i == parameters.size()-1)
|
|
|
|
|
{
|
|
|
|
|
out.printerr("No race specified!");
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// todo: parse more than one race
|
|
|
|
|
target_racename = parameters[i+1];
|
|
|
|
|
i++;
|
|
|
|
|
out << "Forget settings for race " << target_racename << endl;
|
|
|
|
|
parameters.erase(parameters.begin());
|
|
|
|
|
forget_race = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(p == "target")
|
|
|
|
|
{
|
|
|
|
|
// needs at least 5 more parameters:
|
|
|
|
@ -2178,24 +2149,15 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
stringstream fk(parameters[i+1]);
|
|
|
|
|
stringstream mk(parameters[i+2]);
|
|
|
|
|
stringstream fa(parameters[i+3]);
|
|
|
|
|
stringstream ma(parameters[i+4]);
|
|
|
|
|
stringstream fk(parameters[1]);
|
|
|
|
|
stringstream mk(parameters[2]);
|
|
|
|
|
stringstream fa(parameters[3]);
|
|
|
|
|
stringstream ma(parameters[4]);
|
|
|
|
|
fk >> target_fk;
|
|
|
|
|
mk >> target_mk;
|
|
|
|
|
fa >> target_fa;
|
|
|
|
|
ma >> target_ma;
|
|
|
|
|
|
|
|
|
|
// todo: parse more than one race, handle 'all' and 'new'
|
|
|
|
|
target_racename = parameters[i+5];
|
|
|
|
|
i+=5;
|
|
|
|
|
out << "Target count for " << target_racename << ":"
|
|
|
|
|
<< " fk=" << target_fk
|
|
|
|
|
<< " mk=" << target_mk
|
|
|
|
|
<< " fa=" << target_fa
|
|
|
|
|
<< " ma=" << target_ma
|
|
|
|
|
<< endl;
|
|
|
|
|
parameters.erase(parameters.begin(), parameters.begin()+5);
|
|
|
|
|
change_target = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -2218,14 +2180,6 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
out << "Unknown command: " << p << endl;
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( target_racename == "all" ||
|
|
|
|
|
target_racename == "new" )
|
|
|
|
|
{
|
|
|
|
|
out << "'all' and 'new' are not supported yet, sorry." << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(list_watched)
|
|
|
|
|
{
|
|
|
|
@ -2248,102 +2202,123 @@ command_result df_autobutcher(color_ostream &out, vector <string> & parameters)
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse rest of parameters for commands followed by a list of races
|
|
|
|
|
if( watch_race
|
|
|
|
|
|| unwatch_race
|
|
|
|
|
|| forget_race
|
|
|
|
|
|| change_target )
|
|
|
|
|
{
|
|
|
|
|
if(!parameters.size())
|
|
|
|
|
{
|
|
|
|
|
out.printerr("No race(s) specified!");
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
}
|
|
|
|
|
while(parameters.size())
|
|
|
|
|
{
|
|
|
|
|
string tr = parameters.back();
|
|
|
|
|
target_racenames.push_back(tr);
|
|
|
|
|
parameters.pop_back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( target_racenames.size() &&
|
|
|
|
|
(target_racenames[0] == "all" ||
|
|
|
|
|
target_racenames[0] == "new") )
|
|
|
|
|
{
|
|
|
|
|
out << "'all' and 'new' are not supported yet, sorry." << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t num_races = df::global::world->raws.creatures.all.size();
|
|
|
|
|
while(target_racenames.size())
|
|
|
|
|
{
|
|
|
|
|
bool found_race = false;
|
|
|
|
|
for(size_t i=0; i<num_races; i++)
|
|
|
|
|
{
|
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[i];
|
|
|
|
|
if(raw->creature_id == target_racename)
|
|
|
|
|
if(raw->creature_id == target_racenames.back())
|
|
|
|
|
{
|
|
|
|
|
target_raceid = i;
|
|
|
|
|
target_raceids.push_back(i);
|
|
|
|
|
target_racenames.pop_back();
|
|
|
|
|
found_race = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!found_race)
|
|
|
|
|
{
|
|
|
|
|
out << "Race not found!" << endl;
|
|
|
|
|
out << "Race not found: " << target_racenames.back() << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(unwatch_race)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
while(target_raceids.size())
|
|
|
|
|
{
|
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
|
if(w->raceId == target_raceid)
|
|
|
|
|
if(w->raceId == target_raceids.back())
|
|
|
|
|
{
|
|
|
|
|
found=true;
|
|
|
|
|
w->isWatched=false;
|
|
|
|
|
target_raceids.pop_back();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(found)
|
|
|
|
|
out << target_racename << " is not watched anymore." << endl;
|
|
|
|
|
else
|
|
|
|
|
out << target_racename << " was not being watched!" << endl;
|
|
|
|
|
}
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(watch_race || change_target)
|
|
|
|
|
{
|
|
|
|
|
bool watching = false;
|
|
|
|
|
while(target_raceids.size())
|
|
|
|
|
{
|
|
|
|
|
bool entry_found = false;
|
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
|
if(w->raceId == target_raceid)
|
|
|
|
|
if(w->raceId == target_raceids.back())
|
|
|
|
|
{
|
|
|
|
|
if(watch_race)
|
|
|
|
|
{
|
|
|
|
|
if(w->isWatched)
|
|
|
|
|
out << target_racename << " is already being watched." << endl;
|
|
|
|
|
w->isWatched = true;
|
|
|
|
|
watching = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(change_target)
|
|
|
|
|
else if(change_target)
|
|
|
|
|
{
|
|
|
|
|
w->fk = target_fk;
|
|
|
|
|
w->mk = target_mk;
|
|
|
|
|
w->fa = target_fa;
|
|
|
|
|
w->ma = target_ma;
|
|
|
|
|
}
|
|
|
|
|
entry_found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!watching)
|
|
|
|
|
if(!entry_found)
|
|
|
|
|
{
|
|
|
|
|
WatchedRace * w = new WatchedRace(watch_race, target_raceid, target_fk, target_mk, target_fa, target_ma);
|
|
|
|
|
WatchedRace * w = new WatchedRace(watch_race, target_raceids.back(), target_fk, target_mk, target_fa, target_ma);
|
|
|
|
|
watched_races.push_back(w);
|
|
|
|
|
}
|
|
|
|
|
out << target_racename << " is now being watched." << endl;
|
|
|
|
|
target_raceids.pop_back();
|
|
|
|
|
}
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(forget_race)
|
|
|
|
|
{
|
|
|
|
|
bool watched = false;
|
|
|
|
|
while(target_raceids.size())
|
|
|
|
|
{
|
|
|
|
|
for(size_t i=0; i<watched_races.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
WatchedRace * w = watched_races[i];
|
|
|
|
|
if(w->raceId == target_raceid)
|
|
|
|
|
if(w->raceId == target_raceids.back())
|
|
|
|
|
{
|
|
|
|
|
watched_races.erase(watched_races.begin()+i);
|
|
|
|
|
|
|
|
|
|
if(w->isWatched)
|
|
|
|
|
out << target_racename << " is already being watched." << endl;
|
|
|
|
|
w->isWatched = true;
|
|
|
|
|
watched = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!watched)
|
|
|
|
|
{
|
|
|
|
|
out << target_racename << " was not on the watchlist." << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
target_raceids.pop_back();
|
|
|
|
|
}
|
|
|
|
|
out << target_racename << " was forgotten." << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|