2012-02-13 09:43:41 -07:00
|
|
|
// Catsplosion
|
|
|
|
// By Zhentar , Further modified by dark_rabite, peterix, belal
|
|
|
|
// This work of evil makes animals pregnant
|
|
|
|
// and due within 2 in-game hours...
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <climits>
|
|
|
|
#include <stdlib.h> // for rand()
|
|
|
|
#include <algorithm> // for std::transform
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
#include <iterator>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "DFHack.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include <df/caste_raw.h>
|
|
|
|
#include <df/creature_raw.h>
|
2012-03-31 00:31:45 -06:00
|
|
|
#include <df/unit_genes.h>
|
2012-02-13 09:43:41 -07:00
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("catsplosion");
|
2014-12-02 19:44:20 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
|
|
|
|
command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters);
|
2012-02-13 09:43:41 -07:00
|
|
|
|
|
|
|
// Mandatory init function. If you have some global state, create it here.
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
|
|
|
// Fill the command list with your commands.
|
|
|
|
commands.push_back(PluginCommand(
|
2012-04-17 20:12:11 -06:00
|
|
|
"catsplosion", "Make cats just /multiply/.",
|
2012-02-13 09:43:41 -07:00
|
|
|
catsplosion, false,
|
2012-04-17 20:12:11 -06:00
|
|
|
" Makes cats abnormally abundant, if you provide some base population ;)\n"
|
2012-02-13 09:43:41 -07:00
|
|
|
));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters)
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
2015-02-17 12:33:58 -07:00
|
|
|
if (!Core::getInstance().isWorldLoaded())
|
|
|
|
{
|
|
|
|
out.printerr("World not loaded.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2014-05-16 20:00:26 -06:00
|
|
|
bool list_only = false;
|
2012-02-13 09:43:41 -07:00
|
|
|
list<string> s_creatures;
|
2014-05-16 20:00:26 -06:00
|
|
|
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");
|
|
|
|
}
|
2012-02-13 09:43:41 -07:00
|
|
|
// make the creature list unique ... with cats. they are always unique
|
|
|
|
s_creatures.unique();
|
|
|
|
// SUSPEND THE CORE! ::Evil laugh::
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender susp;
|
2012-02-13 09:43:41 -07:00
|
|
|
|
|
|
|
uint32_t numCreatures;
|
|
|
|
if(!(numCreatures = Units::getNumCreatures()))
|
|
|
|
{
|
2015-02-17 12:33:58 -07:00
|
|
|
out.printerr("Can't get any creatures.\n");
|
2012-02-13 09:43:41 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalcount=0;
|
|
|
|
int totalchanged=0;
|
2012-02-14 01:37:30 -07:00
|
|
|
int totalcreated=0;
|
2012-02-13 09:43:41 -07:00
|
|
|
string sextype;
|
|
|
|
|
|
|
|
int maxlength = 0;
|
|
|
|
map<string, vector <df::unit *> > male_counts;
|
|
|
|
map<string, vector <df::unit *> > female_counts;
|
|
|
|
|
|
|
|
// classify
|
|
|
|
for(uint32_t i =0;i < numCreatures;i++)
|
|
|
|
{
|
|
|
|
df::unit * creature = Units::GetCreature(i);
|
2014-08-11 14:07:52 -06:00
|
|
|
df::creature_raw *raw = world->raws.creatures.all[creature->race];
|
2015-01-28 14:26:17 -07:00
|
|
|
if(Units::isFemale(creature))
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
|
|
|
female_counts[raw->creature_id].push_back(creature);
|
|
|
|
male_counts[raw->creature_id].size();
|
|
|
|
}
|
|
|
|
else // male, other, etc.
|
|
|
|
{
|
|
|
|
male_counts[raw->creature_id].push_back(creature);
|
|
|
|
female_counts[raw->creature_id].size(); //auto initialize the females as well
|
|
|
|
}
|
|
|
|
}
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2015-02-17 12:33:58 -07:00
|
|
|
if (list_only)
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
2015-02-17 12:33:58 -07:00
|
|
|
out.print("Type Male # Female #\n");
|
|
|
|
for (auto it1 = male_counts.begin(); it1!=male_counts.end(); it1++)
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
2015-02-17 12:33:58 -07:00
|
|
|
out.print("%22s %6d %8d\n", it1->first.c_str(), it1->second.size(), female_counts[it1->first].size());
|
2012-02-13 09:43:41 -07:00
|
|
|
}
|
2014-05-16 20:00:26 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2015-02-17 12:33:58 -07:00
|
|
|
|
2012-02-13 09:43:41 -07:00
|
|
|
// process
|
|
|
|
for (list<string>::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it)
|
|
|
|
{
|
|
|
|
std::string clinput = *it;
|
|
|
|
std::transform(clinput.begin(), clinput.end(), clinput.begin(), ::toupper);
|
2012-02-14 01:37:30 -07:00
|
|
|
vector <df::unit *> &females = female_counts[clinput];
|
2012-02-13 09:43:41 -07:00
|
|
|
uint32_t sz_fem = females.size();
|
|
|
|
totalcount += sz_fem;
|
2012-02-14 01:37:30 -07:00
|
|
|
for(uint32_t i = 0; i < sz_fem; i++)// max 1 pregnancy
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
2012-02-14 01:37:30 -07:00
|
|
|
df::unit * female = females[i];
|
|
|
|
// accelerate
|
|
|
|
if(female->relations.pregnancy_timer != 0)
|
2012-02-13 09:43:41 -07:00
|
|
|
{
|
2012-02-14 01:37:30 -07:00
|
|
|
female->relations.pregnancy_timer = rand() % 100 + 1;
|
2012-02-13 09:43:41 -07:00
|
|
|
totalchanged++;
|
|
|
|
}
|
2013-08-09 17:57:11 -06:00
|
|
|
else if(!female->relations.pregnancy_genes)
|
2012-02-14 01:37:30 -07:00
|
|
|
{
|
2012-03-31 00:31:45 -06:00
|
|
|
df::unit_genes *preg = new df::unit_genes;
|
|
|
|
preg->appearance = female->appearance.genes.appearance;
|
|
|
|
preg->colors = female->appearance.genes.colors;
|
2013-08-09 17:57:11 -06:00
|
|
|
female->relations.pregnancy_genes = preg;
|
2012-02-14 01:37:30 -07:00
|
|
|
female->relations.pregnancy_timer = rand() % 100 + 1;
|
2013-08-09 17:57:11 -06:00
|
|
|
female->relations.pregnancy_caste = 1;
|
2012-02-14 01:37:30 -07:00
|
|
|
totalcreated ++;
|
|
|
|
}
|
2012-02-13 09:43:41 -07:00
|
|
|
}
|
|
|
|
}
|
2012-02-14 01:37:30 -07:00
|
|
|
if(totalchanged)
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("%d pregnancies accelerated.\n", totalchanged);
|
2012-02-14 01:37:30 -07:00
|
|
|
if(totalcreated)
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("%d pregnancies created.\n", totalcreated);
|
2015-02-17 12:33:58 -07:00
|
|
|
if (!totalcount)
|
|
|
|
{
|
|
|
|
out.printerr("No creatures matched.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Total creatures checked: %d\n", totalcount);
|
2012-02-13 09:43:41 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|