[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: |
Wed, 13 Jul 2005 02:07:25 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13429 >
Updated patch.
It contains also missing win32 part of 13306.
I didn't tested if win32 client compiles.
--
mateusz
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.528
diff -u -r1.528 packhand.c
--- client/packhand.c 9 Jul 2005 17:46:07 -0000 1.528
+++ client/packhand.c 13 Jul 2005 09:01:52 -0000
@@ -1416,7 +1416,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);
@@ -1470,6 +1470,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);
@@ -2172,7 +2174,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.313
diff -u -r1.313 tilespec.c
--- client/tilespec.c 9 Jul 2005 17:46:07 -0000 1.313
+++ client/tilespec.c 13 Jul 2005 09:01:59 -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 13 Jul 2005 09:02:02 -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 13 Jul 2005 09:02:02 -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.227
diff -u -r1.227 game.c
--- common/game.c 12 Jul 2005 21:51:23 -0000 1.227
+++ common/game.c 13 Jul 2005 09:02:03 -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 13 Jul 2005 09:02:05 -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 && plr->team);
+ return &(plr->team->research);
}
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.158
diff -u -r1.158 player.h
--- common/player.h 7 Jul 2005 08:34:38 -0000 1.158
+++ common/player.h 13 Jul 2005 09:02:06 -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 13 Jul 2005 09:02:06 -0000
@@ -86,12 +86,16 @@
* situation. */
team_remove_player(pplayer);
+
+ if (!pteam) {
+ pteam = find_empty_team();
+ }
+
/* 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 +191,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 13 Jul 2005 09:02:06 -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 13 Jul 2005 09:02:07 -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.57
diff -u -r1.57 tech.h
--- common/tech.h 8 Jul 2005 03:31:18 -0000 1.57
+++ common/tech.h 13 Jul 2005 09:02:09 -0000
@@ -109,6 +109,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,
@@ -138,6 +189,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.261
diff -u -r1.261 savegame.c
--- server/savegame.c 10 Jul 2005 16:03:11 -0000 1.261
+++ server/savegame.c 13 Jul 2005 09:02:25 -0000
@@ -1739,7 +1739,14 @@
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);
+ team_add_player(plr, pteam);
+
+ research = get_player_research(plr);
server_player_init(plr, TRUE, FALSE);
ai = ai_data_get(plr);
@@ -1792,14 +1799,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 = game.control.nation_count - 1;
}
@@ -3399,7 +3398,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");
@@ -3491,6 +3490,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,
@@ -3579,6 +3579,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.277
diff -u -r1.277 srv_main.c
--- server/srv_main.c 11 Jul 2005 19:31:13 -0000 1.277
+++ server/srv_main.c 13 Jul 2005 09:02:26 -0000
@@ -1910,14 +1910,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);
|
|