Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] Re: (PR#18623) [Patch] is_native_tile()
Home

[Freeciv-Dev] Re: (PR#18623) [Patch] is_native_tile()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#18623) [Patch] is_native_tile()
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Sun, 16 Jul 2006 15:39:01 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18623 >

Marko Lindqvist wrote:
> 
>   Some interface changes in preparation for wheeled units.
> 
>   - Added functions is_native_tile() and is_native_tile_to_class(). Most 
> users of is_native_terrain() and is_native_to_class() converted to use 
> these.
>   - Added parameter 'bv_special special' to is_native_terrain() and 
> is_native_to_class().

  - Updated


  - ML

diff -Nurd -X.diff_ignore freeciv/common/aicore/pf_tools.c 
freeciv/common/aicore/pf_tools.c
--- freeciv/common/aicore/pf_tools.c    2006-07-16 18:48:37.437500000 +0300
+++ freeciv/common/aicore/pf_tools.c    2006-07-17 01:31:32.984375000 +0300
@@ -54,7 +54,7 @@
 static int seamove(const struct tile *ptile, enum direction8 dir,
                    const struct tile *ptile1, struct pf_parameter *param)
 {
-  if (is_native_to_class(param->class, ptile1->terrain)) {
+  if (is_native_tile_to_class(param->class, ptile1)) {
     return single_move_cost(param, ptile, ptile1);
   } else if (ptile1->city
              || is_non_allied_unit_tile(ptile1, param->owner)) {
@@ -72,9 +72,9 @@
                          const struct tile *ptile1,
                          struct pf_parameter *param)
 {
-  if (!ptile->city && !is_native_to_class(param->class, ptile1->terrain)) {
+  if (!ptile->city && !is_native_tile_to_class(param->class, ptile1)) {
     return PF_IMPOSSIBLE_MC;
-  } else if (!is_native_to_class(param->class, ptile1->terrain)) {
+  } else if (!is_native_tile_to_class(param->class, ptile1)) {
     return SINGLE_MOVE;
   }
   return single_move_cost(param, ptile, ptile1);
@@ -88,7 +88,7 @@
                              const struct tile *ptile1,
                              struct pf_parameter *param)
 {
-  if (is_native_to_class(param->class, ptile1->terrain)) {
+  if (is_native_tile_to_class(param->class, ptile1)) {
     return single_move_cost(param, ptile, ptile1);
   } else if (is_allied_city_tile(ptile1, param->owner)) {
     /* Entering port */
@@ -110,11 +110,11 @@
                            struct pf_parameter *param)
 {
   if (is_allied_city_tile(ptile, param->owner)
-      && is_native_to_class(param->class, ptile1->terrain)) {
+      && is_native_tile_to_class(param->class, ptile1)) {
     return single_move_cost(param, ptile, ptile1);
-  } else if (!is_native_to_class(param->class, ptile->terrain)) {
+  } else if (!is_native_tile_to_class(param->class, ptile)) {
     return PF_IMPOSSIBLE_MC;
-  } else if (is_native_to_class(param->class, ptile1->terrain)) {
+  } else if (is_native_tile_to_class(param->class, ptile1)) {
     return single_move_cost(param, ptile, ptile1);
   } else {
     /* Entering port or bombardment */
@@ -130,16 +130,16 @@
                           const struct tile *dest_tile,
                           struct pf_parameter *param)
 {
-  if (is_native_to_class(param->class, src_tile->terrain)) {
+  if (is_native_tile_to_class(param->class, src_tile)) {
     if (is_non_allied_unit_tile(src_tile, param->owner)) {
       return PF_IMPOSSIBLE_MC;
     }
-    if (is_native_to_class(param->class, dest_tile->terrain)) {
+    if (is_native_tile_to_class(param->class, dest_tile)) {
       return single_move_cost(param, src_tile, dest_tile);
     }
     return SINGLE_MOVE;
   } else if (is_allied_city_tile(src_tile, param->owner)
-            && is_native_to_class(param->class, dest_tile->terrain)) {
+            && is_native_tile_to_class(param->class, dest_tile)) {
     return single_move_cost(param, src_tile, dest_tile);
   }
 
@@ -153,16 +153,15 @@
                            const struct tile *ptile1,
                            struct pf_parameter *param)
 {
-  struct terrain *terrain1 = ptile1->terrain;
   int move_cost;
 
-  if (!is_native_to_class(param->class, terrain1)) {
+  if (!is_native_tile_to_class(param->class, ptile1)) {
     if (unit_class_transporter_capacity(ptile1, param->owner, param->class) > 
0) {
       move_cost = SINGLE_MOVE;
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (!is_native_to_class(param->class, ptile->terrain)) {
+  } else if (!is_native_tile_to_class(param->class, ptile)) {
     if (!BV_ISSET(param->unit_flags, F_MARINES)
         && (is_non_allied_unit_tile(ptile1, param->owner) 
             || is_non_allied_city_tile(ptile1, param->owner))) {
@@ -187,7 +186,7 @@
 {
   int move_cost;
 
-  if (!is_native_to_class(param->class, tgt_tile->terrain)) {
+  if (!is_native_tile_to_class(param->class, tgt_tile)) {
 
     /* Any-to-Sea */
     if (unit_class_transporter_capacity(tgt_tile, param->owner, param->class) 
> 0) {
@@ -195,7 +194,7 @@
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (!is_native_to_class(param->class, src_tile->terrain)) {
+  } else if (!is_native_tile_to_class(param->class, src_tile)) {
 
     /* Sea-to-Land. */
     if (!is_non_allied_unit_tile(tgt_tile, param->owner)
@@ -233,9 +232,9 @@
   one, so we don't venture too far into the ocean ;)
 
   Alternatively, we can change the flow to
-  if (!is_native_to_class(param->class, ptile->terrain)) {
+  if (!is_native_tile_to_class(param->class, ptile)) {
     move_cost = PF_IMPOSSIBLE_MC;
-  } else if (!is_native_to_class(param->class, terrain1)) {
+  } else if (!is_native_tile_to_class(param->class, ptile1)) {
     move_cost = SINGLE_MOVE;
   } else {
     move_cost = single_move_cost(param, ptile, ptile1);
@@ -246,10 +245,9 @@
                             const struct tile *ptile1,
                             struct pf_parameter *param)
 {
-  struct terrain *terrain1 = ptile1->terrain;
   int move_cost;
 
-  if (!is_native_to_class(param->class, terrain1)) {
+  if (!is_native_tile_to_class(param->class, ptile1)) {
     move_cost = SINGLE_MOVE;
   } else {
     move_cost = single_move_cost(param, ptile, ptile1);
@@ -267,11 +265,9 @@
                             const struct tile *ptile,
                             struct pf_parameter *param)
 {
-  struct terrain *terrain0 = tile0->terrain;
-  struct terrain *terrain1 = ptile->terrain;
   int move_cost = PF_IMPOSSIBLE_MC;
 
-  if (!is_native_to_class(param->class, terrain1)) {
+  if (!is_native_to_class(param->class, ptile)) {
     if (unit_class_transporter_capacity(ptile, param->owner, param->class) > 
0) {
       /* Landing */
       move_cost = terrain0->movement_cost * SINGLE_MOVE;
@@ -279,7 +275,7 @@
       /* Nothing to land from */
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (!is_native_to_class(param->class, terrain0)) {
+  } else if (!is_native_tile_to_class(param->class, tile0)) {
     /* Boarding */
     move_cost = SINGLE_MOVE;
   } else {
@@ -299,13 +295,13 @@
 {
   int move_cost;
 
-  if (!is_native_to_class(param->class, ptile1->terrain)) {
+  if (!is_native_tile_to_class(param->class, ptile1)) {
     if (unit_class_transporter_capacity(ptile1, param->owner, param->class) > 
0) {
       move_cost = MOVE_COST_ROAD;
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (!is_native_to_class(param->class, ptile->terrain)) {
+  } else if (!is_native_tile_to_class(param->class, ptile)) {
     if (!BV_ISSET(param->unit_flags, F_MARINES)
         && (is_non_allied_unit_tile(ptile1, param->owner) 
             || is_non_allied_city_tile(ptile1, param->owner))) {
@@ -334,14 +330,14 @@
 {
   int move_cost;
 
-  if (!is_native_to_class(param->class, ptile->terrain)) {
+  if (!is_native_to_class(param->class, ptile)) {
     if (unit_class_transporter_capacity(ptile, param->owner, param->class) > 
0) {
       /* Landing */
       move_cost = MOVE_COST_ROAD;
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (!is_native_to_class(param->class, tile0->terrain)) {
+  } else if (!is_native_to_class(param->class, tile0)) {
     /* Boarding */
     move_cost = MOVE_COST_ROAD;
   } else {
@@ -361,9 +357,9 @@
                           struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool src_ferry = is_native_to_class(amphibious->sea.class, 
ptile->terrain);
-  const bool dst_ferry = is_native_to_class(amphibious->sea.class, 
ptile1->terrain);
-  const bool dst_psng = is_native_to_class(amphibious->land.class, 
ptile1->terrain);
+  const bool src_ferry = is_native_tile_to_class(amphibious->sea.class, ptile);
+  const bool dst_ferry = is_native_tile_to_class(amphibious->sea.class, 
ptile1);
+  const bool dst_psng = is_native_tile_to_class(amphibious->land.class, 
ptile1);
   int cost, scale;
 
   if (src_ferry && dst_ferry) {
@@ -429,7 +425,7 @@
                                 struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool ferry_move = is_native_to_class(amphibious->sea.class, 
ptile->terrain);
+  const bool ferry_move = is_native_tile_to_class(amphibious->sea.class, 
ptile);
   int cost, scale;
 
   if (known == TILE_UNKNOWN) {
@@ -466,7 +462,7 @@
                                           enum known_type known,
                                           struct pf_parameter *param)
 {
-  if (!is_native_to_class(param->class, ptile->terrain)) {
+  if (!is_native_tile_to_class(param->class, ptile)) {
     return TB_DONT_LEAVE;
   }
   return TB_NORMAL;
@@ -525,7 +521,7 @@
                                               struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool ferry_move = is_native_to_class(amphibious->sea.class, 
ptile->terrain);
+  const bool ferry_move = is_native_tile_to_class(amphibious->sea.class, 
ptile);
 
   /* Simply a wrapper for the sea or land tile_behavior callbacks. */
   if (ferry_move && amphibious->sea.get_TB) {
@@ -597,7 +593,7 @@
   /* Unsafe tiles without cities are dangerous. */
   /* Pretend all land tiles are safe. */
   return (ptile->city == NULL
-         && is_native_to_class(param->class, ptile->terrain)
+         && is_native_tile_to_class(param->class, ptile)
          && terrain_has_flag(ptile->terrain, TER_UNSAFE));
 }
 
@@ -621,7 +617,7 @@
                                        struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool ferry_move = is_native_to_class(amphibious->sea.class, 
ptile->terrain);
+  const bool ferry_move = is_native_tile_to_class(amphibious->sea.class, 
ptile);
 
   /* Simply a wrapper for the sea or land danger callbacks. */
   if (ferry_move && amphibious->sea.is_pos_dangerous) {
diff -Nurd -X.diff_ignore freeciv/common/map.c freeciv/common/map.c
--- freeciv/common/map.c        2006-07-16 18:48:38.109375000 +0300
+++ freeciv/common/map.c        2006-07-17 01:28:31.703125000 +0300
@@ -623,7 +623,7 @@
 
   if (punit) {
     pclass = get_unit_class(punit->type);
-    native = is_native_terrain(punit->type, t2->terrain);
+    native = is_native_tile(punit->type, t2);
   }
 
   if (game.info.slow_invasions
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2006-07-16 18:48:38.203125000 +0300
+++ freeciv/common/movement.c   2006-07-17 01:28:31.843750000 +0300
@@ -175,25 +175,52 @@
     return TRUE;
   }
 
-  return is_native_terrain(punit->type, ptile->terrain);
+  return is_native_tile(punit->type, ptile);
 }
 
 /****************************************************************************
-  This terrain is native to unit. Units that require fuel dont survive
-  even on native terrain. All terrains are native to air units.
+  This tile is native to unit.
+
+  See is_native_to_class()
+****************************************************************************/
+bool is_native_tile(const struct unit_type *punittype,
+                    const struct tile *ptile)
+{
+  return is_native_to_class(get_unit_class(punittype), ptile->terrain,
+                            ptile->special);
+}
+
+
+/****************************************************************************
+  This terrain is native to unit.
+
+  See is_native_to_class()
 ****************************************************************************/
 bool is_native_terrain(const struct unit_type *punittype,
-                       const struct terrain *pterrain)
+                       const struct terrain *pterrain,
+                       bv_special special)
 {
-  return is_native_to_class(get_unit_class(punittype), pterrain);
+  return is_native_to_class(get_unit_class(punittype), pterrain, special);
+}
+
+/****************************************************************************
+  This tile is native to unit class.
+
+  See is_native_to_class()
+****************************************************************************/
+bool is_native_tile_to_class(const struct unit_class *punitclass,
+                             const struct tile *ptile)
+{
+  return is_native_to_class(punitclass, ptile->terrain, ptile->special);
 }
 
 /****************************************************************************
   This terrain is native to unit class. Units that require fuel dont survive
-  even on native terrain. All terrains are native to air units.
+  even on native terrain.
 ****************************************************************************/
 bool is_native_to_class(const struct unit_class *punitclass,
-                        const struct terrain *pterrain)
+                        const struct terrain *pterrain,
+                        bv_special special)
 {
   if (!pterrain) {
     /* Unknown is considered native terrain */
@@ -501,7 +528,7 @@
   unit_list_iterate(ptile->units, ptransport) {
     if (get_transporter_capacity(ptransport) > 
get_transporter_occupancy(ptransport)
         && can_unit_transport(ptransport, punit)
-        && is_native_terrain(unit_type(ptransport), ptile->terrain)) {
+        && is_native_tile(unit_type(ptransport), ptile)) {
       return ptransport;
     }
   } unit_list_iterate_end;
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h   2006-07-16 18:48:38.234375000 +0300
+++ freeciv/common/movement.h   2006-07-17 01:28:31.875000000 +0300
@@ -30,10 +30,16 @@
 bool is_heli_unittype(const struct unit_type *punittype);
 bool is_ground_unittype(const struct unit_type *punittype);
 
+bool is_native_tile(const struct unit_type *punittype,
+                    const struct tile *ptile);
+bool is_native_tile_to_class(const struct unit_class *punitclass,
+                             const struct tile *ptile);
 bool is_native_terrain(const struct unit_type *punittype,
-                       const struct terrain *pterrain);
+                       const struct terrain *pterrain,
+                       bv_special special);
 bool is_native_to_class(const struct unit_class *punitclass,
-                        const struct terrain *pterrain);
+                        const struct terrain *pterrain,
+                        bv_special special);
 bool can_unit_exist_at_tile(const struct unit *punit, const struct tile 
*ptile);
 bool can_unit_survive_at_tile(const struct unit *punit,
                              const struct tile *ptile);
diff -Nurd -X.diff_ignore freeciv/server/edithand.c freeciv/server/edithand.c
--- freeciv/server/edithand.c   2006-07-16 18:50:51.109375000 +0300
+++ freeciv/server/edithand.c   2006-07-17 01:28:31.906250000 +0300
@@ -134,7 +134,7 @@
     if (!(ptile->city
          && !(is_sailing_unittype(punittype)
               && !is_ocean_near_tile(ptile)))
-       && !is_native_terrain(punittype, ptile->terrain)) {
+       && !is_native_tile(punittype, ptile)) {
       notify_player(pplayer, ptile, E_BAD_COMMAND,
                     _("Cannot create %s unit on this terrain."),
                     punittype->name);
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2006-07-16 18:50:56.578125000 +0300
+++ freeciv/server/unittools.c  2006-07-17 01:28:31.953125000 +0300
@@ -2070,7 +2070,8 @@
 
   /* Safe terrain according to player map? */
   if (!is_native_terrain(punit->type,
-                         map_get_player_tile(ptile, pplayer)->terrain)) {
+                         map_get_player_tile(ptile, pplayer)->terrain,
+                         map_get_player_tile(ptile, pplayer)->special)) {
     notify_player(pplayer, ptile, E_BAD_COMMAND,
                      _("This unit cannot paradrop into %s."),
                        get_name(map_get_player_tile(ptile, pplayer)->terrain));

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#18623) [Patch] is_native_tile(), Marko Lindqvist <=