diff --git a/NEWS b/NEWS index 2f790e653..064b9db10 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,7 @@ DFHack Future tradereq-pet-gender: Displays pet genders on the trade request screen Removed Misc Improvements + catsplosion: Can now trigger pregnancies in (most) other creatures exportlegends: 'info' and 'all' exports legends_plus xml with more data for legends utilities remotefortressreader: Exposes more information diff --git a/plugins/catsplosion.cpp b/plugins/catsplosion.cpp index 1e68268eb..eee39a996 100644 --- a/plugins/catsplosion.cpp +++ b/plugins/catsplosion.cpp @@ -50,9 +50,31 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) command_result catsplosion (color_ostream &out, std::vector & parameters) { + if (!Core::getInstance().isWorldLoaded()) + { + out.printerr("World not loaded.\n"); + return CR_FAILURE; + } + bool list_only = false; list s_creatures; - // only cats for now. - s_creatures.push_back("CAT"); + if (parameters.size()) + { + for (size_t i = 0; i < parameters.size(); i++) + { + if (parameters[i] == "list") + { + list_only = true; + } + else + { + s_creatures.push_back(parameters[i]); + } + } + } + else + { + s_creatures.push_back("CAT"); + } // make the creature list unique ... with cats. they are always unique s_creatures.unique(); // SUSPEND THE CORE! ::Evil laugh:: @@ -61,7 +83,7 @@ command_result catsplosion (color_ostream &out, std::vector & 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; } @@ -70,8 +92,6 @@ command_result catsplosion (color_ostream &out, std::vector & para int totalcreated=0; string sextype; - // shows all the creatures and returns. - int maxlength = 0; map > male_counts; map > female_counts; @@ -93,17 +113,16 @@ command_result catsplosion (color_ostream &out, std::vector & 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()); } + return CR_OK; } - // process for (list::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it) { @@ -137,6 +156,11 @@ command_result catsplosion (color_ostream &out, std::vector & 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; }