Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13429) Move player_research to team
Home

[Freeciv-Dev] (PR#13429) Move player_research to team

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13429) Move player_research to team
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Tue, 19 Jul 2005 00:13:27 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Updated patch
--
mateusz
? civscore.log
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.534
diff -u -r1.534 packhand.c
--- client/packhand.c   18 Jul 2005 22:46:27 -0000      1.534
+++ client/packhand.c   19 Jul 2005 07:04:00 -0000
@@ -1417,7 +1417,7 @@
   bool poptechup, new_tech = FALSE;
   char msg[MAX_LEN_MSG];
   struct player *pplayer = &game.players[pinfo->playerno];
-  struct player_research* research = get_player_research(pplayer);
+  struct player_research* research;
 
   sz_strlcpy(pplayer->name, pinfo->name);
 
@@ -1481,6 +1481,8 @@
    * only send the player info out at appropriate times - e.g., while the
    * game is running. */
   new_tech = read_player_info_techs(pplayer, pinfo->inventions);
+  
+  research = get_player_research(pplayer);
 
   poptechup = (research->researching != pinfo->researching
                || research->tech_goal != pinfo->tech_goal);
@@ -2174,7 +2176,7 @@
       if (tech_exists(b->obsolete_by)) {
        freelog(LOG_DEBUG, "  obsolete_by %2d/%s",
                b->obsolete_by,
-               get_tech_name(game.player_ptr, b->obsolete_by));
+               get_normal_tech_name(b->obsolete_by));
       } else {
        freelog(LOG_DEBUG, "  obsolete_by %2d/Never", b->obsolete_by);
       }
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.315
diff -u -r1.315 tilespec.c
--- client/tilespec.c   18 Jul 2005 22:46:27 -0000      1.315
+++ client/tilespec.c   19 Jul 2005 07:04:09 -0000
@@ -2378,7 +2378,7 @@
       = lookup_sprite_tag_alt(t, advances[id].graphic_str,
                              advances[id].graphic_alt,
                              FALSE, "tech_type",
-                             get_tech_name(game.player_ptr, id));
+                             get_normal_tech_name(id));
 
     /* should maybe do something if NULL, eg generic default? */
   } else {
Index: client/gui-win32/inteldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/inteldlg.c,v
retrieving revision 1.12
diff -u -r1.12 inteldlg.c
--- client/gui-win32/inteldlg.c 5 May 2005 18:32:48 -0000       1.12
+++ client/gui-win32/inteldlg.c 19 Jul 2005 07:04:11 -0000
@@ -124,8 +124,9 @@
   hbox=fcwin_hbox_new(intel_dialog,FALSE);
    
   my_snprintf(buf, sizeof(buf), _("Researching: %s(%d/%d)"),
-             get_tech_name(p, p->research->researching),
-             p->research->bulbs_researched, total_bulbs_required(p));
+             get_tech_name(p, get_player_research(p)->researching),
+             get_player_research(p)->bulbs_researched,
+             total_bulbs_required(p));
   fcwin_box_add_static(hbox,buf,0,SS_CENTER,TRUE,TRUE,10);
   
   pcity = find_palace(p);
Index: client/gui-win32/repodlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/repodlgs.c,v
retrieving revision 1.50
diff -u -r1.50 repodlgs.c
--- client/gui-win32/repodlgs.c 23 May 2005 09:05:43 -0000      1.50
+++ client/gui-win32/repodlgs.c 19 Jul 2005 07:04:12 -0000
@@ -105,13 +105,13 @@
   } tech_type_iterate_end;
 
   my_snprintf(text, sizeof(text), "%d/%d",
-              game.player_ptr->research->bulbs_researched,
+              get_player_research(game.player_ptr)->bulbs_researched,
              total_bulbs_required(game.player_ptr));
 
   SetWindowText(GetDlgItem(science_dlg, ID_SCIENCE_PROG), text);
   ComboBox_ResetContent(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH));
 
-  if (game.player_ptr->research->researching == A_UNSET) {
+  if (get_player_research(game.player_ptr)->researching == A_UNSET) {
     id = ComboBox_AddString(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH),
                            get_tech_name(game.player_ptr, A_NONE));
     ComboBox_SetItemData(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH),
@@ -120,7 +120,7 @@
                       id);
   }
 
-  if (!is_future_tech(game.player_ptr->research->researching)) {
+  if (!is_future_tech(get_player_research(game.player_ptr)->researching)) {
     tech_type_iterate(tech_id) {
       if (get_invention(game.player_ptr, tech_id) != TECH_REACHABLE) {
        continue;
@@ -130,14 +130,14 @@
                              get_tech_name(game.player_ptr, tech_id));
       ComboBox_SetItemData(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH),
                           id, tech_id);
-      if (tech_id == game.player_ptr->research->researching) {
+      if (tech_id == get_player_research(game.player_ptr)->researching) {
        ComboBox_SetCurSel(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH),
                           id);
       }
     } tech_type_iterate_end;
   } else {
       tech_id = game.control.num_tech_types + 1
-               + game.player_ptr->research->future_tech;
+               + get_player_research(game.player_ptr)->future_tech;
       id = ComboBox_AddString(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH),
                              get_tech_name(game.player_ptr, tech_id));
       ComboBox_SetItemData(GetDlgItem(science_dlg, ID_SCIENCE_RESEARCH),
@@ -153,19 +153,19 @@
         && advances[tech_id].req[0] != A_LAST
        && advances[tech_id].req[1] != A_LAST
         && (num_unknown_techs_for_goal(game.player_ptr, tech_id) < 11
-           || tech_id == game.player_ptr->research->tech_goal)) {
+           || tech_id == get_player_research(game.player_ptr)->tech_goal)) {
       id = ComboBox_AddString(GetDlgItem(science_dlg,ID_SCIENCE_GOAL),
                              get_tech_name(game.player_ptr, tech_id));
        ComboBox_SetItemData(GetDlgItem(science_dlg,ID_SCIENCE_GOAL),
                         id, tech_id);
-      if (tech_id == game.player_ptr->research->tech_goal)
+      if (tech_id == get_player_research(game.player_ptr)->tech_goal)
        ComboBox_SetCurSel(GetDlgItem(science_dlg,ID_SCIENCE_GOAL),
                           id);
        
      }
   } tech_type_iterate_end;
 
-  if (game.player_ptr->research->tech_goal == A_UNSET) {
+  if (get_player_research(game.player_ptr)->tech_goal == A_UNSET) {
     id = ComboBox_AddString(GetDlgItem(science_dlg, ID_SCIENCE_GOAL),
                            get_tech_name(game.player_ptr, A_NONE));
     ComboBox_SetItemData(GetDlgItem(science_dlg, ID_SCIENCE_GOAL),
@@ -175,7 +175,7 @@
    }
 
   steps = num_unknown_techs_for_goal(game.player_ptr,
-                                     game.player_ptr->research->tech_goal);
+                            get_player_research(game.player_ptr)->tech_goal);
   my_snprintf(text, sizeof(text),
              PL_("(%d step)", "(%d steps)", steps), steps);
   SetWindowText(GetDlgItem(science_dlg,ID_SCIENCE_STEPS),text);
@@ -217,8 +217,8 @@
                science_dialog_update();
              } else {
                my_snprintf(text, sizeof(text), "%d/%d",
-                           game.player_ptr->research->bulbs_researched,
-                           total_bulbs_required(game.player_ptr));
+                       get_player_research(game.player_ptr)->bulbs_researched,
+                       total_bulbs_required(game.player_ptr));
                SetWindowText(GetDlgItem(hWnd,ID_SCIENCE_PROG),text);
                dsend_packet_player_research(&aconnection, to);
              }
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.229
diff -u -r1.229 game.c
--- common/game.c       16 Jul 2005 08:59:26 -0000      1.229
+++ common/game.c       19 Jul 2005 07:04:14 -0000
@@ -331,7 +331,6 @@
 ***************************************************************/
 void game_free(void)
 {
-  clean_players_research();
   game_remove_all_players();
   map_free();
   idex_free();
@@ -466,9 +465,6 @@
   city_list_free(pplayer->cities);
   pplayer->cities = NULL;
 
-  free(pplayer->research);
-  pplayer->research = NULL;
-
   if (is_barbarian(pplayer)) game.info.nbarbarians--;
 }
 
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.187
diff -u -r1.187 player.c
--- common/player.c     4 Jul 2005 17:48:37 -0000       1.187
+++ common/player.c     19 Jul 2005 07:05:06 -0000
@@ -79,16 +79,6 @@
 }
 
 /***************************************************************
- Fill the structure with some sane values
-***************************************************************/
-void player_research_init(struct player_research* research)
-{
-  memset(research, 0, sizeof(struct player_research));
-  research->tech_goal = A_UNSET;
-  research->changed_from = -1;
-}
-
-/***************************************************************
   In the server you must use server_player_init.  Note that
   this function is matched by game_remove_player() in game.c,
   there is no corresponding player_free() in this file.
@@ -133,8 +123,7 @@
   plr->economic.tax=PLAYER_DEFAULT_TAX_RATE;
   plr->economic.science=PLAYER_DEFAULT_SCIENCE_RATE;
   plr->economic.luxury=PLAYER_DEFAULT_LUXURY_RATE;
-  plr->research = fc_malloc(sizeof(struct player_research));
-  player_research_init(plr->research);
+
   player_limit_to_government_rates(plr);
   spaceship_init(&plr->spaceship);
 
@@ -725,51 +714,11 @@
 }
 
 /****************************************************************************
-  Merges research of two players. This is used by teams
-****************************************************************************/
-void merge_players_research(struct player* p1, struct player* p2)
-{
-  struct player_research* old_research;
-  if (p1->research == p2->research) {
-    return;
-  }
-  old_research = p1->research;
-  players_iterate(aplayer) {
-    if (aplayer->research == old_research) {
-      aplayer->research = p2->research;
-    }
-  } players_iterate_end;
-  free(old_research);
-}
-
-/****************************************************************************
-****************************************************************************/
-void clean_players_research()
-{
-  players_iterate(aplayer) {
-    if (aplayer->research) {
-      players_iterate(bplayer) {
-        if (aplayer == bplayer || aplayer->research != bplayer->research) {
-         continue;
-       }
-       bplayer->research = NULL;
-      } players_iterate_end;
-      free(aplayer->research);
-      aplayer->research = NULL;
-    }
-  } players_iterate_end;
-  
-  players_iterate(aplayer) {
-    aplayer->research = fc_malloc(sizeof (struct player_research));
-    player_research_init(aplayer->research);
-  } players_iterate_end;
-}
-
-/****************************************************************************
   Returns player_research struct of the given player. Note that team
   members share research
 ****************************************************************************/
-struct player_research *get_player_research(const struct player *p1)
+struct player_research *get_player_research(const struct player *plr)
 {
-  return p1->research;
+  assert((plr != NULL) && (plr->team != NULL));
+  return &(plr->team->research);
 }
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.159
diff -u -r1.159 player.h
--- common/player.h     18 Jul 2005 22:46:28 -0000      1.159
+++ common/player.h     19 Jul 2005 07:05:10 -0000
@@ -68,55 +68,6 @@
   int luxury;
 };
 
-struct player_research {
-  /* 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.
-   *
-   * 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;
-
-    /* 
-     * required_techs, num_required_techs and bulbs_required are
-     * cached values. Updated from build_required_techs (which is
-     * called by update_research).
-     */
-    tech_vector required_techs;
-    int num_required_techs, bulbs_required;
-  } inventions[A_LAST];
-
-  /* Tech goal (similar to worklists; when one tech is researched the next
-   * tech toward the goal will be chosen).  May be A_NONE. */
-  Tech_type_id tech_goal;
-
-  /*
-   * Cached values. Updated by update_research.
-   */
-  int num_known_tech_with_flag[TF_LAST];
-};
-
 struct player_score {
   int happy;
   int content;
@@ -225,7 +176,7 @@
   struct city_list *cities;
   struct player_score score;
   struct player_economic economic;
-  struct player_research* research;
+
   int bulbs_last_turn;    /* # bulbs researched last turn only */
   struct player_spaceship spaceship;
   struct player_ai ai;
@@ -247,7 +198,6 @@
   bv_debug debug;
 };
 
-void player_research_init(struct player_research* research);
 void player_init(struct player *plr);
 struct player *find_player_by_name(const char *name);
 struct player *find_player_by_name_prefix(const char *name,
@@ -320,8 +270,6 @@
 
 struct player_research *get_player_research(const struct player *p1);
 
-void merge_players_research(struct player* p1, struct player* p2);
-void clean_players_research(void);
 #define players_iterate(PI_player)                                            \
 {                                                                             \
   struct player *PI_player;                                                   \
Index: common/team.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/team.c,v
retrieving revision 1.5
diff -u -r1.5 team.c
--- common/team.c       24 Jun 2005 04:34:03 -0000      1.5
+++ common/team.c       19 Jul 2005 07:05:10 -0000
@@ -73,7 +73,7 @@
 void team_add_player(struct player *pplayer, struct team *pteam)
 {
   assert(pplayer != NULL);
-  assert(!pteam || &teams[pteam->index] == pteam);
+  assert(pteam != NULL && &teams[pteam->index] == pteam);
 
   freelog(LOG_DEBUG, "Adding player %d/%s to team %s.",
          pplayer->player_no, pplayer->username,
@@ -88,10 +88,9 @@
 
   /* Put the player on the new team. */
   pplayer->team = pteam;
-  if (pteam) {
-    pteam->players++;
-    assert(pteam->players <= MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS);
-  }
+  
+  pteam->players++;
+  assert(pteam->players <= MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS);
 }
 
 /****************************************************************************
@@ -187,5 +186,6 @@
     sz_strlcpy(teams[i].name, names[i]);
 
     teams[i].players = 0;
+    player_research_init(&(teams[i].research));
   }
 }
Index: common/team.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/team.h,v
retrieving revision 1.2
diff -u -r1.2 team.h
--- common/team.h       21 May 2005 19:40:24 -0000      1.2
+++ common/team.h       19 Jul 2005 07:05:10 -0000
@@ -16,11 +16,15 @@
 
 #include "fc_types.h"
 
+#include "tech.h"
+
 #define MAX_NUM_TEAMS (MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS)
 
 struct team {
   Team_type_id index;
   char name[MAX_LEN_NAME];
+  
+  struct player_research research;
 
   int players; /* # of players on the team */
 };
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.98
diff -u -r1.98 tech.c
--- common/tech.c       8 Jul 2005 03:31:18 -0000       1.98
+++ common/tech.c       19 Jul 2005 07:05:10 -0000
@@ -629,6 +629,16 @@
 }
 
 /**************************************************************************
+ Return the name of the given tech. You don't have to free the return
+ pointer.
+**************************************************************************/
+const char *get_normal_tech_name(Tech_type_id tech)
+{
+  assert(tech_exists(tech));
+  return advances[tech].name;
+}
+
+/**************************************************************************
  Returns true if the costs for the given technology will stay constant
  during the game. False otherwise.
 **************************************************************************/
@@ -678,3 +688,13 @@
     tech_free(i);
   }
 }
+
+/***************************************************************
+ Fill the structure with some sane values
+***************************************************************/
+void player_research_init(struct player_research* research)
+{
+  memset(research, 0, sizeof(struct player_research));
+  research->tech_goal = A_UNSET;
+  research->changed_from = -1;
+}
Index: common/tech.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v
retrieving revision 1.58
diff -u -r1.58 tech.h
--- common/tech.h       18 Jul 2005 22:46:28 -0000      1.58
+++ common/tech.h       19 Jul 2005 07:05:11 -0000
@@ -108,6 +108,57 @@
 
 BV_DEFINE(tech_vector, A_LAST);
 
+struct player_research {
+  /* 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.
+   *
+   * 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;
+
+    /* 
+     * required_techs, num_required_techs and bulbs_required are
+     * cached values. Updated from build_required_techs (which is
+     * called by update_research).
+     */
+    tech_vector required_techs;
+    int num_required_techs, bulbs_required;
+  } inventions[A_LAST];
+
+  /* Tech goal (similar to worklists; when one tech is researched the next
+   * tech toward the goal will be chosen).  May be A_NONE. */
+  Tech_type_id tech_goal;
+
+  /*
+   * Cached values. Updated by update_research.
+   */
+  int num_known_tech_with_flag[TF_LAST];
+};
+
+void player_research_init(struct player_research* research);
+
 enum tech_state get_invention(const struct player *pplayer,
                              Tech_type_id tech);
 void set_invention(struct player *pplayer, Tech_type_id tech,
@@ -137,6 +188,7 @@
                            Tech_type_id goal);
 bool is_future_tech(Tech_type_id tech);
 const char *get_tech_name(const struct player *pplayer, Tech_type_id tech);
+const char *get_normal_tech_name(Tech_type_id tech);
 
 void precalc_tech_data(void);
 
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.263
diff -u -r1.263 savegame.c
--- server/savegame.c   18 Jul 2005 22:46:29 -0000      1.263
+++ server/savegame.c   19 Jul 2005 07:05:27 -0000
@@ -1738,7 +1738,18 @@
   int id;
   int target_no;
   struct team *pteam;
-  struct player_research *research = get_player_research(plr);
+  struct player_research *research;
+
+  /* not all players have teams */
+  id = secfile_lookup_int_default(file, -1, "player%d.team_no", plrno);
+  pteam = team_get_by_id(id);
+  if (pteam == NULL) {
+    pteam = find_empty_team();
+  }
+  
+  team_add_player(plr, pteam);
+  
+  research = get_player_research(plr);
 
   server_player_init(plr, TRUE, FALSE);
   ai = ai_data_get(plr);
@@ -1791,14 +1802,6 @@
   /* Add techs from game and nation, but ignore game.info.tech. */
   init_tech(plr, 0);
 
-  /* not all players have teams */
-  id = secfile_lookup_int_default(file, -1, "player%d.team_no", plrno);
-  pteam = team_get_by_id(id);
-  if (pteam) {
-    /* Players with no team will be assigned to an empty team later. */
-    team_add_player(plr, pteam);
-  }
-
   if (is_barbarian(plr) && plr->nation == NO_NATION_SELECTED) {
     plr->nation = pick_barbarian_nation();
   }
@@ -3398,7 +3401,7 @@
 
     game.info.min_players   = secfile_lookup_int(file, "game.min_players");
     game.info.max_players   = secfile_lookup_int(file, "game.max_players");
-    game.info.nplayers      = secfile_lookup_int(file, "game.nplayers");
+
     game.info.heating = secfile_lookup_int_default(file, 0, "game.heating");
     game.info.globalwarming = secfile_lookup_int(file, "game.globalwarming");
     game.info.warminglevel  = secfile_lookup_int(file, "game.warminglevel");
@@ -3490,6 +3493,7 @@
        game.info.diplchance = 100 - (10 * (game.info.diplchance - 1));
       }
     }
+
     game.info.aqueductloss = secfile_lookup_int_default(file, 
game.info.aqueductloss,
                                                   "game.aqueductloss");
     game.info.killcitizen = secfile_lookup_int_default(file, 
game.info.killcitizen,
@@ -3578,6 +3582,9 @@
     load_rulesets();
   }
 
+  game.info.nplayers      = secfile_lookup_int(file, "game.nplayers");
+
+
   script_state_load(file);
 
   {
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.279
diff -u -r1.279 srv_main.c
--- server/srv_main.c   18 Jul 2005 22:46:29 -0000      1.279
+++ server/srv_main.c   19 Jul 2005 07:05:30 -0000
@@ -1843,14 +1843,6 @@
    } players_iterate_end;
   }
   
-  players_iterate(pplayer) {
-    players_iterate(pdest) {
-      if (players_on_same_team(pplayer, pdest)
-          && pplayer->player_no != pdest->player_no) {
-       merge_players_research(pplayer, pdest);
-      }
-    } players_iterate_end;
-  } players_iterate_end;
   /* tell the gamelog about the players */
   players_iterate(pplayer) {
     gamelog(GAMELOG_PLAYER, pplayer);

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