diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h index e998dc386..41d05ac38 100644 --- a/library/include/DataDefs.h +++ b/library/include/DataDefs.h @@ -268,3 +268,7 @@ DF_KNOWN_GLOBALS #undef GLOBAL #undef SIMPLE_GLOBAL } + +// A couple of headers that have to be included at once +#include "df/coord2d.h" +#include "df/coord.h" diff --git a/library/include/df/.gitignore b/library/include/df/.gitignore index 7cd9ae481..feeeba782 100644 --- a/library/include/df/.gitignore +++ b/library/include/df/.gitignore @@ -1,3 +1,3 @@ *.h -*.inc +static*.inc *.xml diff --git a/library/include/df/custom/coord.methods.inc b/library/include/df/custom/coord.methods.inc new file mode 100644 index 000000000..64d170376 --- /dev/null +++ b/library/include/df/custom/coord.methods.inc @@ -0,0 +1,45 @@ +coord(const coord2d &c, uint16_t _z) : x(c.x), y(c.y), z(_z) {} +coord(uint16_t _x, uint16_t _y, uint16_t _z) : x(_x), y(_y), z(_z) {} + +operator coord2d() const { return coord2d(x,y); } + +bool isValid() const { return x != -30000; } +void clear() { x = y = z = -30000; } + +bool operator==(const coord &other) const +{ + return (x == other.x) && (y == other.y) && (z == other.z); +} +bool operator!=(const coord &other) const +{ + return (x != other.x) || (y != other.y) || (z != other.z); +} + +bool operator<(const coord &other) const +{ + if (x != other.x) return (x < other.x); + if (y != other.y) return (y < other.y); + return z < other.z; +} + +coord operator/(int number) const +{ + return coord(x/number, y/number, z); +} +coord operator*(int number) const +{ + return coord(x*number, y*number, z); +} +coord operator%(int number) const +{ + return coord(x%number, y%number, z); +} + +coord operator-(int number) const +{ + return coord(x,y,z-number); +} +coord operator+(int number) const +{ + return coord(x,y,z+number); +} diff --git a/library/include/df/custom/coord2d.methods.inc b/library/include/df/custom/coord2d.methods.inc new file mode 100644 index 000000000..b6b47bca1 --- /dev/null +++ b/library/include/df/custom/coord2d.methods.inc @@ -0,0 +1,32 @@ +coord2d(uint16_t _x, uint16_t _y) : x(_x), y(_y) {} + +bool isValid() const { return x != -30000; } +void clear() { x = y = -30000; } + +bool operator==(const coord2d &other) const +{ + return (x == other.x) && (y == other.y); +} +bool operator!=(const coord2d &other) const +{ + return (x != other.x) || (y != other.y); +} + +bool operator<(const coord2d &other) const +{ + if (x != other.x) return (x < other.x); + return y < other.y; +} + +coord2d operator/(int number) const +{ + return coord2d(x/number, y/number); +} +coord2d operator*(int number) const +{ + return coord2d(x*number, y*number); +} +coord2d operator%(int number) const +{ + return coord2d(x%number, y%number); +} diff --git a/library/include/df/custom/coord_path.methods.inc b/library/include/df/custom/coord_path.methods.inc new file mode 100644 index 000000000..d3c48de7f --- /dev/null +++ b/library/include/df/custom/coord_path.methods.inc @@ -0,0 +1,8 @@ +unsigned size() const { return x.size(); } + +coord operator[] (unsigned idx) const { + if (idx >= x.size() || idx >= y.size() || idx >= z.size()) + return coord(); + else + return coord(x[idx], y[idx], z[idx]); +} diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 3b731c0d0..43c763a59 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -409,9 +409,9 @@ bool Items::copyItem(df::item * itembase, DFHack::dfh_item &item) return false; df::item * itreal = (df::item *) itembase; item.origin = itembase; - item.x = itreal->x; - item.y = itreal->y; - item.z = itreal->z; + item.x = itreal->pos.x; + item.y = itreal->pos.y; + item.z = itreal->pos.z; item.id = itreal->id; item.age = itreal->age; item.flags = itreal->flags; diff --git a/library/modules/Vermin.cpp b/library/modules/Vermin.cpp index 6b83d76bb..689a9edda 100644 --- a/library/modules/Vermin.cpp +++ b/library/modules/Vermin.cpp @@ -60,9 +60,9 @@ bool Vermin::Read (const uint32_t index, t_vermin & sp) sp.caste = verm->caste; sp.visible = verm->visible; sp.countdown = verm->countdown; - sp.x = verm->x; - sp.y = verm->y; - sp.z = verm->z; + sp.x = verm->pos.x; + sp.y = verm->pos.y; + sp.z = verm->pos.z; sp.is_colony = verm->flags.bits.is_colony; return true; } @@ -76,9 +76,9 @@ bool Vermin::Write (const uint32_t index, t_vermin & sp) verm->caste = sp.caste; verm->visible = sp.visible; verm->countdown = sp.countdown; - verm->x = sp.x; - verm->y = sp.y; - verm->z = sp.z; + verm->pos.x = sp.x; + verm->pos.y = sp.y; + verm->pos.z = sp.z; verm->flags.bits.is_colony = sp.is_colony; return true; } diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index d36854bbf..a7cebf7bb 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -143,7 +143,7 @@ static command_result autodump_main(Core * c, vector & parameters) for(std::size_t i=0; i< numItems; i++) { df::item * itm = world->items.all[i]; - DFCoord pos_item(itm->x, itm->y, itm->z); + DFCoord pos_item(itm->pos.x, itm->pos.y, itm->pos.z); // keep track how many items are at places. all items. coordmap::iterator it = counts.find(pos_item); @@ -185,7 +185,7 @@ static command_result autodump_main(Core * c, vector & parameters) { // yes... cerr << "Moving from block to block!" << endl; - df_block * bl_src = Maps->getBlock(itm->x /16, itm->y/16, itm->z); + df_block * bl_src = Maps->getBlock(itm->pos.x /16, itm->pos.y/16, itm->pos.z); df_block * bl_tgt = Maps->getBlock(cx /16, cy/16, cz); if(bl_src) { @@ -206,9 +206,9 @@ static command_result autodump_main(Core * c, vector & parameters) } // Move the item - itm->x = pos_cursor.x; - itm->y = pos_cursor.y; - itm->z = pos_cursor.z; + itm->pos.x = pos_cursor.x; + itm->pos.y = pos_cursor.y; + itm->pos.z = pos_cursor.z; } else // destroy { diff --git a/plugins/cleaners.cpp b/plugins/cleaners.cpp index 1ee4b3406..9351d15ea 100644 --- a/plugins/cleaners.cpp +++ b/plugins/cleaners.cpp @@ -10,6 +10,7 @@ #include "df/block_square_event_material_spatterst.h" #include "df/item_actual.h" #include "df/unit.h" +#include "df/unit_spatter.h" #include "df/matter_state.h" #include "df/cursor.h" #include "df/builtin_mats.h" diff --git a/plugins/deramp.cpp b/plugins/deramp.cpp index a86b61e8e..2549fb83c 100644 --- a/plugins/deramp.cpp +++ b/plugins/deramp.cpp @@ -51,7 +51,7 @@ DFhackCExport command_result df_deramp (Core * c, vector & parameters) for (int i = 0; i < blocks_total; i++) { df::map_block *block = world->map.map_blocks[i]; - df::map_block *above = getBlock(block->map_x, block->map_y, block->map_z + 1); + df::map_block *above = getBlock(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1); for (int x = 0; x < 16; x++) {