From e2a563367efeaddcb9237043814b08f39e61b93f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 3 Sep 2022 02:07:17 +0300 Subject: [PATCH 45/45] Move code not related to cities out from update_city_activities() Add new update_national_activities() where those updates are made instead. See osdn #45492 Signed-off-by: Marko Lindqvist --- server/cityturn.c | 53 +++-------------------------------------------- server/cityturn.h | 7 +++++-- server/plrhand.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ server/plrhand.h | 4 +++- server/srv_main.c | 14 ++++++++----- 5 files changed, 70 insertions(+), 58 deletions(-) diff --git a/server/cityturn.c b/server/cityturn.c index 00cb254891..686725725e 100644 --- a/server/cityturn.c +++ b/server/cityturn.c @@ -132,9 +132,6 @@ static citizens city_reduce_workers(struct city *pcity, citizens change); static bool city_balance_treasury_buildings(struct city *pcity); static bool city_balance_treasury_units(struct city *pcity); -static bool player_balance_treasury_units_and_buildings - (struct player *pplayer); -static bool player_balance_treasury_units(struct player *pplayer); static bool disband_city(struct city *pcity); @@ -579,15 +576,12 @@ void send_city_turn_notifications(struct connection *pconn) **************************************************************************/ void update_city_activities(struct player *pplayer) { - char buf[4 * MAX_LEN_NAME]; - int n, gold; + int n; fc_assert(NULL != pplayer); fc_assert(NULL != pplayer->cities); n = city_list_size(pplayer->cities); - gold = pplayer->economic.gold; - pplayer->server.bulbs_last_turn = 0; if (n > 0) { struct city *cities[n]; @@ -650,47 +644,7 @@ void update_city_activities(struct player *pplayer) update_city_activity(cities[r]); cities[r] = cities[--i]; } - - if (pplayer->economic.infra_points < 0) { - pplayer->economic.infra_points = 0; - } - - if (pplayer->economic.gold < 0) { - switch (game.info.gold_upkeep_style) { - case GOLD_UPKEEP_CITY: - break; - case GOLD_UPKEEP_MIXED: - /* Nation pays for units. */ - player_balance_treasury_units(pplayer); - break; - case GOLD_UPKEEP_NATION: - /* Nation pays for units and buildings. */ - player_balance_treasury_units_and_buildings(pplayer); - break; - } - } - - /* Should not happen. */ - fc_assert(pplayer->economic.gold >= 0); - } - - /* This test includes the cost of the units because - * units are paid for in update_city_activity() or - * player_balance_treasury_units(). */ - if (gold - (gold - pplayer->economic.gold) * 3 < 0) { - notify_player(pplayer, NULL, E_LOW_ON_FUNDS, ftc_server, - _("WARNING, we're LOW on FUNDS %s."), - ruler_title_for_player(pplayer, buf, sizeof(buf))); - } - -#if 0 - /* Uncomment to unbalance the game, like in civ1 (CLG). */ - if (pplayer->got_tech && pplayer->research->researched > 0) { - pplayer->research->researched = 0; } -#endif - - city_refresh_queue_processing(); } /**********************************************************************//** @@ -2950,8 +2904,7 @@ static struct unit *sell_random_unit(struct player *pplayer, /**********************************************************************//** Balance the gold of a nation by selling some random units and buildings. **************************************************************************/ -static bool player_balance_treasury_units_and_buildings - (struct player *pplayer) +bool player_balance_treasury_units_and_buildings(struct player *pplayer) { struct cityimpr_list *pimprlist; bool sell_unit = TRUE; @@ -3014,7 +2967,7 @@ static bool player_balance_treasury_units_and_buildings /**********************************************************************//** Balance the gold of a nation by selling some units which need gold upkeep. **************************************************************************/ -static bool player_balance_treasury_units(struct player *pplayer) +bool player_balance_treasury_units(struct player *pplayer) { if (!pplayer) { return FALSE; diff --git a/server/cityturn.h b/server/cityturn.h index 315802d66c..f569d7f1a4 100644 --- a/server/cityturn.h +++ b/server/cityturn.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,4 +54,7 @@ void check_disasters(void); void city_style_refresh(struct city *pcity); -#endif /* FC__CITYTURN_H */ +bool player_balance_treasury_units_and_buildings(struct player *pplayer); +bool player_balance_treasury_units(struct player *pplayer); + +#endif /* FC__CITYTURN_H */ diff --git a/server/plrhand.c b/server/plrhand.c index a9bbe4eaa7..514f3da58e 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -3410,3 +3410,53 @@ void player_set_under_human_control(struct player *pplayer) } cancel_all_meetings(pplayer); } + +/**********************************************************************//** + National level turn change activities. +**************************************************************************/ +void update_national_activities(struct player *pplayer, int old_gold) +{ + char buf[200 + MAX_LEN_NAME]; + + if (pplayer->economic.gold < 0) { + switch (game.info.gold_upkeep_style) { + case GOLD_UPKEEP_CITY: + break; + case GOLD_UPKEEP_MIXED: + /* Nation pays for units. */ + player_balance_treasury_units(pplayer); + break; + case GOLD_UPKEEP_NATION: + /* Nation pays for units and buildings. */ + player_balance_treasury_units_and_buildings(pplayer); + break; + } + } + + /* This test includes the cost of the units because + * units are paid for in update_city_activity() or + * player_balance_treasury_units(). */ + if (old_gold - (old_gold - pplayer->economic.gold) * 3 < 0) { + notify_player(pplayer, NULL, E_LOW_ON_FUNDS, ftc_server, + _("WARNING, we're LOW on FUNDS %s."), + ruler_title_for_player(pplayer, buf, sizeof(buf))); + } + +#if 0 + /* Uncomment to unbalance the game, like in civ1 (CLG). */ + if (pplayer->got_tech && pplayer->research->researched > 0) { + pplayer->research->researched = 0; + } +#endif + + if (pplayer->economic.infra_points < 0) { + pplayer->economic.infra_points = 0; + } + + pplayer->history += nation_history_gain(pplayer); + + research_get(pplayer)->researching_saved = A_UNKNOWN; + /* Reduce the number of bulbs by the amount needed for tech upkeep and + * check for finished research */ + update_bulbs(pplayer, -player_tech_upkeep(pplayer), TRUE); +} diff --git a/server/plrhand.h b/server/plrhand.h index beef551e10..d4f73f8409 100644 --- a/server/plrhand.h +++ b/server/plrhand.h @@ -169,4 +169,6 @@ void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level); void player_set_under_human_control(struct player *pplayer); -#endif /* FC__PLRHAND_H */ +void update_national_activities(struct player *pplayer, int old_gold); + +#endif /* FC__PLRHAND_H */ diff --git a/server/srv_main.c b/server/srv_main.c index 4fad204291..3c18dca1e2 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1446,6 +1446,7 @@ static void end_phase(void) alive_phase_players_iterate(pplayer) { int plrid = player_number(pplayer); + int old_gold; do_tech_parasite_effect(pplayer); script_server_signal_emit("player_alive_phase_end", pplayer); @@ -1466,13 +1467,16 @@ static void end_phase(void) _("Automatically placed spaceship parts that were still not placed.")); } + old_gold = pplayer->economic.gold; + pplayer->server.bulbs_last_turn = 0; + update_city_activities(pplayer); + + update_national_activities(pplayer, old_gold); + + city_refresh_queue_processing(); city_thaw_workers_queue(); - pplayer->history += nation_history_gain(pplayer); - research_get(pplayer)->researching_saved = A_UNKNOWN; - /* reduce the number of bulbs by the amount needed for tech upkeep and - * check for finished research */ - update_bulbs(pplayer, -player_tech_upkeep(pplayer), TRUE); + flush_packets(); } alive_phase_players_iterate_end; -- 2.35.1