? three_dirs.diff Index: common/map.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.c,v retrieving revision 1.90 diff -u -r1.90 map.c --- common/map.c 2001/09/23 16:09:39 1.90 +++ common/map.c 2001/09/23 17:04:08 @@ -41,9 +41,15 @@ struct terrain_misc terrain_control; struct tile_type tile_types[T_LAST]; -/* used to compute neighboring tiles */ +#if USE_8_DIRS_HORIZONTAL const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 }; const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 }; +#endif + +#if USE_8_DIRS_ROTATIONAL +const int DIR_DX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }; +const int DIR_DY[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }; +#endif /* like DIR_DX[] and DIR_DY[], only cartesian */ const int CAR_DIR_DX[4] = {1, 0, -1, 0}; Index: common/map.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/map.h,v retrieving revision 1.93 diff -u -r1.93 map.h --- common/map.h 2001/09/23 16:09:39 1.93 +++ common/map.h 2001/09/23 17:04:09 @@ -20,6 +20,44 @@ struct Sprite; /* opaque; client-gui specific */ +/* + * Set this to 1 to enable a direction system which uses 8 directions + * (n,w,s,e,nw,ne,sw,se). You have to set one of the USE_8_DIRS_* + * constants to choose a ordering of the 8 directions. + */ +#define USE_8_DIRS 1 + +/* + * Set this to 1 to get an ordering like in the following: + * + * ------- + * |0|1|2| + * |-+-+-| + * |3| |4| + * |-+-+-| + * |5|6|7| + * ------- + */ +#define USE_8_DIRS_HORIZONTAL 1 + +/* + * Set this to 1 to get an ordering like in the following: + * + * ------- + * |7|0|1| + * |-+-+-| + * |6| |2| + * |-+-+-| + * |5|4|3| + * ------- + */ +#define USE_8_DIRS_ROTATIONAL 0 + +/* + * Set this to 1 to get an ordering which has no particular ordering. + */ +#define USE_8_DIRS_RANDOM 0 + #define NUM_DIRECTION_NSEW 16 struct map_position { @@ -168,6 +206,150 @@ struct map_position start_positions[MAX_NUM_NATIONS]; }; +#if USE_8_DIRS + +/* + * Each one of the USE_8_DIRS_* choices has to define: + * - the DIRSTEP macro + * - the DIR_REVERSE macro + * - enum direction8 + */ + +#define GENERAL_8_DIRS_DIR_REVERSE(dir) \ +((dir)==DIR8_WEST ? DIR8_EAST : \ + ((dir)==DIR8_EAST ? DIR8_WEST : \ + ((dir)==DIR8_NORTH ? DIR8_SOUTH : \ + ((dir)==DIR8_SOUTH ? DIR8_NORTH : \ + ((dir)==DIR8_NORTHWEST ? DIR8_SOUTHEAST : \ + ((dir)==DIR8_NORTHEAST ? DIR8_SOUTHWEST : \ + ((dir)==DIR8_SOUTHWEST ? DIR8_NORTHEAST : \ + ((dir)==DIR8_SOUTHEAST ? DIR8_NORTHWEST : \ + (dir)/0)))))))) + +#define GENERAL_8_DIRS_DIRSTEP(dest_x, dest_y, dir) \ + ((dest_x) = \ + (((dir)==DIR8_WEST || (dir)==DIR8_NORTHWEST || (dir)==DIR8_SOUTHWEST)? -1: \ + (((dir)==DIR8_NORTH || (dir)==DIR8_SOUTH)? 0: \ + (((dir)==DIR8_EAST || (dir)==DIR8_NORTHEAST || (dir)==DIR8_SOUTHEAST)? +1: \ + ((dir)/0)))), \ + (dest_y) = \ + (((dir)==DIR8_NORTH || (dir)==DIR8_NORTHWEST || (dir)==DIR8_NORTHEAST)? -1: \ + (((dir)==DIR8_WEST || (dir)==DIR8_EAST)? 0: \ + (((dir)==DIR8_SOUTH || (dir)==DIR8_SOUTHWEST || (dir)==DIR8_SOUTHEAST)? +1: \ + ((dir)/0))))) + +#if USE_8_DIRS_HORIZONTAL + +/* +used to compute neighboring tiles: using DIRSTEP(x, y, dir) will give +you the tile as shown below. +------- +|0|1|2| +|-+-+-| +|3| |4| +|-+-+-| +|5|6|7| +------- +*/ + +extern const int DIR_DX[8]; +extern const int DIR_DY[8]; + +#define DIRSTEP(dest_x, dest_y, dir) \ +( (dest_x) = DIR_DX[(dir)], \ + (dest_y) = DIR_DY[(dir)]) + +enum direction8 { + /* FIXME: DIR8 is used to avoid conflict with + * enum Directions in client/tilespec.h */ + DIR8_NORTHWEST = 0, + DIR8_NORTH = 1, + DIR8_NORTHEAST = 2, + DIR8_WEST = 3, + DIR8_EAST = 4, + DIR8_SOUTHWEST = 5, + DIR8_SOUTH = 6, + DIR8_SOUTHEAST = 7 +}; + +/* return the reverse of the direction */ +#define DIR_REVERSE(dir) (7 - (dir)) +#endif + +#if USE_8_DIRS_ROTATIONAL + +/* +used to compute neighboring tiles: using DIRSTEP(x, y, dir) will give +you the tile as shown below. +------- +|7|0|1| +|-+-+-| +|6| |2| +|-+-+-| +|5|4|3| +------- +*/ + +extern const int DIR_DX[8]; +extern const int DIR_DY[8]; + +#define DIRSTEP(dest_x, dest_y, dir) \ +( (dest_x) = DIR_DX[(dir)], \ + (dest_y) = DIR_DY[(dir)]) + +enum direction8 { + /* FIXME: DIR8 is used to avoid conflict with + * enum Directions in client/tilespec.h */ + DIR8_NORTHWEST = 0, + DIR8_NORTH = 1, + DIR8_NORTHEAST = 2, + DIR8_WEST = 3, + DIR8_EAST = 4, + DIR8_SOUTHWEST = 5, + DIR8_SOUTH = 6, + DIR8_SOUTHEAST = 7 +}; + +/* return the reverse of the direction */ +#define DIR_REVERSE(dir) ((dir) ^ 4) +#endif + +#if USE_8_DIRS_RANDOM + +/* + * This ordering is intended to have no special properties in the + * ordering of the directions. To achive this the odering has been + * obtained used md5 of the English strings as in the following python + * program: +import md5 +dirs = map(lambda dir: (dir, md5.new(dir).digest()), + ["north","south","west","east","northwest", + "southwest","northeast", "southeast"]) +dirs.sort(lambda x,y: cmp(x[1],y[1])) +for dir in dirs: print dir[0] +*/ + +#define DIRSTEP(dest_x, dest_y, dir) \ + GENERAL_8_DIRS_DIRSTEP((dest_x), (dest_y), (dir)) + +enum direction8 { + /* FIXME: DIR8 is used to avoid conflict with + * enum Directions in client/tilespec.h */ + DIR8_SOUTHWEST = 0, + DIR8_EAST = 1, + DIR8_SOUTH = 2, + DIR8_NORTH = 3, + DIR8_NORTHWEST = 4, + DIR8_NORTHEAST = 5, + DIR8_WEST = 6, + DIR8_SOUTHEAST = 7 +}; + +#define DIR_REVERSE(dir) GENERAL_8_DIRS_DIR_REVERSE(dir) +#endif + +#endif /* USE_8_DIRS */ + int map_is_empty(void); void map_init(void); void map_allocate(void); @@ -204,9 +386,6 @@ #define map_inx(x,y) \ ((x)+(y)*map.xsize) -#define DIRSTEP(dest_x, dest_y, dir) \ -( (dest_x) = DIR_DX[(dir)], \ - (dest_y) = DIR_DY[(dir)]) #define MAPSTEP(dest_x, dest_y, src_x, src_y, dir) \ ( DIRSTEP(dest_x, dest_y, dir), \ @@ -424,38 +603,6 @@ #define whole_map_iterate_end \ } -/* -used to compute neighboring tiles: -using -x1 = x + DIR_DX[dir]; -y1 = y + DIR_DX[dir]; -will give you the tile as shown below. -------- -|0|1|2| -|-+-+-| -|3| |4| -|-+-+-| -|5|6|7| -------- -Note that you must normalize x1 and y1 yourself. -*/ - -enum direction8 { - /* FIXME: DIR8 is used to avoid conflict with - * enum Directions in client/tilespec.h */ - DIR8_NORTHWEST = 0, - DIR8_NORTH = 1, - DIR8_NORTHEAST = 2, - DIR8_WEST = 3, - DIR8_EAST = 4, - DIR8_SOUTHWEST = 5, - DIR8_SOUTH = 6, - DIR8_SOUTHEAST = 7 -}; - -/* return the reverse of the direction */ -#define DIR_REVERSE(dir) (7 - (dir)) - /* is the direction "cardinal"? Cardinal directions * (also called cartesian) are the four main ones */ #define DIR_IS_CARDINAL(dir) \ @@ -463,9 +610,6 @@ (dir) == DIR8_WEST || (dir) == DIR8_SOUTH) const char* dir_get_name(enum direction8 dir); - -extern const int DIR_DX[8]; -extern const int DIR_DY[8]; /* like DIR_DX[] and DIR_DY[], only cartesian */ extern const int CAR_DIR_DX[4];