Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11418) loading saved games causes a crash in 2.0
Home

[Freeciv-Dev] (PR#11418) loading saved games causes a crash in 2.0

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11418) loading saved games causes a crash in 2.0
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Dec 2004 09:12:17 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11418 >

Here's another problem and a patch for the dev branch.  The AI code
considers techs that don't exist.  I guess it doesn't actually target
them though becuase this patch doesn't change autogames at all.

-jason

Index: ai/aitech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitech.c,v
retrieving revision 1.46
diff -u -r1.46 aitech.c
--- ai/aitech.c 8 Dec 2004 20:48:32 -0000       1.46
+++ ai/aitech.c 9 Dec 2004 17:04:53 -0000
@@ -126,55 +126,62 @@
   /* Fill in values for the techs: want of the tech 
    * + average want of those we will discover en route */
   tech_type_iterate(i) {
-    int steps = num_unknown_techs_for_goal(pplayer, i);
+    if (tech_exists(i)) {
+      int steps = num_unknown_techs_for_goal(pplayer, i);
 
-    /* We only want it if we haven't got it (so AI is human after all) */
-    if (steps > 0) { 
-      values[i] += pplayer->ai.tech_want[i];
-      tech_type_iterate(k) {
-       if (is_tech_a_req_for_goal(pplayer, k, i)) {
-         values[k] += pplayer->ai.tech_want[i] / steps;
-       }
-      } tech_type_iterate_end;
+      /* We only want it if we haven't got it (so AI is human after all) */
+      if (steps > 0) { 
+       values[i] += pplayer->ai.tech_want[i];
+       tech_type_iterate(k) {
+         if (is_tech_a_req_for_goal(pplayer, k, i)) {
+           values[k] += pplayer->ai.tech_want[i] / steps;
+         }
+       } tech_type_iterate_end;
+      }
     }
   } tech_type_iterate_end;
 
   /* Fill in the values for the tech goals */
   tech_type_iterate(i) {
-    int steps = num_unknown_techs_for_goal(pplayer, i);
+    if (tech_exists(i)) {
+      int steps = num_unknown_techs_for_goal(pplayer, i);
 
-    if (steps == 0) {
-      continue;
-    }
+      if (steps == 0) {
+       continue;
+      }
 
-    goal_values[i] = values[i];      
-    tech_type_iterate(k) {
-      if (is_tech_a_req_for_goal(pplayer, k, i)) {
-       goal_values[i] += values[k];
-      }
-    } tech_type_iterate_end;
-    /* This is the best I could do.  It still sometimes does freaky stuff
-     * like setting goal to Republic and learning Monarchy, but that's what
-     * it's supposed to be doing; it just looks strange. -- Syela */
-    goal_values[i] /= steps;
-    if (steps < 6) {
-      freelog(LOG_DEBUG, "%s: want = %d, value = %d, goal_value = %d",
-             get_tech_name(pplayer, i), pplayer->ai.tech_want[i],
-             values[i], goal_values[i]);
+      goal_values[i] = values[i];      
+      tech_type_iterate(k) {
+       if (is_tech_a_req_for_goal(pplayer, k, i)) {
+         goal_values[i] += values[k];
+       }
+      } tech_type_iterate_end;
+
+      /* This is the best I could do.  It still sometimes does freaky stuff
+       * like setting goal to Republic and learning Monarchy, but that's what
+       * it's supposed to be doing; it just looks strange. -- Syela */
+      goal_values[i] /= steps;
+      if (steps < 6) {
+       freelog(LOG_DEBUG, "%s: want = %d, value = %d, goal_value = %d",
+               get_tech_name(pplayer, i), pplayer->ai.tech_want[i],
+               values[i], goal_values[i]);
+      }
     }
   } tech_type_iterate_end;
 
   newtech = A_UNSET;
   newgoal = A_UNSET;
   tech_type_iterate(i) {
-    if (values[i] > values[newtech]
-        && tech_is_available(pplayer, i)
-        && get_invention(pplayer, i) == TECH_REACHABLE) {
-      newtech = i;
-    }
-    if (goal_values[i] > goal_values[newgoal]
-        && tech_is_available(pplayer, i)) {
-      newgoal = i;
+    if (tech_exists(i)) {
+      if (values[i] > values[newtech]
+         && tech_is_available(pplayer, i)
+         && get_invention(pplayer, i) == TECH_REACHABLE) {
+       newtech = i;
+      }
+      if (goal_values[i] > goal_values[newgoal]
+         && tech_is_available(pplayer, i)) {
+       newgoal = i;
+      }
     }
   } tech_type_iterate_end;
   freelog(LOG_DEBUG, "%s wants %s with desire %d (%d).", 

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