Added DIR_* to script constants

* Adjusted a few location in source to use the constants.
Thanks to @Lemongrass3110!
This commit is contained in:
aleos89
2016-04-22 23:12:47 -04:00
parent e8f2fc166f
commit 10bac969ee
6 changed files with 48 additions and 33 deletions

View File

@@ -2456,15 +2456,6 @@ THANATOS_KEEP 10009
4_F_REBELLION3 10202
4_M_ILYA 10203
DIR_NORTH 0
DIR_NORTHWEST 1
DIR_WEST 2
DIR_SOUTHWEST 3
DIR_SOUTH 4
DIR_SOUTHEAST 5
DIR_EAST 6
DIR_NORTHEAST 7
MOBG_Branch_Of_Dead_Tree 0
MOBG_Poring_Box 1
MOBG_Bloody_Dead_Branch 2

View File

@@ -19,10 +19,10 @@
#define SET_OPEN 0
#define SET_CLOSED 1
#define DIR_NORTH 1
#define DIR_WEST 2
#define DIR_SOUTH 4
#define DIR_EAST 8
#define PATH_DIR_NORTH 1
#define PATH_DIR_WEST 2
#define PATH_DIR_SOUTH 4
#define PATH_DIR_EAST 8
/// @name Structures and defines for A* pathfinding
/// @{
@@ -53,9 +53,9 @@ BHEAP_STRUCT_DECL(node_heap, struct path_node*);
// Translates dx,dy into walking direction
static const unsigned char walk_choices [3][3] =
{
{1,0,7},
{2,-1,6},
{3,4,5},
{DIR_NORTHWEST,DIR_NORTH,DIR_NORTHEAST},
{DIR_WEST,DIR_CENTER,DIR_EAST},
{DIR_SOUTHWEST,DIR_SOUTH,DIR_SOUTHEAST},
};
/*==========================================
@@ -371,28 +371,28 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x
break;
}
if (y < ys && !map_getcellp(md, x, y+1, cell)) allowed_dirs |= DIR_NORTH;
if (y > 0 && !map_getcellp(md, x, y-1, cell)) allowed_dirs |= DIR_SOUTH;
if (x < xs && !map_getcellp(md, x+1, y, cell)) allowed_dirs |= DIR_EAST;
if (x > 0 && !map_getcellp(md, x-1, y, cell)) allowed_dirs |= DIR_WEST;
if (y < ys && !map_getcellp(md, x, y+1, cell)) allowed_dirs |= PATH_DIR_NORTH;
if (y > 0 && !map_getcellp(md, x, y-1, cell)) allowed_dirs |= PATH_DIR_SOUTH;
if (x < xs && !map_getcellp(md, x+1, y, cell)) allowed_dirs |= PATH_DIR_EAST;
if (x > 0 && !map_getcellp(md, x-1, y, cell)) allowed_dirs |= PATH_DIR_WEST;
#define chk_dir(d) ((allowed_dirs & (d)) == (d))
// Process neighbors of current node
if (chk_dir(DIR_SOUTH|DIR_EAST) && !map_getcellp(md, x+1, y-1, cell))
if (chk_dir(PATH_DIR_SOUTH|PATH_DIR_EAST) && !map_getcellp(md, x+1, y-1, cell))
e += add_path(&open_set, tp, x+1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y-1, x1, y1)); // (x+1, y-1) 5
if (chk_dir(DIR_EAST))
if (chk_dir(PATH_DIR_EAST))
e += add_path(&open_set, tp, x+1, y, g_cost + MOVE_COST, current, heuristic(x+1, y, x1, y1)); // (x+1, y) 6
if (chk_dir(DIR_NORTH|DIR_EAST) && !map_getcellp(md, x+1, y+1, cell))
if (chk_dir(PATH_DIR_NORTH|PATH_DIR_EAST) && !map_getcellp(md, x+1, y+1, cell))
e += add_path(&open_set, tp, x+1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y+1, x1, y1)); // (x+1, y+1) 7
if (chk_dir(DIR_NORTH))
if (chk_dir(PATH_DIR_NORTH))
e += add_path(&open_set, tp, x, y+1, g_cost + MOVE_COST, current, heuristic(x, y+1, x1, y1)); // (x, y+1) 0
if (chk_dir(DIR_NORTH|DIR_WEST) && !map_getcellp(md, x-1, y+1, cell))
if (chk_dir(PATH_DIR_NORTH|PATH_DIR_WEST) && !map_getcellp(md, x-1, y+1, cell))
e += add_path(&open_set, tp, x-1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y+1, x1, y1)); // (x-1, y+1) 1
if (chk_dir(DIR_WEST))
if (chk_dir(PATH_DIR_WEST))
e += add_path(&open_set, tp, x-1, y, g_cost + MOVE_COST, current, heuristic(x-1, y, x1, y1)); // (x-1, y) 2
if (chk_dir(DIR_SOUTH|DIR_WEST) && !map_getcellp(md, x-1, y-1, cell))
if (chk_dir(PATH_DIR_SOUTH|PATH_DIR_WEST) && !map_getcellp(md, x-1, y-1, cell))
e += add_path(&open_set, tp, x-1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y-1, x1, y1)); // (x-1, y-1) 3
if (chk_dir(DIR_SOUTH))
if (chk_dir(PATH_DIR_SOUTH))
e += add_path(&open_set, tp, x, y-1, g_cost + MOVE_COST, current, heuristic(x, y-1, x1, y1)); // (x, y-1) 4
#undef chk_dir
if (e) {

View File

@@ -22,6 +22,19 @@ struct shootpath_data {
int y[MAX_WALKPATH];
};
enum directions{
DIR_CENTER = -1,
DIR_NORTH = 0,
DIR_NORTHWEST = 1,
DIR_WEST = 2,
DIR_SOUTHWEST = 3,
DIR_SOUTH = 4,
DIR_SOUTHEAST = 5,
DIR_EAST = 6,
DIR_NORTHEAST = 7,
DIR_MAX
};
#define check_distance_bl(bl1, bl2, distance) check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
#define check_distance_blxy(bl, x1, y1, distance) check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
#define check_distance_xy(x0, y0, x1, y1, distance) check_distance((x0)-(x1), (y0)-(y1), distance)

View File

@@ -19243,12 +19243,12 @@ BUILDIN_FUNC(pushpc)
dir = script_getnum(st,2);
cells = script_getnum(st,3);
if(dir>7)
if(dir>DIR_NORTHEAST)
{
ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", dir);
script_reportsrc(st);
dir%= 8; // trim spin-over
dir%= DIR_MAX; // trim spin-over
}
if(!cells)
@@ -19257,7 +19257,7 @@ BUILDIN_FUNC(pushpc)
}
else if(cells<0)
{// pushing backwards
dir = (dir+4)%8; // turn around
dir = (dir+DIR_MAX/2)%DIR_MAX; // turn around
cells = -cells;
}

View File

@@ -3042,6 +3042,16 @@
export_constant(ADOPT_MORE_CHILDREN);
export_constant(ADOPT_LEVEL_70);
export_constant(ADOPT_MARRIED);
/* directions */
export_constant(DIR_NORTH);
export_constant(DIR_NORTHWEST);
export_constant(DIR_WEST);
export_constant(DIR_SOUTHWEST);
export_constant(DIR_SOUTH);
export_constant(DIR_SOUTHEAST);
export_constant(DIR_EAST);
export_constant(DIR_NORTHEAST);
#undef export_constant

View File

@@ -33,8 +33,9 @@
// 1 0 7
// 2 . 6
// 3 4 5
const short dirx[8]={0,-1,-1,-1,0,1,1,1}; ///lookup to know where will move to x according dir
const short diry[8]={1,1,0,-1,-1,-1,0,1}; ///lookup to know where will move to y according dir
// See also path.c walk_choices
const short dirx[DIR_MAX]={0,-1,-1,-1,0,1,1,1}; ///lookup to know where will move to x according dir
const short diry[DIR_MAX]={1,1,0,-1,-1,-1,0,1}; ///lookup to know where will move to y according dir
//early declaration
static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data);