From 9e99678ec94cfaee65c9d19ed55951483ceb286f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 5 Feb 2023 09:26:08 +0200 Subject: [PATCH 15/15] player_limit_to_max_rates(): Adjust rates directly to player Stop passing entire economy structure as value. All callers were setting it to the same player structure anyway. If that's to change in the future, it will be easy to add economy pointer parameter. See osdn #45420 Signed-off-by: Marko Lindqvist --- server/edithand.c | 2 +- server/legacysave.c | 2 +- server/plrhand.c | 51 ++++++++++++++++++++++----------------------- server/plrhand.h | 2 +- server/savegame2.c | 2 +- server/savegame3.c | 2 +- server/srv_main.c | 2 +- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/server/edithand.c b/server/edithand.c index 71cbaa1c42..ab348afcc7 100644 --- a/server/edithand.c +++ b/server/edithand.c @@ -961,7 +961,7 @@ void handle_edit_player_create(struct connection *pc, int tag) pplayer->server.got_first_city = FALSE; pplayer->economic.gold = 0; - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); presearch = research_get(pplayer); init_tech(presearch, TRUE); diff --git a/server/legacysave.c b/server/legacysave.c index d7f89337b7..6de49cf8f3 100644 --- a/server/legacysave.c +++ b/server/legacysave.c @@ -4373,7 +4373,7 @@ static void game_load_internal(struct section_file *file) /* Check max rates (rules may have changed since saving) */ players_iterate(pplayer) { - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); } players_iterate_end; /* Restore game random state, just in case various initialization code diff --git a/server/plrhand.c b/server/plrhand.c index 683d5a8fce..019c1177b7 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -597,7 +597,7 @@ void check_player_max_rates(struct player *pplayer) { struct player_economic old_econ = pplayer->economic; - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); if (old_econ.tax > pplayer->economic.tax) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, ftc_server, _("Tax rate exceeded the max rate; adjusted.")); @@ -1395,7 +1395,7 @@ void server_player_init(struct player *pplayer, bool initmap, * to always have one server_player_init() call with * needs_team TRUE. */ if (needs_team) { - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); } adv_data_default(pplayer); @@ -1801,50 +1801,49 @@ void server_remove_player(struct player *pplayer) Returns actual max rate used. This function should be called after team information are defined. **************************************************************************/ -struct player_economic player_limit_to_max_rates(struct player *pplayer) +void player_limit_to_max_rates(struct player *pplayer) { int maxrate, surplus; - struct player_economic economic; + struct player_economic *economic; /* AI players allowed to cheat */ if (is_ai(pplayer) && !has_handicap(pplayer, H_RATES)) { - return pplayer->economic; + return; } - economic = pplayer->economic; + economic = &(pplayer->economic); maxrate = get_player_maxrate(pplayer); surplus = 0; - if (economic.luxury > maxrate) { - surplus += economic.luxury - maxrate; - economic.luxury = maxrate; + if (economic->luxury > maxrate) { + surplus += economic->luxury - maxrate; + economic->luxury = maxrate; } - if (economic.tax > maxrate) { - surplus += economic.tax - maxrate; - economic.tax = maxrate; + if (economic->tax > maxrate) { + surplus += economic->tax - maxrate; + economic->tax = maxrate; } - if (economic.science > maxrate) { - surplus += economic.science - maxrate; - economic.science = maxrate; + if (economic->science > maxrate) { + surplus += economic->science - maxrate; + economic->science = maxrate; } fc_assert(surplus % 10 == 0); + while (surplus > 0) { - if (economic.science < maxrate) { - economic.science += 10; - } else if (economic.tax < maxrate) { - economic.tax += 10; - } else if (economic.luxury < maxrate) { - economic.luxury += 10; + if (economic->science < maxrate) { + economic->science += 10; + } else if (economic->tax < maxrate) { + economic->tax += 10; + } else if (economic->luxury < maxrate) { + economic->luxury += 10; } else { fc_assert_msg(FALSE, "Failed to distribute the surplus. " "maxrate = %d.", maxrate); } surplus -= 10; } - - return economic; } /**************************************************************************** @@ -2622,9 +2621,9 @@ static struct player *split_player(struct player *pplayer) } research_update(old_research); - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); - /* copy the maps */ + /* Copy the maps */ give_map_from_player_to_player(pplayer, cplayer); @@ -2638,7 +2637,7 @@ static struct player *split_player(struct player *pplayer) CALL_PLR_AI_FUNC(split_by_civil_war, pplayer, pplayer, cplayer); CALL_PLR_AI_FUNC(created_by_civil_war, cplayer, pplayer, cplayer); - cplayer->economic = player_limit_to_max_rates(cplayer); + player_limit_to_max_rates(cplayer); return cplayer; } diff --git a/server/plrhand.h b/server/plrhand.h index cf0ce915f9..29165b4383 100644 --- a/server/plrhand.h +++ b/server/plrhand.h @@ -42,7 +42,7 @@ void government_change(struct player *pplayer, struct government *gov, bool revolution_finished); int revolution_length(struct government *gov, struct player *plr); -struct player_economic player_limit_to_max_rates(struct player *pplayer); +void player_limit_to_max_rates(struct player *pplayer); void server_player_set_name(struct player *pplayer, const char *name); bool server_player_set_name_full(const struct connection *caller, diff --git a/server/savegame2.c b/server/savegame2.c index f7339b5f10..e236829a25 100644 --- a/server/savegame2.c +++ b/server/savegame2.c @@ -5276,7 +5276,7 @@ static void sg_load_sanitycheck(struct loaddata *loading) /* Check max rates (rules may have changed since saving) */ players_iterate(pplayer) { - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); } players_iterate_end; if (0 == strlen(server.game_identifier) diff --git a/server/savegame3.c b/server/savegame3.c index eb5598474b..09291c0cb9 100644 --- a/server/savegame3.c +++ b/server/savegame3.c @@ -7237,7 +7237,7 @@ static void sg_load_sanitycheck(struct loaddata *loading) /* Check max rates (rules may have changed since saving) */ players_iterate(pplayer) { - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); } players_iterate_end; if (0 == strlen(server.game_identifier) diff --git a/server/srv_main.c b/server/srv_main.c index 0fb12a0e56..1ed5fa0b93 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -3224,7 +3224,7 @@ static void srv_ready(void) players_iterate(pplayer) { player_map_init(pplayer); - pplayer->economic = player_limit_to_max_rates(pplayer); + player_limit_to_max_rates(pplayer); pplayer->economic.gold = game.info.gold; } players_iterate_end; -- 2.39.1