Index: common/map.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.c,v retrieving revision 1.124 diff -u -r1.124 map.c --- common/map.c 2002/08/07 11:21:46 1.124 +++ common/map.c 2002/09/07 09:58:56 @@ -1457,6 +1457,64 @@ } /************************************************************************** + Returns the next direction clock-wise. +**************************************************************************/ +enum direction8 dir_cw(enum direction8 dir) +{ + /* a switch statement is used so the ordering can be changed easily */ + switch (dir) { + case DIR8_NORTH: + return DIR8_NORTHEAST; + case DIR8_NORTHEAST: + return DIR8_EAST; + case DIR8_EAST: + return DIR8_SOUTHEAST; + case DIR8_SOUTHEAST: + return DIR8_SOUTH; + case DIR8_SOUTH: + return DIR8_SOUTHWEST; + case DIR8_SOUTHWEST: + return DIR8_WEST; + case DIR8_WEST: + return DIR8_NORTHWEST; + case DIR8_NORTHWEST: + return DIR8_NORTH; + default: + assert(0); + return -1; + } +} + +/************************************************************************** + Returns the next direction counter-clock-wise. +**************************************************************************/ +enum direction8 dir_ccw(enum direction8 dir) +{ + /* a switch statement is used so the ordering can be changed easily */ + switch (dir) { + case DIR8_NORTH: + return DIR8_NORTHWEST; + case DIR8_NORTHEAST: + return DIR8_NORTH; + case DIR8_EAST: + return DIR8_NORTHEAST; + case DIR8_SOUTHEAST: + return DIR8_EAST; + case DIR8_SOUTH: + return DIR8_SOUTHEAST; + case DIR8_SOUTHWEST: + return DIR8_SOUTH; + case DIR8_WEST: + return DIR8_SOUTHWEST; + case DIR8_NORTHWEST: + return DIR8_WEST; + default: + assert(0); + return -1; + } +} + +/************************************************************************** Return true and sets dir to the direction of the step if (end_x, end_y) can be reached from (start_x, start_y) in one step. Return false otherwise (value of dir is unchanged in this case). Index: common/map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.129 diff -u -r1.129 map.h --- common/map.h 2002/08/07 11:21:47 1.129 +++ common/map.h 2002/09/07 09:58:57 @@ -236,34 +236,6 @@ (dest_y) += (src_y), \ normalize_map_pos(&(dest_x), &(dest_y))) -/* - * Returns the next direction clock-wise - */ -#define DIR_CW(dir) \ - ((dir)==DIR8_WEST ? DIR8_NORTHWEST : \ - ((dir)==DIR8_EAST ? DIR8_SOUTHEAST : \ - ((dir)==DIR8_NORTH ? DIR8_NORTHEAST : \ - ((dir)==DIR8_SOUTH ? DIR8_SOUTHWEST : \ - ((dir)==DIR8_NORTHWEST ? DIR8_NORTH : \ - ((dir)==DIR8_NORTHEAST ? DIR8_EAST : \ - ((dir)==DIR8_SOUTHWEST ? DIR8_WEST : \ - ((dir)==DIR8_SOUTHEAST ? DIR8_SOUTH : \ - (dir)/0)))))))) - -/* - * Returns the next direction counter-clock-wise - */ -#define DIR_CCW(dir) \ - ((dir)==DIR8_WEST ? DIR8_SOUTHWEST : \ - ((dir)==DIR8_EAST ? DIR8_NORTHEAST : \ - ((dir)==DIR8_NORTH ? DIR8_NORTHWEST : \ - ((dir)==DIR8_SOUTH ? DIR8_SOUTHEAST : \ - ((dir)==DIR8_NORTHWEST ? DIR8_WEST : \ - ((dir)==DIR8_NORTHEAST ? DIR8_NORTH : \ - ((dir)==DIR8_SOUTHWEST ? DIR8_SOUTH : \ - ((dir)==DIR8_SOUTHEAST ? DIR8_EAST : \ - (dir)/0)))))))) - struct city *map_get_city(int x, int y); void map_set_city(int x, int y, struct city *pcity); enum tile_terrain_type map_get_terrain(int x, int y); @@ -568,6 +540,8 @@ ((dir) == DIR8_NORTH || (dir) == DIR8_EAST || \ (dir) == DIR8_WEST || (dir) == DIR8_SOUTH) +enum direction8 dir_cw(enum direction8 dir); +enum direction8 dir_ccw(enum direction8 dir); const char* dir_get_name(enum direction8 dir); extern const int DIR_DX[8];