Author: cazfi Date: Sun Nov 20 11:26:26 2016 New Revision: 34582 URL: http://svn.gna.org/viewcvs/freeciv?rev=34582&view=rev Log: Made AI to adjust policy values.
Requested by Jacob Nevins <jtn> See patch #6080 Modified: trunk/ai/default/aidata.c trunk/ai/default/aidata.h trunk/ai/default/aihand.c Modified: trunk/ai/default/aidata.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aidata.c?rev=34582&r1=34581&r2=34582&view=diff ============================================================================== --- trunk/ai/default/aidata.c (original) +++ trunk/ai/default/aidata.c Sun Nov 20 11:26:26 2016 @@ -19,6 +19,7 @@ #include "game.h" #include "government.h" #include "map.h" +#include "multipliers.h" #include "research.h" /* server */ @@ -423,6 +424,86 @@ } /**************************************************************************** + Adjust multiplier values. +****************************************************************************/ +void dai_adjust_policies(struct ai_type *ait, struct player *pplayer) +{ + bool needs_back_rearrange = FALSE; + struct adv_data *adv; + + adv = adv_data_get(pplayer, NULL); + + multipliers_iterate(ppol) { + int orig_value = 0; + int mp_val = player_multiplier_value(pplayer, ppol); + int pidx = multiplier_index(ppol); + bool better_found = FALSE; + + city_list_iterate(pplayer->cities, pcity) { + orig_value += dai_city_want(pplayer, pcity, adv, NULL); + } city_list_iterate_end; + + /* Consider reducing policy value */ + if (mp_val > ppol->start) { + int new_value = 0; + + pplayer->multipliers[pidx] = MAX(mp_val - ppol->step, ppol->start); + + city_list_iterate(pplayer->cities, acity) { + auto_arrange_workers(acity); + } city_list_iterate_end; + + city_list_iterate(pplayer->cities, pcity) { + new_value += dai_city_want(pplayer, pcity, adv, NULL); + } city_list_iterate_end; + + if (new_value > orig_value) { + /* This is step to right direction, leave it in effect. */ + pplayer->multipliers_target[pidx] = pplayer->multipliers[pidx]; + + needs_back_rearrange = FALSE; + better_found = TRUE; + } + } + + /* Consider increasing policy value */ + if (!better_found && mp_val < ppol->stop) { + int new_value = 0; + + pplayer->multipliers[pidx] = MIN(mp_val + ppol->step, ppol->stop); + + city_list_iterate(pplayer->cities, acity) { + auto_arrange_workers(acity); + } city_list_iterate_end; + + city_list_iterate(pplayer->cities, pcity) { + new_value += dai_city_want(pplayer, pcity, adv, NULL); + } city_list_iterate_end; + + if (new_value > orig_value) { + /* This is step to right direction, leave it in effect. */ + pplayer->multipliers_target[pidx] = pplayer->multipliers[pidx]; + + needs_back_rearrange = FALSE; + better_found = TRUE; + } + } + + if (!better_found) { + /* Restore original multiplier value */ + pplayer->multipliers[pidx] = mp_val; + needs_back_rearrange = TRUE; + } + } multipliers_iterate_end; + + if (needs_back_rearrange) { + city_list_iterate(pplayer->cities, acity) { + auto_arrange_workers(acity); + } city_list_iterate_end; + } +} + +/**************************************************************************** Set value of the government. ****************************************************************************/ void dai_gov_value(struct ai_type *ait, struct player *pplayer, Modified: trunk/ai/default/aidata.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aidata.h?rev=34582&r1=34581&r2=34582&view=diff ============================================================================== --- trunk/ai/default/aidata.h (original) +++ trunk/ai/default/aidata.h Sun Nov 20 11:26:26 2016 @@ -122,4 +122,6 @@ void dai_gov_value(struct ai_type *ait, struct player *pplayer, struct government *gov, adv_want *val, bool *override); +void dai_adjust_policies(struct ai_type *ait, struct player *pplayer); + #endif /* FC__AIDATA_H */ Modified: trunk/ai/default/aihand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aihand.c?rev=34582&r1=34581&r2=34582&view=diff ============================================================================== --- trunk/ai/default/aihand.c (original) +++ trunk/ai/default/aihand.c Sun Nov 20 11:26:26 2016 @@ -765,6 +765,7 @@ dai_clear_tech_wants(ait, pplayer); dai_manage_government(ait, pplayer); + dai_adjust_policies(ait, pplayer); TIMING_LOG(AIT_TAXES, TIMER_START); dai_manage_taxes(ait, pplayer); TIMING_LOG(AIT_TAXES, TIMER_STOP); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits