Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7db467a

Browse files
committed
Update code to accomodate the new coord/coord2d/coord_path structs.
Also replicate the methods of DFCoord.
1 parent d75292a commit 7db467a

10 files changed

Lines changed: 106 additions & 16 deletions

File tree

library/include/DataDefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,7 @@ DF_KNOWN_GLOBALS
268268
#undef GLOBAL
269269
#undef SIMPLE_GLOBAL
270270
}
271+
272+
// A couple of headers that have to be included at once
273+
#include "df/coord2d.h"
274+
#include "df/coord.h"

library/include/df/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
*.h
2-
*.inc
2+
static*.inc
33
*.xml
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
coord(const coord2d &c, uint16_t _z) : x(c.x), y(c.y), z(_z) {}
2+
coord(uint16_t _x, uint16_t _y, uint16_t _z) : x(_x), y(_y), z(_z) {}
3+
4+
operator coord2d() const { return coord2d(x,y); }
5+
6+
bool isValid() const { return x != -30000; }
7+
void clear() { x = y = z = -30000; }
8+
9+
bool operator==(const coord &other) const
10+
{
11+
return (x == other.x) && (y == other.y) && (z == other.z);
12+
}
13+
bool operator!=(const coord &other) const
14+
{
15+
return (x != other.x) || (y != other.y) || (z != other.z);
16+
}
17+
18+
bool operator<(const coord &other) const
19+
{
20+
if (x != other.x) return (x < other.x);
21+
if (y != other.y) return (y < other.y);
22+
return z < other.z;
23+
}
24+
25+
coord operator/(int number) const
26+
{
27+
return coord(x/number, y/number, z);
28+
}
29+
coord operator*(int number) const
30+
{
31+
return coord(x*number, y*number, z);
32+
}
33+
coord operator%(int number) const
34+
{
35+
return coord(x%number, y%number, z);
36+
}
37+
38+
coord operator-(int number) const
39+
{
40+
return coord(x,y,z-number);
41+
}
42+
coord operator+(int number) const
43+
{
44+
return coord(x,y,z+number);
45+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
coord2d(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
2+
3+
bool isValid() const { return x != -30000; }
4+
void clear() { x = y = -30000; }
5+
6+
bool operator==(const coord2d &other) const
7+
{
8+
return (x == other.x) && (y == other.y);
9+
}
10+
bool operator!=(const coord2d &other) const
11+
{
12+
return (x != other.x) || (y != other.y);
13+
}
14+
15+
bool operator<(const coord2d &other) const
16+
{
17+
if (x != other.x) return (x < other.x);
18+
return y < other.y;
19+
}
20+
21+
coord2d operator/(int number) const
22+
{
23+
return coord2d(x/number, y/number);
24+
}
25+
coord2d operator*(int number) const
26+
{
27+
return coord2d(x*number, y*number);
28+
}
29+
coord2d operator%(int number) const
30+
{
31+
return coord2d(x%number, y%number);
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
unsigned size() const { return x.size(); }
2+
3+
coord operator[] (unsigned idx) const {
4+
if (idx >= x.size() || idx >= y.size() || idx >= z.size())
5+
return coord();
6+
else
7+
return coord(x[idx], y[idx], z[idx]);
8+
}

library/modules/Items.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ bool Items::copyItem(df::item * itembase, DFHack::dfh_item &item)
409409
return false;
410410
df::item * itreal = (df::item *) itembase;
411411
item.origin = itembase;
412-
item.x = itreal->x;
413-
item.y = itreal->y;
414-
item.z = itreal->z;
412+
item.x = itreal->pos.x;
413+
item.y = itreal->pos.y;
414+
item.z = itreal->pos.z;
415415
item.id = itreal->id;
416416
item.age = itreal->age;
417417
item.flags = itreal->flags;

library/modules/Vermin.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ bool Vermin::Read (const uint32_t index, t_vermin & sp)
6060
sp.caste = verm->caste;
6161
sp.visible = verm->visible;
6262
sp.countdown = verm->countdown;
63-
sp.x = verm->x;
64-
sp.y = verm->y;
65-
sp.z = verm->z;
63+
sp.x = verm->pos.x;
64+
sp.y = verm->pos.y;
65+
sp.z = verm->pos.z;
6666
sp.is_colony = verm->flags.bits.is_colony;
6767
return true;
6868
}
@@ -76,9 +76,9 @@ bool Vermin::Write (const uint32_t index, t_vermin & sp)
7676
verm->caste = sp.caste;
7777
verm->visible = sp.visible;
7878
verm->countdown = sp.countdown;
79-
verm->x = sp.x;
80-
verm->y = sp.y;
81-
verm->z = sp.z;
79+
verm->pos.x = sp.x;
80+
verm->pos.y = sp.y;
81+
verm->pos.z = sp.z;
8282
verm->flags.bits.is_colony = sp.is_colony;
8383
return true;
8484
}

plugins/autodump.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
143143
for(std::size_t i=0; i< numItems; i++)
144144
{
145145
df::item * itm = world->items.all[i];
146-
DFCoord pos_item(itm->x, itm->y, itm->z);
146+
DFCoord pos_item(itm->pos.x, itm->pos.y, itm->pos.z);
147147

148148
// keep track how many items are at places. all items.
149149
coordmap::iterator it = counts.find(pos_item);
@@ -185,7 +185,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
185185
{
186186
// yes...
187187
cerr << "Moving from block to block!" << endl;
188-
df_block * bl_src = Maps->getBlock(itm->x /16, itm->y/16, itm->z);
188+
df_block * bl_src = Maps->getBlock(itm->pos.x /16, itm->pos.y/16, itm->pos.z);
189189
df_block * bl_tgt = Maps->getBlock(cx /16, cy/16, cz);
190190
if(bl_src)
191191
{
@@ -206,9 +206,9 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
206206
}
207207

208208
// Move the item
209-
itm->x = pos_cursor.x;
210-
itm->y = pos_cursor.y;
211-
itm->z = pos_cursor.z;
209+
itm->pos.x = pos_cursor.x;
210+
itm->pos.y = pos_cursor.y;
211+
itm->pos.z = pos_cursor.z;
212212
}
213213
else // destroy
214214
{

plugins/cleaners.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "df/block_square_event_material_spatterst.h"
1111
#include "df/item_actual.h"
1212
#include "df/unit.h"
13+
#include "df/unit_spatter.h"
1314
#include "df/matter_state.h"
1415
#include "df/cursor.h"
1516
#include "df/builtin_mats.h"

plugins/deramp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
5151
for (int i = 0; i < blocks_total; i++)
5252
{
5353
df::map_block *block = world->map.map_blocks[i];
54-
df::map_block *above = getBlock(block->map_x, block->map_y, block->map_z + 1);
54+
df::map_block *above = getBlock(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1);
5555

5656
for (int x = 0; x < 16; x++)
5757
{

0 commit comments

Comments
 (0)