Author: cazfi
Date: Sun Nov 20 11:26:31 2016
New Revision: 34583

URL: http://svn.gna.org/viewcvs/freeciv?rev=34583&view=rev
Log:
Made AI to adjust policy values.

Requested by Jacob Nevins <jtn>

See patch #6080

Modified:
    branches/S2_6/ai/default/aidata.c
    branches/S2_6/ai/default/aidata.h
    branches/S2_6/ai/default/aihand.c

Modified: branches/S2_6/ai/default/aidata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aidata.c?rev=34583&r1=34582&r2=34583&view=diff
==============================================================================
--- branches/S2_6/ai/default/aidata.c   (original)
+++ branches/S2_6/ai/default/aidata.c   Sun Nov 20 11:26:31 2016
@@ -19,6 +19,7 @@
 #include "game.h"
 #include "government.h"
 #include "map.h"
+#include "multipliers.h"
 #include "research.h"
 
 /* server */
@@ -418,6 +419,86 @@
   }
 
   *player_intel_slot = NULL;
+}
+
+/****************************************************************************
+  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;
+  }
 }
 
 /****************************************************************************

Modified: branches/S2_6/ai/default/aidata.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aidata.h?rev=34583&r1=34582&r2=34583&view=diff
==============================================================================
--- branches/S2_6/ai/default/aidata.h   (original)
+++ branches/S2_6/ai/default/aidata.h   Sun Nov 20 11:26:31 2016
@@ -116,4 +116,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: branches/S2_6/ai/default/aihand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aihand.c?rev=34583&r1=34582&r2=34583&view=diff
==============================================================================
--- branches/S2_6/ai/default/aihand.c   (original)
+++ branches/S2_6/ai/default/aihand.c   Sun Nov 20 11:26:31 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

Reply via email to