Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] Re: (PR#2715) introducing tech_type_iterate
Home

[Freeciv-Dev] Re: (PR#2715) introducing tech_type_iterate

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2715) introducing tech_type_iterate
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Wed, 8 Jan 2003 13:48:09 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, Jan 08, 2003 at 01:04:11PM -0800, Raimar Falke via RT wrote:
> tech has itself as requirement. Thats it. Nothing more special. Given
> these it is clear that code like:
> 
>     return (req == A_NONE
>             || (get_invention(pplayer, req) == TECH_KNOWN)
>             || player_owns_active_govchange_wonder(pplayer));
> 
> can and _should_ be written as
> 
>     return (get_invention(pplayer, req) == TECH_KNOWN
>             || player_owns_active_govchange_wonder(pplayer));

And the patch to fix these simple things. Browsing the code I found
the following:
 - A_NONE is used to denote an improvement which is never
 obsoleted. This should be A_LAST. Also get_invention should be
 expanded to return TECH_UNKNOWN for A_LAST. Then we have to two flag
 values "always" and "never" and can test against them. This may also
 be expanded further by making a real A_NEVER tech just like A_NONE
 (which is A_ALWAYS).

 - the science goal code and the AI uses A_NONE quite heavy. Sometimes
 for "next step to goal" sometimes for really none and sometimes to
 indicate a future tech. I have to clean this up.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
    1) Customers cause problems.
    2) Marketing is trying to create more customers.
  Therefore:
    3) Marketing is evil.

Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.36
diff -u -u -r1.36 government.c
--- common/government.c 2002/12/18 17:36:19     1.36
+++ common/government.c 2003/01/08 21:38:28
@@ -246,12 +246,12 @@
         government >= 0 && government < game.government_count);
 
   req = governments[government].required_tech;
-  if (!tech_exists(req))
+  if (!tech_exists(req)) {
     return FALSE;
-  else 
-    return (req == A_NONE
-           || (get_invention(pplayer, req) == TECH_KNOWN)
+  } else {
+    return (get_invention(pplayer, req) == TECH_KNOWN
            || player_owns_active_govchange_wonder(pplayer));
+  }
 }
 
 /***************************************************************
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.53
diff -u -u -r1.53 tech.c
--- common/tech.c       2002/12/18 17:36:19     1.53
+++ common/tech.c       2003/01/08 21:38:32
@@ -95,8 +95,7 @@
 {
   /* The is_tech_a_req_for_goal condition is true if the tech is
    * already marked */
-  if (tech == A_NONE || !tech_exists(tech)
-      || get_invention(pplayer, tech) == TECH_KNOWN
+  if (!tech_exists(tech) || get_invention(pplayer, tech) == TECH_KNOWN
       || is_tech_a_req_for_goal(pplayer, tech, goal)) {
     return;
   }
@@ -223,8 +222,7 @@
 **************************************************************************/
 Tech_Type_id get_next_tech(struct player *pplayer, Tech_Type_id goal)
 {
-  if (goal == A_NONE || !tech_exists(goal) ||
-      get_invention(pplayer, goal) == TECH_KNOWN) {
+  if (!tech_exists(goal) || get_invention(pplayer, goal) == TECH_KNOWN) {
     return A_NONE;
   }
   return (get_next_tech_rec(pplayer, goal));
@@ -490,7 +488,7 @@
 **************************************************************************/
 static int precalc_tech_data_helper(Tech_Type_id tech, bool *counted)
 {
-  if (tech == A_NONE || !tech_exists(tech) || counted[tech]) {
+  if (!tech_exists(tech) || counted[tech]) {
     return 0;
   }
 

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