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-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
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("catsplosion");
|
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(
|
|
|
|
"catsplosion", "Do nothing, look pretty.",
|
|
|
|
catsplosion, false,
|
|
|
|
" This command does nothing at all. For now.\n"
|
|
|
|
));
|
|
|
|
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
|
|
|
{
|
|
|
|
list<string> s_creatures;
|
|
|
|
// only cats for now.
|
|
|
|
s_creatures.push_back("CAT");
|
|
|
|
// 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()))
|
|
|
|
{
|
|
|
|
cerr << "Can't get any creatures." << endl;
|
|
|
|
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;
|
|
|
|
|
|
|
|
// shows all the creatures and returns.
|
|
|
|
|
|
|
|
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);
|
|
|
|
df::creature_raw *raw = df::global::world->raws.creatures.all[creature->race];
|
|
|
|
if(creature->sex == 0) // female
|
|
|
|
{
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// print (optional)
|
|
|
|
//if (showcreatures == 1)
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Type Male # Female #\n");
|
2012-02-13 09:43:41 -07:00
|
|
|
for(auto it1 = male_counts.begin();it1!=male_counts.end();it1++)
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("%20s %6d %8d\n", it1->first.c_str(), it1->second.size(), female_counts[it1->first].size());
|
2012-02-13 09:43:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 01:37:30 -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++;
|
|
|
|
}
|
2012-02-14 01:37:30 -07:00
|
|
|
else if(!female->relations.pregnancy_ptr)
|
|
|
|
{
|
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;
|
2012-02-14 01:37:30 -07:00
|
|
|
female->relations.pregnancy_ptr = preg;
|
|
|
|
female->relations.pregnancy_timer = rand() % 100 + 1;
|
|
|
|
female->relations.pregnancy_mystery = 1; // WTF is this?
|
|
|
|
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);
|
|
|
|
out.print("Total creatures checked: %d\n", totalcount);
|
2012-02-13 09:43:41 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|