[Freeciv-Dev] (PR#11325) simplify output in net code
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=11325 >
This patch changes several network packets to use an array form. The
data structures in server and client already use the array form so this
just simplifies them.
jason
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.431
diff -u -r1.431 packhand.c
--- client/packhand.c 4 Dec 2004 00:29:37 -0000 1.431
+++ client/packhand.c 4 Dec 2004 01:03:44 -0000
@@ -421,12 +421,12 @@
} else if (draw_city_productions
&& (pcity->is_building_unit != packet->is_building_unit
|| pcity->currently_building != packet->currently_building
- || pcity->surplus[O_SHIELD] != packet->shield_surplus
+ || pcity->surplus[O_SHIELD] != packet->surplus[O_SHIELD]
|| pcity->shield_stock != packet->shield_stock)) {
update_descriptions = TRUE;
} else if (draw_city_names && draw_city_growth &&
(pcity->food_stock != packet->food_stock ||
- pcity->surplus[O_FOOD] != packet->food_surplus)) {
+ pcity->surplus[O_FOOD] != packet->surplus[O_FOOD])) {
/* If either the food stock or surplus have changed, the time-to-grow
is likely to have changed as well. */
update_descriptions = TRUE;
@@ -457,10 +457,10 @@
}
pcity->food_prod=packet->food_prod;
- pcity->surplus[O_FOOD] = packet->food_surplus;
+ output_type_iterate(o) {
+ pcity->surplus[o] = packet->surplus[o];
+ } output_type_iterate_end;
pcity->shield_prod=packet->shield_prod;
- pcity->surplus[O_SHIELD] = packet->shield_surplus;
- pcity->surplus[O_TRADE] = packet->trade_prod;
pcity->tile_trade=packet->tile_trade;
pcity->corruption=packet->corruption;
pcity->shield_waste=packet->shield_waste;
@@ -2415,30 +2415,12 @@
gov->free_gold = p->free_gold;
output_type_iterate(o) {
- gov->output_before_penalty[o] = FC_INFINITY;
- gov->celeb_output_before_penalty[o] = FC_INFINITY;
+ gov->output_before_penalty[o] = p->output_before_penalty[o];
+ gov->celeb_output_before_penalty[o] = p->celeb_output_before_penalty[o];
+ gov->output_inc_tile[o] = p->output_inc_tile[o];
+ gov->celeb_output_inc_tile[o] = p->celeb_output_inc_tile[o];
} output_type_iterate_end;
- gov->output_before_penalty[O_TRADE] = p->trade_before_penalty;
- gov->output_before_penalty[O_SHIELD] = p->shields_before_penalty;
- gov->output_before_penalty[O_FOOD] = p->food_before_penalty;
-
- gov->celeb_output_before_penalty[O_TRADE] = p->celeb_trade_before_penalty;
- gov->celeb_output_before_penalty[O_SHIELD]
- = p->celeb_shields_before_penalty;
- gov->celeb_output_before_penalty[O_FOOD] = p->celeb_food_before_penalty;
-
- memset(gov->output_inc_tile, 0, O_COUNT * sizeof(*gov->output_inc_tile));
- gov->output_inc_tile[O_TRADE] = p->trade_bonus;
- gov->output_inc_tile[O_SHIELD] = p->shield_bonus;
- gov->output_inc_tile[O_FOOD] = p->food_bonus;
-
- memset(gov->celeb_output_inc_tile, 0,
- O_COUNT * sizeof(*gov->celeb_output_inc_tile));
- gov->celeb_output_inc_tile[O_TRADE] = p->celeb_trade_bonus;
- gov->celeb_output_inc_tile[O_SHIELD] = p->celeb_shield_bonus;
- gov->celeb_output_inc_tile[O_FOOD] = p->celeb_food_bonus;
-
gov->corruption_level = p->corruption_level;
gov->fixed_corruption_distance = p->fixed_corruption_distance;
gov->corruption_distance_factor = p->corruption_distance_factor;
@@ -2512,22 +2494,18 @@
sz_strlcpy(t->graphic_alt, p->graphic_alt);
t->movement_cost = p->movement_cost;
t->defense_bonus = p->defense_bonus;
- memset(t->output, 0, O_COUNT * sizeof(*t->output));
- t->output[O_FOOD] = p->food;
- t->output[O_SHIELD] = p->shield;
- t->output[O_TRADE] = p->trade;
+
+ output_type_iterate(o) {
+ t->output[o] = p->output[o];
+ t->special[0].output[o] = p->output_special_1[o];
+ t->special[1].output[o] = p->output_special_2[o];
+ } output_type_iterate_end;
+
sz_strlcpy(t->special[0].name_orig, p->special_1_name);
t->special[0].name = t->special[0].name_orig;
- memset(t->special[0].output, 0, O_COUNT * sizeof(*t->special[0].output));
- t->special[0].output[O_FOOD] = p->food_special_1;
- t->special[0].output[O_SHIELD] = p->shield_special_1;
- t->special[0].output[O_TRADE] = p->trade_special_1;
+
sz_strlcpy(t->special[1].name_orig, p->special_2_name);
t->special[1].name = t->special[1].name_orig;
- memset(t->special[1].output, 0, O_COUNT * sizeof(*t->special[1].output));
- t->special[1].output[O_FOOD] = p->food_special_2;
- t->special[1].output[O_SHIELD] = p->shield_special_2;
- t->special[1].output[O_TRADE] = p->trade_special_2;
sz_strlcpy(t->special[0].graphic_str, p->graphic_str_special_1);
sz_strlcpy(t->special[0].graphic_alt, p->graphic_alt_special_1);
@@ -2665,10 +2643,9 @@
game.rgame.forced_science = packet->forced_science;
game.rgame.forced_luxury = packet->forced_luxury;
game.rgame.forced_gold = packet->forced_gold;
- game.rgame.min_city_center_output[O_FOOD] = packet->min_city_center_food;
- game.rgame.min_city_center_output[O_SHIELD]
- = packet->min_city_center_shield;
- game.rgame.min_city_center_output[O_TRADE] = packet->min_city_center_trade;
+ output_type_iterate(o) {
+ game.rgame.min_city_center_output[o] = packet->min_city_center_output[o];
+ } output_type_iterate_end;
game.rgame.min_dist_bw_cities = packet->min_dist_bw_cities;
game.rgame.init_vis_radius_sq = packet->init_vis_radius_sq;
game.rgame.hut_overflight = packet->hut_overflight;
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.198
diff -u -r1.198 capstr.c
--- common/capstr.c 4 Dec 2004 00:29:37 -0000 1.198
+++ common/capstr.c 4 Dec 2004 01:03:44 -0000
@@ -82,7 +82,7 @@
* as long as possible. We want to maintain network compatibility with
* the stable branch for as long as possible.
*/
-#define CAPABILITY "+Freeciv.Devel.2004.Dec.2"
+#define CAPABILITY "+Freeciv.Devel.2004.Dec.3"
void init_our_capability(void)
{
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.63
diff -u -r1.63 packets.def
--- common/packets.def 4 Dec 2004 00:29:37 -0000 1.63
+++ common/packets.def 4 Dec 2004 01:03:44 -0000
@@ -401,8 +401,9 @@
UINT8 specialists[SP_MAX];
- UINT16 food_prod, shield_prod, trade_prod;
- SINT16 food_surplus, shield_surplus, tile_trade;
+ SINT16 surplus[O_MAX];
+ UINT16 food_prod, shield_prod;
+ SINT16 tile_trade;
UINT16 food_stock, shield_stock, corruption;
UINT16 trade[NUM_TRADEROUTES];
@@ -977,9 +978,7 @@
UINT8 forced_science;
UINT8 forced_luxury;
UINT8 forced_gold;
- UINT8 min_city_center_food;
- UINT8 min_city_center_shield;
- UINT8 min_city_center_trade;
+ UINT8 min_city_center_output[O_MAX];
UINT8 min_dist_bw_cities;
UINT8 init_vis_radius_sq;
UINT8 hut_overflight;
@@ -1040,22 +1039,11 @@
UINT8 free_shield;
UINT8 free_food;
UINT8 free_gold;
-
- UINT8 trade_before_penalty;
- UINT8 shields_before_penalty;
- UINT8 food_before_penalty;
-
- UINT8 celeb_trade_before_penalty;
- UINT8 celeb_shields_before_penalty;
- UINT8 celeb_food_before_penalty;
-
- UINT8 trade_bonus;
- UINT8 shield_bonus;
- UINT8 food_bonus;
-
- UINT8 celeb_trade_bonus;
- UINT8 celeb_shield_bonus;
- UINT8 celeb_food_bonus;
+
+ UINT8 output_before_penalty[O_MAX];
+ UINT8 celeb_output_before_penalty[O_MAX];
+ UINT8 output_inc_tile[O_MAX];
+ UINT8 celeb_output_inc_tile[O_MAX];
UINT16 corruption_level;
UINT8 fixed_corruption_distance;
@@ -1173,21 +1161,15 @@
UINT8 movement_cost;
UINT8 defense_bonus;
- UINT8 food;
- UINT8 shield;
- UINT8 trade;
+ UINT8 output[O_MAX];
STRING special_1_name[MAX_LEN_NAME];
- UINT8 food_special_1;
- UINT8 shield_special_1;
- UINT8 trade_special_1;
+ UINT8 output_special_1[O_MAX];
STRING graphic_str_special_1[MAX_LEN_NAME];
STRING graphic_alt_special_1[MAX_LEN_NAME];
STRING special_2_name[MAX_LEN_NAME];
- UINT8 food_special_2;
- UINT8 shield_special_2;
- UINT8 trade_special_2;
+ UINT8 output_special_2[O_MAX];
STRING graphic_str_special_2[MAX_LEN_NAME];
STRING graphic_alt_special_2[MAX_LEN_NAME];
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.284
diff -u -r1.284 citytools.c
--- server/citytools.c 3 Dec 2004 23:00:02 -0000 1.284
+++ server/citytools.c 4 Dec 2004 01:03:45 -0000
@@ -1547,11 +1547,11 @@
packet->trade_value[i]=pcity->trade_value[i];
}
+ output_type_iterate(o) {
+ packet->surplus[o] = pcity->surplus[o];
+ } output_type_iterate_end;
packet->food_prod = pcity->food_prod;
- packet->food_surplus = pcity->surplus[O_FOOD];
packet->shield_prod = pcity->shield_prod;
- packet->shield_surplus = pcity->surplus[O_SHIELD];
- packet->trade_prod = pcity->surplus[O_TRADE];
packet->tile_trade = pcity->tile_trade;
packet->corruption = pcity->corruption;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.208
diff -u -r1.208 ruleset.c
--- server/ruleset.c 4 Dec 2004 00:29:38 -0000 1.208
+++ server/ruleset.c 4 Dec 2004 01:03:46 -0000
@@ -2934,19 +2934,14 @@
packet.movement_cost = t->movement_cost;
packet.defense_bonus = t->defense_bonus;
- packet.food = t->output[O_FOOD];
- packet.shield = t->output[O_SHIELD];
- packet.trade = t->output[O_TRADE];
+ output_type_iterate(o) {
+ packet.output[o] = t->output[o];
+ packet.output_special_1[o] = t->special[0].output[o];
+ packet.output_special_2[o] = t->special[1].output[o];
+ } output_type_iterate_end;
sz_strlcpy(packet.special_1_name, t->special[0].name_orig);
- packet.food_special_1 = t->special[0].output[O_FOOD];
- packet.shield_special_1 = t->special[0].output[O_SHIELD];
- packet.trade_special_1 = t->special[0].output[O_TRADE];
-
sz_strlcpy(packet.special_2_name, t->special[1].name_orig);
- packet.food_special_2 = t->special[1].output[O_FOOD];
- packet.shield_special_2 = t->special[1].output[O_SHIELD];
- packet.trade_special_2 = t->special[1].output[O_TRADE];
sz_strlcpy(packet.graphic_str_special_1, t->special[0].graphic_str);
sz_strlcpy(packet.graphic_alt_special_1, t->special[0].graphic_alt);
@@ -3019,22 +3014,12 @@
gov.free_food = g->free_food;
gov.free_gold = g->free_gold;
- gov.trade_before_penalty = g->output_before_penalty[O_TRADE];
- gov.shields_before_penalty = g->output_before_penalty[O_SHIELD];
- gov.food_before_penalty = g->output_before_penalty[O_FOOD];
-
- gov.celeb_trade_before_penalty = g->celeb_output_before_penalty[O_TRADE];
- gov.celeb_shields_before_penalty
- = g->celeb_output_before_penalty[O_SHIELD];
- gov.celeb_food_before_penalty = g->celeb_output_before_penalty[O_FOOD];
-
- gov.trade_bonus = g->output_inc_tile[O_TRADE];
- gov.shield_bonus = g->output_inc_tile[O_SHIELD];
- gov.food_bonus = g->output_inc_tile[O_FOOD];
-
- gov.celeb_trade_bonus = g->celeb_output_inc_tile[O_TRADE];
- gov.celeb_shield_bonus = g->celeb_output_inc_tile[O_SHIELD];
- gov.celeb_food_bonus = g->celeb_output_inc_tile[O_FOOD];
+ output_type_iterate(o) {
+ gov.output_before_penalty[o] = g->output_before_penalty[o];
+ gov.celeb_output_before_penalty[o] = g->celeb_output_before_penalty[o];
+ gov.output_inc_tile[o] = g->output_inc_tile[o];
+ gov.celeb_output_inc_tile[o] = g->celeb_output_inc_tile[o];
+ } output_type_iterate_end;
gov.corruption_level = g->corruption_level;
gov.fixed_corruption_distance = g->fixed_corruption_distance;
@@ -3162,10 +3147,9 @@
misc_p.forced_science = game.rgame.forced_science;
misc_p.forced_luxury = game.rgame.forced_luxury;
misc_p.forced_gold = game.rgame.forced_gold;
- misc_p.min_city_center_food = game.rgame.min_city_center_output[O_FOOD];
- misc_p.min_city_center_shield
- = game.rgame.min_city_center_output[O_SHIELD];
- misc_p.min_city_center_trade = game.rgame.min_city_center_output[O_TRADE];
+ output_type_iterate(o) {
+ misc_p.min_city_center_output[o] = game.rgame.min_city_center_output[o];
+ } output_type_iterate_end;
misc_p.min_dist_bw_cities = game.rgame.min_dist_bw_cities;
misc_p.init_vis_radius_sq = game.rgame.init_vis_radius_sq;
misc_p.hut_overflight = game.rgame.hut_overflight;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#11325) simplify output in net code,
Jason Short <=
|
|