Gnome basic functionality

- let the "#" key work as per Guidebook
- role selection didn't work if you had gender specified in your .nethackrc
  similar problems would occur for other .nethackrc selections
- fix an obvious memory leak
- fix one crash bug from accessing a freed pointer (M-? dismiss M-?)
- note some invalid behavior in comments for a real Gnome developer to fix
- reformatted some code so I could follow it
This commit is contained in:
cohrs
2002-03-17 20:16:57 +00:00
parent 0ffb78e6a4
commit 61b6bf1ce9
4 changed files with 207 additions and 204 deletions
+38 -40
View File
@@ -112,49 +112,50 @@ void gnome_init_nhwindows(int* argc, char** argv)
offers a Quit option, it is its responsibility to clean up and terminate
the process. You need to fill in pl_character[0].
*/
void gnome_player_selection()
void
gnome_player_selection()
{
int num_roles, availcount, i, nRole;
const char** choices;
int num_roles, availcount, i, nRole;
const char** choices;
int* rolemap;
/* select a role */
for (num_roles = 0; roles[num_roles].name.m; ++num_roles) continue;
choices = (const char **)alloc(sizeof(char *) * (num_roles+1));
for (;;) {
availcount = 0;
for (i = 0; i < num_roles; i++) {
choices[i] = 0;
if (ok_role(i, flags.initrace,
flags.initgend, flags.initalign)) {
choices[i] = roles[i].name.m;
if (flags.initgend >= 0 && flags.female && roles[i].name.f)
choices[i] = roles[i].name.f;
++availcount;
}
/* select a role */
for (num_roles = 0; roles[num_roles].name.m; ++num_roles) continue;
choices = (const char **)alloc(sizeof(char *) * (num_roles+1));
rolemap = (int*)alloc(sizeof(int) * (num_roles + 1));
for (;;) {
availcount = 0;
for (i = 0; i < num_roles; i++) {
if (ok_role(i, flags.initrace, flags.initgend, flags.initalign)) {
choices[availcount] = roles[i].name.m;
if (flags.initgend >= 0 && flags.female && roles[i].name.f)
choices[availcount] = roles[i].name.f;
rolemap[availcount] = i;
++availcount;
}
}
if (availcount > 0) break;
else if (flags.initalign >= 0) flags.initalign = -1; /* reset */
else if (flags.initgend >= 0) flags.initgend = -1;
else if (flags.initrace >= 0) flags.initrace = -1;
else panic("no available ROLE+race+gender+alignment combinations");
}
if (availcount > 0) break;
else if (flags.initalign >= 0) flags.initalign = -1; /* reset */
else if (flags.initgend >= 0) flags.initgend = -1;
else if (flags.initrace >= 0) flags.initrace = -1;
else panic("no available ROLE+race+gender+alignment combinations");
}
choices[num_roles] = (const char *) 0;
nRole=ghack_player_sel_dialog(choices);
choices[availcount] = (const char *) 0;
nRole = ghack_player_sel_dialog(choices);
/* Quit */
if ( nRole == -1 )
{
clearlocks();
gnome_exit_nhwindows(0);
}
/* Random role */
if ( nRole == -2)
{
nRole = rn2(num_roles);
pline("This game you will be %s", an(choices[nRole]));
if (nRole == -1) { /* Quit */
clearlocks();
gnome_exit_nhwindows(0);
} else if (nRole == -2) { /* Random role */
nRole = rolemap[rn2(availcount)];
pline("This game you will be %s", an(choices[nRole]));
} else {
nRole = rolemap[nRole];
}
flags.initrole = nRole;
flags.initrole = nRole;
free(choices);
free(rolemap);
}
@@ -1008,6 +1009,3 @@ void gnome_outrip(winid wid, int how)
ghack_text_window_rip_string( ripString);
}