Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2006:
[Freeciv-Dev] (PR#6977) Wish List: Goto into unknown area
Home

[Freeciv-Dev] (PR#6977) Wish List: Goto into unknown area

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx, ue80@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#6977) Wish List: Goto into unknown area
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 2 Jan 2006 18:50:34 -0800
Reply-to: bugs@xxxxxxxxxxx

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

By popular demand, here is a backport of the patch to S2_0.

Please test.

-jason

Index: common/aicore/path_finding.h
===================================================================
--- common/aicore/path_finding.h        (revision 11417)
+++ common/aicore/path_finding.h        (working copy)
@@ -42,9 +42,12 @@
  *   path: a list of steps which leads from the start to the end
  *
  *   move cost (MC): move cost of a _single_ step.  MC is always >= 0. 
- *   Note that the MC of a step is taken to be 0 if the target is
- *   unknown.  The idea is that the user can set the unknown move cost
- *   via EC callback.
+ *     [The parameter can specify what the MC of a step into the unknown is
+ *      to be (this is a constant for each map).  This defaults to a
+ *      slightly large value meaning unknown tiles are avoided slightly.
+ *      It's also possible to use 0 here and use TB or EC to control
+ *      movement through unknown tiles, or to use PF_IMPOSSIBLE_MC to
+ *      easily avoid unknown tiles.]
  *
  *   extra cost (EC): extra cost of a _single_ tile.  EC is always >= 0.
  *   The intended meaning for EC is "how much we want to avoid this tile",
@@ -215,8 +218,8 @@
  * path_finding_tools or a mix of these.
  *
  * Hints:
- * 1. Since MC into unknown is 0, it is useful to limit the expansion of 
- * unknown tiles with a get_TB callback.
+ * 1. It is useful to limit the expansion of unknown tiles with a get_TB
+ * callback.  In this case you might set the unknown_MC to be 0.
  * 2. If there are two paths of the same cost to a tile (x,y), you are
  * not guaranteed to get the one with the least steps in it.  If you care,
  * specifying EC to be 1 will do the job.
@@ -311,6 +314,7 @@
    * implementation of the callback. */
   int (*get_MC) (const struct tile *from_tile, enum direction8 dir,
                 const struct tile *to_tile, struct pf_parameter * param);
+  int unknown_MC; /* Move cost into unknown - very large by default */
 
   /* Callback which determines the behavior of a tile. If NULL
    * TB_NORMAL is assumed. It can be assumed that the implementation
Index: common/aicore/pf_tools.c
===================================================================
--- common/aicore/pf_tools.c    (revision 11417)
+++ common/aicore/pf_tools.c    (working copy)
@@ -20,6 +20,8 @@
 
 #include "mem.h"
 
+#include "game.h"
+
 #include "pf_tools.h"
 
 
@@ -401,6 +403,11 @@
                                     enum known_type known,
                                     struct pf_parameter *param)
 {
+  /* Assume that unknown tiles are unsafe. */
+  if (known == TILE_UNKNOWN) {
+    return TRUE;
+  }
+
   /* We test TER_UNSAFE even though under the current ruleset there is no
    * way for a trireme to be on a TER_UNSAFE tile. */
   /* Unsafe or unsafe-ocean tiles without cities are dangerous. */
@@ -537,6 +544,19 @@
                                            struct unit *punit)
 {
   parameter->turn_mode = TM_CAPPED;
+  if (is_air_unit(punit) || is_heli_unit(punit)) {
+    parameter->unknown_MC = SINGLE_MOVE;
+  } else if (is_sailing_unit(punit)) {
+    parameter->unknown_MC = 2 * SINGLE_MOVE;
+  } else {
+    assert(is_ground_unit(punit));
+    parameter->unknown_MC = SINGLE_MOVE;
+    terrain_type_iterate(t) {
+      int mr = 2 * get_tile_type(t)->movement_cost;
+
+      parameter->unknown_MC = MAX(mr, parameter->unknown_MC);
+    } terrain_type_iterate_end;
+  }
   parameter->get_TB = NULL;
   parameter->get_EC = NULL;
   parameter->is_pos_dangerous = NULL;
Index: common/aicore/path_finding.c
===================================================================
--- common/aicore/path_finding.c        (revision 11417)
+++ common/aicore/path_finding.c        (working copy)
@@ -27,9 +27,6 @@
 
 /* For explanations on how to use this module, see path_finding.h */
 
-/* Default move cost into the unknown (see path_finding.h) */
-#define MOVE_COST_UNKNOWN 0
-
 #define INITIAL_QUEUE_SIZE 100
 
 /* Since speed is quite important to us and alloccation of large arrays is
@@ -360,15 +357,18 @@
 
       /* Evaluate the cost of the move */
       if (node1->node_known_type == TILE_UNKNOWN) {
-       cost = MOVE_COST_UNKNOWN;
+       cost = pf_map->params->unknown_MC;
       } else {
        cost = pf_map->params->get_MC(pf_map->tile, dir, tile1,
                                      pf_map->params);
-       if (cost == PF_IMPOSSIBLE_MC) {
-         continue;
-       }
-       cost = adjust_cost(pf_map, cost);
       }
+      if (cost == PF_IMPOSSIBLE_MC) {
+       continue;
+      }
+      cost = adjust_cost(pf_map, cost);
+      if (cost == PF_IMPOSSIBLE_MC) {
+       continue;
+      }
 
       /* Total cost at xy1.  Cost may be negative; see get_turn(). */
       cost += node->cost;
@@ -909,19 +909,22 @@
 
       /* Evaluate the cost of the move */
       if (node1->node_known_type == TILE_UNKNOWN) {
-       cost = MOVE_COST_UNKNOWN;
+       cost = pf_map->params->unknown_MC;
       } else {
        cost = pf_map->params->get_MC(pf_map->tile, dir, tile1,
                                      pf_map->params);
-        cost = danger_adjust_cost(pf_map, cost, d_node1->is_dangerous,
-                                  get_moves_left(pf_map, loc_cost));
-        
-       if (cost == PF_IMPOSSIBLE_MC) {
-          /* This move is deemed impossible */
-         continue;
-       }
       }
+      if (cost == PF_IMPOSSIBLE_MC) {
+       continue;
+      }
+      cost = danger_adjust_cost(pf_map, cost, d_node1->is_dangerous,
+                               get_moves_left(pf_map, loc_cost));
 
+      if (cost == PF_IMPOSSIBLE_MC) {
+       /* This move is deemed impossible */
+       continue;
+      }
+
       /* Total cost at xy1 */
       cost += loc_cost;
 
Index: client/options.h
===================================================================
--- client/options.h    (revision 11417)
+++ client/options.h    (working copy)
@@ -36,6 +36,7 @@
 extern bool auto_center_on_unit;
 extern bool auto_center_on_combat;
 extern bool wakeup_focus;
+extern bool goto_into_unknown;
 extern bool center_when_popup_city;
 extern bool concise_city_production;
 extern bool auto_turn_done;
Index: client/goto.c
===================================================================
--- client/goto.c       (revision 11417)
+++ client/goto.c       (working copy)
@@ -349,10 +349,11 @@
                                       struct pf_parameter *param)
 {
   if (known == TILE_UNKNOWN) {
-    return TB_IGNORE;
-  }
-  if (is_non_allied_unit_tile(ptile, param->owner)
-      || is_non_allied_city_tile(ptile, param->owner)) {
+    if (!goto_into_unknown) {
+      return TB_IGNORE;
+    }
+  } else if (is_non_allied_unit_tile(ptile, param->owner)
+            || is_non_allied_city_tile(ptile, param->owner)) {
     /* Can attack but can't count on going through */
     return TB_DONT_LEAVE;
   }
@@ -368,7 +369,9 @@
                                         struct pf_parameter *param)
 {
   if (known == TILE_UNKNOWN) {
-    return TB_IGNORE;
+    if (!goto_into_unknown) {
+      return TB_IGNORE;
+    }
   } else if (is_non_allied_city_tile(ptile, param->owner)) {
     /* F_TRADE_ROUTE units can travel to, but not through, enemy cities.
      * FIXME: F_HELP_WONDER units cannot.  */
@@ -630,6 +633,22 @@
 }
 
 /********************************************************************** 
+  PF callback to prohibit going into the unknown (conditionally).  Also
+  makes sure we don't plan to attack anyone.
+***********************************************************************/
+static enum tile_behavior no_fights_or_unknown_goto(const struct tile *ptile,
+                                                   enum known_type known,
+                                                   struct pf_parameter *p)
+{
+  if (known == TILE_UNKNOWN && goto_into_unknown) {
+    /* Special case allowing goto into the unknown. */
+    return TB_NORMAL;
+  }
+
+  return no_fights_or_unknown(ptile, known, p);
+}
+
+/********************************************************************** 
   Fill the PF parameter with the correct client-goto values.
 ***********************************************************************/
 static void fill_client_goto_parameter(struct unit *punit,
@@ -671,7 +690,7 @@
             || unit_flag(punit, F_HELP_WONDER)) {
     parameter->get_TB = get_TB_caravan;
   } else {
-    parameter->get_TB = no_fights_or_unknown;
+    parameter->get_TB = no_fights_or_unknown_goto;
   }
 
   /* Note that in connect mode the "time" does not correspond to any actual
Index: client/options.c
===================================================================
--- client/options.c    (revision 11417)
+++ client/options.c    (working copy)
@@ -62,6 +62,7 @@
 bool auto_center_on_unit = TRUE;
 bool auto_center_on_combat = FALSE;
 bool wakeup_focus = TRUE;
+bool goto_into_unknown = TRUE;
 bool center_when_popup_city = TRUE;
 bool concise_city_production = FALSE;
 bool auto_turn_done = FALSE;
@@ -103,6 +104,7 @@
   GEN_BOOL_OPTION(auto_center_on_unit,      N_("Auto Center on Units")),
   GEN_BOOL_OPTION(auto_center_on_combat,    N_("Auto Center on Combat")),
   GEN_BOOL_OPTION(wakeup_focus,             N_("Focus on Awakened Units")),
+  GEN_BOOL_OPTION(goto_into_unknown, N_("Allow goto into the unknown")),
   GEN_BOOL_OPTION(center_when_popup_city,   N_("Center map when Popup city")),
   GEN_BOOL_OPTION(concise_city_production,  N_("Concise City Production")),
   GEN_BOOL_OPTION(auto_turn_done,           N_("End Turn when done moving")),

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#6977) Wish List: Goto into unknown area, Jason Short <=