catsplosion ported, doesn't work

develop
Petr Mrázek 2010-04-15 13:04:58 +02:00
parent ab3a842fdb
commit 59cdbeefe7
6 changed files with 79 additions and 73 deletions

@ -344,7 +344,7 @@ namespace DFHack
t_attrib recuperation; t_attrib recuperation;
t_attrib disease_resistance; t_attrib disease_resistance;
int32_t squad_leader_id; int32_t squad_leader_id;
uint8_t sex; uint8_t sex; // really a caste
uint32_t pregnancy_timer; //Countdown timer to giving birth uint32_t pregnancy_timer; //Countdown timer to giving birth
bool has_default_soul; bool has_default_soul;
t_soul defaultSoul; t_soul defaultSoul;

@ -36,7 +36,7 @@ namespace DFHack
char plural[128]; char plural[128];
char adjective[128]; char adjective[128];
}; };
// this doesn't transfer well across the shm gap...
struct t_creaturetype struct t_creaturetype
{ {
char rawname[128]; char rawname[128];

@ -69,10 +69,10 @@ TARGET_LINK_LIBRARIES(dftreedump dfhack)
ADD_EXECUTABLE(dfspatterdump spatterdump.cpp) ADD_EXECUTABLE(dfspatterdump spatterdump.cpp)
TARGET_LINK_LIBRARIES(dfspatterdump dfhack) TARGET_LINK_LIBRARIES(dfspatterdump dfhack)
# catsplosion - Makes every cat pregnant, and almost due... # catsplosion - Accelerates pregnancy
# Author: Zhentar # Author: Zhentar
# ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp) ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp)
# TARGET_LINK_LIBRARIES(dfcatsplosion dfhack) TARGET_LINK_LIBRARIES(dfcatsplosion dfhack)
IF(UNIX) IF(UNIX)
SET(CURSES_NEED_WIDE "YES") SET(CURSES_NEED_WIDE "YES")

@ -21,28 +21,34 @@ using namespace std;
#include <DFMemInfo.h> #include <DFMemInfo.h>
#include <DFProcess.h> #include <DFProcess.h>
#include <argstream.h> #include <argstream.h>
#include <modules/Materials.h>
#include <modules/Creatures.h>
using namespace DFHack;
vector<DFHack::t_matgloss> creaturestypes;
DFHack::memory_info *mem;
DFHack::Process *proc;
uint32_t creature_pregnancy_offset;
bool femaleonly = 0;
bool showcreatures = 0;
int maxpreg = 1000; // random start value, since its not required and im not sure how to set it to infinity
list<string> s_creatures;
int main ( int argc, char** argv ) int main ( int argc, char** argv )
{ {
vector<DFHack::t_creaturetype> creaturestypes;
DFHack::memory_info *mem;
DFHack::Process *proc;
uint32_t creature_pregnancy_offset;
//bool femaleonly = 0;
bool showcreatures = 0;
int maxpreg = 1000; // random start value, since its not required and im not sure how to set it to infinity
list<string> s_creatures;
// parse input, handle this nice and neat before we get to the connecting // parse input, handle this nice and neat before we get to the connecting
argstream as(argc,argv); argstream as(argc,argv);
as >>option('f',"female",femaleonly,"Impregnate females only") as // >>option('f',"female",femaleonly,"Impregnate females only")
>>option('s',"show",showcreatures,"Show creature list (read only)") >>option('s',"show",showcreatures,"Show creature list (read only)")
>>parameter('m',"max",maxpreg,"The maximum limit of pregnancies ", false) >>parameter('m',"max",maxpreg,"The maximum limit of pregnancies ", false)
>>values<string>(back_inserter(s_creatures), "any number of creatures") >>values<string>(back_inserter(s_creatures), "any number of creatures")
>>help(); >>help();
// make the creature list unique
s_creatures.unique();
if (!as.isOk()) if (!as.isOk())
{ {
cout << as.errorLog(); cout << as.errorLog();
@ -58,8 +64,9 @@ int main ( int argc, char** argv )
} }
else if (s_creatures.size() == 0 && showcreatures != 1) else if (s_creatures.size() == 0 && showcreatures != 1)
{ {
cout << as.usage(); cout << as.usage() << endl << "---------------------------------------" << endl;
return(1); cout << "Creature list empty, assuming CATs" << endl;
s_creatures.push_back("CAT");
} }
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
@ -78,9 +85,11 @@ int main ( int argc, char** argv )
proc = DF.getProcess(); proc = DF.getProcess();
mem = DF.getMemoryInfo(); mem = DF.getMemoryInfo();
DFHack::Materials *Mats = DF.getMaterials();
DFHack::Creatures *Cre = DF.getCreatures();
creature_pregnancy_offset = mem->getOffset("creature_pregnancy"); creature_pregnancy_offset = mem->getOffset("creature_pregnancy");
if(!DF.ReadCreatureMatgloss(creaturestypes)) if(!Mats->ReadCreatureTypesEx(creaturestypes))
{ {
cerr << "Can't get the creature types." << endl; cerr << "Can't get the creature types." << endl;
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
@ -90,7 +99,7 @@ int main ( int argc, char** argv )
} }
uint32_t numCreatures; uint32_t numCreatures;
if(!DF.InitReadCreatures(numCreatures)) if(!Cre->Start(numCreatures))
{ {
cerr << "Can't get creatures" << endl; cerr << "Can't get creatures" << endl;
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
@ -104,68 +113,62 @@ int main ( int argc, char** argv )
string sextype; string sextype;
// shows all the creatures and returns. // shows all the creatures and returns.
if (showcreatures == 1)
int maxlength = 0;
map<string, vector <t_creature> > male_counts;
map<string, vector <t_creature> > female_counts;
// classify
for(uint32_t i =0;i < numCreatures;i++)
{ {
int maxlength = 0; DFHack::t_creature creature;
map<string,uint32_t> male_counts; Cre->ReadCreature(i,creature);
map<string,uint32_t> female_counts; DFHack::t_creaturetype & crt = creaturestypes[creature.race];
for(uint32_t i =0;i < numCreatures;i++) string castename = crt.castes[creature.sex].rawname;
if(castename == "FEMALE")
{ {
DFHack::t_creature creature; female_counts[creaturestypes[creature.race].rawname].push_back(creature);
DF.ReadCreature(i,creature); male_counts[creaturestypes[creature.race].rawname].size();
if(creature.sex == 1){
male_counts[creaturestypes[creature.type].id]++;
female_counts[creaturestypes[creature.type].id]+=0; //auto initialize the females as well
}
else{
female_counts[creaturestypes[creature.type].id]++;
male_counts[creaturestypes[creature.type].id]+=0;
}
} }
cout << "Type\t\t\tMale #\tFemale #" << endl; else // male, other, etc.
for(map<string, uint32_t>::iterator it1 = male_counts.begin();it1!=male_counts.end();it1++)
{ {
cout << it1->first << "\t\t" << it1->second << "\t" << female_counts[it1->first] << endl; male_counts[creaturestypes[creature.race].rawname].push_back(creature);
female_counts[creaturestypes[creature.race].rawname].size(); //auto initialize the females as well
} }
return(1);
} }
for(uint32_t i = 0; i < numCreatures && totalchanged != maxpreg; i++) // print (optional)
if (showcreatures == 1)
{ {
DFHack::t_creature creature; cout << "Type\t\tMale #\tFemale #" << endl;
DF.ReadCreature(i,creature); for(map<string, vector <t_creature> >::iterator it1 = male_counts.begin();it1!=male_counts.end();it1++)
if (showcreatures == 1)
{ {
if (creature.sex == 0) { sextype = "Female"; } else { sextype = "Male";} cout << it1->first << "\t\t" << it1->second.size() << "\t" << female_counts[it1->first].size() << endl;
cout << string(creaturestypes[creature.type].id) << ":" << sextype << "" << endl;
} }
else }
// 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];
uint32_t sz_fem = females.size();
totalcount += sz_fem;
for(uint32_t i = 0; i < sz_fem && totalchanged != maxpreg; i++)
{ {
s_creatures.unique(); t_creature & female = females[i];
for (list<string>::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it) uint32_t preg_timer = proc->readDWord(female.origin + creature_pregnancy_offset);
if(preg_timer != 0)
{ {
std::string clinput = *it; proc->writeDWord(female.origin + creature_pregnancy_offset, rand() % 100 + 1);
std::transform(clinput.begin(), clinput.end(), clinput.begin(), ::toupper); totalchanged++;
if(string(creaturestypes[creature.type].id) == clinput)
{
if((femaleonly == 1 && creature.sex == 0) || (femaleonly != 1))
{
proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1);
totalchanged+=1;
totalcount+=1;
}
else
{
totalcount+=1;
}
}
} }
} }
} }
cout << totalchanged << " animals impregnated out of a possible " << totalcount << "." << endl; cout << totalchanged << " pregnancies accelerated. Total creatures checked: " << totalcount << "." << endl;
Cre->Finish();
DF.FinishReadCreatures();
DF.Detach(); DF.Detach();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;

@ -350,7 +350,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
} }
int main (void) int main (int numargs, char ** args)
{ {
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
try try
@ -365,6 +365,9 @@ int main (void)
#endif #endif
return 1; return 1;
} }
string check = "";
if(numargs == 2)
check = args[1];
DFHack::Creatures * Creatures = DF.getCreatures(); DFHack::Creatures * Creatures = DF.getCreatures();
DFHack::Materials * Materials = DF.getMaterials(); DFHack::Materials * Materials = DF.getMaterials();
@ -407,7 +410,7 @@ int main (void)
{ {
DFHack::t_creature temp; DFHack::t_creature temp;
Creatures->ReadCreature(i,temp); Creatures->ReadCreature(i,temp);
if(string(creaturestypes[temp.race].id) == "HORSE") if(check.empty() || string(creaturestypes[temp.race].id) == check)
{ {
cout << "index " << i << " "; cout << "index " << i << " ";

@ -1135,7 +1135,9 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_soulskill_vector">0X1F4</Offset> <Offset name="creature_soulskill_vector">0X1F4</Offset>
<Offset name="creature_pickup_equipment_bit">0X21C</Offset> <Offset name="creature_pickup_equipment_bit">0X21C</Offset>
<Offset name="creature_mood">0x238</Offset> <Offset name="creature_mood">0x238</Offset>
<!--<Offset name="creature_pregnancy">0x23C</Offset>-->
<Offset name="creature_pregnancy">0x28C</Offset>
<Offset name="creature_pregnancy_ptr">0x290</Offset>
<Offset name="creature_physical">0x464</Offset> <Offset name="creature_physical">0x464</Offset>
<!-- <!--
@ -1372,8 +1374,6 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_soulskill_vector">0X1F4</Offset> <Offset name="creature_soulskill_vector">0X1F4</Offset>
<Offset name="creature_pickup_equipment_bit">0X21C</Offset> <Offset name="creature_pickup_equipment_bit">0X21C</Offset>
<!--<Offset name="creature_mood">0x238</Offset>--> <!--<Offset name="creature_mood">0x238</Offset>-->
<Offset name="creature_pregnancy">0x28C</Offset>
<Offset name="creature_pregnancy_ptr">0x290</Offset>
<Offset name="creature_physical">0x464</Offset> <Offset name="creature_physical">0x464</Offset>
<!-- <!--