[Freeciv-Dev] (PR#9511) fix DIR_IS_CARDINAL
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9511 >
This patch fixes DIR_IS_CARDINAL in three ways:
- It turns it from an inline function (which is not justified) into a
normal function.
- It renames it from DIR_IS_CARDINAL to is_cardinal_dir. This
corresponds with is_valid_dir.
- It corrects the logic for hex topologies which was reversed. The fix
which I hastily applied last night fixed non-hex topologies but was
still reversed for hex topologies.
Most of the users are just substituted. However in one place I used
is_tileset_dir_cardinal and in one place I changed an adjc_dir_iterate
to cardinal_adjc_iterate.
jason
? diff
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.321
diff -u -r1.321 aiunit.c
--- ai/aiunit.c 25 Jun 2004 23:43:01 -0000 1.321
+++ ai/aiunit.c 26 Jul 2004 16:58:15 -0000
@@ -314,7 +314,7 @@
sum = 50;
adjc_dir_iterate(x, y, x1, y1, dir) {
if (map_is_known(x1, y1, pplayer)) {
- if (DIR_IS_CARDINAL(dir)) {
+ if (is_cardinal_dir(dir)) {
/* If a tile is cardinally adjacent, we can tell if the
* central tile is ocean or not by the appearance of
* the adjacent tile. So, given that we can tell,
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.190
diff -u -r1.190 tilespec.c
--- client/tilespec.c 26 Jul 2004 03:07:39 -0000 1.190
+++ client/tilespec.c 26 Jul 2004 16:58:15 -0000
@@ -2176,7 +2176,8 @@
road_near[dir] = contains_special(tspecial_near[dir], S_ROAD);
rail_near[dir] = contains_special(tspecial_near[dir], S_RAILROAD);
- if (draw_diagonal_roads || DIR_IS_CARDINAL(map_to_gui_dir(dir))) {
+ if (draw_diagonal_roads
+ || is_cardinal_tileset_dir(map_to_gui_dir(dir))) {
/* Draw rail/road if there is a connection from this tile to the
* adjacent tile. But don't draw road if there is also a rail
* connection. */
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.183
diff -u -r1.183 map.c
--- common/map.c 26 Jul 2004 03:38:29 -0000 1.183
+++ common/map.c 26 Jul 2004 16:58:16 -0000
@@ -415,7 +415,7 @@
map.valid_dirs[map.num_valid_dirs] = dir;
map.num_valid_dirs++;
}
- if (DIR_IS_CARDINAL(dir)) {
+ if (is_cardinal_dir(dir)) {
map.cardinal_dirs[map.num_cardinal_dirs] = dir;
map.num_cardinal_dirs++;
}
@@ -1778,9 +1778,11 @@
switch (dir) {
case DIR8_SOUTHEAST:
case DIR8_NORTHWEST:
+ /* These directions are invalid in hex topologies. */
return !(topo_has_flag(TF_HEX) && !topo_has_flag(TF_ISO));
case DIR8_NORTHEAST:
case DIR8_SOUTHWEST:
+ /* These directions are invalid in iso-hex topologies. */
return !(topo_has_flag(TF_HEX) && topo_has_flag(TF_ISO));
case DIR8_NORTH:
case DIR8_EAST:
@@ -1793,6 +1795,32 @@
}
/**************************************************************************
+ Returns TRUE iff the given direction is a cardinal one.
+
+ Cardinal directions are those in which adjacent tiles share an edge not
+ just a vertex.
+**************************************************************************/
+bool is_cardinal_dir(enum direction8 dir)
+{
+ switch (dir) {
+ case DIR8_NORTH:
+ case DIR8_SOUTH:
+ case DIR8_EAST:
+ case DIR8_WEST:
+ return TRUE;
+ case DIR8_SOUTHEAST:
+ case DIR8_NORTHWEST:
+ /* These directions are cardinal in iso-hex topologies. */
+ return topo_has_flag(TF_HEX) && topo_has_flag(TF_ISO);
+ case DIR8_NORTHEAST:
+ case DIR8_SOUTHWEST:
+ /* These directions are cardinal in hexagonal topologies. */
+ return topo_has_flag(TF_HEX) && !topo_has_flag(TF_ISO);
+ }
+ return FALSE;
+}
+
+/**************************************************************************
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).
@@ -1832,7 +1860,7 @@
**************************************************************************/
bool is_move_cardinal(int start_x, int start_y, int end_x, int end_y)
{
- return DIR_IS_CARDINAL(get_direction_for_step(start_x, start_y,
+ return is_cardinal_dir(get_direction_for_step(start_x, start_y,
end_x, end_y));
}
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.201
diff -u -r1.201 map.h
--- common/map.h 26 Jul 2004 07:45:41 -0000 1.201
+++ common/map.h 26 Jul 2004 16:58:16 -0000
@@ -123,7 +123,7 @@
/* The direction8 gives the 8 possible directions. These may be used in
* a number of ways, for instance as an index into the DIR_DX/DIR_DY
* arrays. Not all directions may be valid; see is_valid_dir and
- * DIR_IS_CARDINAL. */
+ * is_cardinal_dir. */
enum direction8 {
/* The DIR8/direction8 naming system is used to avoid conflict with
* DIR4/direction4 in client/tilespec.h
@@ -580,32 +580,11 @@
/* 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 */
-static inline bool DIR_IS_CARDINAL(enum direction8 dir)
-{
- switch (dir) {
- case DIR8_NORTH:
- case DIR8_SOUTH:
- case DIR8_EAST:
- case DIR8_WEST:
- return TRUE;
- case DIR8_SOUTHEAST:
- case DIR8_NORTHWEST:
- /* These directions are cardinal in hexagonal topologies. */
- return topo_has_flag(TF_HEX) && !topo_has_flag(TF_ISO);
- case DIR8_NORTHEAST:
- case DIR8_SOUTHWEST:
- /* These directions are cardinal in iso-hex topologies. */
- return topo_has_flag(TF_HEX) && topo_has_flag(TF_ISO);
- }
- return FALSE;
-}
-
enum direction8 dir_cw(enum direction8 dir);
enum direction8 dir_ccw(enum direction8 dir);
const char* dir_get_name(enum direction8 dir);
bool is_valid_dir(enum direction8 dir);
+bool is_cardinal_dir(enum direction8 dir);
extern const int DIR_DX[8];
extern const int DIR_DY[8];
Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.179
diff -u -r1.179 gotohand.c
--- server/gotohand.c 19 May 2004 00:49:32 -0000 1.179
+++ server/gotohand.c 26 Jul 2004 16:58:17 -0000
@@ -635,7 +635,9 @@
try to move to are x1,y1 */
adjc_dir_iterate(x, y, x1, y1, dir) {
if ((restriction == GOTO_MOVE_CARDINAL_ONLY)
- && !DIR_IS_CARDINAL(dir)) continue;
+ && !is_cardinal_dir(dir)) {
+ continue;
+ }
pdesttile = map_get_tile(x1, y1);
@@ -835,7 +837,7 @@
adjc_dir_iterate(x, y, x1, y1, dir) {
if ((restriction == GOTO_MOVE_CARDINAL_ONLY)
- && !DIR_IS_CARDINAL(dir)) continue;
+ && !is_cardinal_dir(dir)) continue;
if (BV_ISSET(LOCAL_VECTOR(x, y), dir)) {
move_cost = (move_type == SEA_MOVING)
@@ -930,7 +932,7 @@
if (base_get_direction_for_step(punit->x, punit->y, dest_x, dest_y, &dir)
&& TEST_BIT(WARMAP_VECTOR(punit->x, punit->y), dir)
&& !(restriction == GOTO_MOVE_CARDINAL_ONLY
- && !DIR_IS_CARDINAL(dir))) {
+ && !is_cardinal_dir(dir))) {
return dir;
}
}
@@ -955,7 +957,7 @@
*/
if (!TEST_BIT(WARMAP_VECTOR(punit->x, punit->y), dir)
|| ((restriction == GOTO_MOVE_CARDINAL_ONLY)
- && !DIR_IS_CARDINAL(dir))) {
+ && !is_cardinal_dir(dir))) {
/* make sure we don't select it later */
fitness[dir] = DONT_SELECT_ME_FITNESS;
continue;
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.135
diff -u -r1.135 maphand.c
--- server/maphand.c 9 Jul 2004 18:52:36 -0000 1.135
+++ server/maphand.c 26 Jul 2004 16:58:17 -0000
@@ -1290,18 +1290,14 @@
}
/* No, we cannot see it, but maybe we can see the strip of land
* on a tile next to it? */
- adjc_dir_iterate(x1, y1, x2, y2, dir) {
- if (!DIR_IS_CARDINAL(dir)) {
- /* We cannot see strip of land on diagonal tiles */
- continue;
- }
+ cardinal_adjc_iterate(x1, y1, x2, y2) {
if (map_is_known(x2, y2, pplayer)) {
/* Yes, we can see (x2, y2) and it will display
* the strip of land. We can conclude that (x1, y1) is land
* and therefore (x,y) is right next to (or on) the land */
return TRUE;
}
- } adjc_dir_iterate_end; /* around x1,y1 */
+ } cardinal_adjc_iterate_end; /* around x1,y1 */
} square_iterate_end; /* around x,y */
return FALSE;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9511) fix DIR_IS_CARDINAL,
Jason Short <=
|
|