Author: cazfi Date: Thu Apr 28 15:51:06 2016 New Revision: 32521 URL: http://svn.gna.org/viewcvs/freeciv?rev=32521&view=rev Log: Refactored city_unit_unhappiness() to check EFT_MAKE_CONTENT_MIL_PER only when result is needed.
See patch #7149 Modified: branches/S2_5/common/city.c Modified: branches/S2_5/common/city.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/city.c?rev=32521&r1=32520&r2=32521&view=diff ============================================================================== --- branches/S2_5/common/city.c (original) +++ branches/S2_5/common/city.c Thu Apr 28 15:51:06 2016 @@ -2721,24 +2721,38 @@ **************************************************************************/ int city_unit_unhappiness(struct unit *punit, int *free_unhappy) { - struct city *pcity = game_city_by_number(punit->homecity); - struct unit_type *ut = unit_type(punit); - struct player *plr = unit_owner(punit); - int happy_cost = utype_happy_cost(ut, plr); - - if (!punit || !pcity || !free_unhappy || happy_cost <= 0) { + struct city *pcity; + struct unit_type *ut; + struct player *plr; + int happy_cost; + + if (!punit || !free_unhappy) { return 0; } + + pcity = game_city_by_number(punit->homecity); + if (pcity == NULL) { + return 0; + } + + ut = unit_type(punit); + plr = unit_owner(punit); + happy_cost = utype_happy_cost(ut, plr); + if (happy_cost <= 0) { + return 0; + } + fc_assert_ret_val(0 <= *free_unhappy, 0); - - happy_cost -= get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL_PER); if (!unit_being_aggressive(punit) && !is_field_unit(punit)) { return 0; } + + happy_cost -= get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL_PER); if (happy_cost <= 0) { return 0; } + if (*free_unhappy >= happy_cost) { *free_unhappy -= happy_cost; return 0; @@ -2746,6 +2760,7 @@ happy_cost -= *free_unhappy; *free_unhappy = 0; } + return happy_cost; } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits