Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2003:
[Freeciv-Dev] Re: (PR#4017) Few bugfixes for PF
Home

[Freeciv-Dev] Re: (PR#4017) Few bugfixes for PF

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] Re: (PR#4017) Few bugfixes for PF
From: "Gregory Berkolaiko" <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Thu, 17 Apr 2003 11:34:58 -0700
Reply-to: rt@xxxxxxxxxxxxxx

I attached a slightly incorrect patch...

On Thu, 17 Apr 2003, Gregory Berkolaiko wrote:

> 
> Hi,
> 
> Attached is a patch fixing a couple of bugs in the PF, namely
> * ZoC should not prevent us from attacking an enemy
> * we shouldn't attempt to go back further than the initial point of a path
> * if a path to a dangerous tile is requested, return NULL instead of
> crashing
> * correctly print undefined paths (instead of segfaulting).
> 
> G.
> 
> 

? pf_fix.diff
? trir.gz
Index: common/aicore/path_finding.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/path_finding.c,v
retrieving revision 1.2
diff -u -r1.2 path_finding.c
--- common/aicore/path_finding.c        2003/03/21 20:49:27     1.2
+++ common/aicore/path_finding.c        2003/04/17 17:01:41
@@ -208,9 +208,12 @@
     bool my_zoc = (tile->city || tile->terrain == T_OCEAN
                   || is_my_zoc(params->owner, x, y));
     bool allied = (is_allied_unit_tile(tile, params->owner) != NULL);
+    bool enemy = (is_enemy_unit_tile(tile, params->owner) != NULL);
 
     /* if my zoc 2 else if allied 1 else 0 */
-    node->zoc_number = (my_zoc ? 2 : (allied ? 1 : 0));
+    /* Essentially, enemy tile is like allied tile, we should be allowed
+     * to go there (attack), but not to leave, necessarily */
+    node->zoc_number = (my_zoc ? 2 : ((allied || enemy) ? 1 : 0));
   }
 
   /* Evaluate the extra cost of the destination */
@@ -576,8 +579,8 @@
 
     dir_next = node->dir_to_here;
 
-    /* Step further back */
-    if (!MAPSTEP(x, y, x, y, DIR_REVERSE(dir_next))) {
+    /* Step further back, if we haven't finished yet */
+    if (i > 0 && !MAPSTEP(x, y, x, y, DIR_REVERSE(dir_next))) {
       die("pf_next_get_path: wrong directions recorded!");
       return NULL;
     }
@@ -633,14 +636,20 @@
 {
   int i;
 
-  freelog(log_level, "PF: path (at %p) consists of %d positions:", path,
-         path->length);
+  if (path) {
+    freelog(log_level, "PF: path (at %p) consists of %d positions:", path,
+           path->length);
+  } else {
+    freelog(log_level, "PF: path is NULL");
+    return;
+  }
 
   for (i = 0; i < path->length; i++) {
     freelog(log_level,
-           "PF:   %2d/%2d: (%2d,%2d) cost=%2d (%2d, %d) EC=%d",
+           "PF:   %2d/%2d: (%2d,%2d) dir=%2s cost=%2d (%2d, %d) EC=%d",
            i + 1, path->length,
            path->positions[i].x, path->positions[i].y,
+           dir_get_name(path->positions[i].dir_to_next_pos),
            path->positions[i].total_MC, path->positions[i].turn,
            path->positions[i].moves_left, path->positions[i].total_EC);
   }
@@ -942,6 +951,13 @@
     die("illegal TM in path-finding with danger");
     return NULL;
   }
+
+  if (d_node->is_dangerous) {
+    /* "Best" path to a dangerous tile is undefined */
+    /* TODO: return the "safest" path */
+    return NULL;
+  }
+
 
   path->positions 
     = fc_malloc((d_node->step + 1) * sizeof(struct pf_position));

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#4017) Few bugfixes for PF, Gregory Berkolaiko <=