A TODO item

Jordi Negrevernis i Font <jnegrevernis-36PstVvw7Mg+38RGafAZ5wC/[email protected]> Tue, 31 May 2005 18:48:11 +0200
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------020904090608010001000609
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


    Instruct the AI to not research the obsoleting techs of its own 
wonders, and try to research the obsoleting techs of the wonders of the 
enemies.

    I did not decided what to do with allies, and nations at peace or 
cease-fire.


--------------020904090608010001000609
Content-Type: text/x-patch;
 name="wonder_tech.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="wonder_tech.diff"

diff -b -ruN -Xfreeciv-2.0.1/diff_ignore freeciv-2.0.1/ai/aitech.c freeciv-2.0.1-ai_research/ai/aitech.c
--- freeciv-2.0.1/ai/aitech.c	2005-04-01 06:10:17.000000000 +0200
+++ freeciv-2.0.1-ai_research/ai/aitech.c	2005-05-31 17:29:53.000000000 +0200
@@ -260,6 +260,98 @@
 }
 
 /**************************************************************************
+  This function does 2 things:
+  1. Estimulate research of obsoleting techs for enemy wonders
+  2. Deinsentivate research of obsoleting techs for own wonders
+**************************************************************************/
+static void ai_modify_wonders_tech_want(struct player *pplayer)
+{ int city_id = 0;
+  struct city *pcity;
+  int tech_obs = 0, tech_want = 0, i = 0;
+
+  if (is_barbarian(pplayer)|| !pplayer->is_alive) {
+    return;
+  }
+
+  /* calculate the want for an obsoleting a tech */
+  tech_type_iterate(i) {
+    if (pplayer->ai.tech_want[i] > tech_want) {
+      tech_want = pplayer->ai.tech_want[i];
+    }
+  } tech_type_iterate_end;
+  tech_want = MAX(2, tech_want / 20);
+
+  /* searching for the obsoleting techs of current enemy wonders */
+  for (i = 0; i <= B_LAST; i++) {
+    if (improvement_exists(i) && is_wonder(i) && !wonder_obsolete(i)) {
+      city_id = game.global_wonders[i];
+      pcity = find_city_by_id(city_id);
+      if (pcity) {
+        if (pplayers_at_war(pplayer, city_owner(pcity))) {
+          tech_obs = improvement_types[i].obsolete_by;
+	  if (tech_exists(tech_obs) && tech_is_available(pplayer, tech_obs)) {
+	    pplayer->ai.tech_want[tech_obs] += tech_want;
+            freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+	                        "estimulating %s with %d (%d)",
+                    pplayer->name, get_tech_name(pplayer, tech_obs), tech_want,
+		    pplayer->ai.tech_want[tech_obs]);
+
+            /* now, we rise want for prerequisites */
+	    tech_type_iterate(k) {
+	      if (is_tech_a_req_for_goal(pplayer, k, tech_obs)) {
+                pplayer->ai.tech_want[k] += tech_want / 2;
+                freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+	                            "estimulating prereq %s with %d (%d)",
+                        pplayer->name, get_tech_name(pplayer, k), tech_want / 2,
+		        pplayer->ai.tech_want[k]);
+	      }
+	    } tech_type_iterate_end;
+
+          }
+	}
+      }
+    }
+  }
+
+  /* searching for the obsoleting techs of current owned wonders */
+  for (i = 0; i <= B_LAST; i++) {
+    if (improvement_exists(i) && is_wonder(i) && !wonder_obsolete(i)) {
+      city_id = game.global_wonders[i];
+      pcity = find_city_by_id(city_id);
+      if (pcity) {
+        if (pplayer == city_owner(pcity)) {
+          tech_obs = improvement_types[i].obsolete_by;
+	  if (tech_exists(tech_obs) && tech_is_available(pplayer, tech_obs)) {
+	    if (pplayer->ai.tech_want[tech_obs] >= 0) {
+	      pplayer->ai.tech_want[tech_obs] -= tech_want;
+	    }
+            freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+	                        "decrising %s with %d (%d)",
+                    pplayer->name, get_tech_name(pplayer, tech_obs), tech_want,
+		    pplayer->ai.tech_want[tech_obs]);
+
+            /* now, we decrise want for prerequisites */
+	    tech_type_iterate(k) {
+	      if (is_tech_a_req_for_goal(pplayer, k, tech_obs)) {
+                if (pplayer->ai.tech_want[k] >= 0) {
+		  pplayer->ai.tech_want[k] -= tech_want / 2;
+		}
+                freelog(LOG_NORMAL, "ai_modify_wonders_tech_want of %s "
+	                            "decrising prereq %s with %d (%d)",
+                        pplayer->name, get_tech_name(pplayer, k), tech_want / 2,
+		        pplayer->ai.tech_want[k]);
+	      }
+	    } tech_type_iterate_end;
+
+          }
+	}
+      }
+    }
+  }
+
+}
+
+/**************************************************************************
   Key AI research function. Disable if we are in a team with human team
   mates in a research pool.
 **************************************************************************/
@@ -278,6 +370,9 @@
     }
   } players_iterate_end;
 
+  /* we instruct the AI to count on the wonders before selecting a tech */
+  ai_modify_wonders_tech_want(pplayer);
+
   ai_use_gov_tech_hint(pplayer);
 
   ai_select_tech(pplayer, &choice, &goal);

--------------020904090608010001000609--