Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2005:
[Freeciv-Dev] (PR#13148) move future_tech into the research structure
Home

[Freeciv-Dev] (PR#13148) move future_tech into the research structure

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13148) move future_tech into the research structure
From: "Jason Dorje Short" <jdorje@xxxxxxxxx>
Date: Thu, 19 May 2005 18:29:05 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch moves future_tech out of the player structure and into the
research structure.  It looks to me like the current code breaks with
teams and future techs because the future_tech value isn't shared among
research partners.  However I haven't tested this.

I also took it upon myself to clean up the research structure a bit.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.516
diff -u -r1.516 packhand.c
--- client/packhand.c   11 May 2005 20:03:07 -0000      1.516
+++ client/packhand.c   20 May 2005 01:24:47 -0000
@@ -1475,7 +1475,7 @@
   pplayer->research->bulbs_researched = pinfo->bulbs_researched;
   pplayer->research->techs_researched = pinfo->techs_researched;
   pplayer->research->researching=pinfo->researching;
-  pplayer->future_tech=pinfo->future_tech;
+  pplayer->research->future_tech = pinfo->future_tech;
   pplayer->research->tech_goal=pinfo->tech_goal;
   
   if (can_client_change_view() && pplayer == game.player_ptr) {
Index: client/gui-gtk-2.0/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/repodlgs.c,v
retrieving revision 1.87
diff -u -r1.87 repodlgs.c
--- client/gui-gtk-2.0/repodlgs.c       5 May 2005 18:32:47 -0000       1.87
+++ client/gui-gtk-2.0/repodlgs.c       20 May 2005 01:24:48 -0000
@@ -484,10 +484,10 @@
       sorting_list = g_list_prepend(sorting_list, GINT_TO_POINTER(i));
     }
   } else {
-    sorting_list = g_list_prepend(sorting_list,
-                                GINT_TO_POINTER(game.control.num_tech_types + 
1 +
-                                                game.player_ptr->
-                                                future_tech));
+    int value = (game.control.num_tech_types
+                + game.player_ptr->research->future_tech + 1);
+
+    sorting_list = g_list_prepend(sorting_list, GINT_TO_POINTER(value));
   }
 
   /* sort the list and build from it the menu */
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.181
diff -u -r1.181 player.c
--- common/player.c     7 May 2005 14:03:52 -0000       1.181
+++ common/player.c     20 May 2005 01:24:48 -0000
@@ -134,7 +134,6 @@
   plr->ai.fuzzy = 0;
   plr->ai.expand = 100;
   plr->ai.barbarian_type = NOT_A_BARBARIAN;
-  plr->future_tech=0;
   plr->economic.tax=PLAYER_DEFAULT_TAX_RATE;
   plr->economic.science=PLAYER_DEFAULT_SCIENCE_RATE;
   plr->economic.luxury=PLAYER_DEFAULT_LUXURY_RATE;
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.152
diff -u -r1.152 player.h
--- common/player.h     5 May 2005 20:26:13 -0000       1.152
+++ common/player.h     20 May 2005 01:24:48 -0000
@@ -68,21 +68,31 @@
 };
 
 struct player_research {
-  int bulbs_researched;   /* # bulbs reseached for the current tech */    
-  int techs_researched;   /* # techs the player has researched/acquired */
-  /* 
-   * Invention being researched in. Valid values for researching are:
+  /* The number of techs and future techs the player has
+   * researched/acquired. */
+  int techs_researched, future_tech;
+
+  /* Invention being researched in. Valid values for researching are:
    *  - any existing tech but not A_NONE or
    *  - A_FUTURE.
    * In addition A_NOINFO is allowed at the client for enemies.
-   */
-  int researching;        
-  int changed_from;       /* if the player changed techs, which one
-                            changed from */
-  int bulbs_researched_before;  /* if the player changed techs, how
-                                  many points they had before the
-                                  change */
-  bool got_tech; /* if he can change research without penalty */
+   *
+   * bulbs_researched tracks how many bulbs have been accumulated toward
+   * this research target. */
+  Tech_type_id researching;        
+  int bulbs_researched;
+
+  /* If the player changes his research target in a turn, he loses some or
+   * all of the bulbs he's accumulated toward that target.  We save the
+   * original info from the start of the turn so that if he changes back
+   * he will get the bulbs back. */
+  Tech_type_id changed_from;
+  int bulbs_researched_before;
+
+  /* If the player completed a research this turn, this value is turned on
+   * and changing targets may be done without penalty. */
+  bool got_tech;
+
   struct {
     /* One of TECH_UNKNOWN, TECH_KNOWN or TECH_REACHABLE. */
     enum tech_state state;
@@ -98,7 +108,7 @@
 
   /* Tech goal (similar to worklists; when one tech is researched the next
    * tech toward the goal will be chosen).  May be A_NONE. */
-  int tech_goal;
+  Tech_type_id tech_goal;
 
   /*
    * Cached values. Updated by update_research.
@@ -217,7 +227,6 @@
   struct player_research* research;
   int bulbs_last_turn;    /* # bulbs researched last turn only */
   struct player_spaceship spaceship;
-  int future_tech;
   struct player_ai ai;
   bool was_created;                    /* if the player was /created */
   bool is_connected;                  /* observers don't count */
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.92
diff -u -r1.92 tech.c
--- common/tech.c       10 May 2005 20:36:19 -0000      1.92
+++ common/tech.c       20 May 2005 01:24:48 -0000
@@ -580,19 +580,19 @@
     return _("None");
   case A_FUTURE:
     /* pplayer->future_tech == 0 means "Future Tech. 1". */
-    for (i = future.size; i <= pplayer->future_tech; i++) {
+    for (i = future.size; i <= pplayer->research->future_tech; i++) {
       char *ptr = NULL;
 
       string_vector_append(&future, &ptr);
     }
-    if (!future.p[pplayer->future_tech]) {
+    if (!future.p[pplayer->research->future_tech]) {
       char buffer[1024];
 
       my_snprintf(buffer, sizeof(buffer), _("Future Tech. %d"),
-                 pplayer->future_tech + 1);
-      future.p[pplayer->future_tech] = mystrdup(buffer);
+                 pplayer->research->future_tech + 1);
+      future.p[pplayer->research->future_tech] = mystrdup(buffer);
     }
-    return future.p[pplayer->future_tech];
+    return future.p[pplayer->research->future_tech];
   default:
     /* Includes A_NONE */
     if (!tech_exists(tech)) {
Index: server/diplomats.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v
retrieving revision 1.76
diff -u -r1.76 diplomats.c
--- server/diplomats.c  5 May 2005 20:00:42 -0000       1.76
+++ server/diplomats.c  20 May 2005 01:24:49 -0000
@@ -603,7 +603,7 @@
      * Either only future-tech or nothing to steal:
      * If nothing to steal, say so, deduct movement cost and return.
      */
-    if (cplayer->future_tech > pplayer->future_tech) {
+    if (cplayer->research->future_tech > pplayer->research->future_tech) {
       target = -1;
       freelog (LOG_DEBUG, "steal-tech: targeted future-tech: %d", target);
     } else {
@@ -668,13 +668,14 @@
     notify_player_ex(pplayer, pcity->tile, E_MY_DIPLOMAT_THEFT,
                     _("Your %s stole Future Tech. %d from %s."),
                     unit_name(pdiplomat->type),
-                    pplayer->future_tech, cplayer->name);
+                    pplayer->research->future_tech, cplayer->name);
     notify_player_ex(cplayer, pcity->tile, E_ENEMY_DIPLOMAT_THEFT,
                     _("Future Tech. %d stolen by %s %s from %s."),
-                    pplayer->future_tech, get_nation_name(pplayer->nation),
+                    pplayer->research->future_tech,
+                    get_nation_name(pplayer->nation),
                     unit_name(pdiplomat->type), pcity->name);
-    freelog (LOG_DEBUG, "steal-tech: stole future-tech %d",
-            pplayer->future_tech);
+    freelog(LOG_DEBUG, "steal-tech: stole future-tech %d",
+           pplayer->research->future_tech);
   } else {
     /* Steal a technology. */
 
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.377
diff -u -r1.377 plrhand.c
--- server/plrhand.c    11 May 2005 14:57:10 -0000      1.377
+++ server/plrhand.c    20 May 2005 01:24:49 -0000
@@ -393,7 +393,7 @@
 
        my_snprintf(buffer1, sizeof(buffer1), _("Learned %s. "),
                    get_tech_name(plr, plr->research->researching));
-       plr->future_tech++;
+       plr->research->future_tech++;
        my_snprintf(buffer2, sizeof(buffer2), _("Researching %s."),
                    get_tech_name(plr, plr->research->researching));
        notify_player_ex(plr, NULL, E_TECH_LEARNED, "%s%s", buffer1,
@@ -496,7 +496,7 @@
 **************************************************************************/
 void found_new_future_tech(struct player *pplayer)
 {
-  pplayer->future_tech++;
+  pplayer->research->future_tech++;
   pplayer->research->techs_researched++;
 }
 
@@ -519,7 +519,7 @@
     notify_embassies(plr, NULL,
                     _("The %s have researched Future Tech. %d."), 
                     get_nation_name_plural(plr->nation),
-                    plr->future_tech);
+                    plr->research->future_tech);
   
   }
   script_signal_emit("tech_researched", 3,
@@ -709,9 +709,10 @@
   } tech_type_iterate_end;
   if (j == 0)  {
     /* we've moved on to future tech */
-    if (target->future_tech > pplayer->future_tech) {
+    if (target->research->future_tech > pplayer->research->future_tech) {
       found_new_future_tech(pplayer);
-      stolen_tech = game.control.num_tech_types + pplayer->future_tech;
+      stolen_tech
+       = game.control.num_tech_types + pplayer->research->future_tech;
     } else {
       return; /* nothing to learn here, move on */
     }
@@ -1575,7 +1576,7 @@
     packet->bulbs_researched= plr->research->bulbs_researched;
     packet->techs_researched= plr->research->techs_researched;
     packet->researching     = plr->research->researching;
-    packet->future_tech     = plr->future_tech;
+    packet->future_tech     = plr->research->future_tech;
     packet->revolution_finishes = plr->revolution_finishes;
   } else {
     for (i = A_FIRST; i < game.control.num_tech_types; i++) {
Index: server/report.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.c,v
retrieving revision 1.64
diff -u -r1.64 report.c
--- server/report.c     5 May 2005 20:26:14 -0000       1.64
+++ server/report.c     20 May 2005 01:24:50 -0000
@@ -173,7 +173,8 @@
        size[j].value = pplayer->economic.gold;
        break;
       case HISTORIAN_ADVANCED:
-       size[j].value = (pplayer->score.techs + pplayer->future_tech);
+       size[j].value
+         = pplayer->score.techs + pplayer->research->future_tech;
        break;
       case HISTORIAN_MILITARY:
        size[j].value = pplayer->score.units;
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.248
diff -u -r1.248 savegame.c
--- server/savegame.c   10 May 2005 17:27:09 -0000      1.248
+++ server/savegame.c   20 May 2005 01:24:50 -0000
@@ -1873,7 +1873,8 @@
   plr->economic.luxury=secfile_lookup_int(file, "player%d.luxury", plrno);
 
   /* how many future techs were researched already by player */
-  plr->future_tech = secfile_lookup_int(file, "player%d.futuretech", plrno);
+  plr->research->future_tech
+    = secfile_lookup_int(file, "player%d.futuretech", plrno);
 
   /* We use default values for bulbs_researched_before, changed_from
    * and got_tech to preserve backwards-compatibility with save files
@@ -2609,7 +2610,8 @@
   secfile_insert_int(file, plr->economic.science, "player%d.science", plrno);
   secfile_insert_int(file, plr->economic.luxury, "player%d.luxury", plrno);
 
-  secfile_insert_int(file,plr->future_tech,"player%d.futuretech", plrno);
+  secfile_insert_int(file, plr->research->future_tech,
+                    "player%d.futuretech", plrno);
 
   secfile_insert_int(file, plr->research->bulbs_researched, 
                     "player%d.researched", plrno);
Index: server/score.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/score.c,v
retrieving revision 1.21
diff -u -r1.21 score.c
--- server/score.c      7 May 2005 18:58:04 -0000       1.21
+++ server/score.c      20 May 2005 01:24:50 -0000
@@ -433,7 +433,7 @@
       pplayer->score.techs++;
     }
   } tech_type_iterate_end;
-  pplayer->score.techs += pplayer->future_tech * 5 / 2;
+  pplayer->score.techs += pplayer->research->future_tech * 5 / 2;
   
   unit_list_iterate(pplayer->units, punit) {
     if (is_military_unit(punit)) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13148) move future_tech into the research structure, Jason Dorje Short <=