00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef INCL_TILES
00022 #define INCL_TILES 1
00023
00024 #include "exult_constants.h"
00025
00026
00027
00028
00029 class Tile_coord
00030 {
00031 static short neighbors[16];
00032 public:
00033 short tx, ty, tz;
00034 Tile_coord(int x, int y, int z) : tx(x), ty(y), tz(z)
00035 { }
00036 Tile_coord(): tx(0),ty(0),tz(0) { }
00037 int operator==(Tile_coord t2)
00038 { return t2.tx == tx && t2.ty == ty && t2.tz == tz; }
00039 int operator!=(Tile_coord t2)
00040 { return !(*this == t2); }
00041 int distance(Tile_coord t2)
00042 {
00043 int dy = (t2.ty - ty + c_num_tiles)%c_num_tiles;
00044 int dx = (t2.tx - tx + c_num_tiles)%c_num_tiles;
00045 if (dy >= c_num_tiles/2)
00046 dy = c_num_tiles - dy;
00047 if (dx >= c_num_tiles/2)
00048 dx = c_num_tiles - dx;
00049
00050 return (dy > dx ? dy : dx);
00051 }
00052
00053 inline Tile_coord get_neighbor(int dir)
00054 { return Tile_coord(
00055 (tx + neighbors[2*dir] + c_num_tiles)%c_num_tiles,
00056 (ty + neighbors[2*dir + 1] + c_num_tiles)%c_num_tiles,
00057 tz); }
00058 static bool gte(int t1, int t2)
00059 {
00060 int diff = t1 - t2;
00061 return diff >= 0 ? (diff < c_num_tiles/2) :
00062 diff < -c_num_tiles/2;
00063 }
00064
00065 static int delta(int from, int to)
00066 {
00067 int diff = to - from;
00068 return diff >= c_num_tiles/2 ? (diff - c_num_tiles) :
00069 (diff <= -c_num_tiles/2 ? (diff + c_num_tiles) :
00070 diff);
00071 }
00072 };
00073
00074 inline Tile_coord operator+(Tile_coord a, Tile_coord b)
00075 { return Tile_coord(a.tx + b.tx, a.ty + b.ty, a.tz + b.tz); }
00076
00077 #endif