Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11485) put base citizen output into an array
Home

[Freeciv-Dev] (PR#11485) put base citizen output into an array

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11485) put base citizen output into an array
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 11 Dec 2004 17:19:31 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch puts base citizen output (output just from citizens, 
including NO bonuses) into an array pcity->citizen_base[].

One could argue this is not worthwhile, since the only such value 
currently used is the tile_trade.  However I think in the long run doing 
things consistently will give better results.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.443
diff -u -r1.443 packhand.c
--- client/packhand.c   11 Dec 2004 10:34:46 -0000      1.443
+++ client/packhand.c   12 Dec 2004 01:06:08 -0000
@@ -460,8 +460,8 @@
     pcity->surplus[o] = packet->surplus[o];
     pcity->waste[o] = packet->waste[o];
     pcity->prod[o] = packet->prod[o];
+    pcity->citizen_base[o] = packet->citizen_base[o];
   } output_type_iterate_end;
-  pcity->tile_trade=packet->tile_trade;
 
   pcity->food_stock=packet->food_stock;
   pcity->shield_stock=packet->shield_stock;
@@ -692,7 +692,9 @@
   sz_strlcpy(pcity->name, packet->name);
   
   pcity->size=packet->size;
-  pcity->tile_trade = packet->tile_trade;
+
+  /* HACK: special case for trade routes */
+  pcity->citizen_base[O_TRADE] = packet->tile_trade;
 
   /* We can't actually see the internals of the city, but the server tells
    * us this much. */
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.281
diff -u -r1.281 city.c
--- common/city.c       11 Dec 2004 10:41:26 -0000      1.281
+++ common/city.c       12 Dec 2004 01:06:08 -0000
@@ -1008,7 +1008,8 @@
   int bonus = 0;
 
   if (pc1 && pc2) {
-    bonus = (pc1->tile_trade + pc2->tile_trade + 4) / 8;
+    bonus = (pc1->citizen_base[O_TRADE]
+            + pc2->citizen_base[O_TRADE] + 4) / 8;
 
     /* Double if on different continents. */
     if (map_get_continent(pc1->tile) != map_get_continent(pc2->tile)) {
@@ -1732,6 +1733,10 @@
   pcity->prod[O_SCIENCE] += output[O_SCIENCE];
   pcity->prod[O_GOLD] += output[O_GOLD];
 
+  pcity->citizen_base[O_LUXURY] = output[O_LUXURY];
+  pcity->citizen_base[O_SCIENCE] = output[O_SCIENCE];
+  pcity->citizen_base[O_GOLD] = output[O_GOLD];
+
   pcity->prod[O_GOLD] += get_city_tithes_bonus(pcity);
 }
 
@@ -2014,8 +2019,11 @@
   pcity->prod[O_FOOD] = output[O_FOOD];
   pcity->prod[O_SHIELD] = output[O_SHIELD];
   pcity->surplus[O_TRADE] = output[O_TRADE];
-  
-  pcity->tile_trade = pcity->surplus[O_TRADE];
+
+  pcity->citizen_base[O_FOOD] = pcity->prod[O_FOOD];
+  pcity->citizen_base[O_SHIELD] = pcity->prod[O_SHIELD];
+  pcity->citizen_base[O_TRADE] = pcity->surplus[O_TRADE];
+
   pcity->surplus[O_FOOD] = pcity->prod[O_FOOD] - pcity->size * 2;
 
   for (i = 0; i < NUM_TRADEROUTES; i++) {
@@ -2171,7 +2179,7 @@
                          void (*send_unit_info) (struct player * pplayer,
                                                  struct unit * punit))
 {
-  int prev_tile_trade = pcity->tile_trade;
+  int prev_tile_trade = pcity->citizen_base[O_TRADE];
 
   set_food_trade_shields(pcity);
   citizen_happy_size(pcity);
@@ -2185,7 +2193,8 @@
   citizen_happy_wonders(pcity);        /* happy wonders & fundamentalism */
   unhappy_city_check(pcity);
 
-  if (refresh_trade_route_cities && pcity->tile_trade != prev_tile_trade) {
+  if (refresh_trade_route_cities
+      && pcity->citizen_base[O_TRADE] != prev_tile_trade) {
     int i;
 
     for (i = 0; i < NUM_TRADEROUTES; i++) {
@@ -2457,8 +2466,6 @@
   }
   pcity->food_stock = 0;
   pcity->shield_stock = 0;
-  pcity->surplus[O_TRADE] = 0;
-  pcity->tile_trade = 0;
   pcity->original = pplayer->player_no;
 
   /* Initialise improvements list */
@@ -2510,7 +2517,10 @@
   pcity->ai.attack = 0;
   pcity->ai.next_recalc = 0;
 
+  memset(pcity->surplus, 0, O_COUNT * sizeof(*pcity->surplus));
   memset(pcity->waste, 0, O_COUNT * sizeof(*pcity->waste));
+  memset(pcity->prod, 0, O_COUNT * sizeof(*pcity->prod));
+  memset(pcity->citizen_base, 0, O_COUNT * sizeof(*pcity->citizen_base));
   output_type_iterate(o) {
     pcity->bonus[o] = 100;
   } output_type_iterate_end;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.182
diff -u -r1.182 city.h
--- common/city.h       11 Dec 2004 10:34:47 -0000      1.182
+++ common/city.h       12 Dec 2004 01:06:08 -0000
@@ -240,9 +240,7 @@
   int surplus[O_MAX]; /* Final surplus in each category. */
   int waste[O_MAX]; /* Waste/corruption in each category. */
   int prod[O_MAX]; /* Production is total minus waste. */
-
-  /* tile_trade is a special case for trade routes. */
-  int tile_trade;
+  int citizen_base[O_MAX]; /* Base production from citizens. */
 
   /* Cached values for CPU savings. */
   int bonus[O_MAX];
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.73
diff -u -r1.73 packets.def
--- common/packets.def  11 Dec 2004 10:34:47 -0000      1.73
+++ common/packets.def  12 Dec 2004 01:06:08 -0000
@@ -403,7 +403,7 @@
   SINT16 surplus[O_MAX];
   UINT16 waste[O_MAX];
   UINT16 prod[O_MAX];
-  SINT16 tile_trade;
+  SINT16 citizen_base[O_MAX];
   UINT16 food_stock, shield_stock;
 
   UINT16 trade[NUM_TRADEROUTES];
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.292
diff -u -r1.292 citytools.c
--- server/citytools.c  11 Dec 2004 10:34:48 -0000      1.292
+++ server/citytools.c  12 Dec 2004 01:06:09 -0000
@@ -1306,7 +1306,7 @@
   packet->unhappy = pdcity->unhappy;
 
   if (pcity && player_has_traderoute_with_city(pplayer, pcity)) {
-    packet->tile_trade = pcity->tile_trade;
+    packet->tile_trade = pcity->citizen_base[O_TRADE];
   } else {
     packet->tile_trade = 0;
   }
@@ -1548,8 +1548,8 @@
     packet->surplus[o] = pcity->surplus[o];
     packet->waste[o] = pcity->waste[o];
     packet->prod[o] = pcity->prod[o];
+    packet->citizen_base[o] = pcity->citizen_base[o];
   } output_type_iterate_end;
-  packet->tile_trade = pcity->tile_trade;
 
   packet->food_stock=pcity->food_stock;
   packet->shield_stock=pcity->shield_stock;
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.212
diff -u -r1.212 savegame.c
--- server/savegame.c   8 Dec 2004 04:28:27 -0000       1.212
+++ server/savegame.c   12 Dec 2004 01:06:11 -0000
@@ -1971,7 +1971,6 @@
     pcity->shield_stock = secfile_lookup_int(file,
                                             "player%d.c%d.shield_stock", 
                                             plrno, i);
-    pcity->tile_trade = pcity->surplus[O_TRADE] = 0;
     pcity->anarchy = secfile_lookup_int(file, "player%d.c%d.anarchy",
                                        plrno, i);
     pcity->rapture = secfile_lookup_int_default(file, 0,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11485) put base citizen output into an array, Jason Short <=