forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolonies.cpp
More file actions
165 lines (135 loc) · 4.02 KB
/
Copy pathcolonies.cpp
File metadata and controls
165 lines (135 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
#include <dfhack/modules/Vermin.h>
using std::vector;
using std::string;
using namespace DFHack;
#include <DFHack.h>
DFhackCExport command_result colonies (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "colonies";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("colonies",
"List or change wild colonies (ants hills and such)\
\n Options: 'kill' = destroy all colonies\
\n 'bees' = change all colonies to honey bees",
colonies));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK;
}
void destroyColonies(DFHack::SpawnPoints *points);
void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials);
void showColonies(Core *c, DFHack::SpawnPoints *points,
DFHack::Materials *Materials);
DFhackCExport command_result colonies (Core * c, vector <string> & parameters)
{
bool destroy = false;
bool convert = false;
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "kill")
destroy = true;
else if(parameters[i] == "bees")
convert = true;
}
if (destroy && convert)
{
c->con << "Kill or make bees? DECIDE!" << std::endl;
return CR_FAILURE;
}
c->Suspend();
Vermin * vermin = c->getVermin();
Materials * materials = c->getMaterials();
SpawnPoints *points = vermin->getSpawnPoints();
if(!points->isValid())
{
c->con << "vermin not supported for this DF version" << std::endl;
return CR_FAILURE;
}
materials->ReadCreatureTypesEx();
if (destroy)
destroyColonies(points);
else if (convert)
convertColonies(points, materials);
else
showColonies(c, points, materials);
delete points;
vermin->Finish();
materials->Finish();
c->Resume();
return CR_OK;
}
void destroyColonies(DFHack::SpawnPoints *points)
{
uint32_t numSpawnPoints = points->size();
for (uint32_t i = 0; i < numSpawnPoints; i++)
{
DFHack::t_spawnPoint sp;
points->Read(i, sp);
if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp))
{
sp.in_use = false;
points->Write(i, sp);
}
}
}
// Convert all colonies to honey bees.
void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials)
{
int bee_idx = -1;
for (size_t i = 0; i < Materials->raceEx.size(); i++)
if (Materials->raceEx[i].id == "HONEY_BEE")
{
bee_idx = i;
break;
}
if (bee_idx == -1)
{
std::cerr << "Honey bees not present in game." << std::endl;
return;
}
uint32_t numSpawnPoints = points->size();
for (uint32_t i = 0; i < numSpawnPoints; i++)
{
DFHack::t_spawnPoint sp;
points->Read(i, sp);
if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp))
{
sp.race = bee_idx;
points->Write(i, sp);
}
}
}
void showColonies(Core *c, DFHack::SpawnPoints *points,
DFHack::Materials *Materials)
{
uint32_t numSpawnPoints = points->size();
int numColonies = 0;
for (uint32_t i = 0; i < numSpawnPoints; i++)
{
DFHack::t_spawnPoint sp;
points->Read(i, sp);
if (sp.in_use && DFHack::SpawnPoints::isWildColony(sp))
{
numColonies++;
string race="(no race)";
if(sp.race != -1)
race = Materials->raceEx[sp.race].id;
c->con.print("Spawn point %u: %s at %d:%d:%d\n", i,
race.c_str(), sp.x, sp.y, sp.z);
}
}
if (numColonies == 0)
c->con << "No colonies present." << std::endl;
}