Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] (PR#13342) pubserver 2.0 crash in found_new_tech
Home

[Freeciv-Dev] (PR#13342) pubserver 2.0 crash in found_new_tech

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#13342) pubserver 2.0 crash in found_new_tech
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Wed, 7 Sep 2005 00:52:03 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Discussion about:

choose_random_tech()
{
do {
choose(random_tech)
} while(player researching A_UNSET)
}

> > That should work.  Could you make a patch for it?
> 
> Err, sorry, what I meant was: I don't think that's a good way to do it
> (see previous email).  Sorry for the confusion...

But I don't see a problem with that. choose_random_tech is only used
when there's no goal set and current research is A_UNSET.
A patch is attached.
 
> We could take elfstone's "simple" patch for choose_random_tech.  I can't
> see any problems with using that.  But it might be better just to leave
> the buglet in 2.0 or to use the full fix (as in 13354).

There are problems with that patch: some techs may be researched one
turn to late and it doesn't respect techpenalty.
--
mateusz
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.330.2.35
diff -u -r1.330.2.35 plrhand.c
--- server/plrhand.c    24 Aug 2005 17:22:06 -0000      1.330.2.35
+++ server/plrhand.c    7 Sep 2005 07:50:11 -0000
@@ -361,14 +361,14 @@
                       get_tech_name(plr, plr->research.researching),
                       get_tech_name(plr, plr->ai.tech_goal));
     } else {
+      plr->research.researching = A_UNSET;
       if (plr->ai.control || !was_discovery) {
         choose_random_tech(plr);
       } else if (is_future_tech(tech_found)) {
         /* Continue researching future tech. */
         plr->research.researching = A_FUTURE;
-      } else {
-        plr->research.researching = A_UNSET;
       }
+      
       if (plr->research.researching != A_UNSET 
           && (!is_future_tech(plr->research.researching)
              || !is_future_tech(tech_found))) {
@@ -589,30 +589,35 @@
 void choose_random_tech(struct player *plr)
 {
   int chosen, researchable = 0;
-
-  if (plr->research.bulbs_researched >0) {
-    plr->research.bulbs_researched = 0;
-  }
-  tech_type_iterate(i) {
-    if (get_invention(plr, i) == TECH_REACHABLE) {
-      researchable++;
-    }
-  } tech_type_iterate_end;
-  if (researchable == 0) {
-    plr->research.researching = A_FUTURE;
-    return;
+  
+  if (plr->research.researching != A_UNSET) {
+    freelog(LOG_ERROR, "Error: choose_random_tech should only be called "
+                       "when research target is A_UNSET. Please report this "
+                      "bug at <bugs@xxxxxxxxxxxx>.");
   }
-  chosen = myrand(researchable) + 1;
   
-  tech_type_iterate(i) {
-    if (get_invention(plr, i) == TECH_REACHABLE) {
-      chosen--;
-      if (chosen == 0) {
-       plr->research.researching = i;
-       break;
+  do {
+    tech_type_iterate(i) {
+      if (get_invention(plr, i) == TECH_REACHABLE) {
+        researchable++;
       }
+    } tech_type_iterate_end;
+    if (researchable == 0) {
+      choose_tech(plr, A_FUTURE);
+      return;
     }
-  } tech_type_iterate_end;
+    chosen = myrand(researchable) + 1;
+  
+    tech_type_iterate(i) {
+      if (get_invention(plr, i) == TECH_REACHABLE) {
+        chosen--;
+        if (chosen == 0) {
+         choose_tech(plr, i);
+         break;
+        }
+      }
+    } tech_type_iterate_end;
+  } while (plr->research.researching == A_UNSET);
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13342) pubserver 2.0 crash in found_new_tech, Mateusz Stefek <=