Complete.Org: Mailing Lists: Archives: freeciv-ai: August 2003:
[freeciv-ai] virtual cleanup (PR#4672)
Home

[freeciv-ai] virtual cleanup (PR#4672)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [freeciv-ai] virtual cleanup (PR#4672)
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sat, 9 Aug 2003 12:49:34 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch sets some extra variables in the new virtual unit and city
functions, removes one unused AI variable from pcity, and adds the use of
the virtual functions to savegame.c.

This should fix ticket "#4672 more uninitialized AI values".

  - Per

"This is the future for the world we're in at the moment,"
promised Lawrence Di Rita, special assistant to Rumsfeld.
"We'll get better as we do it more often."

Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.193
diff -u -r1.193 city.c
--- common/city.c       21 Jul 2003 01:19:36 -0000      1.193
+++ common/city.c       9 Aug 2003 19:45:10 -0000
@@ -2522,10 +2522,15 @@
 
   pcity->ai.trade_want = 1; /* we always want some */
   memset(pcity->ai.building_want, 0, sizeof(pcity->ai.building_want));
-  pcity->ai.workremain = 1; /* there's always work to be done! */
   pcity->ai.danger = 0;
   pcity->ai.urgency = 0;
   pcity->ai.grave_danger = 0;
+  pcity->ai.wallvalue = 0;
+  pcity->ai.downtown = 0;
+  pcity->ai.invasion = 0;
+  pcity->ai.bcost = 0;
+  pcity->ai.attack = 0;
+
   pcity->corruption = 0;
   pcity->shield_waste = 0;
   pcity->shield_bonus = 100;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.134
diff -u -r1.134 city.h
--- common/city.h       1 Aug 2003 19:58:47 -0000       1.134
+++ common/city.h       9 Aug 2003 19:45:10 -0000
@@ -167,10 +167,9 @@
 };
 
 struct ai_city {
-  int workremain;
-
   /* building desirabilities - easiest to handle them here -- Syela */
   int building_want[B_LAST];    /* not sure these will always be < 256 */
+
   int danger;                   /* danger to be compared to assess_defense */
   bool diplomat_threat;         /* enemy diplomat or spy is near the city */
   bool has_diplomat;            /* this city has diplomat or spy defender */
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.132
diff -u -r1.132 savegame.c
--- server/savegame.c   9 Aug 2003 03:30:44 -0000       1.132
+++ server/savegame.c   9 Aug 2003 19:45:10 -0000
@@ -782,29 +782,18 @@
   city_list_init(&plr->cities);
   ncities=secfile_lookup_int(file, "player%d.ncities", plrno);
   
-  for(i=0; i<ncities; i++) { /* read the cities */
+  for (i = 0; i < ncities; i++) { /* read the cities */
     struct city *pcity;
-    
-    pcity=fc_malloc(sizeof(struct city));
-    pcity->ai.trade_want = TRADE_WEIGHTING;
-    memset(pcity->ai.building_want, 0, sizeof(pcity->ai.building_want));
-    pcity->ai.workremain = 1; /* there's always work to be done! */
-    pcity->ai.danger = -1; /* flag, may come in handy later */
-    pcity->corruption = 0;
-    pcity->shield_waste = 0;
-    pcity->shield_bonus = 100;
-    pcity->tax_bonus = 100;
-    pcity->science_bonus = 100;
- 
+
+    pcity = create_city_virtual(plr,
+                      secfile_lookup_int(file, "player%d.c%d.x", plrno, i),
+                      secfile_lookup_int(file, "player%d.c%d.y", plrno, i),
+                      secfile_lookup_str(file, "player%d.c%d.name", plrno, i));
+
     pcity->id=secfile_lookup_int(file, "player%d.c%d.id", plrno, i);
     alloc_id(pcity->id);
     idex_register_city(pcity);
-    pcity->owner=plrno;
-    pcity->x=secfile_lookup_int(file, "player%d.c%d.x", plrno, i);
-    pcity->y=secfile_lookup_int(file, "player%d.c%d.y", plrno, i);
     
-    sz_strlcpy(pcity->name,
-              secfile_lookup_str(file, "player%d.c%d.name", plrno, i));
     if (section_file_lookup(file, "player%d.c%d.original", plrno, i))
       pcity->original = secfile_lookup_int(file, "player%d.c%d.original", 
                                           plrno,i);
@@ -872,11 +861,10 @@
     pcity->did_sell =
       secfile_lookup_bool_default(file, FALSE, "player%d.c%d.did_sell", 
plrno,i);
     
-    if (game.version >=10300) 
+    if (game.version >= 10300) {
       pcity->airlift=secfile_lookup_bool(file,
                                        "player%d.c%d.airlift", plrno,i);
-    else
-      pcity->airlift = FALSE;
+    }
 
     pcity->city_options =
       secfile_lookup_int_default(file, CITYOPT_DEFAULT,
@@ -977,28 +965,25 @@
   for(i=0; i<nunits; i++) { /* read the units */
     struct unit *punit;
     struct city *pcity;
-    
-    punit=fc_malloc(sizeof(struct unit));
+
+    punit = create_unit_virtual(plr, NULL, 
+                  secfile_lookup_int(file, "player%d.u%d.type", plrno, i),
+                  secfile_lookup_bool(file, "player%d.u%d.veteran", plrno, i));
     punit->id=secfile_lookup_int(file, "player%d.u%d.id", plrno, i);
     alloc_id(punit->id);
     idex_register_unit(punit);
-    punit->owner=plrno;
     punit->x=secfile_lookup_int(file, "player%d.u%d.x", plrno, i);
     punit->y=secfile_lookup_int(file, "player%d.u%d.y", plrno, i);
 
-    punit->veteran=secfile_lookup_bool(file, "player%d.u%d.veteran", plrno, i);
     punit->foul=secfile_lookup_bool_default(file, FALSE, "player%d.u%d.foul",
                                           plrno, i);
     punit->homecity=secfile_lookup_int(file, "player%d.u%d.homecity",
                                       plrno, i);
 
-    if((pcity=find_city_by_id(punit->homecity)))
+    if ((pcity = find_city_by_id(punit->homecity))) {
       unit_list_insert(&pcity->units_supported, punit);
-    else
-      punit->homecity=0;
+    }
     
-    punit->type=secfile_lookup_int(file, "player%d.u%d.type", plrno, i);
-
     punit->moves_left=secfile_lookup_int(file, "player%d.u%d.moves", plrno, i);
     punit->fuel= secfile_lookup_int(file, "player%d.u%d.fuel", plrno, i);
     set_unit_activity(punit, secfile_lookup_int(file, 
"player%d.u%d.activity",plrno, i));
@@ -1026,13 +1011,7 @@
     }
 
     punit->ai.control=secfile_lookup_bool(file, "player%d.u%d.ai", plrno,i);
-    punit->ai.ai_role = AIUNIT_NONE;
-    punit->ai.ferryboat = 0;
-    punit->ai.passenger = 0;
-    punit->ai.bodyguard = 0;
-    punit->ai.charge = 0;
     punit->hp=secfile_lookup_int(file, "player%d.u%d.hp", plrno, i);
-    punit->bribe_cost=-1;      /* flag value */
     
     punit->ord_map=secfile_lookup_int_default(file, 0, "player%d.u%d.ord_map",
                                              plrno, i);
@@ -1051,10 +1030,6 @@
        otherwise these don't get initialized (and AI calculations
        etc may use junk values).
     */
-    punit->unhappiness = 0;
-    punit->upkeep      = 0;
-    punit->upkeep_food = 0;
-    punit->upkeep_gold = 0;
 
     /* load the goto route */
     {

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