Fix catsplosion.

develop
Petr Mrázek 2012-02-14 09:37:30 +01:00
parent f600928ec1
commit bdbfbf5988
3 changed files with 37 additions and 13 deletions

@ -174,8 +174,10 @@ namespace DFHack
DfArray() : m_data(NULL), m_size(0) {}
~DfArray() { free(m_data); }
DfArray(const DfArray<T> &other) : m_data(NULL), m_size(0) {
*this = other;
DfArray(const DfArray<T> &other) : m_data(NULL), m_size(0)
{
resize(other.m_size);
memcpy(m_data, other.m_data,m_size*sizeof(T));
}
T *data() { return m_data; }
@ -189,7 +191,14 @@ namespace DFHack
{
if (new_size == m_size)
return;
m_data = (T*)realloc(m_data, sizeof(T)*new_size);
if(!m_data)
{
m_data = (T*) malloc(sizeof(T)*new_size);
}
else
{
m_data = (T*)realloc(m_data, sizeof(T)*new_size);
}
if (new_size > m_size)
memset(m_data+sizeof(T)*m_size, 0, sizeof(T)*(new_size - m_size));
m_size = new_size;

@ -1 +1 @@
Subproject commit 7fcdca71787d7e998cec2f771999e722609093f1
Subproject commit 03a791f0fff6789ec4bb931b2abd7bf91403a2b5

@ -51,6 +51,7 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
return CR_OK;
}
typedef df::unit::T_relations::T_pregnancy_ptr pregstruct;
command_result catsplosion (Core * c, std::vector <std::string> & parameters)
{
list<string> s_creatures;
@ -70,6 +71,7 @@ command_result catsplosion (Core * c, std::vector <std::string> & parameters)
int totalcount=0;
int totalchanged=0;
int totalcreated=0;
string sextype;
// shows all the creatures and returns.
@ -105,27 +107,40 @@ command_result catsplosion (Core * c, std::vector <std::string> & parameters)
}
}
/*
// 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);
vector <t_creature> &females = female_counts[clinput];
vector <df::unit *> &females = female_counts[clinput];
uint32_t sz_fem = females.size();
totalcount += sz_fem;
for(uint32_t i = 0; i < sz_fem && totalchanged != maxpreg; i++)
for(uint32_t i = 0; i < sz_fem; i++)// max 1 pregnancy
{
t_creature & female = females[i];
uint32_t preg_timer = proc->readDWord(female.origin + creature_pregnancy_offset);
if(preg_timer != 0)
df::unit * female = females[i];
// accelerate
if(female->relations.pregnancy_timer != 0)
{
proc->writeDWord(female.origin + creature_pregnancy_offset, rand() % 100 + 1);
female->relations.pregnancy_timer = rand() % 100 + 1;
totalchanged++;
}
else if(!female->relations.pregnancy_ptr)
{
pregstruct * preg = new pregstruct;
preg->anon_1 = female->appearance.unk_51c;
preg->anon_2 = female->appearance.unk_524;
female->relations.pregnancy_ptr = preg;
female->relations.pregnancy_timer = rand() % 100 + 1;
female->relations.pregnancy_mystery = 1; // WTF is this?
totalcreated ++;
}
}
}
*/
cout << totalchanged << " pregnancies accelerated. Total creatures checked: " << totalcount << "." << endl;
if(totalchanged)
c->con.print("%d pregnancies accelerated.\n", totalchanged);
if(totalcreated)
c->con.print("%d pregnancies created.\n", totalcreated);
c->con.print("Total creatures checked: %d\n", totalcount);
return CR_OK;
}