Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2835) aiunit topology fix
Home

[Freeciv-Dev] (PR#2835) aiunit topology fix

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2835) aiunit topology fix
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Wed, 15 Jan 2003 22:04:26 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Currently the coordinates (0,0) are used to indicate a unit has no goto 
destination specified.  These are fundamentally bad, since there is 
generally no means of checking if this is a valid destination.

This is a problem, and should be fixed.

But in one situation (that is known of), it leads to segfault if (0,0) 
is not a real/normal map position.  The attached patch "fixes" this by 
simply detecting the problem.

This isn't intended as a "real" fix for this problem.  A better solution 
would be to use a label that cannot be confused - like NULL or (-1,-1) - 
to mark an invalid goto destination.  All this patch does is avoid a 
segfault in this situation with gen-topologies.  And this is not the 
only possible workaround; if anyone has a better patch please come 
forward with it.

AFAIK, this is the only *fatal* bug in the AI code with gen-topologies.

jason

Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.253
diff -u -r1.253 aiunit.c
--- ai/aiunit.c 2003/01/12 22:24:04     1.253
+++ ai/aiunit.c 2003/01/16 05:57:01
@@ -2316,7 +2316,12 @@
       if (punit->ai.passenger == 0) punit->ai.passenger = aunit->id; /* oops */
       p++;
       bodyguard = unit_list_find(&map_get_tile(punit->x, punit->y)->units, 
aunit->ai.bodyguard);
-      pcity = map_get_city(aunit->goto_dest_x, aunit->goto_dest_y);
+      if (is_normal_map_pos(aunit->goto_dest_x, aunit->goto_dest_y)) {
+       pcity = map_get_city(aunit->goto_dest_x, aunit->goto_dest_y);
+      } else {
+       /* FIXME: currently (0,0) is used for an "empty" goto */
+       pcity = NULL;
+      }
       if (aunit->ai.bodyguard == BODYGUARD_NONE || bodyguard ||
          (pcity && pcity->ai.invasion >= 2)) {
        if (pcity) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2835) aiunit topology fix, Jason Short via RT <=