diff --git a/library/include/BitArray.h b/library/include/BitArray.h index ec9357839..b3ca6d7c1 100644 --- a/library/include/BitArray.h +++ b/library/include/BitArray.h @@ -174,8 +174,10 @@ namespace DFHack DfArray() : m_data(NULL), m_size(0) {} ~DfArray() { free(m_data); } - DfArray(const DfArray &other) : m_data(NULL), m_size(0) { - *this = other; + DfArray(const DfArray &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; diff --git a/library/xml b/library/xml index 7fcdca717..03a791f0f 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 7fcdca71787d7e998cec2f771999e722609093f1 +Subproject commit 03a791f0fff6789ec4bb931b2abd7bf91403a2b5 diff --git a/plugins/devel/catsplosion.cpp b/plugins/devel/catsplosion.cpp index 1649ea562..6a329f3e5 100644 --- a/plugins/devel/catsplosion.cpp +++ b/plugins/devel/catsplosion.cpp @@ -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 & parameters) { list s_creatures; @@ -70,6 +71,7 @@ command_result catsplosion (Core * c, std::vector & 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 & parameters) } } - /* + // process for (list::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it) { std::string clinput = *it; std::transform(clinput.begin(), clinput.end(), clinput.begin(), ::toupper); - vector &females = female_counts[clinput]; + vector &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; }