Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[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: Wed, 29 Jun 2005 16:12:19 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Interestingly this patch applies almost without changes to 2.0.  Here's
the patch.  I haven't tested it nor do I have any immediate plans to
commit it to 2.0.  However if it gets a lot of testing and people like
it we could do so eventually.
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.74.2.5
diff -u -r1.74.2.5 goto.c
--- client/goto.c       15 Dec 2004 00:57:02 -0000      1.74.2.5
+++ client/goto.c       29 Jun 2005 23:11:20 -0000
@@ -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
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.103.2.4
diff -u -r1.103.2.4 options.c
--- client/options.c    10 Feb 2005 09:42:35 -0000      1.103.2.4
+++ client/options.c    29 Jun 2005 23:11:20 -0000
@@ -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")),
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.38.2.1
diff -u -r1.38.2.1 options.h
--- client/options.h    9 Oct 2004 16:00:37 -0000       1.38.2.1
+++ client/options.h    29 Jun 2005 23:11:20 -0000
@@ -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: common/aicore/path_finding.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/path_finding.c,v
retrieving revision 1.24.2.1
diff -u -r1.24.2.1 path_finding.c
--- common/aicore/path_finding.c        23 Oct 2004 19:15:20 -0000      1.24.2.1
+++ common/aicore/path_finding.c        29 Jun 2005 23:11:21 -0000
@@ -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,7 +357,7 @@
 
       /* 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);
@@ -909,7 +906,7 @@
 
       /* 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);
Index: common/aicore/path_finding.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/path_finding.h,v
retrieving revision 1.10
diff -u -r1.10 path_finding.h
--- common/aicore/path_finding.h        29 Sep 2004 02:24:23 -0000      1.10
+++ common/aicore/path_finding.h        29 Jun 2005 23:11:21 -0000
@@ -42,9 +42,11 @@
  *   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
+ *      very large value meaning unknown tiles are avoided.  It's also
+ *      possible to use 0 here and use TB or EC to control movement through
+ *      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 +217,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 +313,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
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/pf_tools.c,v
retrieving revision 1.23
diff -u -r1.23 pf_tools.c
--- common/aicore/pf_tools.c    29 Sep 2004 02:24:23 -0000      1.23
+++ common/aicore/pf_tools.c    29 Jun 2005 23:11:21 -0000
@@ -401,6 +401,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 +542,7 @@
                                            struct unit *punit)
 {
   parameter->turn_mode = TM_CAPPED;
+  parameter->unknown_MC = 10 * SINGLE_MOVE;
   parameter->get_TB = NULL;
   parameter->get_EC = NULL;
   parameter->is_pos_dangerous = NULL;

[Prev in Thread] Current Thread [Next in Thread]