MCPcopy Create free account
hub / github.com/NetHack/NetHack / pick_role

Function pick_role

src/role.c:1014–1033  ·  view source on GitHub ↗

pick a random role subject to any racenum/gendnum/alignnum constraints */ If pickhow == PICK_RIGID a role is returned only if there is */ a single possibility */

Source from the content-addressed store, hash-verified

1012/* If pickhow == PICK_RIGID a role is returned only if there is */
1013/* a single possibility */
1014int
1015pick_role(int racenum, int gendnum, int alignnum, int pickhow)
1016{
1017 int i;
1018 int roles_ok = 0, set[SIZE(roles)];
1019
1020 for (i = 0; i < SIZE(roles) - 1; i++) {
1021 if (ok_role(i, racenum, gendnum, alignnum)
1022 && ok_race(i, (racenum >= 0) ? racenum : ROLE_RANDOM,
1023 gendnum, alignnum)
1024 && ok_gend(i, racenum,
1025 (gendnum >= 0) ? gendnum : ROLE_RANDOM, alignnum)
1026 && ok_align(i, racenum,
1027 gendnum, (alignnum >= 0) ? alignnum : ROLE_RANDOM))
1028 set[roles_ok++] = i;
1029 }
1030 if (roles_ok == 0 || (roles_ok > 1 && pickhow == PICK_RIGID))
1031 return ROLE_NONE;
1032 return set[rn2(roles_ok)];
1033}
1034
1035/* is racenum compatible with any rolenum/gendnum/alignnum constraints? */
1036boolean

Callers 12

mswin_player_selectionFunction · 0.85
curses_choose_characterFunction · 0.85
winmisc.cFile · 0.85
amii_player_selectionFunction · 0.85
rigid_role_checksFunction · 0.85
genl_player_setupFunction · 0.85
gnome_player_selectionFunction · 0.85
Gem_player_selectionFunction · 0.85
plselFinalSelectionFunction · 0.85
mswin_player_selectionFunction · 0.85

Calls 5

ok_roleFunction · 0.85
ok_raceFunction · 0.85
ok_gendFunction · 0.85
ok_alignFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected