Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#14288) random tech choice isn't made correctly
Home

[Freeciv-Dev] (PR#14288) random tech choice isn't made correctly

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#14288) random tech choice isn't made correctly
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Thu, 13 Oct 2005 01:18:26 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [jdorje - Wed Oct 12 21:25:03 2005]:
> 
> When I run out of techs to choose my tech target and goal will both be 
> "none".  Of course a target will be chosen at the start of the next 
> turn.  If I pick a goal this turn, then the target chosen should be only 
> a target that works toward the goal.  But this isn't the case; it seems 
> any target may be chosen.

Patches are attached.

> This is a recent bug I think.  I hope it wasn't introduced into 2.0!
No, this one is old.
--
mateusz
Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (wersja 11111)
+++ server/srv_main.c   (kopia robocza)
@@ -600,7 +600,9 @@
 
   phase_players_iterate(pplayer) {
     if (get_player_research(pplayer)->researching == A_UNSET) {
-      choose_random_tech(pplayer);
+      if (choose_goal_tech(pplayer) == A_UNSET) {
+        choose_random_tech(pplayer);
+      }
       update_tech(pplayer, 0);
     }
   } phase_players_iterate_end;
Index: server/techtools.c
===================================================================
--- server/techtools.c  (wersja 11111)
+++ server/techtools.c  (kopia robocza)
@@ -81,20 +81,19 @@
 
 /****************************************************************************
   Called to find and choose (pick) a research target on the way to the
-  player's goal.  Return TRUE iff the tech is set.
+  player's goal.  Return a tech iff the tech is set.
 ****************************************************************************/
-static bool choose_goal_tech(struct player *plr)
+Tech_type_id choose_goal_tech(struct player *plr)
 {
-  int sub_goal;
+  Tech_type_id sub_goal;
   struct player_research *research = get_player_research(plr);
 
   sub_goal = get_next_tech(plr, research->tech_goal);
 
   if (sub_goal != A_UNSET) {
-    research->researching = sub_goal;
-    return TRUE;
+    choose_tech(plr, sub_goal);
   }
-  return FALSE;
+  return sub_goal;
 }
 
 /****************************************************************************
@@ -353,9 +352,10 @@
   }
 
   if (tech_found == research->researching) {
+    Tech_type_id next_tech = choose_goal_tech(plr);
     /* try to pick new tech to research */
 
-    if (choose_goal_tech(plr)) {
+    if (next_tech != A_UNSET) {
       notify_team(plr, NULL, E_TECH_LEARNED,
                       _("Learned %s. "
                         "Our scientists focus on %s; goal is %s."),
@@ -595,7 +595,7 @@
 
   /* Mark the reachable techs */
   update_research(plr);
-  if (!choose_goal_tech(plr)) {
+  if (choose_goal_tech(plr) == A_UNSET) {
     choose_random_tech(plr);
   }
 }
Index: server/techtools.h
===================================================================
--- server/techtools.h  (wersja 11111)
+++ server/techtools.h  (kopia robocza)
@@ -27,6 +27,7 @@
 void init_tech(struct player *plr);
 void choose_tech(struct player *plr, Tech_type_id tech);
 void choose_random_tech(struct player* plr);
+Tech_type_id choose_goal_tech(struct player *plr);
 void choose_tech_goal(struct player *plr, Tech_type_id tech);
 Tech_type_id steal_a_tech(struct player *pplayer, struct player *target,
                 Tech_type_id preferred);
Index: server/srv_main.c
===================================================================
--- server/srv_main.c   (wersja 11111)
+++ server/srv_main.c   (kopia robocza)
@@ -563,7 +563,9 @@
   before_end_year();
   players_iterate(pplayer) {
     if (pplayer->research.researching == A_UNSET) {
-      choose_random_tech(pplayer);
+      if (choose_goal_tech(pplayer) == A_UNSET) {
+        choose_random_tech(pplayer);
+      }
       update_tech(pplayer, 0);
     }
   } players_iterate_end;
Index: server/plrhand.c
===================================================================
--- server/plrhand.c    (wersja 11111)
+++ server/plrhand.c    (kopia robocza)
@@ -63,7 +63,6 @@
                                 enum plr_info_level min_info_level);
 static Nation_Type_id pick_available_nation(Nation_Type_id *choices);
 static void tech_researched(struct player* plr);
-static bool choose_goal_tech(struct player *plr);
 static Tech_Type_id pick_random_tech(struct player *plr);
 static enum plr_info_level player_info_level(struct player *plr,
                                             struct player *receiver);
@@ -374,12 +373,13 @@
 
   if (tech_found == plr->research.researching && next_tech == A_NONE) {
     /* try to pick new tech to research */
+    Tech_Type_id next_tech = choose_goal_tech(plr);
 
-    if (choose_goal_tech(plr)) {
+    if (next_tech != A_UNSET) {
       notify_player_ex(plr, NULL, E_TECH_LEARNED,
                       _("Game: Learned %s.  "
                         "Our scientists focus on %s, goal is %s."),
-                      get_tech_name(plr, tech_found),
+                      get_tech_name(plr, next_tech),
                       get_tech_name(plr, plr->research.researching),
                       get_tech_name(plr, plr->ai.tech_goal));
     } else {
@@ -581,9 +581,9 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static bool choose_goal_tech(struct player *plr)
+Tech_Type_id choose_goal_tech(struct player *plr)
 {
-  int sub_goal;
+  Tech_Type_id sub_goal;
 
   if (plr->ai.control) {
     ai_next_tech_goal(plr);    /* tech-AI has been changed */
@@ -600,10 +600,9 @@
   }
 
   if (sub_goal != A_UNSET) {
-    plr->research.researching = sub_goal;
-    return TRUE;
+    choose_tech(plr, sub_goal);
   }
-  return FALSE;
+  return sub_goal;
 }
 
 /**************************************************************************
@@ -726,7 +725,7 @@
 
   /* Mark the reachable techs */
   update_research(plr);
-  if (!choose_goal_tech(plr)) {
+  if (choose_goal_tech(plr) == A_UNSET) {
     choose_random_tech(plr);
   }
 }
Index: server/plrhand.h
===================================================================
--- server/plrhand.h    (wersja 11111)
+++ server/plrhand.h    (kopia robocza)
@@ -68,6 +68,7 @@
 void update_tech(struct player *plr, int bulbs);
 void init_tech(struct player *plr);
 void choose_random_tech(struct player *plr);
+Tech_Type_id choose_goal_tech(struct player *plr);
 void choose_tech(struct player *plr, int tech);
 void choose_tech_goal(struct player *plr, int tech);
 void get_a_tech(struct player *pplayer, struct player *target);

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