[Freeciv-Dev] (PR#11403) put waste values into an array
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=11403 >
This patch puts waste values (corruption and shield waste) into an array
indexed by output type.
This really doesn't cost anything except a few bytes of memory. Down
the road it will make waste handling simpler since special cases for
waste are no longer needed. Consider the citydlg_tooltip patch where
all different output types should be handled by a single function -
anywhere that waste is > 0 it will simply be handled automatically.
Currently waste is treated as an int in the code and a UInt16 in the
network traffict. It is *probably* safe to treat it as an unsigned
8-bit value, if anyone wants to try optimizing it.
jason
? client/gui-gtk/citydlg.c.10508
Index: ai/aisettler.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aisettler.c,v
retrieving revision 1.12
diff -u -r1.12 aisettler.c
--- ai/aisettler.c 8 Dec 2004 07:48:24 -0000 1.12
+++ ai/aisettler.c 8 Dec 2004 08:10:13 -0000
@@ -244,11 +244,11 @@
result->corruption = ai->science_priority
* (city_waste(pcity, O_TRADE,
result->citymap[result->o_x][result->o_y].trade)
- - pcity->corruption);
+ - pcity->waste[O_TRADE]);
result->waste = ai->shield_priority
* (city_waste(pcity, O_SHIELD,
result->citymap[result->o_x][result->o_y].shield)
- - pcity->shield_waste);
+ - pcity->waste[O_SHIELD]);
pcity->size--;
}
result->total -= result->corruption;
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.42
diff -u -r1.42 cityrepdata.c
--- client/cityrepdata.c 3 Dec 2004 09:39:39 -0000 1.42
+++ client/cityrepdata.c 8 Dec 2004 08:10:13 -0000
@@ -399,7 +399,7 @@
const void *data)
{
static char buf[8];
- my_snprintf(buf, sizeof(buf), "%3d", pcity->corruption);
+ my_snprintf(buf, sizeof(buf), "%3d", pcity->waste[O_TRADE]);
return buf;
}
@@ -407,7 +407,7 @@
const void *data)
{
static char buf[8];
- my_snprintf(buf, sizeof(buf), "%3d", pcity->shield_waste);
+ my_snprintf(buf, sizeof(buf), "%3d", pcity->waste[O_SHIELD]);
return buf;
}
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.439
diff -u -r1.439 packhand.c
--- client/packhand.c 7 Dec 2004 18:39:06 -0000 1.439
+++ client/packhand.c 8 Dec 2004 08:10:14 -0000
@@ -459,12 +459,11 @@
pcity->food_prod=packet->food_prod;
output_type_iterate(o) {
pcity->surplus[o] = packet->surplus[o];
+ pcity->waste[o] = packet->waste[o];
} output_type_iterate_end;
pcity->shield_prod=packet->shield_prod;
pcity->tile_trade=packet->tile_trade;
- pcity->corruption=packet->corruption;
- pcity->shield_waste=packet->shield_waste;
-
+
pcity->luxury_total=packet->luxury_total;
pcity->tax_total=packet->tax_total;
pcity->science_total=packet->science_total;
@@ -749,7 +748,7 @@
pcity->food_prod = 0;
memset(pcity->surplus, 0, O_COUNT * sizeof(*pcity->surplus));
pcity->shield_prod = 0;
- pcity->corruption = 0;
+ memset(pcity->waste, 0, O_COUNT * sizeof(*pcity->waste));
pcity->luxury_total = 0;
pcity->tax_total = 0;
pcity->science_total = 0;
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.188
diff -u -r1.188 citydlg.c
--- client/gui-gtk/citydlg.c 30 Nov 2004 08:37:02 -0000 1.188
+++ client/gui-gtk/citydlg.c 8 Dec 2004 08:10:14 -0000
@@ -1691,10 +1691,10 @@
my_snprintf(buf[FOOD], sizeof(buf[FOOD]), "%2d (%+2d)",
pcity->food_prod, pcity->surplus[O_FOOD]);
my_snprintf(buf[SHIELD], sizeof(buf[SHIELD]), "%2d (%+2d)",
- pcity->shield_prod + pcity->shield_waste,
+ pcity->shield_prod + pcity->waste[O_SHIELD],
pcity->surplus[O_SHIELD]);
my_snprintf(buf[TRADE], sizeof(buf[TRADE]), "%2d (%+2d)",
- pcity->surplus[O_TRADE] + pcity->corruption,
+ pcity->surplus[O_TRADE] + pcity->waste[O_TRADE],
pcity->surplus[O_TRADE]);
my_snprintf(buf[GOLD], sizeof(buf[GOLD]), "%2d (%+2d)",
pcity->tax_total, city_gold_surplus(pcity, pcity->tax_total));
@@ -1721,9 +1721,9 @@
}
my_snprintf(buf[CORRUPTION], sizeof(buf[CORRUPTION]), "%2d",
- pcity->corruption);
+ pcity->waste[O_TRADE]);
my_snprintf(buf[WASTE], sizeof(buf[WASTE]), "%2d",
- pcity->shield_waste);
+ pcity->waste[O_SHIELD]);
my_snprintf(buf[POLLUTION], sizeof(buf[POLLUTION]), "%2d",
pcity->pollution);
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.103
diff -u -r1.103 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 5 Dec 2004 18:02:19 -0000 1.103
+++ client/gui-gtk-2.0/citydlg.c 8 Dec 2004 08:10:15 -0000
@@ -1322,10 +1322,10 @@
my_snprintf(buf[FOOD], sizeof(buf[FOOD]), "%2d (%+2d)",
pcity->food_prod, pcity->surplus[O_FOOD]);
my_snprintf(buf[SHIELD], sizeof(buf[SHIELD]), "%2d (%+2d)",
- pcity->shield_prod + pcity->shield_waste,
+ pcity->shield_prod + pcity->waste[O_SHIELD],
pcity->surplus[O_SHIELD]);
my_snprintf(buf[TRADE], sizeof(buf[TRADE]), "%2d (%+2d)",
- pcity->surplus[O_TRADE] + pcity->corruption,
+ pcity->surplus[O_TRADE] + pcity->waste[O_TRADE],
pcity->surplus[O_TRADE]);
my_snprintf(buf[GOLD], sizeof(buf[GOLD]), "%2d (%+2d)",
pcity->tax_total, city_gold_surplus(pcity, pcity->tax_total));
@@ -1351,9 +1351,9 @@
abs(granaryturns));
}
my_snprintf(buf[CORRUPTION], sizeof(buf[CORRUPTION]), "%2d",
- pcity->corruption);
+ pcity->waste[O_TRADE]);
my_snprintf(buf[WASTE], sizeof(buf[WASTE]), "%2d",
- pcity->shield_waste);
+ pcity->waste[O_SHIELD]);
my_snprintf(buf[POLLUTION], sizeof(buf[POLLUTION]), "%2d",
pcity->pollution);
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.86
diff -u -r1.86 citydlg.c
--- client/gui-mui/citydlg.c 25 Nov 2004 23:26:53 -0000 1.86
+++ client/gui-mui/citydlg.c 8 Dec 2004 08:10:15 -0000
@@ -1807,8 +1807,10 @@
pollutionstyle = (pcity->pollution >= 10) ? RED : NORMAL;
settextf(info->food_text, "%2d (%+2d)", pcity->food_prod,
pcity->food_surplus);
- settextf(info->shield_text, "%2d (%+2d)", pcity->shield_prod +
pcity->shield_waste, pcity->shield_surplus);
- settextf(info->trade_text, "%2d (%+2d)", pcity->trade_prod +
pcity->corruption, pcity->trade_prod);
+ settextf(info->shield_text, "%2d (%+2d)", pcity->shield_prod +
pcity->waste[O_SHIELD], pcity->shield_surplus);
+ settextf(info->trade_text, "%2d (%+2d)",
+ pcity->trade_prod + pcity->waste[O_TRADE],
+ pcity->trade_prod);
settextf(info->gold_text, "%2d (%+2d)", pcity->tax_total,
city_gold_surplus(pcity, pcity->tax_total));
settextf(info->luxury_text, "%2d", pcity->luxury_total);
settextf(info->science_text, "%2d", pcity->science_total);
@@ -1829,8 +1831,8 @@
settext(info->growth_text,buf);
}
- settextf(info->corruption_text, "%ld", pcity->corruption);
- settextf(info->waste_text, "%ld", pcity->shield_waste);
+ settextf(info->corruption_text, "%ld", pcity->waste[O_TRADE]);
+ settextf(info->waste_text, "%ld", pcity->waste[O_SHIELD]);
settextf(info->pollution_text, "%ld", pcity->pollution);
}
Index: client/gui-sdl/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/citydlg.c,v
retrieving revision 1.46
diff -u -r1.46 citydlg.c
--- client/gui-sdl/citydlg.c 20 Nov 2004 21:27:17 -0000 1.46
+++ client/gui-sdl/citydlg.c 8 Dec 2004 08:10:16 -0000
@@ -2811,7 +2811,7 @@
/* productions label */
my_snprintf(cBuf, sizeof(cBuf), _("Production : %d (%d) per turn"),
pCity->shield_surplus ,
- pCity->shield_prod + pCity->shield_waste);
+ pCity->shield_prod + pCity->waste[O_SHIELD]);
copy_chars_to_string16(pStr, cBuf);
pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_PROD);
@@ -2829,7 +2829,7 @@
if (pCity->shield_surplus) {
if (pCity->shield_surplus > 0) {
- count = pCity->shield_surplus + pCity->shield_waste;
+ count = pCity->shield_surplus + pCity->waste[O_SHIELD];
pBuf = pIcons->pBIG_Shield;
} else {
count = -1 * pCity->shield_surplus;
@@ -2856,7 +2856,7 @@
/* support shields label */
my_snprintf(cBuf, sizeof(cBuf), Q_("?production:Support : %d"),
- pCity->shield_prod + pCity->shield_waste - pCity->shield_surplus);
+ pCity->shield_prod + pCity->waste[O_SHIELD] - pCity->shield_surplus);
copy_chars_to_string16(pStr, cBuf);
pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_SUPPORT);
@@ -2926,7 +2926,8 @@
}
/* corruption label */
- my_snprintf(cBuf, sizeof(cBuf), _("Corruption : %d"), pCity->corruption);
+ my_snprintf(cBuf, sizeof(cBuf), _("Corruption : %d"),
+ pCity->waste[O_TRADE]);
copy_chars_to_string16(pStr, cBuf);
pStr->fgcol.r = 0;
@@ -2943,19 +2944,19 @@
FREESURFACE(pBuf);
/* draw corruption */
- if (pCity->corruption) {
+ if (pCity->waste[O_TRADE] > 0) {
dest.x = pWindow->size.x + 423;
dest.y =
pWindow->size.y + 316 + (16 - pIcons->pBIG_Trade->h) / 2;
- if (((pIcons->pBIG_Trade_Corr->w + 1) * pCity->corruption) > 30) {
+ if (((pIcons->pBIG_Trade_Corr->w + 1) * pCity->waste[O_TRADE]) > 30) {
step =
- (30 - pIcons->pBIG_Trade_Corr->w) / (pCity->corruption - 1);
+ (30 - pIcons->pBIG_Trade_Corr->w) / (pCity->waste[O_TRADE] - 1);
} else {
step = pIcons->pBIG_Trade_Corr->w + 1;
}
- for (i = 0; i < pCity->corruption; i++) {
+ for (i = 0; i < pCity->waste[O_TRADE]; i++) {
SDL_BlitSurface(pIcons->pBIG_Trade_Corr, NULL, pWindow->dst,
&dest);
dest.x -= step;
Index: client/gui-sdl/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/cityrep.c,v
retrieving revision 1.15
diff -u -r1.15 cityrep.c
--- client/gui-sdl/cityrep.c 13 Sep 2004 15:54:50 -0000 1.15
+++ client/gui-sdl/cityrep.c 8 Dec 2004 08:10:16 -0000
@@ -373,7 +373,7 @@
add_to_gui_list(MAX_ID - pCity->id, pBuf);
/* ----------- */
- my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->corruption);
+ my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->waste[O_TRADE]);
pStr = create_str16_from_char(cBuf, 10);
pStr->style |= SF_CENTER;
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
@@ -429,7 +429,7 @@
/* ----------- */
my_snprintf(cBuf, sizeof(cBuf), "%d",
- pCity->shield_prod + pCity->shield_waste);
+ pCity->shield_prod + pCity->waste[O_SHIELD]);
pStr = create_str16_from_char(cBuf, 10);
pStr->style |= SF_CENTER;
pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_PROD);
@@ -443,7 +443,7 @@
add_to_gui_list(MAX_ID - pCity->id, pBuf);
/* ----------- */
- my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->shield_waste);
+ my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->waste[O_SHIELD]);
pStr = create_str16_from_char(cBuf, 10);
pStr->style |= SF_CENTER;
pBuf = create_iconlabel(NULL, pWindow->dst, pStr,
@@ -457,7 +457,7 @@
/* ----------- */
my_snprintf(cBuf, sizeof(cBuf), "%d",
- pCity->shield_prod + pCity->shield_waste - pCity->shield_surplus);
+ pCity->shield_prod + pCity->waste[O_SHIELD] - pCity->shield_surplus);
pStr = create_str16_from_char(cBuf, 10);
pStr->style |= SF_CENTER;
pStr->fgcol = *get_game_colorRGB(COLOR_STD_CITY_SUPPORT);
@@ -969,7 +969,7 @@
/* corruptions */
pWidget = pWidget->prev;
- my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->corruption);
+ my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->waste[O_TRADE]);
copy_chars_to_string16(pWidget->string16, cBuf);
/* gold surplus */
@@ -990,18 +990,18 @@
/* total production */
pWidget = pWidget->prev;
my_snprintf(cBuf, sizeof(cBuf), "%d",
- pCity->shield_prod + pCity->shield_waste);
+ pCity->shield_prod + pCity->waste[O_SHIELD]);
copy_chars_to_string16(pWidget->string16, cBuf);
/* waste */
pWidget = pWidget->prev;
- my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->shield_waste);
+ my_snprintf(cBuf, sizeof(cBuf), "%d", pCity->waste[O_SHIELD]);
copy_chars_to_string16(pWidget->string16, cBuf);
/* units support */
pWidget = pWidget->prev;
my_snprintf(cBuf, sizeof(cBuf), "%d",
- pCity->shield_prod + pCity->shield_waste - pCity->shield_surplus);
+ pCity->shield_prod + pCity->waste[O_SHIELD] - pCity->shield_surplus);
copy_chars_to_string16(pWidget->string16, cBuf);
/* production income */
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.86
diff -u -r1.86 citydlg.c
--- client/gui-win32/citydlg.c 30 Nov 2004 08:37:03 -0000 1.86
+++ client/gui-win32/citydlg.c 8 Dec 2004 08:10:16 -0000
@@ -443,9 +443,9 @@
my_snprintf(buf, sizeof(buf),
_("Food: %2d (%+2d)\nProd: %2d (%+2d)\nTrade: %2d
(%+2d)"),
pcity->food_prod, pcity->surplus[O_FOOD],
- pcity->shield_prod + pcity->shield_waste,
+ pcity->shield_prod + pcity->waste[O_SHIELD],
pcity->surplus[O_SHIELD],
- pcity->surplus[O_TRADE] + pcity->corruption,
+ pcity->surplus[O_TRADE] + pcity->waste[O_TRADE],
pcity->surplus[O_TRADE]);
SetWindowText(pdialog->prod_area[0],buf);
SetWindowText(pdialog->prod_area[1],buf);
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.124
diff -u -r1.124 citydlg.c
--- client/gui-xaw/citydlg.c 30 Nov 2004 08:37:03 -0000 1.124
+++ client/gui-xaw/citydlg.c 8 Dec 2004 08:10:16 -0000
@@ -241,9 +241,9 @@
pcity=pdialog->pcity;
foodprod=pcity->food_prod;
foodsurplus = pcity->surplus[O_FOOD];
- shieldprod=pcity->shield_prod + pcity->shield_waste;
+ shieldprod=pcity->shield_prod + pcity->waste[O_SHIELD];
shieldsurplus = pcity->surplus[O_SHIELD];
- tradeprod = pcity->surplus[O_TRADE]+pcity->corruption;
+ tradeprod = pcity->surplus[O_TRADE] + pcity->waste[O_TRADE];
tradesurplus = pcity->surplus[O_TRADE];
}
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.275
diff -u -r1.275 city.c
--- common/city.c 8 Dec 2004 07:48:24 -0000 1.275
+++ common/city.c 8 Dec 2004 08:10:17 -0000
@@ -2016,11 +2016,11 @@
trade_between_cities(pcity, find_city_by_id(pcity->trade[i]));
pcity->surplus[O_TRADE] += pcity->trade_value[i];
}
- pcity->corruption = city_waste(pcity, O_TRADE, pcity->surplus[O_TRADE]);
- pcity->surplus[O_TRADE] -= pcity->corruption;
+ pcity->waste[O_TRADE] = city_waste(pcity, O_TRADE, pcity->surplus[O_TRADE]);
+ pcity->surplus[O_TRADE] -= pcity->waste[O_TRADE];
- pcity->shield_waste = city_waste(pcity, O_SHIELD, pcity->shield_prod);
- pcity->shield_prod -= pcity->shield_waste;
+ pcity->waste[O_SHIELD] = city_waste(pcity, O_SHIELD, pcity->shield_prod);
+ pcity->shield_prod -= pcity->waste[O_SHIELD];
}
/**************************************************************************
@@ -2502,8 +2502,7 @@
pcity->ai.attack = 0;
pcity->ai.next_recalc = 0;
- pcity->corruption = 0;
- pcity->shield_waste = 0;
+ memset(pcity->waste, 0, O_COUNT * sizeof(*pcity->waste));
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.177
diff -u -r1.177 city.h
--- common/city.h 8 Dec 2004 07:48:24 -0000 1.177
+++ common/city.h 8 Dec 2004 08:10:17 -0000
@@ -235,12 +235,13 @@
/* the productions */
int surplus[O_MAX]; /* Final surplus in each category. */
+ int waste[O_MAX]; /* Waste/corruption in each category. */
int food_prod;
/* Shield production is shields produced minus shield_waste*/
- int shield_prod, shield_waste;
- int corruption, tile_trade;
+ int shield_prod;
+ int tile_trade;
/* 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.70
diff -u -r1.70 packets.def
--- common/packets.def 7 Dec 2004 18:39:06 -0000 1.70
+++ common/packets.def 8 Dec 2004 08:10:17 -0000
@@ -401,16 +401,17 @@
UINT8 specialists[SP_MAX];
SINT16 surplus[O_MAX];
+ UINT16 waste[O_MAX];
UINT16 food_prod, shield_prod;
SINT16 tile_trade;
- UINT16 food_stock, shield_stock, corruption;
+ UINT16 food_stock, shield_stock;
UINT16 trade[NUM_TRADEROUTES];
UINT8 trade_value[NUM_TRADEROUTES];
UINT16 luxury_total, tax_total, science_total;
- UINT16 pollution, shield_waste;
+ UINT16 pollution;
UINT8 currently_building;
BOOL is_building_unit;
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.289
diff -u -r1.289 citytools.c
--- server/citytools.c 8 Dec 2004 04:28:26 -0000 1.289
+++ server/citytools.c 8 Dec 2004 08:10:18 -0000
@@ -1561,14 +1561,12 @@
output_type_iterate(o) {
packet->surplus[o] = pcity->surplus[o];
+ packet->waste[o] = pcity->waste[o];
} output_type_iterate_end;
packet->food_prod = pcity->food_prod;
packet->shield_prod = pcity->shield_prod;
packet->tile_trade = pcity->tile_trade;
- packet->corruption = pcity->corruption;
-
- packet->shield_waste=pcity->shield_waste;
-
+
packet->luxury_total=pcity->luxury_total;
packet->tax_total=pcity->tax_total;
packet->science_total=pcity->science_total;
Index: server/report.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.c,v
retrieving revision 1.56
diff -u -r1.56 report.c
--- server/report.c 30 Nov 2004 02:08:22 -0000 1.56
+++ server/report.c 8 Dec 2004 08:10:18 -0000
@@ -517,7 +517,7 @@
int result = 0;
city_list_iterate(pplayer->cities, pcity) {
- result += pcity->corruption;
+ result += pcity->waste[O_TRADE];
} city_list_iterate_end;
return result;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#11403) put waste values into an array,
Jason Short <=
|
|