Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2787) Remove use of A_NONE
Home

[Freeciv-Dev] (PR#2787) Remove use of A_NONE

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2787) Remove use of A_NONE
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Thu, 9 Jan 2003 10:11:16 -0800
Reply-to: rt@xxxxxxxxxxxxxx


A_NONE is used to flag various different conditions:
 - no tech for research set
 - no tech goal set
 - researching a future tech

The attached patch fixes this by replacing A_NONE with A_UNSET and
A_FUTURE. This was listed as a FIXME in is_future_tech. In addition to
the replacment the patch also adds some docu and adds a new function
ai_wants_no_science. An autogame differs only in the expected way:

@@ -778,7 +778,7 @@
 is_male=1
 is_alive=1
 ai.control=1
-ai.tech_goal=0
+ai.tech_goal=199
 ai.skill_level=7
 ai.is_barbarian=0
 gold=1624
@@ -791,7 +791,7 @@
 research_got_tech=0
 research_changed_from=-1
 researchpoints=90
-researching=0
+researching=198
 capital=1
 revolution=-1
 
invs="11111111111111111111111111011110111111111111111111111111111111111111111111111111111111111"

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "How about the new language C&? No, that's not 'c ampersand', 'c reference', 
  'reference to c' or 'c and'. It's pronounced 'campersand', to confuse the 
  hell out of people who are unfamiliar with it, and it will, of course, 
  have no pointers."
    -- Xazziri in comp.lang.c++ about C#

Index: ai/advattitude.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advattitude.c,v
retrieving revision 1.6
diff -u -u -r1.6 advattitude.c
--- ai/advattitude.c    2002/12/17 16:04:43     1.6
+++ ai/advattitude.c    2003/01/09 17:59:01
@@ -25,7 +25,7 @@
 /********************************************************************** 
 ... this function should assign a value to choice and want, where 
     want is a value between 1 and 100.
-    if choice is A_NONE this advisor doesn't want any tech researched at
+    if choice is A_UNSET this advisor doesn't want any tech researched at
     the moment
 ***********************************************************************/
 void attitude_advisor_choose_tech(struct player *pplayer, 
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.98
diff -u -u -r1.98 advdomestic.c
--- ai/advdomestic.c    2003/01/09 02:36:36     1.98
+++ ai/advdomestic.c    2003/01/09 17:59:03
@@ -421,7 +421,9 @@
   sci = ((sci + pcity->trade_prod) * t)/2;
   tax = ((tax + pcity->trade_prod) * t)/2;
   /* don't need libraries!! */
-  if (pplayer->research.researching == A_NONE) sci = 0;
+  if (ai_wants_no_science(pplayer)) {
+    sci = 0;
+  }
 
   est_food = 2 * pcity->ppl_scientist + 2 * pcity->ppl_taxman
            + pcity->food_surplus; 
Index: ai/advforeign.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advforeign.c,v
retrieving revision 1.6
diff -u -u -r1.6 advforeign.c
--- ai/advforeign.c     2002/12/17 16:04:43     1.6
+++ ai/advforeign.c     2003/01/09 17:59:03
@@ -25,7 +25,7 @@
 /********************************************************************** 
 ... this function should assign a value to choice and want, where 
     want is a value between 1 and 100.
-    if choice is A_NONE this advisor doesn't want any tech researched at
+    if choice is A_UNSET this advisor doesn't want any tech researched at
     the moment
 ***********************************************************************/
 void foreign_advisor_choose_tech(struct player *pplayer, 
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.130
diff -u -u -r1.130 advmilitary.c
--- ai/advmilitary.c    2003/01/09 02:36:36     1.130
+++ ai/advmilitary.c    2003/01/09 17:59:07
@@ -45,8 +45,8 @@
 This function should assign a value to choice and want, where want is a value
 between 1 and 100.
 
-If choice is A_NONE, this advisor doesn't want any particular tech researched
-at the moment.
+If choice is A_UNSET, this advisor doesn't want any particular tech
+researched at the moment.
 ***********************************************************************/
 void military_advisor_choose_tech(struct player *pplayer,
                                  struct ai_choice *choice)
Index: ai/advscience.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advscience.c,v
retrieving revision 1.6
diff -u -u -r1.6 advscience.c
--- ai/advscience.c     2002/12/17 16:04:44     1.6
+++ ai/advscience.c     2003/01/09 17:59:07
@@ -25,7 +25,7 @@
 /********************************************************************** 
 ... this function should assign a value to choice and want, where 
     want is a value between 1 and 100.
-    if choice is A_NONE this advisor doesn't want any tech researched at
+    if choice is A_UNSET this advisor doesn't want any tech researched at
     the moment
 ***********************************************************************/
 void science_advisor_choose_tech(struct player *pplayer,
Index: ai/advtrade.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advtrade.c,v
retrieving revision 1.6
diff -u -u -r1.6 advtrade.c
--- ai/advtrade.c       2002/12/17 16:04:44     1.6
+++ ai/advtrade.c       2003/01/09 17:59:07
@@ -25,7 +25,7 @@
 /********************************************************************** 
 ... this function should assign a value to choice and want, where 
     want is a value between 1 and 100.
-    if choice is A_NONE this advisor doesn't want any tech researched at
+    if choice is A_UNSET this advisor doesn't want any tech researched at
     the moment
 ***********************************************************************/
 void trade_advisor_choose_tech(struct player *pplayer, struct ai_choice 
*choice)
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.134
diff -u -u -r1.134 aicity.c
--- ai/aicity.c 2002/12/23 18:09:57     1.134
+++ ai/aicity.c 2003/01/09 17:59:09
@@ -654,9 +654,8 @@
 **************************************************************************/
 static bool building_unwanted(struct player *plr, Impr_Type_id i)
 {
-  if (plr->research.researching != A_NONE)
-    return FALSE;
-  return (i == B_LIBRARY || i == B_UNIVERSITY || i == B_RESEARCH);
+  return (ai_wants_no_science(plr)
+         && (i == B_LIBRARY || i == B_UNIVERSITY || i == B_RESEARCH));
 }
 
 /**************************************************************************
@@ -844,10 +843,11 @@
   tax_bonus = city_tax_bonus(pcity);
   science_bonus = city_science_bonus(pcity);
   
-  if (tax_bonus > science_bonus || (city_owner(pcity)->research.researching == 
A_NONE)) 
+  if (tax_bonus > science_bonus || ai_wants_no_science(city_owner(pcity))) {
     make_taxmen(pcity);
-  else
+  } else {
     make_scientists(pcity);
+  }
 
   sync_cities();
 }
Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.73
diff -u -u -r1.73 aihand.c
--- ai/aihand.c 2002/12/23 18:09:58     1.73
+++ ai/aihand.c 2003/01/09 17:59:10
@@ -215,7 +215,7 @@
 /* if the lux rate necessary to celebrate cannot be maintained, don't bother */
   pplayer->economic.luxury = 10 * m;
 
-  if (pplayer->research.researching==A_NONE) {
+  if (ai_wants_no_science(pplayer)) {
     pplayer->economic.tax = 100 - pplayer->economic.luxury;
     while (pplayer->economic.tax > maxrate * 10) {
       pplayer->economic.tax -= 10;
@@ -315,7 +315,7 @@
   int best_gov = 0;
   int best_val = 0;
   int really_best_val = 0;
-  int really_best_req = A_NONE;
+  int really_best_req = A_UNSET;
   int i;
   int bonus = 0; /* in percentage */
   int current_gov = pplayer->government;
Index: ai/aitech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitech.c,v
retrieving revision 1.37
diff -u -u -r1.37 aitech.c
--- ai/aitech.c 2002/12/21 11:44:00     1.37
+++ ai/aitech.c 2003/01/09 17:59:10
@@ -39,7 +39,7 @@
 /**************************************************************************
   Returns tech corresponding to players wonder goal from nations[],
   if it makes sense, and wonder is not already built and not obsolete.
-  Otherwise returns A_NONE.
+  Otherwise returns A_UNSET.
 **************************************************************************/
 static Tech_Type_id get_wonder_tech(struct player *plr)
 {
@@ -53,7 +53,7 @@
     if (tech_exists(tech) && get_invention(plr, tech) != TECH_KNOWN)
       return tech;
   }
-  return A_NONE;
+  return A_UNSET;
 }
 
 /**************************************************************************
@@ -65,7 +65,7 @@
   struct nation_type *prace = get_nation_by_plr(pplayer);
   int bestdist = A_LAST + 1;
   int dist, i;
-  Tech_Type_id goal = A_NONE;
+  Tech_Type_id goal = A_UNSET;
   Tech_Type_id tech;
 
   for (i = 0 ; i < MAX_NUM_TECH_GOALS; i++) {
@@ -80,14 +80,14 @@
     }
   } 
   tech = get_wonder_tech(pplayer);
-  if (tech != A_NONE) {
+  if (tech != A_UNSET) {
     dist = num_unknown_techs_for_goal(pplayer, tech);
     if (dist < bestdist) { 
 /*    bestdist = dist; */ /* useless, reinclude when adding a new if statement 
*/
       goal = tech;
     }
   }
-  if (goal != A_NONE) {
+  if (goal != A_UNSET) {
     choice->choice = goal;
     choice->want = 1;
   }
@@ -154,7 +154,7 @@
     } else goal_values[i] = 0;
   }
 
-  l = A_NONE; k = A_NONE;
+  l = A_UNSET; k = A_UNSET;
   for (i = A_FIRST; i < game.num_tech_types; i++) {
     if (values[i] > values[l] && get_invention(pplayer, i) == TECH_REACHABLE) 
l = i;
     if (goal_values[i] > goal_values[k]) k = i;
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.73
diff -u -u -r1.73 aitools.c
--- ai/aitools.c        2003/01/06 00:39:01     1.73
+++ ai/aitools.c        2003/01/09 17:59:12
@@ -470,7 +470,7 @@
 **************************************************************************/
 void init_choice(struct ai_choice *choice)
 {
-  choice->choice = A_NONE;
+  choice->choice = A_UNSET;
   choice->want = 0;
   choice->type = CT_NONE;
 }
@@ -613,4 +613,12 @@
  
   if (unhap < 0) unhap = 0;
   return unhap > 0;
+}
+
+/**************************************************************************
+  AI doesn't want the score for future techs.
+**************************************************************************/
+bool ai_wants_no_science(struct player *pplayer)
+{
+  return is_future_tech(pplayer->research.researching);
 }
Index: ai/aitools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.h,v
retrieving revision 1.34
diff -u -u -r1.34 aitools.h
--- ai/aitools.h        2003/01/06 00:39:01     1.34
+++ ai/aitools.h        2003/01/09 17:59:12
@@ -65,5 +65,6 @@
 bool ai_assess_military_unhappiness(struct city *pcity, struct government *g);
 
 int ai_evaluate_government(struct player *pplayer, struct government *g);
+bool ai_wants_no_science(struct player *pplayer);
 
 #endif  /* FC__AITOOLS_H */
Index: client/gui-gtk/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v
retrieving revision 1.68
diff -u -u -r1.68 repodlgs.c
--- client/gui-gtk/repodlgs.c   2003/01/01 11:51:33     1.68
+++ client/gui-gtk/repodlgs.c   2003/01/09 17:59:15
@@ -422,7 +422,7 @@
    * hist will hold afterwards the techid of the current choice
    */
   hist=0;
-  if (game.player_ptr->research.researching!=A_NONE) {
+  if (!is_future_tech(game.player_ptr->research.researching)) {
     for(i=A_FIRST; i<game.num_tech_types; i++) {
       if(get_invention(game.player_ptr, i)!=TECH_REACHABLE)
        continue;
@@ -481,7 +481,7 @@
              steps);
   gtk_set_label(science_goal_label,text);
 
-  if (game.player_ptr->ai.tech_goal==A_NONE) {
+  if (game.player_ptr->ai.tech_goal == A_UNSET) {
     item = gtk_menu_item_new_with_label(advances[A_NONE].name);
     gtk_menu_append(GTK_MENU(goalmenu), item);
   }
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.23
diff -u -u -r1.23 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       2002/12/30 02:32:02     1.23
+++ client/gui-gtk-2.0/repodlgs.c       2003/01/09 17:59:20
@@ -425,7 +425,7 @@
    * hist will hold afterwards the techid of the current choice
    */
   hist=0;
-  if (game.player_ptr->research.researching!=A_NONE) {
+  if (!is_future_tech(game.player_ptr->research.researching)) {
     for(i=A_FIRST; i<game.num_tech_types; i++) {
       if(get_invention(game.player_ptr, i)!=TECH_REACHABLE)
        continue;
@@ -481,7 +481,7 @@
              steps);
   gtk_set_label(science_goal_label,text);
 
-  if (game.player_ptr->ai.tech_goal==A_NONE) {
+  if (game.player_ptr->ai.tech_goal == A_UNSET) {
     item = gtk_menu_item_new_with_label(advances[A_NONE].name);
     gtk_menu_shell_append(GTK_MENU_SHELL(goalmenu), item);
   }
Index: client/gui-mui/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/repodlgs.c,v
retrieving revision 1.27
diff -u -u -r1.27 repodlgs.c
--- client/gui-mui/repodlgs.c   2002/11/14 09:14:57     1.27
+++ client/gui-mui/repodlgs.c   2003/01/09 17:59:21
@@ -124,7 +124,7 @@
   int i;
   int to = -1;
 
-  if (game.player_ptr->ai.tech_goal == A_NONE)
+  if (game.player_ptr->ai.tech_goal == A_UNSET)
     if (help_goal_entries[*newgoal] == (STRPTR) advances[A_NONE].name)
       to = 0;
   for (i = A_FIRST; i < game.num_tech_types; i++)
@@ -210,8 +210,7 @@
     help_goal_entries = NULL;
   }
 
-  if (game.player_ptr->research.researching != A_NONE)
-  {
+  if (!is_future_tech(game.player_ptr->research.researching)) {
     for (i = A_FIRST, j = 0; i < game.num_tech_types; i++)
     {
       if (get_invention(game.player_ptr, i) != TECH_REACHABLE)
@@ -246,7 +245,7 @@
        num_unknown_techs_for_goal(game.player_ptr, i) < 11)
       j++;
   }
-  if (game.player_ptr->ai.tech_goal == A_NONE)
+  if (game.player_ptr->ai.tech_goal == A_UNSET)
     j++;
 
   if (j)
@@ -254,7 +253,7 @@
     if ((help_goal_entries = (STRPTR *) malloc((j + 2) * sizeof(STRPTR))))
     {
       j = 0;
-      if (game.player_ptr->ai.tech_goal == A_NONE)
+      if (game.player_ptr->ai.tech_goal == A_UNSET)
        help_goal_entries[j++] = advances[A_NONE].name;
 
 
Index: client/gui-sdl/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/repodlgs.c,v
retrieving revision 1.3
diff -u -u -r1.3 repodlgs.c
--- client/gui-sdl/repodlgs.c   2002/12/30 21:40:50     1.3
+++ client/gui-sdl/repodlgs.c   2003/01/09 17:59:23
@@ -417,7 +417,7 @@
   pStr = create_string16(NULL, 10);
   pStr->style |= (TTF_STYLE_BOLD | SF_CENTER);
 
-  if (game.player_ptr->research.researching != A_NONE) {
+  if (!is_future_tech(game.player_ptr->research.researching)) {
     for (i = A_FIRST; i < game.num_tech_types; i++) {
       if (get_invention(game.player_ptr, i) != TECH_REACHABLE) {
        continue;
Index: client/gui-win32/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/repodlgs.c,v
retrieving revision 1.25
diff -u -u -r1.25 repodlgs.c
--- client/gui-win32/repodlgs.c 2002/11/15 21:24:29     1.25
+++ client/gui-win32/repodlgs.c 2003/01/09 17:59:25
@@ -123,8 +123,7 @@
              total_bulbs_required(game.player_ptr));
   SetWindowText(GetDlgItem(science_dlg,ID_SCIENCE_PROG),text);
   ComboBox_ResetContent(GetDlgItem(science_dlg,ID_SCIENCE_RESEARCH));
-  if (game.player_ptr->research.researching!=A_NONE)
-    {
+  if (!is_future_tech(game.player_ptr->research.researching)) {
       for (i=A_FIRST; i<game.num_tech_types; i++)
        {
          if (get_invention(game.player_ptr,i)!=TECH_REACHABLE)
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.107
diff -u -u -r1.107 player.c
--- common/player.c     2003/01/05 23:24:52     1.107
+++ common/player.c     2003/01/09 17:59:27
@@ -88,7 +88,7 @@
   }
   plr->city_style=0;            /* should be first basic style */
   plr->ai.control=FALSE;
-  plr->ai.tech_goal = A_NONE;
+  plr->ai.tech_goal = A_UNSET;
   plr->ai.handicap = 0;
   plr->ai.skill_level = 0;
   plr->ai.fuzzy = 0;
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.91
diff -u -u -r1.91 player.h
--- common/player.h     2003/01/05 23:24:52     1.91
+++ common/player.h     2003/01/09 17:59:27
@@ -66,7 +66,13 @@
 struct player_research {
   int bulbs_researched;   /* # bulbs reseached for the current tech */    
   int techs_researched;   /* # techs the player has researched/acquired */
-  int researching;        /* invention being researched in */
+  /* 
+   * Invention being researched in. Valid values for researching are:
+   *  - any existing tech but not A_NONE or
+   *  - A_FUTURE.
+   * In addition A_UNSET is allowed at the client for enemies.
+   */
+  int researching;        
   int changed_from;       /* if the player changed techs, which one
                             changed from */
   int bulbs_researched_before;  /* if the player changed techs, how
@@ -116,6 +122,12 @@
 
 struct player_ai {
   bool control;
+
+  /* 
+   * Valid values for tech_goal are:
+   *  - any existing tech but not A_NONE or
+   *  - A_UNSET.
+   */
   int tech_goal;
   int prev_gold;
   int maxbuycost;
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.54
diff -u -u -r1.54 tech.c
--- common/tech.c       2003/01/09 16:03:43     1.54
+++ common/tech.c       2003/01/09 17:59:28
@@ -201,13 +201,13 @@
   Tech_Type_id sub_goal;
 
   if (!tech_exists(goal) || get_invention(pplayer, goal) == TECH_KNOWN) {
-    return A_NONE;
+    return A_UNSET;
   }
   if (get_invention(pplayer, goal) == TECH_REACHABLE) {
     return goal;
   }
   sub_goal = get_next_tech_rec(pplayer, advances[goal].req[0]);
-  if (sub_goal != A_NONE) {
+  if (sub_goal != A_UNSET) {
     return sub_goal;
   } else {
     return get_next_tech_rec(pplayer, advances[goal].req[1]);
@@ -223,7 +223,7 @@
 Tech_Type_id get_next_tech(struct player *pplayer, Tech_Type_id goal)
 {
   if (!tech_exists(goal) || get_invention(pplayer, goal) == TECH_KNOWN) {
-    return A_NONE;
+    return A_UNSET;
   }
   return (get_next_tech_rec(pplayer, goal));
 }
@@ -518,12 +518,7 @@
 **************************************************************************/
 bool is_future_tech(Tech_Type_id tech)
 {
-  /*
-   * Future techs can be identify in two ways: the "tech >=
-   * game.num_tech_types" condition and the "tech == A_NONE"
-   * condition. FIXME: clean this up.
-   */
-  return (tech >= game.num_tech_types) || (tech == A_NONE);
+  return tech == A_FUTURE;
 }
 
 /**************************************************************************
@@ -535,6 +530,7 @@
   static char buffer[200];
 
   if (!is_future_tech(tech)) {
+    assert(tech_exists(tech));
     my_snprintf(buffer, sizeof(buffer), "%s", advances[tech].name);
   } else {
     my_snprintf(buffer, sizeof(buffer), _("Future Tech. %d"),
Index: common/tech.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v
retrieving revision 1.37
diff -u -u -r1.37 tech.h
--- common/tech.h       2003/01/03 08:58:47     1.37
+++ common/tech.h       2003/01/09 17:59:29
@@ -27,11 +27,20 @@
 #define A_NONE 0
 #define A_FIRST 1
 #define A_LAST MAX_NUM_ITEMS
+#define A_UNSET (A_LAST-1)
+#define A_FUTURE (A_LAST-2)
+
 /*
-   A_NONE is a special tech value, used as a flag in various
-   cases where no tech is required.
+   A_NONE is the root tech. All players always know this tech. It is
+   used as a flag in various cases where there is no tech-requirement.
 
    A_FIRST is the first real tech id value
+
+   A_UNSET is a value which indicates that no tech is selected (for
+   research).
+
+   A_FUTURE is a value which indicates that the player is researching
+   a future tech.
 
    A_LAST is a value which is guaranteed to be larger than all
    actual tech id values.  It is used as a flag value; it can
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.254
diff -u -u -r1.254 plrhand.c
--- server/plrhand.c    2003/01/05 23:24:52     1.254
+++ server/plrhand.c    2003/01/09 17:59:34
@@ -56,7 +56,7 @@
                                 struct player *receiver,
                                 enum plr_info_level min_info_level);
 static void tech_researched(struct player* plr);
-static int choose_goal_tech(struct player *plr);
+static bool choose_goal_tech(struct player *plr);
 static enum plr_info_level player_info_level(struct player *plr,
                                             struct player *receiver);
 
@@ -211,6 +211,10 @@
   bool macro_polo_was_obsolete = wonder_obsolete(B_MARCO);
   struct city *pcity;
 
+  assert((tech_exists(tech_found)
+         && get_invention(plr, tech_found) != TECH_KNOWN)
+        || tech_found == A_FUTURE);
+
   plr->got_tech = TRUE;
   plr->research.techs_researched++;
   was_first = (game.global_advances[tech_found] == 0);
@@ -233,8 +237,7 @@
   }
 
   for (i=0; i<game.government_count; i++) {
-    if (tech_found == governments[i].required_tech
-       && tech_found != A_NONE) {
+    if (tech_found == governments[i].required_tech) {
       notify_player_ex(plr,-1,-1, E_NEW_GOVERNMENT,
                       _("Game: Discovery of %s makes the government form %s"
                         " available. You may want to start a revolution."),
@@ -267,15 +270,16 @@
     unit_list_iterate_end;
   }
 
-  if (tech_found==plr->ai.tech_goal)
-    plr->ai.tech_goal=A_NONE;
+  if (tech_found == plr->ai.tech_goal) {
+    plr->ai.tech_goal = A_UNSET;
+  }
 
   if (tech_found==plr->research.researching) {
     /* need to pick new tech to research */
 
     int saved_bulbs = plr->research.bulbs_researched;
 
-    if (choose_goal_tech(plr) != 0) {
+    if (choose_goal_tech(plr)) {
       notify_player_ex(plr, -1, -1, E_TECH_LEARNED,
                       _("Game: Learned %s.  "
                         "Our scientists focus on %s, goal is %s."),
@@ -424,7 +428,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static int choose_goal_tech(struct player *plr)
+static bool choose_goal_tech(struct player *plr)
 {
   int sub_goal;
 
@@ -432,22 +436,24 @@
     plr->research.bulbs_researched = 0;
   }
   if (plr->ai.control) {
-    ai_next_tech_goal(plr); /* tech-AI has been changed */
-    sub_goal = get_next_tech(plr, plr->ai.tech_goal); /* should be changed */
-  } else sub_goal = get_next_tech(plr, plr->ai.tech_goal);
-  if (sub_goal == 0) {
+    ai_next_tech_goal(plr);    /* tech-AI has been changed */
+  }
+  sub_goal = get_next_tech(plr, plr->ai.tech_goal);
+
+  if (sub_goal == A_UNSET) {
     if (plr->ai.control || plr->research.techs_researched == 1) {
       ai_next_tech_goal(plr);
       sub_goal = get_next_tech(plr, plr->ai.tech_goal);
     } else {
-      plr->ai.tech_goal = A_NONE; /* clear goal when it is achieved */
+      plr->ai.tech_goal = A_UNSET;     /* clear goal when it is achieved */
     }
   }
 
-  if (sub_goal != 0) {
-    plr->research.researching=sub_goal;
-  }   
-  return sub_goal;
+  if (sub_goal != A_UNSET) {
+    plr->research.researching = sub_goal;
+    return TRUE;
+  }
+  return FALSE;
 }
 
 
@@ -468,7 +474,7 @@
     }
   }
   if (researchable == 0) {
-    plr->research.researching = A_NONE;
+    plr->research.researching = A_FUTURE;
     return;
   }
   choosen = myrand(researchable) + 1;
@@ -559,7 +565,7 @@
 
   /* Mark the reachable techs */
   update_research(plr);
-  if (choose_goal_tech(plr) == 0) {
+  if (!choose_goal_tech(plr)) {
     choose_random_tech(plr);
   }
 }
@@ -1202,7 +1208,7 @@
     packet->luxury          = 0;
     packet->bulbs_researched= 0;
     packet->techs_researched= 0;
-    packet->researching     = A_NONE;
+    packet->researching     = A_UNSET;
     packet->future_tech     = 0;
     packet->revolution      = 0;
 
@@ -1233,8 +1239,18 @@
   if (info_level >= INFO_FULL) {
     packet->tech_goal       = plr->ai.tech_goal;
   } else {
-    packet->tech_goal       = A_NONE;
+    packet->tech_goal       = A_UNSET;
   }
+
+  /* 
+   * This may be an odd time to check these values but we can be sure
+   * to have a consistent state here.
+   */
+  assert((tech_exists(plr->research.researching)
+         && plr->research.researching != A_NONE)
+        || is_future_tech(plr->research.researching));
+  assert((tech_exists(plr->ai.tech_goal) && plr->ai.tech_goal != A_NONE)
+        || plr->ai.tech_goal == A_UNSET);
 }
 
 /**************************************************************************
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.128
diff -u -u -r1.128 ruleset.c
--- server/ruleset.c    2003/01/03 08:58:48     1.128
+++ server/ruleset.c    2003/01/09 17:59:40
@@ -2144,7 +2144,7 @@
       freelog(LOG_VERBOSE, "No valid goal techs for %s", pl->name);
     }
     while( j < MAX_NUM_TECH_GOALS )
-      pl->goals.tech[j++] = A_NONE;
+      pl->goals.tech[j++] = A_UNSET;
     if (techs) free(techs);
 
     /* AI wonder & government */

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