Skip to content

Commit c631270

Browse files
committed
Fix squads on Linux
Sync catsplosion
1 parent eccdc68 commit c631270

File tree

2 files changed

+104
-21
lines changed

2 files changed

+104
-21
lines changed

Diff for: examples/catsplosion.cpp

+103-20
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,67 @@
11
// Catsplosion
2-
// By Zhentar
3-
// This work of evil makes every cat, male or female, grown or kitten, pregnant
2+
// By Zhentar , Further modified by dark_rabite, peterix, belal
3+
// This work of evil makes animals pregnant
44
// and due within 2 in-game hours...
55

66
#include <iostream>
7-
#include <climits>
87
#include <integers.h>
9-
#include <vector>
8+
#include <cstdlib>
9+
#include <assert.h>
10+
#include <climits>
1011
#include <stdlib.h> // for rand()
12+
#include <algorithm> // for std::transform
13+
#include <vector>
14+
#include <list>
15+
#include <iterator>
1116
using namespace std;
1217

1318
#include <DFError.h>
1419
#include <DFTypes.h>
1520
#include <DFHackAPI.h>
1621
#include <DFMemInfo.h>
1722
#include <DFProcess.h>
23+
#include <argstream/argstream.h>
1824

1925

2026
vector<DFHack::t_matgloss> creaturestypes;
2127
DFHack::memory_info *mem;
2228
DFHack::Process *proc;
2329
uint32_t creature_pregnancy_offset;
2430

25-
int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature)
31+
bool femaleonly = 0;
32+
bool showcreatures = 0;
33+
int maxpreg = 1000; // random start value, since its not required and im not sure how to set it to infinity
34+
list<string> s_creatures;
35+
36+
int main ( int argc, char** argv )
2637
{
27-
if(string(creaturestypes[creature.type].id) == "CAT")
38+
// parse input, handle this nice and neat before we get to the connecting
39+
argstream as(argc,argv);
40+
as >>option('f',"female",femaleonly,"Impregnate females only")
41+
>>option('s',"show",showcreatures,"Show creature list (read only)")
42+
>>parameter('m',"max",maxpreg,"The maximum limit of pregnancies ", false)
43+
>>values<string>(back_inserter(s_creatures), "any number of creatures")
44+
>>help();
45+
46+
if (!as.isOk())
2847
{
29-
proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1);
30-
return 1;
48+
cout << as.errorLog();
49+
return(0);
50+
}
51+
else if (as.helpRequested())
52+
{
53+
cout<<as.usage()<<endl;
54+
return(1);
55+
}
56+
else if(showcreatures==1)
57+
{
58+
}
59+
else if (s_creatures.size() == 0 && showcreatures != 1)
60+
{
61+
cout << as.usage();
62+
return(1);
3163
}
32-
return 0;
33-
}
3464

35-
int main (void)
36-
{
3765
DFHack::API DF("Memory.xml");
3866
try
3967
{
@@ -58,7 +86,7 @@ int main (void)
5886
#ifndef LINUX_BUILD
5987
cin.ignore();
6088
#endif
61-
return 1;
89+
return 1;
6290
}
6391

6492
uint32_t numCreatures;
@@ -71,16 +99,71 @@ int main (void)
7199
return 1;
72100
}
73101

74-
int cats=0;
102+
int totalcount=0;
103+
int totalchanged=0;
104+
string sextype;
105+
106+
// shows all the creatures and returns.
107+
if (showcreatures == 1)
108+
{
109+
int maxlength = 0;
110+
map<string,uint32_t> male_counts;
111+
map<string,uint32_t> female_counts;
112+
for(uint32_t i =0;i < numCreatures;i++)
113+
{
114+
DFHack::t_creature creature;
115+
DF.ReadCreature(i,creature);
116+
if(creature.sex == 1){
117+
male_counts[creaturestypes[creature.type].id]++;
118+
female_counts[creaturestypes[creature.type].id]+=0; //auto initialize the females as well
119+
}
120+
else{
121+
female_counts[creaturestypes[creature.type].id]++;
122+
male_counts[creaturestypes[creature.type].id]+=0;
123+
}
124+
}
125+
cout << "Type\t\t\tMale #\tFemale #" << endl;
126+
for(map<string, uint32_t>::iterator it1 = male_counts.begin();it1!=male_counts.end();it1++)
127+
{
128+
cout << it1->first << "\t\t" << it1->second << "\t" << female_counts[it1->first] << endl;
129+
}
130+
return(1);
131+
}
75132

76-
for(uint32_t i = 0; i < numCreatures; i++)
133+
for(uint32_t i = 0; i < numCreatures && totalchanged != maxpreg; i++)
77134
{
78-
DFHack::t_creature temp;
79-
DF.ReadCreature(i,temp);
80-
cats+=fertilizeCat(DF,temp);
135+
DFHack::t_creature creature;
136+
DF.ReadCreature(i,creature);
137+
if (showcreatures == 1)
138+
{
139+
if (creature.sex == 0) { sextype = "Female"; } else { sextype = "Male";}
140+
cout << string(creaturestypes[creature.type].id) << ":" << sextype << "" << endl;
141+
}
142+
else
143+
{
144+
s_creatures.unique();
145+
for (list<string>::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it)
146+
{
147+
std::string clinput = *it;
148+
std::transform(clinput.begin(), clinput.end(), clinput.begin(), ::toupper);
149+
if(string(creaturestypes[creature.type].id) == clinput)
150+
{
151+
if((femaleonly == 1 && creature.sex == 0) || (femaleonly != 1))
152+
{
153+
proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1);
154+
totalchanged+=1;
155+
totalcount+=1;
156+
}
157+
else
158+
{
159+
totalcount+=1;
160+
}
161+
}
162+
}
163+
}
81164
}
82165

83-
cout << cats << " cats impregnated." << endl;
166+
cout << totalchanged << " animals impregnated out of a possible " << totalcount << "." << endl;
84167

85168
DF.FinishReadCreatures();
86169
DF.Detach();
@@ -89,4 +172,4 @@ int main (void)
89172
cin.ignore();
90173
#endif
91174
return 0;
92-
}
175+
}

Diff for: output/Memory.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@
16191619
<Offset name="creature_squad_name">0x00F0</Offset>
16201620
<Offset name="creature_mood">0x160</Offset>
16211621
<Offset name="creature_pregnancy">0x164</Offset>
1622-
<Offset name="creature_squad_leader_id">0x00A0</Offset>
1622+
<Offset name="creature_squad_leader_id">0x190</Offset>
16231623
<Offset name="creature_money">0x02F8</Offset> <!-- most probably wrong -->
16241624
<Offset name="creature_current_job">0x0200</Offset>
16251625
<Offset name="creature_blood_max">0x264</Offset>

0 commit comments

Comments
 (0)