Fix squads on Linux

Sync catsplosion
develop
Petr Mrázek 2010-03-30 20:20:34 +02:00
parent eccdc6896e
commit c631270425
2 changed files with 104 additions and 21 deletions

@ -1,13 +1,18 @@
// Catsplosion
// By Zhentar
// This work of evil makes every cat, male or female, grown or kitten, pregnant
// 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 <climits>
#include <integers.h>
#include <vector>
#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 <DFError.h>
@ -15,6 +20,7 @@ using namespace std;
#include <DFHackAPI.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <argstream/argstream.h>
vector<DFHack::t_matgloss> creaturestypes;
@ -22,18 +28,40 @@ DFHack::memory_info *mem;
DFHack::Process *proc;
uint32_t creature_pregnancy_offset;
int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature)
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 )
{
if(string(creaturestypes[creature.type].id) == "CAT")
// parse input, handle this nice and neat before we get to the connecting
argstream as(argc,argv);
as >>option('f',"female",femaleonly,"Impregnate females only")
>>option('s',"show",showcreatures,"Show creature list (read only)")
>>parameter('m',"max",maxpreg,"The maximum limit of pregnancies ", false)
>>values<string>(back_inserter(s_creatures), "any number of creatures")
>>help();
if (!as.isOk())
{
proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1);
return 1;
cout << as.errorLog();
return(0);
}
else if (as.helpRequested())
{
cout<<as.usage()<<endl;
return(1);
}
else if(showcreatures==1)
{
}
else if (s_creatures.size() == 0 && showcreatures != 1)
{
cout << as.usage();
return(1);
}
return 0;
}
int main (void)
{
DFHack::API DF("Memory.xml");
try
{
@ -58,7 +86,7 @@ int main (void)
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
return 1;
}
uint32_t numCreatures;
@ -71,16 +99,71 @@ int main (void)
return 1;
}
int cats=0;
int totalcount=0;
int totalchanged=0;
string sextype;
// shows all the creatures and returns.
if (showcreatures == 1)
{
int maxlength = 0;
map<string,uint32_t> male_counts;
map<string,uint32_t> female_counts;
for(uint32_t i =0;i < numCreatures;i++)
{
DFHack::t_creature creature;
DF.ReadCreature(i,creature);
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;
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;
}
return(1);
}
for(uint32_t i = 0; i < numCreatures; i++)
for(uint32_t i = 0; i < numCreatures && totalchanged != maxpreg; i++)
{
DFHack::t_creature temp;
DF.ReadCreature(i,temp);
cats+=fertilizeCat(DF,temp);
DFHack::t_creature creature;
DF.ReadCreature(i,creature);
if (showcreatures == 1)
{
if (creature.sex == 0) { sextype = "Female"; } else { sextype = "Male";}
cout << string(creaturestypes[creature.type].id) << ":" << sextype << "" << endl;
}
else
{
s_creatures.unique();
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);
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 << cats << " cats impregnated." << endl;
cout << totalchanged << " animals impregnated out of a possible " << totalcount << "." << endl;
DF.FinishReadCreatures();
DF.Detach();
@ -89,4 +172,4 @@ int main (void)
cin.ignore();
#endif
return 0;
}
}

@ -1619,7 +1619,7 @@
<Offset name="creature_squad_name">0x00F0</Offset>
<Offset name="creature_mood">0x160</Offset>
<Offset name="creature_pregnancy">0x164</Offset>
<Offset name="creature_squad_leader_id">0x00A0</Offset>
<Offset name="creature_squad_leader_id">0x190</Offset>
<Offset name="creature_money">0x02F8</Offset> <!-- most probably wrong -->
<Offset name="creature_current_job">0x0200</Offset>
<Offset name="creature_blood_max">0x264</Offset>