Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] (PR#18400) [Patch] PF & is_native_terrain()
Home

[Freeciv-Dev] (PR#18400) [Patch] PF & is_native_terrain()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#18400) [Patch] PF & is_native_terrain()
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Sat, 8 Jul 2006 07:50:13 -0700
Reply-to: bugs@xxxxxxxxxxx

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


  This patch replaces is_ocean() checks with is_native_terrain() checks 
in pathfinding code. is_native_terrain() check added for air units. Now 
pathfinding should adapt when is_native_terrain() changes.

  Applies on top of #18390

  One problem I noticed while writing this; Air units entering city in 
non-native terrain are not handled correctly.


  - 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-08 17:03:41.218750000 +0300
+++ freeciv/common/aicore/pf_tools.c    2006-07-08 17:09:06.296875000 +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_ocean(ptile1->terrain)) {
+  if (is_native_terrain(param->utype, ptile1->terrain)) {
     return single_move_cost(param, ptile, ptile1);
   } else if (ptile1->city
              || is_non_allied_unit_tile(ptile1, param->owner)) {
@@ -72,6 +72,9 @@
                          const struct tile *ptile1,
                          struct pf_parameter *param)
 {
+  if (!is_native_terrain(param->utype, ptile1->terrain)) {
+    return PF_IMPOSSIBLE_MC;
+  }
   return single_move_cost(param, ptile, ptile1);
 }
 
@@ -83,7 +86,7 @@
                              const struct tile *ptile1,
                              struct pf_parameter *param)
 {
-  if (is_ocean(ptile1->terrain)) {
+  if (is_native_terrain(param->utype, ptile1->terrain)) {
     return single_move_cost(param, ptile, ptile1);
   } else if (is_allied_city_tile(ptile1, param->owner)) {
     /* Entering port */
@@ -105,11 +108,11 @@
                            struct pf_parameter *param)
 {
   if (is_allied_city_tile(ptile, param->owner)
-      && is_ocean(ptile1->terrain)) {
+      && is_native_terrain(param->utype, ptile1->terrain)) {
     return single_move_cost(param, ptile, ptile1);
-  } else if (!is_ocean(ptile->terrain)) {
+  } else if (!is_native_terrain(param->utype, ptile->terrain)) {
     return PF_IMPOSSIBLE_MC;
-  } else if (is_ocean(ptile1->terrain)) {
+  } else if (is_native_terrain(param->utype, ptile1->terrain)) {
     return single_move_cost(param, ptile, ptile1);
   } else {
     /* Entering port or bombardment */
@@ -125,16 +128,16 @@
                           const struct tile *dest_tile,
                           struct pf_parameter *param)
 {
-  if (is_ocean(src_tile->terrain)) {
+  if (is_native_terrain(param->utype, src_tile->terrain)) {
     if (is_non_allied_unit_tile(src_tile, param->owner)) {
       return PF_IMPOSSIBLE_MC;
     }
-    if (is_ocean(dest_tile->terrain)) {
+    if (is_native_terrain(param->utype, dest_tile->terrain)) {
       return single_move_cost(param, src_tile, dest_tile);
     }
     return SINGLE_MOVE;
   } else if (is_allied_city_tile(src_tile, param->owner)
-            && is_ocean(dest_tile->terrain)) {
+            && is_native_terrain(param->utype, dest_tile->terrain)) {
     return single_move_cost(param, src_tile, dest_tile);
   }
 
@@ -151,13 +154,13 @@
   struct terrain *terrain1 = ptile1->terrain;
   int move_cost;
 
-  if (is_ocean(terrain1)) {
+  if (!is_native_terrain(param->utype, terrain1)) {
     if (ground_unit_transporter_capacity(ptile1, param->owner) > 0) {
       move_cost = SINGLE_MOVE;
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (is_ocean(ptile->terrain)) {
+  } else if (!is_native_terrain(param->utype, ptile->terrain)) {
     if (!BV_ISSET(param->unit_flags, F_MARINES)
         && (is_non_allied_unit_tile(ptile1, param->owner) 
             || is_non_allied_city_tile(ptile1, param->owner))) {
@@ -182,7 +185,7 @@
 {
   int move_cost;
 
-  if (is_ocean(tgt_tile->terrain)) {
+  if (!is_native_terrain(param->utype, tgt_tile->terrain)) {
 
     /* Any-to-Sea */
     if (ground_unit_transporter_capacity(tgt_tile, param->owner) > 0) {
@@ -190,7 +193,7 @@
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (is_ocean(src_tile->terrain)) {
+  } else if (!is_native_terrain(param->utype, src_tile->terrain)) {
 
     /* Sea-to-Land. */
     if (!is_non_allied_unit_tile(tgt_tile, param->owner)
@@ -228,9 +231,9 @@
   one, so we don't venture too far into the ocean ;)
 
   Alternatively, we can change the flow to
-  if (is_ocean(ptile->terrain)) {
+  if (!is_native_terrain(param->utype, ptile->terrain)) {
     move_cost = PF_IMPOSSIBLE_MC;
-  } else if (is_ocean(terrain1)) {
+  } else if (!is_native_terrain(param->utype, terrain1)) {
     move_cost = SINGLE_MOVE;
   } else {
     move_cost = single_move_cost(param, ptile, ptile1);
@@ -244,7 +247,7 @@
   struct terrain *terrain1 = ptile1->terrain;
   int move_cost;
 
-  if (is_ocean(terrain1)) {
+  if (!is_native_terrain(param->utype, terrain1)) {
     move_cost = SINGLE_MOVE;
   } else {
     move_cost = single_move_cost(param, ptile, ptile1);
@@ -266,7 +269,7 @@
   struct terrain *terrain1 = ptile->terrain;
   int move_cost = PF_IMPOSSIBLE_MC;
 
-  if (is_ocean(terrain1)) {
+  if (!is_native_terrain(param->utype, terrain1)) {
     if (ground_unit_transporter_capacity(ptile, param->owner) > 0) {
       /* Landing */
       move_cost = terrain0->movement_cost * SINGLE_MOVE;
@@ -274,7 +277,7 @@
       /* Nothing to land from */
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (is_ocean(terrain0)) {
+  } else if (!is_native_terrain(param->utype, terrain0)) {
     /* Boarding */
     move_cost = SINGLE_MOVE;
   } else {
@@ -294,13 +297,13 @@
 {
   int move_cost;
 
-  if (is_ocean(ptile1->terrain)) {
+  if (!is_native_terrain(param->utype, ptile1->terrain)) {
     if (ground_unit_transporter_capacity(ptile1, param->owner) > 0) {
       move_cost = MOVE_COST_ROAD;
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (is_ocean(ptile->terrain)) {
+  } else if (!is_native_terrain(param->utype, ptile->terrain)) {
     if (!BV_ISSET(param->unit_flags, F_MARINES)
         && (is_non_allied_unit_tile(ptile1, param->owner) 
             || is_non_allied_city_tile(ptile1, param->owner))) {
@@ -330,14 +333,14 @@
 {
   int move_cost;
 
-  if (is_ocean(ptile->terrain)) {
+  if (!is_native_terrain(param->utype, ptile->terrain)) {
     if (ground_unit_transporter_capacity(ptile, param->owner) > 0) {
       /* Landing */
       move_cost = MOVE_COST_ROAD;
     } else {
       move_cost = PF_IMPOSSIBLE_MC;
     }
-  } else if (is_ocean(tile0->terrain)) {
+  } else if (!is_native_terrain(param->utype, tile0->terrain)) {
     /* Boarding */
     move_cost = MOVE_COST_ROAD;
   } else {
@@ -356,28 +359,33 @@
                           const struct tile *ptile1,
                           struct pf_parameter *param)
 {
-  const bool ocean = is_ocean(ptile->terrain);
-  const bool ocean1 = is_ocean(ptile1->terrain);
   struct pft_amphibious *amphibious = param->data;
+  const bool src_ferry = is_native_terrain(amphibious->sea.utype, 
ptile->terrain);
+  const bool dst_ferry = is_native_terrain(amphibious->sea.utype, 
ptile1->terrain);
+  const bool dst_psng = is_native_terrain(amphibious->land.utype, 
ptile1->terrain);
   int cost, scale;
 
-  if (ocean && ocean1) {
+  if (src_ferry && dst_ferry) {
     /* Sea move */
     cost = amphibious->sea.get_MC(ptile, dir, ptile1, &amphibious->sea);
     scale = amphibious->sea_scale;
-  } else if (ocean && is_allied_city_tile(ptile1, param->owner)) {
-    /* Entering port (same as sea move) */
+  } else if (src_ferry && is_allied_city_tile(ptile1, param->owner)) {
+    /* Moving from native terrain to a city. */
     cost = amphibious->sea.get_MC(ptile, dir, ptile1, &amphibious->sea);
     scale = amphibious->sea_scale;
-  } else if (ocean) {
+  } else if (src_ferry && dst_psng) {
     /* Disembark; use land movement function to handle F_MARINES */
     cost = amphibious->land.get_MC(ptile, dir, ptile1, &amphibious->land);
     scale = amphibious->land_scale;
-  } else if (is_allied_city_tile(ptile, param->owner) && ocean1) {
+  } else if (src_ferry) {
+    /* Neither ferry nor passenger can enter tile. */
+    cost = PF_IMPOSSIBLE_MC;
+    scale = amphibious->sea_scale;
+  } else if (is_allied_city_tile(ptile, param->owner) && dst_ferry) {
     /* Leaving port (same as sea move) */
     cost = amphibious->sea.get_MC(ptile, dir, ptile1, &amphibious->sea);
     scale = amphibious->sea_scale;
-  } else if (ocean1) {
+  } else if (!dst_psng) {
     /* Now we have disembarked, our ferry can not help us - we have to
      * stay on the land. */
     cost = PF_IMPOSSIBLE_MC;
@@ -420,18 +428,18 @@
                                 struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool ocean = is_ocean(ptile->terrain);
+  const bool ferry_move = is_native_terrain(amphibious->sea.utype, 
ptile->terrain);
   int cost, scale;
 
   if (known == TILE_UNKNOWN) {
     /* We can travel almost anywhere */
     cost = SINGLE_MOVE;
     scale = MAX(amphibious->sea_scale, amphibious->land_scale);
-  } else if (ocean && amphibious->sea.get_EC) {
+  } else if (ferry_move && amphibious->sea.get_EC) {
     /* Do the EC callback for sea moves. */
     cost = amphibious->sea.get_EC(ptile, known, &amphibious->sea);
     scale = amphibious->sea_scale;
-  } else if (!ocean && amphibious->land.get_EC) {
+  } else if (!ferry_move && amphibious->land.get_EC) {
     /* Do the EC callback for land moves. */
     cost = amphibious->land.get_EC(ptile, known, &amphibious->land);
     scale = amphibious->land_scale;
@@ -450,14 +458,14 @@
 /* ===================== Tile Behaviour Callbacks ==================== */
 
 /*********************************************************************
-  A callback for maps overlapping one square into the ocean.  Insures 
-  that we don't continue walking over ocean.
+  A callback for maps overlapping one square into the non-native
+  terrain.  Insures that we don't continue walking over ocean.
 *********************************************************************/
 static enum tile_behavior dont_cross_ocean(const struct tile *ptile,
                                           enum known_type known,
                                           struct pf_parameter *param)
 {
-  if (is_ocean(ptile->terrain)) {
+  if (!is_native_terrain(param->utype, ptile->terrain)) {
     return TB_DONT_LEAVE;
   }
   return TB_NORMAL;
@@ -516,12 +524,12 @@
                                               struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool ocean = is_ocean(ptile->terrain);
+  const bool ferry_move = is_native_terrain(amphibious->sea.utype, 
ptile->terrain);
 
   /* Simply a wrapper for the sea or land tile_behavior callbacks. */
-  if (ocean && amphibious->sea.get_TB) {
+  if (ferry_move && amphibious->sea.get_TB) {
     return amphibious->sea.get_TB(ptile, known, &amphibious->sea);
-  } else if (!ocean && amphibious->land.get_TB) {
+  } else if (!ferry_move && amphibious->land.get_TB) {
     return amphibious->land.get_TB(ptile, known, &amphibious->land);
   }
   return TB_NORMAL;
@@ -588,7 +596,7 @@
   /* Unsafe tiles without cities are dangerous. */
   /* Pretend all land tiles are safe. */
   return (ptile->city == NULL
-         && is_ocean(ptile->terrain)
+         && is_native_terrain(param->utype, ptile->terrain)
          && terrain_has_flag(ptile->terrain, TER_UNSAFE));
 }
 
@@ -612,12 +620,12 @@
                                        struct pf_parameter *param)
 {
   struct pft_amphibious *amphibious = param->data;
-  const bool ocean = is_ocean(ptile->terrain);
+  const bool ferry_move = is_native_terrain(amphibious->sea.utype, 
ptile->terrain);
 
   /* Simply a wrapper for the sea or land danger callbacks. */
-  if (ocean && amphibious->sea.is_pos_dangerous) {
+  if (ferry_move && amphibious->sea.is_pos_dangerous) {
     return amphibious->sea.is_pos_dangerous(ptile, known, param);
-  } else if (!ocean && amphibious->land.is_pos_dangerous) {
+  } else if (!ferry_move && amphibious->land.is_pos_dangerous) {
     return amphibious->land.is_pos_dangerous(ptile, known, param);
   }
   return FALSE;
@@ -693,7 +701,7 @@
 }
 
 /**********************************************************************
-  Switch on one tile overlapping into the sea/land.
+  Switch on one tile overlapping into the non-native terrain.
   For sea/land bombardment and for ferries.
 **********************************************************************/
 void pft_fill_unit_overlap_param(struct pf_parameter *parameter,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#18400) [Patch] PF & is_native_terrain(), Marko Lindqvist <=