Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#7259) new function tile_has_river
Home

[Freeciv-Dev] (PR#7259) new function tile_has_river

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7259) new function tile_has_river
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 17 Jan 2004 11:17:30 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7259 >

This patch adds a function tile_has_river.  It simply checks for T_RIVER 
and S_RIVER.  This clears up the logic in several places in the code.

On that note, what is the purpose of T_RIVER?  The impression I get is 
that this is just used for civ1 compatability.  But this could easily be 
accomplished just by restricting S_RIVER to grassland tiles (if that 
level of compatability is even desired).

jason

Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.155
diff -u -r1.155 map.c
--- common/map.c        2004/01/17 17:21:20     1.155
+++ common/map.c        2004/01/17 19:15:41
@@ -662,16 +662,14 @@
 
   ptile = map_get_tile(x, y);
   if (is_ocean(ptile->terrain)
-      || ptile->terrain == T_RIVER
-      || tile_has_special(ptile, S_RIVER)
+      || tile_has_river(ptile)
       || tile_has_special(ptile, S_IRRIGATION))
     return TRUE;
 
   cartesian_adjacent_iterate(x, y, x1, y1) {
     ptile = map_get_tile(x1, y1);
     if (is_ocean(ptile->terrain)
-       || ptile->terrain == T_RIVER
-       || tile_has_special(ptile, S_RIVER)
+       || tile_has_river(ptile)
        || tile_has_special(ptile, S_IRRIGATION))
       return TRUE;
   } cartesian_adjacent_iterate_end;
@@ -963,8 +961,7 @@
   if (tile_has_special(t1, S_ROAD) && tile_has_special(t2, S_ROAD))
     return MOVE_COST_ROAD;
 
-  if (((t1->terrain == T_RIVER) && (t2->terrain == T_RIVER)) ||
-      (tile_has_special(t1, S_RIVER) && tile_has_special(t2, S_RIVER))) {
+  if (tile_has_river(t1) && tile_has_river(t2)) {
     cardinal_move = is_move_cardinal(x1, y1, x2, y2);
     switch (terrain_control.river_move_mode) {
     case RMV_NORMAL:
@@ -1172,7 +1169,15 @@
 {
   return contains_special(ptile->special, special);
 }
-  
+
+/****************************************************************************
+  Return TRUE iff there is a river on this tile.
+****************************************************************************/
+bool tile_has_river(struct tile *ptile)
+{
+  return (ptile->terrain == T_RIVER || tile_has_special(ptile, S_RIVER));
+}
+
 /***************************************************************
  Returns TRUE iff the given special is found in the given set.
 ***************************************************************/
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.167
diff -u -r1.167 map.h
--- common/map.h        2004/01/17 17:21:20     1.167
+++ common/map.h        2004/01/17 19:15:41
@@ -270,6 +270,7 @@
                      enum tile_special_type to_test_for);
 bool contains_special(enum tile_special_type all,
                      enum tile_special_type to_test_for);
+bool tile_has_river(struct tile *ptile);
 
 /*
  * A "border position" is any one that _may have_ positions within
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.194
diff -u -r1.194 unit.c
--- common/unit.c       2004/01/11 17:45:04     1.194
+++ common/unit.c       2004/01/17 19:15:41
@@ -684,7 +684,7 @@
     return (terrain_control.may_road &&
            unit_flag(punit, F_SETTLERS) &&
            !tile_has_special(ptile, S_ROAD) && type->road_time != 0 &&
-           ((ptile->terrain != T_RIVER && !tile_has_special(ptile, S_RIVER))
+           (!tile_has_river(ptile)
             || player_knows_techs_with_flag(pplayer, TF_BRIDGE)));
 
   case ACTIVITY_MINE:
@@ -764,7 +764,7 @@
            (tile_has_special(ptile, S_ROAD) ||
             (punit->connecting &&
              (type->road_time != 0 &&
-              ((ptile->terrain!=T_RIVER && !tile_has_special(ptile, S_RIVER))
+              (!tile_has_river(ptile)
                || player_knows_techs_with_flag(pplayer, TF_BRIDGE))))) &&
            !tile_has_special(ptile, S_RAILROAD) &&
            player_knows_techs_with_flag(pplayer, TF_RAILROAD));
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.125
diff -u -r1.125 mapgen.c
--- server/mapgen.c     2004/01/17 17:21:20     1.125
+++ server/mapgen.c     2004/01/17 19:15:42
@@ -289,9 +289,9 @@
   int num_adjacent  = 0;
 
   cartesian_adjacent_iterate(x, y, x1, y1) {
-    if (map_get_terrain(x1, y1) == T_RIVER
-       || map_has_special(x1, y1, S_RIVER))
+    if (tile_has_river(map_get_tile(x1, y1))) {
       num_adjacent++;
+    }
   } cartesian_adjacent_iterate_end;
 
   return num_adjacent;
@@ -665,18 +665,19 @@
   /* The main loop in this function. */
   while (current_riverlength < desirable_riverlength
         && iteration_counter < RIVERS_MAXTRIES) {
+    struct tile *ptile;
 
     rand_map_pos(&x, &y);
+    ptile = map_get_tile(x, y);
 
     /* Check if it is suitable to start a river on the current tile.
      */
     if (
        /* Don't start a river on ocean. */
-       !is_ocean(map_get_terrain(x, y)) &&
+       !is_ocean(ptile->terrain) &&
 
        /* Don't start a river on river. */
-       map_get_terrain(x, y) != T_RIVER &&
-       !map_has_special(x, y, S_RIVER) &&
+       !tile_has_river(ptile) &&
 
        /* Don't start a river on a tile is surrounded by > 1 river +
           ocean tile. */
@@ -692,22 +693,22 @@
 
        /* Don't start a river on hills unless it is hard to find
           somewhere else to start it. */
-       (map_get_terrain(x, y) != T_HILLS ||
+       (ptile->terrain != T_HILLS ||
         iteration_counter == RIVERS_MAXTRIES/10 * 6) &&
 
        /* Don't start a river on mountains unless it is hard to find
           somewhere else to start it. */
-       (map_get_terrain(x, y) != T_MOUNTAINS ||
+       (ptile->terrain != T_MOUNTAINS ||
         iteration_counter == RIVERS_MAXTRIES/10 * 7) &&
 
        /* Don't start a river on arctic unless it is hard to find
           somewhere else to start it. */
-       (map_get_terrain(x, y) != T_ARCTIC ||
+       (ptile->terrain != T_ARCTIC ||
         iteration_counter == RIVERS_MAXTRIES/10 * 8) &&
 
        /* Don't start a river on desert unless it is hard to find
           somewhere else to start it. */
-       (map_get_terrain(x, y) != T_DESERT ||
+       (ptile->terrain != T_DESERT ||
         iteration_counter == RIVERS_MAXTRIES/10 * 9)){
 
 
@@ -790,15 +791,13 @@
 {
   whole_map_iterate(map_x, map_y) {
     if (terrain_is_clean(map_x, map_y)) {
-      if (map_get_terrain(map_x, map_y) != T_RIVER
-         && !map_has_special(map_x, map_y, S_RIVER)) {
+      if (tile_has_river(map_get_tile(map_x, map_y))) {
        map_set_terrain(map_x, map_y, T_HILLS);
       }
       cartesian_adjacent_iterate(map_x, map_y, x1, y1) {
        if (myrand(100) > 66
            && !is_ocean(map_get_terrain(x1, y1))
-           && map_get_terrain(x1, y1) != T_RIVER
-           && !map_has_special(x1, y1, S_RIVER)) {
+           && !tile_has_river(map_get_tile(x1, y1))) {
          map_set_terrain(x1, y1, T_HILLS);
        }
       } cartesian_adjacent_iterate_end;
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.131
diff -u -r1.131 maphand.c
--- server/maphand.c    2003/11/28 17:37:22     1.131
+++ server/maphand.c    2004/01/17 19:15:42
@@ -57,8 +57,7 @@
 **************************************************************************/
 static bool is_terrain_ecologically_wet(int x, int y)
 {
-  return (map_get_terrain(x, y) == T_RIVER
-         || map_has_special(x, y, S_RIVER)
+  return (tile_has_river(map_get_tile(x, y))
          || is_ocean_near_tile(x, y)
          || is_terrain_near_tile(x, y, T_RIVER)
          || is_special_near_tile(x, y, S_RIVER));
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.177
diff -u -r1.177 settlers.c
--- server/settlers.c   2004/01/11 17:45:06     1.177
+++ server/settlers.c   2004/01/17 19:15:43
@@ -525,19 +525,17 @@
 **************************************************************************/
 static bool is_wet(struct player *pplayer, int x, int y)
 {
-  enum tile_terrain_type t;
-  enum tile_special_type s;
+  struct tile *ptile;
 
   if (!pplayer->ai.control && !map_is_known(x, y, pplayer)) {
     return FALSE;
   }
 
-  t=map_get_terrain(x,y);
-  if (is_ocean(t) || t == T_RIVER) {
+  ptile = map_get_tile(x, y);
+  if (is_ocean(ptile->terrain) || tile_has_river(ptile)) {
     return TRUE;
   }
-  s=map_get_special(x,y);
-  if (contains_special(s, S_RIVER) || contains_special(s, S_IRRIGATION)) 
return TRUE;
+
   return FALSE;
 }
 
@@ -727,8 +725,8 @@
   struct tile *ptile = map_get_tile(mx, my);
 
   if (!is_ocean(ptile->terrain) &&
-      (((ptile->terrain != T_RIVER) && !tile_has_special(ptile, S_RIVER)) ||
-       player_knows_techs_with_flag(pplayer, TF_BRIDGE)) &&
+      (!tile_has_river(ptile)
+       || player_knows_techs_with_flag(pplayer, TF_BRIDGE)) &&
       !tile_has_special(ptile, S_ROAD)) {
     ptile->special|=S_ROAD; /* have to do this to avoid reset_move_costs -- 
Syela */
     m = city_tile_value(pcity, cx, cy, 0, 0);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7259) new function tile_has_river, Jason Short <=