Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] PATCH: optimized ai/aitech.c, ai/aitools.c
Home

[Freeciv-Dev] PATCH: optimized ai/aitech.c, ai/aitools.c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: optimized ai/aitech.c, ai/aitools.c
From: Dirk Stoecker <stoecker@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Sep 2000 14:44:57 +0200 (MET DST)

Hi,

removed compiler warnings from ai/aitech.c and ai/aitools.c:

/ai/aitech.c 211: macro invocation may call function multiple times
/ai/aitech.c 150: dead assignment eliminated "bestdist"
/ai/aitech.c 102: dead assignment eliminated "tech"
/ai/aitools.c 137: dead assignment eliminated "prod"
/ai/aitools.c 275: dead assignment eliminated "score"
/ai/aitools.c 307: dead assignment eliminated "unhappy_cities"

- removed useless assignments, variables
- removed some older comments to make the code much better readable
- reduced return statements in get_wonder_tech(struct player *plr) to 2

Well this is the last of 4 patches to ai-directory. If these get applied all,
ai-directory is free of warnings on my system.

Ciao
 ____  _ _  ____  _ _    _ _  ____
|    |  |  |    |  | \  / |  |    | the cool Gremlin from Bischofswerda
|  __   |   ____|  |  \/  |  |    | WWW: http://home.pages.de/~stoecker/
|    |  |  |       |      |  |    | PGP key available on www page.
|____| _|_ |____| _|_    _|_ |____| I hope AMIGA never ends to make fun!
diff -ur ../../freeciv-cvs/freeciv/ai/aitech.c ./ai/aitech.c
--- ../../freeciv-cvs/freeciv/ai/aitech.c       Wed Sep 20 08:56:44 2000
+++ ./ai/aitech.c       Wed Sep 20 10:39:02 2000
@@ -99,19 +99,17 @@
 **************************************************************************/
 static int get_wonder_tech(struct player *plr)
 {
-  Tech_Type_id tech = A_NONE;
   int building = get_nation_by_plr(plr)->goals.wonder;
   
-  if (!improvement_exists(building))
-    return A_NONE;
-  if (game.global_wonders[building] || wonder_obsolete(building)) 
-    return A_NONE;
-  tech = improvement_types[building].tech_req;
-  if (!tech_exists(tech))
-    return A_NONE;
-  if (get_invention(plr, tech) == TECH_KNOWN)
-    return A_NONE;
-  return tech;
+  if(improvement_exists(building) && !game.global_wonders[building] &&
+  !wonder_obsolete(building))
+  {
+    Tech_Type_id tech = improvement_types[building].tech_req;
+
+    if(tech_exists(tech) && get_invention(plr, tech) != TECH_KNOWN)
+      return tech;
+  }
+  return A_NONE;
 }
 
 static void ai_next_tech_goal_default(struct player *pplayer, 
@@ -147,7 +145,7 @@
   if (tech != A_NONE) {
     dist = tech_goal_turns(pplayer, tech);
     if (dist < bestdist) { 
-      bestdist = dist;
+/*    bestdist = dist; */ /* useless, reinclude when adding a new if statement 
*/
       goal = tech;
     }
   }
@@ -208,7 +206,8 @@
 #define CACHE_SET(i,k)  cache[i][(k)/8] |= (1<<((k)%8))
 #define CACHE_TEST(i,k) cache[i][(k)/8] &  (1<<((k)%8))
   
-  num_cities_nonzero = MAX(1, city_list_size(&pplayer->cities));
+  if((num_cities_nonzero = city_list_size(&pplayer->cities)) < 1)
+    num_cities_nonzero = 1;
   memset(values, 0, sizeof(values));
   memset(goal_values, 0, sizeof(goal_values));
   memset(cache, 0, sizeof(cache));
diff -ur ../../freeciv-cvs/freeciv/ai/aitools.c ./ai/aitools.c
--- ../../freeciv-cvs/freeciv/ai/aitools.c      Wed Sep 20 08:56:44 2000
+++ ./ai/aitools.c      Wed Sep 20 10:46:49 2000
@@ -126,7 +126,7 @@
 { /* I prefer the ai_choice as a return value; gcc prefers it as an arg -- 
Syela */
   int i;
   int id = B_LAST;
-  int prod = 0, danger = 0, downtown = 0, cities = 0;
+  int danger = 0, downtown = 0, cities = 0;
   int want=0;
   struct player *plr;
         
@@ -134,7 +134,6 @@
      
   /* too bad plr->score isn't kept up to date. */
   city_list_iterate(plr->cities, acity)
-    prod += acity->shield_prod;
     danger += acity->ai.danger;
     downtown += acity->ai.downtown;
     cities++;
@@ -145,14 +144,10 @@
        (!pcity->is_building_unit && is_wonder(pcity->currently_building) &&
        pcity->shield_stock >= improvement_value(i) / 2) ||
        (!is_building_other_wonder(pcity) &&
-/* built_elsewhere removed; it was very, very bad with multi-continent empires 
*/
-/* city_got_building(pcity, B_TEMPLE) && - too much to ask for, I think */
         !pcity->ai.grave_danger && /* otherwise caravans will be killed! */
-/*        pcity->shield_prod * cities >= prod &&         this shouldn't matter 
much */
         pcity->ai.downtown * cities >= downtown &&
         pcity->ai.danger * cities <= danger)) { /* too many restrictions? */
 /* trying to keep wonders in safe places with easy caravan access -- Syela */
-/* new code 980620; old code proved grossly inadequate after extensive testing 
-- Syela */
       if(pcity->ai.building_want[i]>want) {
 /* we have to do the can_build check to avoid Built Granary.  Now Building 
Granary. */
         if (can_build_improvement(pcity, i)) {
@@ -266,13 +261,8 @@
   int trade_prod       = 0;
   int shield_need      = 0;
   int food_need        = 0;
-  /*
-  int happy            = 0;
-  int unhappy          = 0;
-  */
-  int unhappy_cities   = 0;
   int gov_overthrown   = 0;
-  int score            = 0;
+  int score;
 
   pplayer->government = g->index;
 
@@ -298,13 +288,8 @@
       food_surplus   += tmp_city.food_surplus;
     else
       food_need      += tmp_city.food_surplus;
-    /*
-    happy            += tmp_city.happy;
-    unhappy          += tmp_city.unhappy;
-    */
 
     if (city_unhappy (&tmp_city)) {
-      unhappy_cities++;
       /* the following is essential to prevent falling into anarchy */
       if (tmp_city.anarchy > 0
          && government_has_flag(g, G_REVOLUTION_WHEN_UNHAPPY)) 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] PATCH: optimized ai/aitech.c, ai/aitools.c, Dirk Stoecker <=