1
1
// 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
4
4
// and due within 2 in-game hours...
5
5
6
6
#include < iostream>
7
- #include < climits>
8
7
#include < integers.h>
9
- #include < vector>
8
+ #include < cstdlib>
9
+ #include < assert.h>
10
+ #include < climits>
10
11
#include < stdlib.h> // for rand()
12
+ #include < algorithm> // for std::transform
13
+ #include < vector>
14
+ #include < list>
15
+ #include < iterator>
11
16
using namespace std ;
12
17
13
18
#include < DFError.h>
14
19
#include < DFTypes.h>
15
20
#include < DFHackAPI.h>
16
21
#include < DFMemInfo.h>
17
22
#include < DFProcess.h>
23
+ #include < argstream/argstream.h>
18
24
19
25
20
26
vector<DFHack::t_matgloss> creaturestypes;
21
27
DFHack::memory_info *mem;
22
28
DFHack::Process *proc;
23
29
uint32_t creature_pregnancy_offset;
24
30
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 )
26
37
{
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 ())
28
47
{
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 );
31
63
}
32
- return 0 ;
33
- }
34
64
35
- int main (void )
36
- {
37
65
DFHack::API DF (" Memory.xml" );
38
66
try
39
67
{
@@ -58,7 +86,7 @@ int main (void)
58
86
#ifndef LINUX_BUILD
59
87
cin.ignore ();
60
88
#endif
61
- return 1 ;
89
+ return 1 ;
62
90
}
63
91
64
92
uint32_t numCreatures;
@@ -71,16 +99,71 @@ int main (void)
71
99
return 1 ;
72
100
}
73
101
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\t Male #\t Female #" << 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
+ }
75
132
76
- for (uint32_t i = 0 ; i < numCreatures; i++)
133
+ for (uint32_t i = 0 ; i < numCreatures && totalchanged != maxpreg ; i++)
77
134
{
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
+ }
81
164
}
82
165
83
- cout << cats << " cats impregnated." << endl;
166
+ cout << totalchanged << " animals impregnated out of a possible " << totalcount << " ." << endl;
84
167
85
168
DF.FinishReadCreatures ();
86
169
DF.Detach ();
@@ -89,4 +172,4 @@ int main (void)
89
172
cin.ignore ();
90
173
#endif
91
174
return 0 ;
92
- }
175
+ }
0 commit comments