Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2003:
[Freeciv-Dev] Re: (PR#6174) Loading transports
Home

[Freeciv-Dev] Re: (PR#6174) Loading transports

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#6174) Loading transports
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 Sep 2003 09:13:32 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Here's an elementary sanity check for the transported_by field.

Unfortunately, it fails.  Seems like a serious bug...

jason

? core.25071
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.31
diff -u -r1.31 sanitycheck.c
--- server/sanitycheck.c        2003/08/01 15:58:08     1.31
+++ server/sanitycheck.c        2003/09/16 16:04:34
@@ -22,11 +22,12 @@
 #include "log.h"
 #include "map.h"
 #include "player.h"
+#include "terrain.h"
 #include "unit.h"
 
 #include "maphand.h"
-
 #include "sanitycheck.h"
+#include "unittools.h"
 
 #ifndef NDEBUG
 
@@ -225,6 +226,22 @@
   } whole_map_iterate_end;
 }
 
+/****************************************************************************
+  Expensive function to check how many units are in the transport.
+****************************************************************************/
+static int get_transporter_occupancy(struct unit *ptrans)
+{
+  int occupied = 0;
+
+  unit_list_iterate(map_get_tile(ptrans->x, ptrans->y)->units, pcargo) {
+    if (pcargo->transported_by == ptrans->id) {
+      occupied++;
+    }
+  } unit_list_iterate_end;
+
+  return occupied;
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -261,6 +278,17 @@
 
       assert(punit->moves_left >= 0);
       assert(punit->hp > 0);
+
+      /* Check for ground units in the ocean. */
+      if (is_ocean(map_get_terrain(punit->x, punit->y))
+         && is_ground_unit(punit)) {
+       assert(punit->transported_by != -1);
+       assert(!is_ground_unit(find_unit_by_id(punit->transported_by)));
+      }
+
+      /* Check for over-full transports. */
+      assert(get_transporter_occupancy(punit)
+            <= get_transporter_capacity(punit));
     } unit_list_iterate_end;
   } players_iterate_end;
 }

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