Improve error detection and only list creatures when necessary

develop
lethosor 2015-02-17 14:33:58 -05:00
parent 645c2a7f86
commit 2921879be8
1 changed files with 16 additions and 12 deletions

@ -50,6 +50,11 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters)
{
if (!Core::getInstance().isWorldLoaded())
{
out.printerr("World not loaded.\n");
return CR_FAILURE;
}
bool list_only = false;
list<string> s_creatures;
if (parameters.size())
@ -78,7 +83,7 @@ command_result catsplosion (color_ostream &out, std::vector <std::string> & para
uint32_t numCreatures;
if(!(numCreatures = Units::getNumCreatures()))
{
cerr << "Can't get any creatures." << endl;
out.printerr("Can't get any creatures.\n");
return CR_FAILURE;
}
@ -87,8 +92,6 @@ command_result catsplosion (color_ostream &out, std::vector <std::string> & para
int totalcreated=0;
string sextype;
// shows all the creatures and returns.
int maxlength = 0;
map<string, vector <df::unit *> > male_counts;
map<string, vector <df::unit *> > female_counts;
@ -110,20 +113,16 @@ command_result catsplosion (color_ostream &out, std::vector <std::string> & para
}
}
// print (optional)
//if (showcreatures == 1)
if (list_only)
{
out.print("Type Male # Female #\n");
for(auto it1 = male_counts.begin();it1!=male_counts.end();it1++)
out.print("Type Male # Female #\n");
for (auto it1 = male_counts.begin(); it1!=male_counts.end(); it1++)
{
out.print("%20s %6d %8d\n", it1->first.c_str(), it1->second.size(), female_counts[it1->first].size());
out.print("%22s %6d %8d\n", it1->first.c_str(), it1->second.size(), female_counts[it1->first].size());
}
}
if (list_only)
{
return CR_OK;
}
// process
for (list<string>::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it)
{
@ -157,6 +156,11 @@ command_result catsplosion (color_ostream &out, std::vector <std::string> & para
out.print("%d pregnancies accelerated.\n", totalchanged);
if(totalcreated)
out.print("%d pregnancies created.\n", totalcreated);
if (!totalcount)
{
out.printerr("No creatures matched.\n");
return CR_FAILURE;
}
out.print("Total creatures checked: %d\n", totalcount);
return CR_OK;
}