From a4d7d421362f467e19f74a1acc7ea081f4b9a14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Thu, 20 Oct 2022 01:26:10 +0300 Subject: [PATCH] Send city counter updates to client See osdn #45429 diff --git a/client/packhand.c b/client/packhand.c index 0dee0bf3d9..a90c6501a7 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -5526,3 +5526,28 @@ void handle_ruleset_counter(const struct packet_ruleset_counter *packet) attach_city_counter(curr); } + +/**********************************************************************//** +Handle updating city's counter, when server request +**************************************************************************/ +void handle_city_update_counter(const struct packet_city_update_counter *packet) +{ + int counter = packet->counter; + int counter_count = counters_get_city_counters_count(); + struct city *pcity = game_city_by_number(packet->city); + + if (NULL == pcity) { + + return; + } + + if (counter_count <= counter || 0 > counter) { + + return; + } + + pcity->counter_values[counter] = packet->value; + + update_city_description(pcity); + city_report_dialog_update_city(pcity); +} diff --git a/common/networking/packets.def b/common/networking/packets.def index 23a8cb35c9..d378d1d79c 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -3,7 +3,7 @@ Max used id: ============ -Max id: 513 +Max id: 514 Packets are not ordered by their id, but by their category. New packet with higher id may get added to existing category, and not to the end of file. @@ -304,6 +304,7 @@ type ACTION_ID = uint8(action_id) type ACTION_TGT = SINT32 type ACTION_SUB_TGT = SINT16 type BASE = sint8(Base_type_id) +type COUNTER = UINT32 type ROAD = sint8(Road_type_id) type CITY = UINT16 # city id, with space for special values @@ -773,6 +774,12 @@ PACKET_CITY_INFO = 31; sc, lsend, is-game-info, force, cancel(PACKET_CITY_SHORT_ UNIT_ORDER rally_point_orders[MAX_LEN_ROUTE:rally_point_length]; end +PACKET_CITY_UPDATE_COUNTER = 514; sc, lsend + CITY city; + COUNTER counter; + UINT32 value; +end + PACKET_CITY_SHORT_INFO = 32; sc, lsend, is-game-info, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION) CITY id; key TILE tile; @@ -1966,6 +1973,7 @@ PACKET_RULESET_DESCRIPTION_PART = 247; sc, lsend STRING text[MAX_LEN_CONTENT]; end + /********************************************************* Below are the packets that control single-player mode. *********************************************************/ diff --git a/fc_version b/fc_version index 7e45b66ebf..74a95459ba 100755 --- a/fc_version +++ b/fc_version @@ -61,7 +61,7 @@ DEFAULT_FOLLOW_TAG=S3_2 # - No new mandatory capabilities can be added to the release branch; doing # so would break network capability of supposedly "compatible" releases. # -NETWORK_CAPSTRING="+Freeciv.Devel-${MAIN_VERSION}-2022.Oct.17" +NETWORK_CAPSTRING="+Freeciv.Devel-${MAIN_VERSION}-2022.Oct.22" FREECIV_DISTRIBUTOR="" diff --git a/server/citytools.c b/server/citytools.c index 8c3830f18e..3080a64be7 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1226,6 +1226,7 @@ bool transfer_city(struct player *ptaker, struct city *pcity, city_counters_iterate(pcount) { if (pcount->type == CB_CITY_OWNED_TURNS) { pcity->counter_values[pcount->index] = 0; + city_counter_refresh(pcity, pcount->index); } } city_counters_iterate_end; } diff --git a/server/cityturn.c b/server/cityturn.c index 158acc691e..470b567664 100644 --- a/server/cityturn.c +++ b/server/cityturn.c @@ -4259,3 +4259,19 @@ void city_style_refresh(struct city *pcity) { pcity->style = city_style(pcity); } + +/**********************************************************************//** + Send updated (by server) counter information of + a given city. +**************************************************************************/ +void city_counter_refresh(struct city *pcity, int number) +{ + struct packet_city_update_counter packet; + + packet.city = pcity->id; + packet.counter = number; + packet.value = pcity->counter_values[number]; + + lsend_packet_city_update_counter(pcity->owner->connections, &packet); + lsend_packet_city_update_counter(game.glob_observers, &packet); +} diff --git a/server/cityturn.h b/server/cityturn.h index f569d7f1a4..42b63c46cd 100644 --- a/server/cityturn.h +++ b/server/cityturn.h @@ -57,4 +57,6 @@ void city_style_refresh(struct city *pcity); bool player_balance_treasury_units_and_buildings(struct player *pplayer); bool player_balance_treasury_units(struct player *pplayer); +void city_counter_refresh(struct city *pcity, int number); + #endif /* FC__CITYTURN_H */ diff --git a/server/srv_main.c b/server/srv_main.c index 716e71da4e..afafc65ae5 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1535,9 +1535,16 @@ static void end_turn(void) players_iterate(pplayer) { city_list_iterate(pplayer->cities, pcity) { city_counters_iterate(pcount) { + int old_val = pcity->counter_values[pcount->index]; + if (pcount->type == CB_CITY_OWNED_TURNS) { pcity->counter_values[pcount->index]++; } + + if (pcity->counter_values[pcount->index] != old_val) { + + city_counter_refresh(pcity, pcount->index); + } } city_counters_iterate_end; } city_list_iterate_end; } players_iterate_end; -- 2.38.1