[Freeciv-Dev] (PR#2801) get_nation_leader_names is ugly
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#2801) get_nation_leader_names is ugly |
From: |
"Jason Short via RT" <rt@xxxxxxxxxxxxxx> |
Date: |
Sun, 12 Jan 2003 11:04:55 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
The implementation is ugly. A cleaner implementation as
get_nation_leaders is more useful.
jason
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.117
diff -u -r1.117 dialogs.c
--- client/gui-gtk/dialogs.c 2003/01/01 11:51:32 1.117
+++ client/gui-gtk/dialogs.c 2003/01/12 19:02:39
@@ -1846,7 +1846,7 @@
static void select_random_leader(void)
{
int j, leader_num;
- char **leaders;
+ struct leader *leaders;
char unique_name[MAX_LEN_NAME];
/* weirdness happens by not doing it this way */
@@ -1859,9 +1859,9 @@
leader_strings = NULL;
/* fill leader names combo box */
- leaders = get_nation_leader_names(selected_nation, &leader_num);
+ leaders = get_nation_leaders(selected_nation, &leader_num);
for(j = 0; j < leader_num; j++) {
- leader_strings = g_list_append(leader_strings, leaders[j]);
+ leader_strings = g_list_append(leader_strings, leaders[j].name);
}
gtk_combo_set_value_in_list(GTK_COMBO(races_name), FALSE, FALSE);
gtk_combo_set_popdown_strings(GTK_COMBO(races_name), leader_strings);
@@ -1872,11 +1872,10 @@
/* initialize leader names */
selected_leader = myrand(leader_num);
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(races_name)->entry),
- leaders[selected_leader]);
+ leaders[selected_leader].name);
/* initialize leader sex */
- selected_sex = get_nation_leader_sex(selected_nation,
- leaders[selected_leader]);
+ selected_sex = leaders[selected_leader].is_male;
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(
races_sex_toggles[selected_sex ? 0 : 1]), TRUE);
} else {
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.30
diff -u -r1.30 dialogs.c
--- client/gui-gtk-2.0/dialogs.c 2003/01/01 11:51:33 1.30
+++ client/gui-gtk-2.0/dialogs.c 2003/01/12 19:02:40
@@ -1761,7 +1761,7 @@
static void select_random_leader(void)
{
int j, leader_num;
- char **leaders;
+ struct leader *leaders;
char unique_name[MAX_LEN_NAME];
/* weirdness happens by not doing it this way */
@@ -1775,9 +1775,9 @@
leader_strings = NULL;
/* fill leader names combo box */
- leaders = get_nation_leader_names( selected_nation, &leader_num);
+ leaders = get_nation_leaders(selected_nation, &leader_num);
for(j = 0; j < leader_num; j++) {
- leader_strings = g_list_append(leader_strings, leaders[j]);
+ leader_strings = g_list_append(leader_strings, leaders[j].name);
}
gtk_combo_set_value_in_list(GTK_COMBO(races_name), FALSE, FALSE);
gtk_combo_set_popdown_strings(GTK_COMBO(races_name), leader_strings);
@@ -1789,11 +1789,10 @@
/* initialize leader names */
selected_leader = myrand(leader_num);
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(races_name)->entry),
- leaders[selected_leader]);
+ leaders[selected_leader].name);
/* initialize leader sex */
- selected_sex = get_nation_leader_sex(selected_nation,
- leaders[selected_leader]);
+ selected_sex = leaders[selected_leader].is_male;
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(
races_sex_toggles[selected_sex ? 0 : 1]), TRUE);
} else {
Index: client/gui-mui/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/dialogs.c,v
retrieving revision 1.46
diff -u -r1.46 dialogs.c
--- client/gui-mui/dialogs.c 2002/11/28 19:09:57 1.46
+++ client/gui-mui/dialogs.c 2003/01/12 19:02:41
@@ -1592,16 +1592,16 @@
static void nations_nation_active(void)
{
int i, leader_count;
- char **leaders;
+ struct leader *leaders;
Object *list = (Object*)xget(nations_leader_poplist,MUIA_Popobject_Object);
Nation_Type_id nation = get_active_nation();
set(nations_flag_sprite, MUIA_Sprite_Sprite,
get_nation_by_idx(nation)->flag_sprite);
- leaders = get_nation_leader_names( nation, &leader_count);
- setstring(nations_leader_string, leaders[0]);
+ leaders = get_nation_leaders(nation, &leader_count);
+ setstring(nations_leader_string, leaders[0].name);
- set(nations_sex_radio, MUIA_Radio_Active,
get_nation_leader_sex(nation,leaders[0])?0:1);
+ set(nations_sex_radio, MUIA_Radio_Active, leaders[0].is_male);
if(list)
{
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.4
diff -u -r1.4 dialogs.c
--- client/gui-sdl/dialogs.c 2002/12/30 21:40:50 1.4
+++ client/gui-sdl/dialogs.c 2003/01/12 19:02:42
@@ -1429,10 +1429,9 @@
**************************************************************************/
static int get_leader_sex(Nation_Type_id nation, Uint8 leader)
{
- int max;
- return get_nation_leader_sex(nation,
- get_nation_leader_names(nation,
- &max)[leader]);
+ int dim;
+ struct leader *leaders = get_nation_leaders(nation, &dim);
+ return leaders[leader].is_male;
}
/**************************************************************************
@@ -1449,15 +1448,15 @@
**************************************************************************/
static void select_random_leader(Nation_Type_id nation)
{
- int j;
- char **leaders;
+ int j, dim;
+ struct leader *leaders;
- leaders =
- get_nation_leader_names(nation, (int *) &pNations->max_leaders);
+ leaders = get_nation_leaders(nation, &dim);
+ pNations->max_leaders = dim;
pNations->leaders = CALLOC(pNations->max_leaders, sizeof(Uint16 *));
for (j = 0; j < pNations->max_leaders; j++) {
- pNations->leaders[j] = convert_to_utf16(leaders[j]);
+ pNations->leaders[j] = convert_to_utf16(leaders[j].name);
}
pNations->selected_leader = myrand(pNations->max_leaders);
@@ -1465,9 +1464,7 @@
pNations->leaders[pNations->selected_leader];
/* initialize leader sex */
- pNations->leader_sex = get_nation_leader_sex(nation,
- leaders[pNations->
- selected_leader]);
+ pNations->leader_sex = leaders[pNations->selected_leader].is_male;
if (pNations->leader_sex) {
pNations->change_sex_button->string16->text = pNations->male_str;
Index: client/gui-win32/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v
retrieving revision 1.27
diff -u -r1.27 dialogs.c
--- client/gui-win32/dialogs.c 2002/11/29 09:38:15 1.27
+++ client/gui-win32/dialogs.c 2003/01/12 19:02:43
@@ -287,19 +287,18 @@
**************************************************************************/
static void select_random_leader(HWND hWnd)
{
- char **leaders;
int j,leader_num;
- leaders=get_nation_leader_names(selected_nation,&leader_num);
+ struct leader *leaders = get_nation_leaders(selected_nation, &leader_num);
+
ComboBox_ResetContent(GetDlgItem(hWnd,ID_RACESDLG_LEADER));
- for(j=0;j<leader_num;j++)
- {
- ComboBox_AddString(GetDlgItem(hWnd,ID_RACESDLG_LEADER),leaders[j]);
- }
+ for (j = 0; j < leader_num; j++) {
+ ComboBox_AddString(GetDlgItem(hWnd,ID_RACESDLG_LEADER), leaders[j].name);
+ }
selected_leader=myrand(leader_num);
ComboBox_SetCurSel(GetDlgItem(hWnd,ID_RACESDLG_LEADER),selected_leader);
- SetWindowText(GetDlgItem(hWnd,ID_RACESDLG_LEADER),leaders[selected_leader]);
- if (get_nation_leader_sex(selected_nation,
- leaders[selected_leader])) {
+ SetWindowText(GetDlgItem(hWnd,ID_RACESDLG_LEADER),
+ leaders[selected_leader].name);
+ if (leaders[selected_leader].is_male) {
selected_leader_sex=ID_RACESDLG_MALE;
CheckRadioButton(hWnd,ID_RACESDLG_MALE,ID_RACESDLG_FEMALE,
ID_RACESDLG_MALE);
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.76
diff -u -r1.76 dialogs.c
--- client/gui-xaw/dialogs.c 2003/01/01 11:51:34 1.76
+++ client/gui-xaw/dialogs.c 2003/01/12 19:02:44
@@ -2196,7 +2196,7 @@
int race = races_toggles_to_nations[index];
int j;
int leader_count;
- char **leaders = get_nation_leader_names(race, &leader_count);
+ struct leader *leaders = get_nation_leaders(race, &leader_count);
Widget entry;
if(races_leader_pick_popupmenu)
@@ -2212,7 +2212,7 @@
for(j=0; j<leader_count; j++) {
entry =
- XtVaCreateManagedWidget(leaders[j],
+ XtVaCreateManagedWidget(leaders[j].name,
smeBSBObjectClass,
races_leader_pick_popupmenu,
NULL);
@@ -2246,15 +2246,12 @@
void races_leader_set_values(int race, int lead)
{
int leader_count;
- char **leaders;
- int sex;
+ struct leader *leaders = get_nation_leaders(race, &leader_count);
- leaders = get_nation_leader_names(race, &leader_count);
- XtVaSetValues(races_leader, XtNstring, leaders[lead], NULL);
- XawTextSetInsertionPoint(races_leader, strlen(leaders[lead]));
+ XtVaSetValues(races_leader, XtNstring, leaders[lead].name, NULL);
+ XawTextSetInsertionPoint(races_leader, strlen(leaders[lead].name));
- sex = !(get_nation_leader_sex(race, leaders[lead]));
- races_sex_buttons_set_current(sex);
+ races_sex_buttons_set_current(!leaders[lead].is_male);
}
/**************************************************************************
Index: common/nation.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.c,v
retrieving revision 1.32
diff -u -r1.32 nation.c
--- common/nation.c 2003/01/12 18:04:07 1.32
+++ common/nation.c 2003/01/12 19:02:44
@@ -86,20 +86,13 @@
Returns pointer to the array of the nation leader names, and
sets dim to number of leaders.
***************************************************************/
-char **get_nation_leader_names(Nation_Type_id nation, int *dim)
+struct leader *get_nation_leaders(Nation_Type_id nation, int *dim)
{
- static char **result = NULL;
- int i;
-
if (!bounds_check_nation_id(nation, LOG_FATAL, "get_nation_leader_names")) {
die("wrong nation %d", nation);
}
*dim = nations[nation].leader_count;
- result = fc_realloc(result, sizeof(char *) * (*dim));
- for (i = 0; i < *dim; i++) {
- result[i] = nations[nation].leaders[i].name;
- }
- return result;
+ return nations[nation].leaders;
}
/***************************************************************
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.19
diff -u -r1.19 nation.h
--- common/nation.h 2003/01/12 18:04:07 1.19
+++ common/nation.h 2003/01/12 19:02:44
@@ -110,7 +110,7 @@
Nation_Type_id find_nation_by_name(const char *name);
const char *get_nation_name(Nation_Type_id nation);
const char *get_nation_name_plural(Nation_Type_id nation);
-char **get_nation_leader_names(Nation_Type_id nation, int *dim);
+struct leader *get_nation_leaders(Nation_Type_id nation, int *dim);
bool get_nation_leader_sex(Nation_Type_id nation, const char *name);
struct nation_type *get_nation_by_plr(struct player *plr);
struct nation_type *get_nation_by_idx(Nation_Type_id nation);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.112
diff -u -r1.112 srv_main.c
--- server/srv_main.c 2003/01/05 23:24:52 1.112
+++ server/srv_main.c 2003/01/12 19:02:46
@@ -1685,19 +1685,23 @@
void pick_ai_player_name(Nation_Type_id nation, char *newname)
{
int i, names_count;
- char **names;
+ struct leader *leaders;
- names = get_nation_leader_names(nation, &names_count);
+ leaders = get_nation_leaders(nation, &names_count);
/* Try random names (scattershot), then all available,
* then "Player 1" etc:
*/
for(i=0; i<names_count; i++) {
- if (good_name(names[myrand(names_count)], newname)) return;
+ if (good_name(leaders[myrand(names_count)].name, newname)) {
+ return;
+ }
}
for(i=0; i<names_count; i++) {
- if (good_name(names[i], newname)) return;
+ if (good_name(leaders[i].name, newname)) {
+ return;
+ }
}
for(i=1; /**/; i++) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2801) get_nation_leader_names is ugly,
Jason Short via RT <=
|
|