Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11376) die() in the sanity check code
Home

[Freeciv-Dev] (PR#11376) die() in the sanity check code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11376) die() in the sanity check code
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Dec 2004 23:37:27 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Here's a patch to remove it.  SANITY_CHECK is used along with some
corrective code.

-jason

Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.56
diff -u -r1.56 sanitycheck.c
--- server/sanitycheck.c        8 Dec 2004 04:28:26 -0000       1.56
+++ server/sanitycheck.c        15 Dec 2004 07:37:00 -0000
@@ -258,10 +258,30 @@
     }
   } city_map_iterate_end;
   if (workers + city_specialists(pcity) != pcity->size + 1) {
-    die("%s is illegal (size%d w%d s%s) in %s line %d",
-       pcity->name, pcity->size, workers,
-       specialists_string(pcity->specialists), file, line);
+    int diff = pcity->size + 1 - workers - city_specialists(pcity);
 
+    SANITY_CHECK(workers + city_specialists(pcity) == pcity->size + 1);
+    if (diff > 0) {
+      pcity->specialists[DEFAULT_SPECIALIST] += diff;
+    } else if (diff < 0) {
+      specialist_type_iterate(sp) {
+       int num = MIN(-diff, pcity->specialists[sp]);
+
+       diff += num;
+       pcity->specialists[sp] -= num;
+      } specialist_type_iterate_end;
+
+      if (diff < 0) {
+       city_map_checked_iterate(pcity->tile, city_x, city_y, ptile) {
+         if (ptile->worked == pcity && diff < 0) {
+           server_remove_worker_city(pcity, city_x, city_y);
+           diff++;
+         }
+       } city_map_checked_iterate_end;
+      }
+    }
+
+    generic_city_refresh(pcity, TRUE, NULL);
   }
 }
 

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