Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] [PATCH] make ai_choice->type enum choice_type (PR#1318)
Home

[Freeciv-Dev] [PATCH] make ai_choice->type enum choice_type (PR#1318)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] make ai_choice->type enum choice_type (PR#1318)
From: Markus Linnala <maage@xxxxxxxxx>
Date: Sun, 10 Mar 2002 08:47:33 -0800 (PST)

As ai_choice->type is usually of type enum choice_type, make it
so. Use common initialisation function, clear_ai_choice.
aitech.c used type for something else, so add new field
tech_want to ai_choice.

diff -ur -X freeciv/diff_ignore freeciv/ai/advdomestic.c
freeciv-ai-choice-tech-want/ai/advdomestic.c
--- freeciv/ai/advdomestic.c    Fri Mar  8 19:06:18 2002
+++ freeciv-ai-choice-tech-want/ai/advdomestic.c        Sun Mar 10 18:42:40 2002
@@ -653,9 +653,7 @@
   /* Continent where the city is - important for caravans */
   int continent = map_get_continent(pcity->x, pcity->y);
 
-  choice->choice = 0;
-  choice->want   = 0;
-  choice->type   = CT_NONE;
+  clear_ai_choice(choice);
 
   /* Find out desire for settlers */
 
diff -ur -X freeciv/diff_ignore freeciv/ai/advmilitary.c 
freeciv-ai-choice-tech-want/ai/advmilitary.c
--- freeciv/ai/advmilitary.c    Wed Mar  6 12:05:09 2002
+++ freeciv-ai-choice-tech-want/ai/advmilitary.c        Sun Mar 10 18:42:40 2002
@@ -945,9 +945,8 @@
   struct unit virtualunit;
   struct city *acity = 0;
   struct unit *aunit = 0;
-  choice->choice = 0;
-  choice->want   = 0;
-  choice->type   = CT_NONE;
+
+  clear_ai_choice(choice);
 
 /* TODO: recognize units that can DEFEND_HOME but are in the field. -- Syela */
 
diff -ur -X freeciv/diff_ignore freeciv/ai/aicity.c 
freeciv-ai-choice-tech-want/ai/aicity.c
--- freeciv/ai/aicity.c Fri Mar  8 19:06:18 2002
+++ freeciv-ai-choice-tech-want/ai/aicity.c     Sun Mar 10 18:42:40 2002
@@ -192,9 +192,7 @@
 {
   struct ai_choice bestchoice, curchoice;
 
-  bestchoice.choice = A_NONE;      
-  bestchoice.want   = 0;
-  bestchoice.type   = CT_NONE;
+  clear_ai_choice(&bestchoice);
 
   if( is_barbarian(pplayer) ) {    /* always build best attack unit */
     Unit_Type_id i, iunit, bestunit = -1;
@@ -240,6 +238,7 @@
     pcity->ai.choice.choice = bestchoice.choice; /* we want to spend gold 
later */
     pcity->ai.choice.want = bestchoice.want; /* so that we spend it in the 
right city */
     pcity->ai.choice.type = bestchoice.type; /* instead of the one atop the 
list */
+    pcity->ai.choice.tech_want = bestchoice.tech_want;
   }
 
   if (bestchoice.want != 0) { /* Note - on fallbacks, will NOT get stopped 
building msg */
@@ -348,15 +347,14 @@
     if (reserve > pplayer->economic.gold)
       break;
 
-    bestchoice.want = 0;
-    bestchoice.type = CT_NONE;
-    bestchoice.choice = 0;
+    clear_ai_choice(&bestchoice);
     city_list_iterate(pplayer->cities, acity)
       if (acity->anarchy != 0) continue;
       if (acity->ai.choice.want > bestchoice.want && ai_fuzzy(pplayer, TRUE)) {
         bestchoice.choice = acity->ai.choice.choice;
         bestchoice.want = acity->ai.choice.want;
         bestchoice.type = acity->ai.choice.type;
+        bestchoice.tech_want = acity->ai.choice.tech_want;
         pcity = acity;
       }
     city_list_iterate_end;
diff -ur -X freeciv/diff_ignore freeciv/ai/aitech.c 
freeciv-ai-choice-tech-want/ai/aitech.c
--- freeciv/ai/aitech.c Tue Mar  5 12:20:02 2002
+++ freeciv-ai-choice-tech-want/ai/aitech.c     Sun Mar 10 18:42:40 2002
@@ -225,14 +225,14 @@
   if (choice) {
     choice->choice = l;
     choice->want = values[l] / num_cities_nonzero;
-    choice->type = values[pplayer->research.researching] / num_cities_nonzero;
+    choice->tech_want = values[pplayer->research.researching] / 
num_cities_nonzero;
     /* hijacking this ... in order to leave tech_wants alone */
   }
 
   if (gol) {
     gol->choice = k;
     gol->want = goal_values[k] / num_cities_nonzero;
-    gol->type = goal_values[pplayer->ai.tech_goal] / num_cities_nonzero;
+    gol->tech_want = goal_values[pplayer->ai.tech_goal] / num_cities_nonzero;
     freelog(LOG_DEBUG,
            "Gol->choice = %s, gol->want = %d, goal_value = %d, "
            "num_cities_nonzero = %d",
@@ -289,7 +289,7 @@
   ai_select_tech(pplayer, &choice, &gol);
   if (choice.choice != pplayer->research.researching) {
     /* changing */
-    if ((choice.want - choice.type) > penalty &&
+    if ((choice.want - choice.tech_want) > penalty &&
        penalty + pplayer->research.bulbs_researched <=
        total_bulbs_required(pplayer)) {
       freelog(LOG_DEBUG, "%s switching from %s to %s with penalty of %d.",
@@ -301,7 +301,7 @@
   /* crossing my fingers on this one! -- Syela (seems to have worked!) */
   if (gol.choice != pplayer->ai.tech_goal) {
     freelog(LOG_DEBUG, "%s changing goal from %s (want = %d) to %s (want = 
%d)",
-           pplayer->name, advances[pplayer->ai.tech_goal].name, gol.type,
+           pplayer->name, advances[pplayer->ai.tech_goal].name, gol.tech_want,
            advances[gol.choice].name, gol.want);
     choose_tech_goal(pplayer, gol.choice);
   }
diff -ur -X freeciv/diff_ignore freeciv/ai/aitools.c 
freeciv-ai-choice-tech-want/ai/aitools.c
--- freeciv/ai/aitools.c        Wed Mar  6 05:02:41 2002
+++ freeciv-ai-choice-tech-want/ai/aitools.c    Sun Mar 10 18:42:40 2002
@@ -109,13 +109,21 @@
 /**************************************************************************
 ...
 **************************************************************************/
+void clear_ai_choice(struct ai_choice *choice)
+{
+  choice->choice = 0;
+  choice->want   = 0;
+  choice->type   = CT_NONE;
+  choice->tech_want = 0;
+}
 
 void copy_if_better_choice(struct ai_choice *cur, struct ai_choice *best)
 {
   if (cur->want > best->want) {
-    best->choice =cur->choice;
+    best->choice = cur->choice;
     best->want = cur->want;
     best->type = cur->type;
+    best->tech_want = cur->tech_want;
   }
 }
 
diff -ur -X freeciv/diff_ignore freeciv/ai/aitools.h 
freeciv-ai-choice-tech-want/ai/aitools.h
--- freeciv/ai/aitools.h        Tue Mar  5 12:20:02 2002
+++ freeciv-ai-choice-tech-want/ai/aitools.h    Sun Mar 10 18:42:40 2002
@@ -26,6 +26,7 @@
 int ai_gold_reserve(struct player *pplayer);
 
 void adjust_choice(int value, struct ai_choice *choice);
+void clear_ai_choice(struct ai_choice *choice);
 void copy_if_better_choice(struct ai_choice *cur, struct ai_choice *best);
 void ai_advisor_choose_building(struct city *pcity, struct ai_choice *choice);
 bool ai_assess_military_unhappiness(struct city *pcity, struct government *g);
diff -ur -X freeciv/diff_ignore freeciv/common/city.h 
freeciv-ai-choice-tech-want/common/city.h
--- freeciv/common/city.h       Fri Mar  8 19:06:24 2002
+++ freeciv-ai-choice-tech-want/common/city.h   Sun Mar 10 18:42:40 2002
@@ -177,7 +177,8 @@
 struct ai_choice {
   int choice;            /* what the advisor wants */
   int want;              /* how bad it wants it (0-100) */
-  int type;              /* unit/building or other depending on question */
+  int tech_want;
+  enum choice_type type; /* unit/building or other depending on question */
 };
 
 struct ai_city {

-- 
//Markus



[Prev in Thread] Current Thread [Next in Thread]