static int role_gendercount(int rolenum) { int gendcount = 0; if (validrole(rolenum)) { if (roles[rolenum].allow & ROLE_MALE) ++gendcount; if (roles[rolenum].allow & ROLE_FEMALE) ++gendcount; if (roles[rolenum].allow & ROLE_NEUTER) ++gendcount; } return gendcount; }
char *nh_build_plselection_prompt(char *buf, int buflen, int rolenum, int racenum, int gendnum, int alignnum) { const char *defprompt = "需要我帮你选一个角色吗?"; int num_post_attribs = 0; char tmpbuf[BUFSZ]; if (buflen < QBUFSZ) return (char *)defprompt; strcpy(tmpbuf, "需要我选择"); if (racenum != ROLE_NONE || validrole(rolenum)) strcat(tmpbuf, "你的"); else { strcat(tmpbuf, "一个"); } /* <your> */ nh_root_plselection_prompt(eos(tmpbuf), buflen - strlen(tmpbuf), rolenum, racenum, gendnum, alignnum); sprintf(buf, "%s", s_suffix(tmpbuf)); /* buf should now be: * < your lawful female gnomish cavewoman's> || <your lawful female gnome's> * || <your lawful female character's> * * Now append the post attributes to it */ num_post_attribs = post_attribs; if (post_attribs) { if (pa[BP_RACE]) { promptsep(eos(buf), num_post_attribs); strcat(buf, "种族"); } if (pa[BP_ROLE]) { promptsep(eos(buf), num_post_attribs); strcat(buf, "角色"); } if (pa[BP_GEND]) { promptsep(eos(buf), num_post_attribs); strcat(buf, "性别"); } if (pa[BP_ALIGN]) { promptsep(eos(buf), num_post_attribs); strcat(buf, "阵营"); } } strcat(buf, "吗?"); return buf; }
boolean nh_start_game(int fd, const char *name, int irole, int irace, int igend, int ialign, enum nh_game_modes playmode) { unsigned int seed = 0; if (!api_entry_checkpoint()) return FALSE; /* init failed; programmer error! */ if (fd == -1 || !name || !*name) goto err_out; if (!program_state.restoring) { turntime = (unsigned long long)time(NULL); seed = turntime ^ get_seedval(); /* initialize the random number generator */ mt_srand(seed); } /* else: turntime and rng seeding are done in logreplay.c */ startup_common(name, playmode); if (!validrole(irole) || !validrace(irole, irace) || !validgend(irole, irace, igend) || !validalign(irole, irace, ialign)) goto err_out; u.initrole = irole; u.initrace = irace; u.initgend = igend; u.initalign = ialign; /* write out a new logfile header "NHGAME ..." with all the initial details */ log_init(); log_newgame(fd, turntime, seed, playmode); newgame(); was_on_elbereth = !sengr_at("Elbereth", u.ux, u.uy); /* force botl update later */ wd_message(); api_exit(); return TRUE; err_out: api_exit(); return FALSE; }
/* Get the player selection character */ #if 0 /* New function at the bottom */ void amii_player_selection() { register struct Window *cwin; register struct IntuiMessage *imsg; register int aredone = 0; register struct Gadget *gd; static int once = 0; long class, code; amii_clear_nhwindow( WIN_BASE ); if (validrole(flags.initrole)) return; else { flags.initrole=randrole(); return; } #if 0 /* Don't query the user ... instead give random character -jhsa */ #if 0 /* OBSOLETE */ if( *pl_character ){ pl_character[ 0 ] = toupper( pl_character[ 0 ] ); if( index( pl_classes, pl_character[ 0 ] ) ) return; } #endif if( !once ){ if( bigscreen ){ Type_NewWindowStructure1.TopEdge = (HackScreen->Height/2) - (Type_NewWindowStructure1.Height/2); } for( gd = Type_NewWindowStructure1.FirstGadget; gd; gd = gd->NextGadget ) { if( gd->GadgetID != 0 ) SetBorder( gd ); } once = 1; } if( WINVERS_AMIV ) { # ifdef INTUI_NEW_LOOK Type_NewWindowStructure1.Extension = wintags; Type_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; fillhook.h_Entry = (ULONG(*)())LayerFillHook; fillhook.h_Data = (void *)-2; fillhook.h_SubEntry = 0; #endif } Type_NewWindowStructure1.Screen = HackScreen; if( ( cwin = OpenShWindow( (void *)&Type_NewWindowStructure1 ) ) == NULL ) { return; } #if 0 WindowToFront( cwin ); #endif while( !aredone ) { WaitPort( cwin->UserPort ); while( ( imsg = (void *) GetMsg( cwin->UserPort ) ) != NULL ) { class = imsg->Class; code = imsg->Code; gd = (struct Gadget *)imsg->IAddress; ReplyMsg( (struct Message *)imsg ); switch( class ) { case VANILLAKEY: if( index( pl_classes, toupper( code ) ) ) { pl_character[0] = toupper( code ); aredone = 1; } else if( code == ' ' || code == '\n' || code == '\r' ) { flags.initrole = randrole(); #if 0 /* OBSOLETE */ #ifdef TOURIST strcpy( pl_character, roles[ rnd( 11 ) ] ); #else strcpy( pl_character, roles[ rnd( 10 ) ] ); #endif #endif aredone = 1; amii_clear_nhwindow( WIN_BASE ); CloseShWindow( cwin ); RandomWindow( pl_character ); return; } else if( code == 'q' || code == 'Q' ) { CloseShWindow( cwin ); clearlocks(); exit_nhwindows(NULL); terminate(0); } else DisplayBeep( NULL ); break; case GADGETUP: switch( gd->GadgetID ) { case 1: /* Random Character */ flags.initrole = randrole(); #if 0 /* OBSOLETE */ #ifdef TOURIST strcpy( pl_character, roles[ rnd( 11 ) ] ); #else strcpy( pl_character, roles[ rnd( 10 ) ] ); #endif #endif amii_clear_nhwindow( WIN_BASE ); CloseShWindow( cwin ); RandomWindow( pl_character ); return; default: pl_character[0] = gd->GadgetID; break; } aredone = 1; break; case CLOSEWINDOW: CloseShWindow( cwin ); clearlocks(); exit_nhwindows(NULL); terminate(0); break; } } } amii_clear_nhwindow( WIN_BASE ); CloseShWindow( cwin ); #endif /* Do not query user ... -jhsa */ }
const char *nh_root_plselection_prompt(char *suppliedbuf, int buflen, int rolenum, int racenum, int gendnum, int alignnum) { int k, gendercount = 0, aligncount = 0; char buf[BUFSZ]; static const char err_ret[] = "人物的"; boolean donefirst = FALSE; if (!suppliedbuf || buflen < 1) return err_ret; /* initialize these static variables each time this is called */ post_attribs = 0; for (k=0; k < NUM_BP; ++k) pa[k] = 0; buf[0] = '\0'; *suppliedbuf = '\0'; /* How many alignments are allowed for the desired race? */ if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) aligncount = race_alignmentcount(racenum); if (alignnum != ROLE_NONE && alignnum != ROLE_RANDOM) { /* if race specified, and multiple choice of alignments for it */ strcat(buf, aligns[alignnum].adj); donefirst = TRUE; } else { /* if alignment not specified, but race is specified and only one choice of alignment for that race then don't include it in the later list */ if ((((racenum != ROLE_NONE && racenum != ROLE_RANDOM) && ok_race(rolenum, racenum, gendnum, alignnum)) && (aligncount > 1)) || (racenum == ROLE_NONE || racenum == ROLE_RANDOM)) { pa[BP_ALIGN] = 1; post_attribs++; } } /* <your lawful> */ /* How many genders are allowed for the desired role? */ if (validrole(rolenum)) gendercount = role_gendercount(rolenum); if (gendnum != ROLE_NONE && gendnum != ROLE_RANDOM) { if (validrole(rolenum)) { /* if role specified, and multiple choice of genders for it, and name of role itself does not distinguish gender */ if ((rolenum != ROLE_NONE) && (gendercount > 1) && !roles[rolenum].name.f) { strcat(buf, genders[gendnum].adj + 2); donefirst = TRUE; } } else { strcat(buf, genders[gendnum].adj + 2); donefirst = TRUE; } } else { /* if gender not specified, but role is specified and only one choice of gender then don't include it in the later list */ if ((validrole(rolenum) && (gendercount > 1)) || !validrole(rolenum)) { pa[BP_GEND] = 1; post_attribs++; } } /* <your lawful female> */ if (racenum != ROLE_NONE && racenum != ROLE_RANDOM) { if (validrole(rolenum) && ok_race(rolenum, racenum, gendnum, alignnum)) { strcat(buf, (rolenum == ROLE_NONE) ? races[racenum].noun : races[racenum].adj); donefirst = TRUE; } else if (!validrole(rolenum)) { strcat(buf, races[racenum].noun); donefirst = TRUE; } else { pa[BP_RACE] = 1; post_attribs++; } } else { pa[BP_RACE] = 1; post_attribs++; } /* <your lawful female gnomish> || <your lawful female gnome> */ if (validrole(rolenum)) { if (gendnum != ROLE_NONE) { if (gendnum == 1 && roles[rolenum].name.f) strcat(buf, roles[rolenum].name.f); else strcat(buf, roles[rolenum].name.m + 2); } else { if (roles[rolenum].name.f) { strcat(buf, roles[rolenum].name.m + 2); strcat(buf, "/"); strcat(buf, roles[rolenum].name.f); } else strcat(buf, roles[rolenum].name.m + 2); } donefirst = TRUE; } else if (rolenum == ROLE_NONE) { pa[BP_ROLE] = 1; post_attribs++; } if ((racenum == ROLE_NONE || racenum == ROLE_RANDOM) && !validrole(rolenum)) { strcat(buf, "人物"); } /* <your lawful female gnomish cavewoman> || <your lawful female gnome> * || <your lawful female character> */ if (buflen > (int) (strlen(buf) + 1)) { strcpy(suppliedbuf, buf); return suppliedbuf; } else return err_ret; }
/* * Special setup modifications here: * * Unfortunately, this is going to have to be done * on each newgame or restore, because you lose the permonst mods * across a save/restore. :-) * * 1 - The Rogue Leader is the Tourist Nemesis. * 2 - Priests start with a random alignment - convert the leader and * guardians here. * 3 - Elves can have one of two different leaders, but can't work it * out here because it requires hacking the level file data (see * sp_lev.c). * * This code also replaces quest_init(). */ void role_init(void) { int alignmnt; /* Check for a valid role. Try u.initrole first. */ if (!validrole(u.initrole)) { /* Try the player letter second */ if ((u.initrole = str2role(pl_character)) < 0) /* None specified; pick a random role */ u.initrole = randrole(); } /* We now have a valid role index. Copy the role name back. */ /* This should become OBSOLETE */ strcpy(pl_character, roles[u.initrole].name.m); pl_character[PL_CSIZ-1] = '\0'; /* Check for a valid race */ if (!validrace(u.initrole, u.initrace)) u.initrace = randrace(u.initrole); /* Check for a valid gender. If new game, check both initgend * and female. On restore, assume flags.female is correct. */ if (flags.pantheon == -1) { /* new game */ if (!validgend(u.initrole, u.initrace, flags.female)) flags.female = !flags.female; } if (!validgend(u.initrole, u.initrace, u.initgend)) /* Note that there is no way to check for an unspecified gender. */ u.initgend = flags.female; /* Check for a valid alignment */ if (!validalign(u.initrole, u.initrace, u.initalign)) /* Pick a random alignment */ u.initalign = randalign(u.initrole, u.initrace); alignmnt = aligns[u.initalign].value; /* Initialize urole and urace */ urole = roles[u.initrole]; urace = races[u.initrace]; /* Fix up the quest leader */ pm_leader = mons[urole.ldrnum]; if (urole.ldrnum != NON_PM) { pm_leader.msound = MS_LEADER; pm_leader.mflags2 |= (M2_PEACEFUL); pm_leader.mflags3 |= M3_CLOSE; pm_leader.maligntyp = alignmnt * 3; } /* Fix up the quest guardians */ pm_guardian = mons[urole.guardnum]; if (urole.guardnum != NON_PM) { pm_guardian.mflags2 |= (M2_PEACEFUL); pm_guardian.maligntyp = alignmnt * 3; } /* Fix up the quest nemesis */ pm_nemesis = mons[urole.neminum]; if (urole.neminum != NON_PM) { pm_nemesis.msound = MS_NEMESIS; pm_nemesis.mflags2 &= ~(M2_PEACEFUL); pm_nemesis.mflags2 |= (M2_NASTY|M2_STALK|M2_HOSTILE); pm_nemesis.mflags3 |= M3_WANTSARTI | M3_WAITFORU; } /* Fix up the god names */ if (flags.pantheon == -1) { /* new game */ flags.pantheon = u.initrole; /* use own gods */ while (!roles[flags.pantheon].lgod) /* unless they're missing */ flags.pantheon = randrole(); } if (!urole.lgod) { urole.lgod = roles[flags.pantheon].lgod; urole.ngod = roles[flags.pantheon].ngod; urole.cgod = roles[flags.pantheon].cgod; } /* Fix up initial roleplay flags */ if (Role_if(PM_MONK)) flags.vegetarian = TRUE; flags.vegan |= flags.ascet; flags.vegetarian |= flags.vegan; /* Artifacts are fixed in hack_artifacts() */ /* Success! */ return; }