<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40389 >
2008/7/22 Marko Lindqvist: > 2008/7/22 Jason Dorje Short: >> On the other hand changing the function to return the new value (a >> struct player_economic) so that it didn't have side effects, might be >> worthwhile. > > Yes, that would probably be the cleanest solution. Patch Also renames some xxx_government_rates stuff as xxx_max_rates, since there can be other effect sources besides governments. User visible message not changed in S2_1, but only in S2_2/TRUNK. - ML
diff -Nurd -X.diff_ignore freeciv/ai/aihand.c freeciv/ai/aihand.c --- freeciv/ai/aihand.c 2008-01-15 04:04:30.000000000 +0200 +++ freeciv/ai/aihand.c 2008-07-22 21:26:34.000000000 +0300 @@ -302,7 +302,7 @@ pplayer->government = gov; /* Ideally we should change tax rates here, but since * this is a rather big CPU operation, we'd rather not. */ - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); city_list_iterate(pplayer->cities, acity) { auto_arrange_workers(acity); } city_list_iterate_end; diff -Nurd -X.diff_ignore freeciv/common/player.c freeciv/common/player.c --- freeciv/common/player.c 2008-04-16 22:05:32.000000000 +0300 +++ freeciv/common/player.c 2008-07-22 21:22:05.000000000 +0300 @@ -210,7 +210,7 @@ plr->economic.science=PLAYER_DEFAULT_SCIENCE_RATE; plr->economic.luxury=PLAYER_DEFAULT_LUXURY_RATE; - player_limit_to_government_rates(plr); + plr->economic = player_limit_to_max_rates(plr); spaceship_init(&plr->spaceship); plr->gives_shared_vision = 0; @@ -610,49 +610,54 @@ it adjusts rates automatically adding the extra to the 2nd highest rate, preferring science to taxes and taxes to luxuries. (It assumes that for any government maxrate>=50) +Returns actual max rate used. **************************************************************************/ -void player_limit_to_government_rates(struct player *pplayer) +struct player_economic player_limit_to_max_rates(struct player *pplayer) { int maxrate, surplus; + struct player_economic economic; /* ai players allowed to cheat */ if (pplayer->ai.control) { - return; + return pplayer->economic; } + economic = pplayer->economic; + maxrate = get_player_bonus(pplayer, EFT_MAX_RATES); if (maxrate == 0) { maxrate = 100; /* effects not initialized yet */ } + surplus = 0; - if (pplayer->economic.luxury > maxrate) { - surplus += pplayer->economic.luxury - maxrate; - pplayer->economic.luxury = maxrate; + if (economic.luxury > maxrate) { + surplus += economic.luxury - maxrate; + economic.luxury = maxrate; } - if (pplayer->economic.tax > maxrate) { - surplus += pplayer->economic.tax - maxrate; - pplayer->economic.tax = maxrate; + if (economic.tax > maxrate) { + surplus += economic.tax - maxrate; + economic.tax = maxrate; } - if (pplayer->economic.science > maxrate) { - surplus += pplayer->economic.science - maxrate; - pplayer->economic.science = maxrate; + if (economic.science > maxrate) { + surplus += economic.science - maxrate; + economic.science = maxrate; } assert(surplus % 10 == 0); while (surplus > 0) { - if (pplayer->economic.science < maxrate) { - pplayer->economic.science += 10; - } else if (pplayer->economic.tax < maxrate) { - pplayer->economic.tax += 10; - } else if (pplayer->economic.luxury < maxrate) { - pplayer->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 { die("byebye"); } surplus -= 10; } - return; + return economic; } /************************************************************************** diff -Nurd -X.diff_ignore freeciv/common/player.h freeciv/common/player.h --- freeciv/common/player.h 2008-01-15 04:04:30.000000000 +0200 +++ freeciv/common/player.h 2008-07-22 21:20:37.000000000 +0300 @@ -259,7 +259,7 @@ enum tech_flag_id flag); int player_get_expected_income(const struct player *pplayer); -void player_limit_to_government_rates(struct player *pplayer); +struct player_economic player_limit_to_max_rates(struct player *pplayer); struct city *find_palace(const struct player *pplayer); diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c --- freeciv/server/plrhand.c 2008-05-16 01:50:15.000000000 +0300 +++ freeciv/server/plrhand.c 2008-07-22 21:27:24.000000000 +0300 @@ -258,7 +258,7 @@ = 100 - pplayer->economic.science - pplayer->economic.tax; } - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); global_city_refresh(pplayer); send_player_info(pplayer, pplayer); } @@ -337,7 +337,7 @@ _("Revolution: returning to anarchy.")); } - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); global_city_refresh(pplayer); send_player_info(pplayer, pplayer); @@ -414,25 +414,22 @@ form of government. Has to be called when switching governments or when toggling from AI to human. **************************************************************************/ -void check_player_government_rates(struct player *pplayer) +void check_player_max_rates(struct player *pplayer) { struct player_economic old_econ = pplayer->economic; - bool changed = FALSE; - player_limit_to_government_rates(pplayer); - if (pplayer->economic.tax != old_econ.tax) { - changed = TRUE; + + pplayer->economic = player_limit_to_max_rates(pplayer); + if (old_econ.tax > pplayer->economic.tax) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, _("Tax rate exceeded the max rate for %s; adjusted."), government_name_for_player(pplayer)); } - if (pplayer->economic.science != old_econ.science) { - changed = TRUE; + if (old_econ.science > pplayer->economic.science) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, _("Science rate exceeded the max rate for %s; adjusted."), government_name_for_player(pplayer)); } - if (pplayer->economic.luxury != old_econ.luxury) { - changed = TRUE; + if (old_econ.luxury > pplayer->economic.luxury) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, _("Luxury rate exceeded the max rate for %s; adjusted."), government_name_for_player(pplayer)); @@ -1548,7 +1545,7 @@ } players_iterate_end; } - player_limit_to_government_rates(pplayer); + pplayer->economic = player_limit_to_max_rates(pplayer); /* copy the maps */ diff -Nurd -X.diff_ignore freeciv/server/plrhand.h freeciv/server/plrhand.h --- freeciv/server/plrhand.h 2008-05-10 01:12:31.000000000 +0300 +++ freeciv/server/plrhand.h 2008-07-22 21:25:37.000000000 +0300 @@ -39,7 +39,7 @@ bool ignore_conflicts, bool only_available); -void check_player_government_rates(struct player *pplayer); +void check_player_max_rates(struct player *pplayer); void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile); void maybe_make_contact(struct tile *ptile, struct player *pplayer); diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c --- freeciv/server/srv_main.c 2008-07-21 12:28:08.000000000 +0300 +++ freeciv/server/srv_main.c 2008-07-22 21:30:21.000000000 +0300 @@ -2072,7 +2072,7 @@ players_iterate(pplayer) { player_map_allocate(pplayer); init_tech(pplayer, TRUE); - player_limit_to_government_rates(pplayer); + pplayer->economic = player_limit_to_max_rates(pplayer); pplayer->economic.gold = game.info.gold; } players_iterate_end; diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c --- freeciv/server/stdinhand.c 2008-07-21 12:28:08.000000000 +0300 +++ freeciv/server/stdinhand.c 2008-07-22 21:31:17.000000000 +0300 @@ -802,9 +802,9 @@ _("%s is now under human control."), player_name(pplayer)); - /* because the hard AI `cheats' with government rates but humans shouldn't */ + /* because the AI `cheats' with government rates but humans shouldn't */ if (!game.info.is_new_game) { - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); } /* Remove hidden dialogs from clients. This way the player can initiate * new meeting */
diff -Nurd -X.diff_ignore freeciv/ai/aihand.c freeciv/ai/aihand.c --- freeciv/ai/aihand.c 2008-07-03 21:58:05.000000000 +0300 +++ freeciv/ai/aihand.c 2008-07-22 21:35:59.000000000 +0300 @@ -313,7 +313,7 @@ pplayer->government = gov; /* Ideally we should change tax rates here, but since * this is a rather big CPU operation, we'd rather not. */ - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); city_list_iterate(pplayer->cities, acity) { auto_arrange_workers(acity); } city_list_iterate_end; diff -Nurd -X.diff_ignore freeciv/common/player.c freeciv/common/player.c --- freeciv/common/player.c 2008-04-17 10:49:41.000000000 +0300 +++ freeciv/common/player.c 2008-07-22 21:35:59.000000000 +0300 @@ -218,7 +218,7 @@ plr->economic.science=PLAYER_DEFAULT_SCIENCE_RATE; plr->economic.luxury=PLAYER_DEFAULT_LUXURY_RATE; - player_limit_to_government_rates(plr); + plr->economic = player_limit_to_max_rates(plr); spaceship_init(&plr->spaceship); plr->gives_shared_vision = 0; @@ -648,49 +648,54 @@ it adjusts rates automatically adding the extra to the 2nd highest rate, preferring science to taxes and taxes to luxuries. (It assumes that for any government maxrate>=50) +Returns actual max rate used. **************************************************************************/ -void player_limit_to_government_rates(struct player *pplayer) +struct player_economic player_limit_to_max_rates(struct player *pplayer) { int maxrate, surplus; + struct player_economic economic; /* ai players allowed to cheat */ if (pplayer->ai.control) { - return; + return pplayer->economic; } + economic = pplayer->economic; + maxrate = get_player_bonus(pplayer, EFT_MAX_RATES); if (maxrate == 0) { maxrate = 100; /* effects not initialized yet */ } + surplus = 0; - if (pplayer->economic.luxury > maxrate) { - surplus += pplayer->economic.luxury - maxrate; - pplayer->economic.luxury = maxrate; + if (economic.luxury > maxrate) { + surplus += economic.luxury - maxrate; + economic.luxury = maxrate; } - if (pplayer->economic.tax > maxrate) { - surplus += pplayer->economic.tax - maxrate; - pplayer->economic.tax = maxrate; + if (economic.tax > maxrate) { + surplus += economic.tax - maxrate; + economic.tax = maxrate; } - if (pplayer->economic.science > maxrate) { - surplus += pplayer->economic.science - maxrate; - pplayer->economic.science = maxrate; + if (economic.science > maxrate) { + surplus += economic.science - maxrate; + economic.science = maxrate; } assert(surplus % 10 == 0); while (surplus > 0) { - if (pplayer->economic.science < maxrate) { - pplayer->economic.science += 10; - } else if (pplayer->economic.tax < maxrate) { - pplayer->economic.tax += 10; - } else if (pplayer->economic.luxury < maxrate) { - pplayer->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 { die("byebye"); } surplus -= 10; } - return; + return economic; } /************************************************************************** diff -Nurd -X.diff_ignore freeciv/common/player.h freeciv/common/player.h --- freeciv/common/player.h 2008-06-24 01:37:50.000000000 +0300 +++ freeciv/common/player.h 2008-07-22 21:35:59.000000000 +0300 @@ -253,7 +253,7 @@ enum tech_flag_id flag); int player_get_expected_income(const struct player *pplayer); -void player_limit_to_government_rates(struct player *pplayer); +struct player_economic player_limit_to_max_rates(struct player *pplayer); struct city *find_palace(const struct player *pplayer); diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c --- freeciv/server/plrhand.c 2008-07-03 21:58:06.000000000 +0300 +++ freeciv/server/plrhand.c 2008-07-22 21:37:14.000000000 +0300 @@ -266,7 +266,7 @@ = 100 - pplayer->economic.science - pplayer->economic.tax; } - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); city_refresh_for_player(pplayer); send_player_info(pplayer, pplayer); } @@ -345,7 +345,7 @@ _("Revolution: returning to anarchy.")); } - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); city_refresh_for_player(pplayer); send_player_info(pplayer, pplayer); @@ -422,28 +422,22 @@ form of government. Has to be called when switching governments or when toggling from AI to human. **************************************************************************/ -void check_player_government_rates(struct player *pplayer) +void check_player_max_rates(struct player *pplayer) { struct player_economic old_econ = pplayer->economic; - bool changed = FALSE; - player_limit_to_government_rates(pplayer); - if (pplayer->economic.tax != old_econ.tax) { - changed = TRUE; + + pplayer->economic = player_limit_to_max_rates(pplayer); + if (old_econ.tax > pplayer->economic.tax) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, - _("Tax rate exceeded the max rate for %s; adjusted."), - government_name_for_player(pplayer)); + _("Tax rate exceeded the max rate; adjusted.")); } - if (pplayer->economic.science != old_econ.science) { - changed = TRUE; + if (old_econ.science > pplayer->economic.science) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, - _("Science rate exceeded the max rate for %s; adjusted."), - government_name_for_player(pplayer)); + _("Science rate exceeded the max rate; adjusted.")); } - if (pplayer->economic.luxury != old_econ.luxury) { - changed = TRUE; + if (old_econ.luxury > pplayer->economic.luxury) { notify_player(pplayer, NULL, E_NEW_GOVERNMENT, - _("Luxury rate exceeded the max rate for %s; adjusted."), - government_name_for_player(pplayer)); + _("Luxury rate exceeded the max rate; adjusted.")); } } @@ -1577,7 +1571,7 @@ } players_iterate_end; } - player_limit_to_government_rates(pplayer); + pplayer->economic = player_limit_to_max_rates(pplayer); /* copy the maps */ diff -Nurd -X.diff_ignore freeciv/server/plrhand.h freeciv/server/plrhand.h --- freeciv/server/plrhand.h 2008-05-10 01:12:41.000000000 +0300 +++ freeciv/server/plrhand.h 2008-07-22 21:35:59.000000000 +0300 @@ -40,7 +40,7 @@ bool only_available, enum barbarian_type barb_type); -void check_player_government_rates(struct player *pplayer); +void check_player_max_rates(struct player *pplayer); void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile); void maybe_make_contact(struct tile *ptile, struct player *pplayer); diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c --- freeciv/server/srv_main.c 2008-07-18 22:08:35.000000000 +0300 +++ freeciv/server/srv_main.c 2008-07-22 21:35:59.000000000 +0300 @@ -2073,7 +2073,7 @@ players_iterate(pplayer) { player_map_allocate(pplayer); init_tech(pplayer, TRUE); - player_limit_to_government_rates(pplayer); + pplayer->economic = player_limit_to_max_rates(pplayer); pplayer->economic.gold = game.info.gold; } players_iterate_end; diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c --- freeciv/server/stdinhand.c 2008-07-21 12:41:51.000000000 +0300 +++ freeciv/server/stdinhand.c 2008-07-22 21:35:59.000000000 +0300 @@ -786,9 +786,9 @@ _("%s is now under human control."), player_name(pplayer)); - /* because the hard AI `cheats' with government rates but humans shouldn't */ + /* because the AI `cheats' with government rates but humans shouldn't */ if (!game.info.is_new_game) { - check_player_government_rates(pplayer); + check_player_max_rates(pplayer); } /* Remove hidden dialogs from clients. This way the player can initiate * new meeting */
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev