Update code to accomodate the new coord/coord2d/coord_path structs.

Also replicate the methods of DFCoord.
develop
Alexander Gavrilov 2012-01-19 14:30:22 +04:00
parent d75292acc7
commit 7db467a740
10 changed files with 106 additions and 16 deletions

@ -268,3 +268,7 @@ DF_KNOWN_GLOBALS
#undef GLOBAL #undef GLOBAL
#undef SIMPLE_GLOBAL #undef SIMPLE_GLOBAL
} }
// A couple of headers that have to be included at once
#include "df/coord2d.h"
#include "df/coord.h"

@ -1,3 +1,3 @@
*.h *.h
*.inc static*.inc
*.xml *.xml

@ -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);
}

@ -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);
}

@ -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]);
}

@ -409,9 +409,9 @@ bool Items::copyItem(df::item * itembase, DFHack::dfh_item &item)
return false; return false;
df::item * itreal = (df::item *) itembase; df::item * itreal = (df::item *) itembase;
item.origin = itembase; item.origin = itembase;
item.x = itreal->x; item.x = itreal->pos.x;
item.y = itreal->y; item.y = itreal->pos.y;
item.z = itreal->z; item.z = itreal->pos.z;
item.id = itreal->id; item.id = itreal->id;
item.age = itreal->age; item.age = itreal->age;
item.flags = itreal->flags; item.flags = itreal->flags;

@ -60,9 +60,9 @@ bool Vermin::Read (const uint32_t index, t_vermin & sp)
sp.caste = verm->caste; sp.caste = verm->caste;
sp.visible = verm->visible; sp.visible = verm->visible;
sp.countdown = verm->countdown; sp.countdown = verm->countdown;
sp.x = verm->x; sp.x = verm->pos.x;
sp.y = verm->y; sp.y = verm->pos.y;
sp.z = verm->z; sp.z = verm->pos.z;
sp.is_colony = verm->flags.bits.is_colony; sp.is_colony = verm->flags.bits.is_colony;
return true; return true;
} }
@ -76,9 +76,9 @@ bool Vermin::Write (const uint32_t index, t_vermin & sp)
verm->caste = sp.caste; verm->caste = sp.caste;
verm->visible = sp.visible; verm->visible = sp.visible;
verm->countdown = sp.countdown; verm->countdown = sp.countdown;
verm->x = sp.x; verm->pos.x = sp.x;
verm->y = sp.y; verm->pos.y = sp.y;
verm->z = sp.z; verm->pos.z = sp.z;
verm->flags.bits.is_colony = sp.is_colony; verm->flags.bits.is_colony = sp.is_colony;
return true; return true;
} }

@ -143,7 +143,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
for(std::size_t i=0; i< numItems; i++) for(std::size_t i=0; i< numItems; i++)
{ {
df::item * itm = world->items.all[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. // keep track how many items are at places. all items.
coordmap::iterator it = counts.find(pos_item); coordmap::iterator it = counts.find(pos_item);
@ -185,7 +185,7 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
{ {
// yes... // yes...
cerr << "Moving from block to block!" << endl; 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); df_block * bl_tgt = Maps->getBlock(cx /16, cy/16, cz);
if(bl_src) if(bl_src)
{ {
@ -206,9 +206,9 @@ static command_result autodump_main(Core * c, vector <string> & parameters)
} }
// Move the item // Move the item
itm->x = pos_cursor.x; itm->pos.x = pos_cursor.x;
itm->y = pos_cursor.y; itm->pos.y = pos_cursor.y;
itm->z = pos_cursor.z; itm->pos.z = pos_cursor.z;
} }
else // destroy else // destroy
{ {

@ -10,6 +10,7 @@
#include "df/block_square_event_material_spatterst.h" #include "df/block_square_event_material_spatterst.h"
#include "df/item_actual.h" #include "df/item_actual.h"
#include "df/unit.h" #include "df/unit.h"
#include "df/unit_spatter.h"
#include "df/matter_state.h" #include "df/matter_state.h"
#include "df/cursor.h" #include "df/cursor.h"
#include "df/builtin_mats.h" #include "df/builtin_mats.h"

@ -51,7 +51,7 @@ DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
for (int i = 0; i < blocks_total; i++) for (int i = 0; i < blocks_total; i++)
{ {
df::map_block *block = world->map.map_blocks[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++) for (int x = 0; x < 16; x++)
{ {