[Freeciv-Dev] (PR#13689) put team names in the ruleset
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13689 >
As discussed a while ago, team names should go into the ruleset to allow
"factions" to be easily modified.
This patch does that.
-jason
? data/default/diff
Index: client/plrdlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/plrdlg_common.c,v
retrieving revision 1.22
diff -p -u -r1.22 plrdlg_common.c
--- client/plrdlg_common.c 11 Jun 2005 19:07:30 -0000 1.22
+++ client/plrdlg_common.c 16 Aug 2005 19:07:34 -0000
@@ -97,7 +97,7 @@ static const char *col_nation(const stru
*******************************************************************/
static const char *col_team(const struct player *player)
{
- return _(player->team->name);
+ return team_get_name(player->team);
}
/******************************************************************
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.134
diff -p -u -r1.134 gui_main.c
--- client/gui-gtk-2.0/gui_main.c 4 Aug 2005 16:57:36 -0000 1.134
+++ client/gui-gtk-2.0/gui_main.c 16 Aug 2005 19:07:35 -0000
@@ -1292,7 +1292,7 @@ void update_conn_list_dialog(void)
nation = get_nation_name(pplayer->nation);
leader = pplayer->name;
}
- team = pplayer->team ? _(pplayer->team->name) : "";
+ team = pplayer->team ? team_get_name(pplayer->team) : "";
gtk_list_store_append(conn_model, &it);
gtk_list_store_set(conn_model, &it,
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.37
diff -p -u -r1.37 pages.c
--- client/gui-gtk-2.0/pages.c 8 Aug 2005 16:30:22 -0000 1.37
+++ client/gui-gtk-2.0/pages.c 16 Aug 2005 19:07:35 -0000
@@ -963,7 +963,7 @@ static void team_menu_entry_chosen(GtkMe
if (pteam != team_menu_player->team) {
my_snprintf(buf, sizeof(buf), "/team \"%s\" \"%s\"",
- team_menu_player->name, pteam->name);
+ team_menu_player->name, team_get_name_orig(pteam));
send_chat(buf);
}
}
@@ -993,8 +993,9 @@ static GtkWidget *create_team_menu(struc
need_empty_team = FALSE;
}
- entry = gtk_menu_item_new_with_label(_(pteam->name));
- g_object_set_data_full(G_OBJECT(menu), pteam->name, entry,
+ entry = gtk_menu_item_new_with_label(team_get_name(pteam));
+ g_object_set_data_full(G_OBJECT(menu),
+ team_get_name_orig(pteam), entry,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show(entry);
gtk_container_add(GTK_CONTAINER(menu), entry);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.150
diff -p -u -r1.150 packets.def
--- common/packets.def 11 Aug 2005 04:43:25 -0000 1.150
+++ common/packets.def 16 Aug 2005 19:07:35 -0000
@@ -453,6 +453,9 @@ PACKET_GAME_INFO=15; sc
UINT8 save_compress_level;
STRING start_units[MAX_LEN_STARTUNIT];
+
+ UINT8 num_teams;
+ STRING team_names_orig[MAX_NUM_TEAMS:num_teams][MAX_LEN_NAME];
/* True if at least one civilization has researched a tech */
BOOL global_advances[A_LAST]; diff
Index: common/team.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/team.c,v
retrieving revision 1.6
diff -p -u -r1.6 team.c
--- common/team.c 20 Jul 2005 07:19:20 -0000 1.6
+++ common/team.c 16 Aug 2005 19:07:36 -0000
@@ -42,12 +42,13 @@ struct team *team_find_by_name(const cha
int index;
assert(team_name != NULL);
+ assert(NUM_TEAMS <= MAX_NUM_TEAMS);
/* Can't use team_iterate here since it skips empty teams. */
- for (index = 0; index < MAX_NUM_TEAMS; index++) {
+ for (index = 0; index < NUM_TEAMS; index++) {
struct team *pteam = team_get_by_id(index);
- if (mystrcasecmp(team_name, pteam->name) == 0) {
+ if (mystrcasecmp(team_name, team_get_name_orig(pteam)) == 0) {
return pteam;
}
}
@@ -60,7 +61,7 @@ struct team *team_find_by_name(const cha
****************************************************************************/
struct team *team_get_by_id(Team_type_id id)
{
- if (id < 0 || id >= MAX_NUM_TEAMS) {
+ if (id < 0 || id >= NUM_TEAMS) {
return NULL;
}
return &teams[id];
@@ -77,7 +78,7 @@ void team_add_player(struct player *ppla
freelog(LOG_DEBUG, "Adding player %d/%s to team %s.",
pplayer->player_no, pplayer->username,
- pteam ? pteam->name : "(none)");
+ pteam ? team_get_name(pteam) : "(none)");
/* Remove the player from the old team, if any. The player's team should
* only be NULL for a few instants after the player was created; after
@@ -105,7 +106,7 @@ void team_remove_player(struct player *p
if (pplayer->team) {
freelog(LOG_DEBUG, "Removing player %d/%s from team %s (%d)",
pplayer->player_no, pplayer->username,
- pplayer->team ? pplayer->team->name : "(none)",
+ pplayer->team ? team_get_name(pplayer->team) : "(none)",
pplayer->team ? pplayer->team->players : 0);
pplayer->team->players--;
assert(pplayer->team->players >= 0);
@@ -114,6 +115,25 @@ void team_remove_player(struct player *p
}
/****************************************************************************
+ Return the translated name of the team.
+****************************************************************************/
+const char *team_get_name(const struct team *pteam)
+{
+ return _(team_get_name_orig(pteam));
+}
+
+/****************************************************************************
+ Return the untranslated name of the team.
+****************************************************************************/
+const char *team_get_name_orig(const struct team *pteam)
+{
+ if (!pteam) {
+ return N_("(none)");
+ }
+ return game.info.team_names_orig[pteam->index];
+}
+
+/****************************************************************************
Returns the most empty team available. This is the team that should be
assigned to a newly-created player.
****************************************************************************/
@@ -123,7 +143,7 @@ struct team *find_empty_team(void)
struct team *pbest = NULL;
/* Can't use teams_iterate here since it skips empty teams! */
- for (i = 0; i < MAX_NUM_TEAMS; i++) {
+ for (i = 0; i < NUM_TEAMS; i++) {
struct team *pteam = team_get_by_id(i);
if (!pbest || pbest->players > pteam->players) {
@@ -144,46 +164,10 @@ struct team *find_empty_team(void)
void teams_init(void)
{
Team_type_id i;
- char *names[] = {
- N_("Team 1"),
- N_("Team 2"),
- N_("Team 3"),
- N_("Team 4"),
- N_("Team 5"),
- N_("Team 6"),
- N_("Team 7"),
- N_("Team 8"),
- N_("Team 9"),
- N_("Team 10"),
- N_("Team 11"),
- N_("Team 12"),
- N_("Team 13"),
- N_("Team 14"),
- N_("Team 15"),
- N_("Team 16"),
- N_("Team 17"),
- N_("Team 18"),
- N_("Team 19"),
- N_("Team 20"),
- N_("Team 21"),
- N_("Team 22"),
- N_("Team 23"),
- N_("Team 24"),
- N_("Team 25"),
- N_("Team 26"),
- N_("Team 27"),
- N_("Team 28"),
- N_("Team 29"),
- N_("Team 30"),
- N_("Team 31"),
- N_("Team 32"),
- };
- assert(ARRAY_SIZE(names) == MAX_NUM_TEAMS);
for (i = 0; i < MAX_NUM_TEAMS; i++) {
/* mark as unused */
teams[i].index = i;
- 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.3
diff -p -u -r1.3 team.h
--- common/team.h 20 Jul 2005 07:19:20 -0000 1.3
+++ common/team.h 16 Aug 2005 19:07:36 -0000
@@ -19,10 +19,10 @@
#include "tech.h"
#define MAX_NUM_TEAMS (MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS)
+#define NUM_TEAMS (game.info.num_teams)
struct team {
Team_type_id index;
- char name[MAX_LEN_NAME];
struct player_research research;
@@ -35,6 +35,9 @@ struct team *team_get_by_id(Team_type_id
void team_add_player(struct player *pplayer, struct team *pteam);
void team_remove_player(struct player *pplayer);
+const char *team_get_name(const struct team *pteam);
+const char *team_get_name_orig(const struct team *pteam);
+
struct team *find_empty_team(void);
#define team_iterate(pteam) \
Index: data/civ1/game.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ1/game.ruleset,v
retrieving revision 1.19
diff -p -u -r1.19 game.ruleset
--- data/civ1/game.ruleset 10 Jun 2005 02:20:07 -0000 1.19
+++ data/civ1/game.ruleset 16 Aug 2005 19:07:36 -0000
@@ -96,3 +96,37 @@ total_factor = 100
;If this options is set to 0, only the defender unit is destroyed.
killstack = 1
+[teams]
+names =
+ _("Team 1"),
+ _("Team 2"),
+ _("Team 3"),
+ _("Team 4"),
+ _("Team 5"),
+ _("Team 6"),
+ _("Team 7"),
+ _("Team 8"),
+ _("Team 9"),
+ _("Team 10"),
+ _("Team 11"),
+ _("Team 12"),
+ _("Team 13"),
+ _("Team 14"),
+ _("Team 15"),
+ _("Team 16"),
+ _("Team 17"),
+ _("Team 18"),
+ _("Team 19"),
+ _("Team 20"),
+ _("Team 21"),
+ _("Team 22"),
+ _("Team 23"),
+ _("Team 24"),
+ _("Team 25"),
+ _("Team 26"),
+ _("Team 27"),
+ _("Team 28"),
+ _("Team 29"),
+ _("Team 30"),
+ _("Team 31"),
+ _("Team 32")
Index: data/civ2/game.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/civ2/game.ruleset,v
retrieving revision 1.19
diff -p -u -r1.19 game.ruleset
--- data/civ2/game.ruleset 10 Jun 2005 02:20:08 -0000 1.19
+++ data/civ2/game.ruleset 16 Aug 2005 19:07:36 -0000
@@ -96,3 +96,37 @@ total_factor = 100
;If this options is set to 0, only the defender unit is destroyed.
killstack = 1
+[teams]
+names =
+ _("Team 1"),
+ _("Team 2"),
+ _("Team 3"),
+ _("Team 4"),
+ _("Team 5"),
+ _("Team 6"),
+ _("Team 7"),
+ _("Team 8"),
+ _("Team 9"),
+ _("Team 10"),
+ _("Team 11"),
+ _("Team 12"),
+ _("Team 13"),
+ _("Team 14"),
+ _("Team 15"),
+ _("Team 16"),
+ _("Team 17"),
+ _("Team 18"),
+ _("Team 19"),
+ _("Team 20"),
+ _("Team 21"),
+ _("Team 22"),
+ _("Team 23"),
+ _("Team 24"),
+ _("Team 25"),
+ _("Team 26"),
+ _("Team 27"),
+ _("Team 28"),
+ _("Team 29"),
+ _("Team 30"),
+ _("Team 31"),
+ _("Team 32")
Index: data/default/game.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/game.ruleset,v
retrieving revision 1.23
diff -p -u -r1.23 game.ruleset
--- data/default/game.ruleset 27 Jun 2005 14:30:19 -0000 1.23
+++ data/default/game.ruleset 16 Aug 2005 19:07:36 -0000
@@ -123,3 +123,38 @@ slow_invasions = 1
;destroyed along with the defender. This is the freeciv default.
;If this options is set to 0, only the defender unit is destroyed.
killstack = 1
+
+[teams]
+names =
+ _("Team 1"),
+ _("Team 2"),
+ _("Team 3"),
+ _("Team 4"),
+ _("Team 5"),
+ _("Team 6"),
+ _("Team 7"),
+ _("Team 8"),
+ _("Team 9"),
+ _("Team 10"),
+ _("Team 11"),
+ _("Team 12"),
+ _("Team 13"),
+ _("Team 14"),
+ _("Team 15"),
+ _("Team 16"),
+ _("Team 17"),
+ _("Team 18"),
+ _("Team 19"),
+ _("Team 20"),
+ _("Team 21"),
+ _("Team 22"),
+ _("Team 23"),
+ _("Team 24"),
+ _("Team 25"),
+ _("Team 26"),
+ _("Team 27"),
+ _("Team 28"),
+ _("Team 29"),
+ _("Team 30"),
+ _("Team 31"),
+ _("Team 32")
Index: data/history/game.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/history/game.ruleset,v
retrieving revision 1.11
diff -p -u -r1.11 game.ruleset
--- data/history/game.ruleset 10 Jun 2005 02:20:08 -0000 1.11
+++ data/history/game.ruleset 16 Aug 2005 19:07:36 -0000
@@ -95,3 +95,38 @@ total_factor = 100
;destroyed along with the defender. This is the freeciv default.
;If this options is set to 0, only the defender unit is destroyed.
killstack = 1
+
+[teams]
+names =
+ _("Team 1"),
+ _("Team 2"),
+ _("Team 3"),
+ _("Team 4"),
+ _("Team 5"),
+ _("Team 6"),
+ _("Team 7"),
+ _("Team 8"),
+ _("Team 9"),
+ _("Team 10"),
+ _("Team 11"),
+ _("Team 12"),
+ _("Team 13"),
+ _("Team 14"),
+ _("Team 15"),
+ _("Team 16"),
+ _("Team 17"),
+ _("Team 18"),
+ _("Team 19"),
+ _("Team 20"),
+ _("Team 21"),
+ _("Team 22"),
+ _("Team 23"),
+ _("Team 24"),
+ _("Team 25"),
+ _("Team 26"),
+ _("Team 27"),
+ _("Team 28"),
+ _("Team 29"),
+ _("Team 30"),
+ _("Team 31"),
+ _("Team 32")
Index: server/gamelog.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamelog.c,v
retrieving revision 1.53
diff -p -u -r1.53 gamelog.c
--- server/gamelog.c 26 Jul 2005 16:36:00 -0000 1.53
+++ server/gamelog.c 16 Aug 2005 19:07:36 -0000
@@ -500,7 +500,7 @@ void gamelog(int level, ...)
pteam = va_arg(args, struct team *);
my_snprintf(buf, sizeof(buf), "<id>%d</id><name>%s</name>",
- pteam->index, pteam->name);
+ pteam->index, team_get_name_orig(pteam));
players_iterate(aplayer) {
if (aplayer->team == pteam) {
cat_snprintf(buf, sizeof(buf), "<n>%d</n>", aplayer->player_no);
@@ -553,7 +553,8 @@ void gamelog(int level, ...)
cat_snprintf(buf, sizeof(buf), "<n>%d</n>", aplayer->player_no);
}
} players_iterate_end;
- my_snprintf(msg, sizeof(msg), "Team victory to %s", pteam->name);
+ my_snprintf(msg, sizeof(msg), "Team victory to %s",
+ team_get_name_orig(pteam));
break;
default:
break;
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.278
diff -p -u -r1.278 ruleset.c
--- server/ruleset.c 1 Aug 2005 22:38:26 -0000 1.278
+++ server/ruleset.c 16 Aug 2005 19:07:37 -0000
@@ -2460,9 +2460,10 @@ Load ruleset file
static void load_ruleset_game(void)
{
struct section_file file;
- char *sval;
+ char *sval, **svec;
const char *filename;
int *food_ini;
+ int i;
openload_ruleset_file(&file, "game");
filename = secfile_filename(&file);
@@ -2615,7 +2616,18 @@ static void load_ruleset_game(void)
/* Enable/Disable killstack */
game.info.killstack = secfile_lookup_bool(&file, "combat_rules.killstack");
-
+
+ svec = secfile_lookup_str_vec(&file, &game.info.num_teams, "teams.names");
+ game.info.num_teams = MIN(MAX_NUM_TEAMS, game.info.num_teams);
+ if (game.info.num_teams <= 0) {
+ freelog(LOG_FATAL, "Missing team names in game.ruleset.");
+ exit(EXIT_FAILURE);
+ }
+ for (i = 0; i < game.info.num_teams; i++) {
+ sz_strlcpy(game.info.team_names_orig[i], svec[i]);
+ }
+ free(svec);
+
section_file_check_unused(&file, filename);
section_file_free(&file);
}
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.70
diff -p -u -r1.70 sanitycheck.c
--- server/sanitycheck.c 14 Jul 2005 19:25:46 -0000 1.70
+++ server/sanitycheck.c 16 Aug 2005 19:07:37 -0000
@@ -117,6 +117,7 @@ static void check_misc(void)
SANITY_CHECK(nbarbs == game.info.nbarbarians);
SANITY_CHECK(game.info.nplayers <= MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS);
+ SANITY_CHECK(NUM_TEAMS <= MAX_NUM_TEAMS);
}
/**************************************************************************
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.285
diff -p -u -r1.285 srv_main.c
--- server/srv_main.c 15 Aug 2005 03:33:27 -0000 1.285
+++ server/srv_main.c 16 Aug 2005 19:07:37 -0000
@@ -259,7 +259,7 @@ bool is_game_over(void)
} players_iterate_end;
if (win) {
notify_conn_ex(game.est_connections, NULL, E_GAME_END,
- _("Team victory to %s"), pteam->name);
+ _("Team victory to %s"), team_get_name_orig(pteam));
gamelog(GAMELOG_JUDGE, GL_TEAMWIN, pteam);
return TRUE;
}
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.430
diff -p -u -r1.430 stdinhand.c
--- server/stdinhand.c 11 Aug 2005 04:43:26 -0000 1.430
+++ server/stdinhand.c 16 Aug 2005 19:07:38 -0000
@@ -2063,7 +2063,7 @@ static bool team_command(struct connecti
team_add_player(pplayer, pteam);
send_player_info(pplayer, NULL);
cmd_reply(CMD_TEAM, caller, C_OK, _("Player %s set to team %s."),
- pplayer->name, _(pteam->name));
+ pplayer->name, team_get_name(pteam));
}
res = TRUE;
@@ -3942,7 +3942,7 @@ void show_players(struct connection *cal
get_nation_name_plural(pplayer->nation));
}
cat_snprintf(buf2, sizeof(buf2), _(", team %s"),
- pplayer->team->name);
+ team_get_name(pplayer->team));
if (server_state == PRE_GAME_STATE && pplayer->is_connected) {
if (pplayer->is_ready) {
cat_snprintf(buf2, sizeof(buf2), _(", ready"));
@@ -3997,7 +3997,7 @@ static void show_teams(struct connection
PL_("%2d : '%s' : %d player",
"%2d : '%s' : %d players",
pteam->players),
- team_no, _(pteam->name), pteam->players);
+ team_no, team_get_name(pteam), pteam->players);
players_iterate(pplayer) {
if (pplayer->team == pteam) {
cmd_reply(CMD_LIST, caller, C_COMMENT, " %s", pplayer->name);
@@ -4015,12 +4015,12 @@ static void show_teams(struct connection
cmd_reply(CMD_LIST, caller, C_COMMENT,
_("%2d : '%s' : 1 player : %s"),
- team_no, _(pteam->name), teamplayer->name);
+ team_no, team_get_name(pteam), teamplayer->name);
}
}
cmd_reply(CMD_LIST, caller, C_COMMENT, " ");
cmd_reply(CMD_LIST, caller, C_COMMENT,
- _("Empty team: %s"), find_empty_team()->name);
+ _("Empty team: %s"), team_get_name(find_empty_team()));
cmd_reply(CMD_LIST, caller, C_COMMENT, horiz_line);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13689) put team names in the ruleset,
Jason Short <=
|
|