1 /* NetHack 3.6 role.c $NHDT-Date: 1456907852 2016/03/02 08:37:32 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.37 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985-1999. */
3 /* NetHack may be freely redistributed. See license for details. */
7 /*** Table of all roles ***/
8 /* According to AD&D, HD for some classes (ex. Wizard) should be smaller
9 * (4-sided for wizards). But this is not AD&D, and using the AD&D
10 * rule here produces an unplayable character. Thus I have used a minimum
11 * of an 10-sided hit die for everything. Another AD&D change: wizards get
12 * a minimum strength of 4 since without one you can't teleport or cast
15 * As the wizard has been updated (wizard patch 5 jun '96) their HD can be
16 * brought closer into line with AD&D. This forces wizards to use magic more
17 * and distance themselves from their attackers. --LSZ
19 * With the introduction of races, some hit points and energy
20 * has been reallocated for each race. The values assigned
21 * to the roles has been reduced by the amount allocated to
24 * God names use a leading underscore to flag goddesses.
26 const struct Role roles
[] = {
27 { { "Archeologist", 0 },
29 { "Field Worker", 0 },
30 { "Investigator", 0 },
34 { "Speleologist", 0 },
37 "Quetzalcoatl", "Camaxtli", "Huhetotl", /* Central American */
39 "the College of Archeology",
40 "the Tomb of the Toltec Kings",
46 PM_MINION_OF_HUHETOTL
,
52 MH_HUMAN
| MH_DWARF
| MH_GNOME
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
54 /* Str Int Wis Dex Con Cha */
55 { 7, 10, 10, 7, 7, 7 },
56 { 20, 20, 20, 10, 20, 10 },
57 /* Init Lower Higher */
58 { 11, 0, 0, 8, 1, 0 }, /* Hit points */
70 { { "Plunderer", "Plunderess" },
77 { "Chieftain", "Chieftainess" },
78 { "Conqueror", "Conqueress" } },
79 "Mitra", "Crom", "Set", /* Hyborian */
81 "the Camp of the Duali Tribe",
94 MH_HUMAN
| MH_ORC
| ROLE_MALE
| ROLE_FEMALE
| ROLE_NEUTRAL
96 /* Str Int Wis Dex Con Cha */
97 { 16, 7, 7, 15, 16, 6 },
98 { 30, 6, 7, 20, 30, 7 },
99 /* Init Lower Higher */
100 { 14, 0, 0, 10, 2, 0 }, /* Hit points */
101 { 1, 0, 0, 1, 0, 1 },
111 { { "Caveman", "Cavewoman" },
112 { { "Troglodyte", 0 },
121 "Anu", "_Ishtar", "Anshar", /* Babylonian */
123 "the Caves of the Ancestors",
135 ART_SCEPTRE_OF_MIGHT
,
136 MH_HUMAN
| MH_DWARF
| MH_GNOME
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
138 /* Str Int Wis Dex Con Cha */
139 { 10, 7, 7, 7, 8, 6 },
140 { 30, 6, 7, 20, 30, 7 },
141 /* Init Lower Higher */
142 { 14, 0, 0, 8, 2, 0 }, /* Hit points */
143 { 1, 0, 0, 1, 0, 1 },
154 { { "Rhizotomist", 0 },
158 { "Medicus ossium", "Medica ossium" },
160 { "Magister", "Magistra" },
162 { "Chirurgeon", 0 } },
163 "_Athena", "Hermes", "Poseidon", /* Greek */
165 "the Temple of Epidaurus",
166 "the Temple of Coeus",
177 ART_STAFF_OF_AESCULAPIUS
,
178 MH_HUMAN
| MH_GNOME
| ROLE_MALE
| ROLE_FEMALE
| ROLE_NEUTRAL
,
179 /* Str Int Wis Dex Con Cha */
180 { 7, 7, 13, 7, 11, 16 },
181 { 15, 20, 20, 15, 25, 5 },
182 /* Init Lower Higher */
183 { 11, 0, 0, 8, 1, 0 }, /* Hit points */
184 { 1, 4, 0, 1, 0, 2 },
201 { "Chevalier", "Chevaliere" },
202 { "Seignieur", "Dame" },
204 "Lugh", "_Brigit", "Manannan Mac Lir", /* Celtic */
218 ART_MAGIC_MIRROR_OF_MERLIN
,
219 MH_HUMAN
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
,
220 /* Str Int Wis Dex Con Cha */
221 { 13, 7, 14, 8, 10, 17 },
222 { 30, 15, 15, 10, 20, 10 },
223 /* Init Lower Higher */
224 { 14, 0, 0, 8, 2, 0 }, /* Hit points */
225 { 1, 4, 0, 1, 0, 2 },
236 { { "Candidate", 0 },
239 { "Student of Stones", 0 },
240 { "Student of Waters", 0 },
241 { "Student of Metals", 0 },
242 { "Student of Winds", 0 },
243 { "Student of Fire", 0 },
245 "Shan Lai Ching", "Chih Sung-tzu", "Huan Ti", /* Chinese */
247 "the Monastery of Chan-Sune",
248 "the Monastery of the Earth-Lord",
259 ART_EYES_OF_THE_OVERWORLD
,
260 MH_HUMAN
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
| ROLE_NEUTRAL
262 /* Str Int Wis Dex Con Cha */
263 { 10, 7, 8, 8, 7, 7 },
264 { 25, 10, 20, 20, 15, 10 },
265 /* Init Lower Higher */
266 { 12, 0, 0, 8, 1, 0 }, /* Hit points */
267 { 2, 2, 0, 2, 0, 2 },
277 { { "Priest", "Priestess" },
281 { "Priest", "Priestess" },
283 { "Canon", "Canoness" },
285 { "Patriarch", "Matriarch" },
286 { "High Priest", "High Priestess" } },
287 0, 0, 0, /* deities from a randomly chosen other role will be used */
290 "the Temple of Nalzok",
301 ART_MITRE_OF_HOLINESS
,
302 MH_HUMAN
| MH_ELF
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
| ROLE_NEUTRAL
304 /* Str Int Wis Dex Con Cha */
305 { 7, 7, 10, 7, 7, 7 },
306 { 15, 10, 30, 15, 20, 10 },
307 /* Init Lower Higher */
308 { 12, 0, 0, 8, 1, 0 }, /* Hit points */
309 { 4, 3, 0, 2, 0, 2 },
319 /* Note: Rogue precedes Ranger so that use of `-R' on the command line
320 retains its traditional meaning. */
329 { "Magsman", "Magswoman" },
331 "Issek", "Mog", "Kos", /* Nehwon */
333 "the Thieves' Guild Hall",
334 "the Assassins' Guild Hall",
338 PM_MASTER_OF_THIEVES
,
345 ART_MASTER_KEY_OF_THIEVERY
,
346 MH_HUMAN
| MH_ORC
| ROLE_MALE
| ROLE_FEMALE
| ROLE_CHAOTIC
,
347 /* Str Int Wis Dex Con Cha */
348 { 7, 7, 7, 10, 7, 6 },
349 { 20, 10, 10, 30, 20, 10 },
350 /* Init Lower Higher */
351 { 10, 0, 0, 8, 1, 0 }, /* Hit points */
352 { 1, 0, 0, 1, 0, 1 },
366 {"Edhel", "Elleth"}, /* elf-maid */
367 {"Ohtar", "Ohtie"}, /* warrior */
368 {"Kano", "Kanie"}, /* commander (Q.) ['a] educated guess,
369 until further research- SAC */
370 {"Arandur"," Aranduriel"}, /* king's servant, minister (Q.) - guess */
371 {"Hir", "Hiril"}, /* lord, lady (S.) ['ir] */
372 {"Aredhel", "Arwen"}, /* noble elf, maiden (S.) */
373 {"Ernil", "Elentariel"}, /* prince (S.), elf-maiden (Q.) */
374 {"Elentar", "Elentari"}, /* Star-king, -queen (Q.) */
375 "Solonor Thelandira", "Aerdrie Faenya", "Lolth", /* Elven */
379 { "Trailblazer", 0 },
380 { "Reconnoiterer", "Reconnoiteress" },
382 { "Arbalester", 0 }, /* One skilled at crossbows */
384 { "Sharpshooter", 0 },
385 { "Marksman", "Markswoman" } },
386 "Mercury", "_Venus", "Mars", /* Roman/planets */
389 "the cave of the wumpus",
392 PM_LITTLE_DOG
/* Orion & canis major */,
400 ART_LONGBOW_OF_DIANA
,
401 MH_HUMAN
| MH_ELF
| MH_GNOME
| MH_ORC
| ROLE_MALE
| ROLE_FEMALE
402 | ROLE_NEUTRAL
| ROLE_CHAOTIC
,
403 /* Str Int Wis Dex Con Cha */
404 { 13, 13, 13, 9, 13, 7 },
405 { 30, 10, 10, 20, 20, 10 },
406 /* Init Lower Higher */
407 { 13, 0, 0, 6, 1, 0 }, /* Hit points */
408 { 1, 0, 0, 1, 0, 1 },
419 { { "Hatamoto", 0 }, /* Banner Knight */
420 { "Ronin", 0 }, /* no allegiance */
421 { "Ninja", "Kunoichi" }, /* secret society */
422 { "Joshu", 0 }, /* heads a castle */
423 { "Ryoshu", 0 }, /* has a territory */
424 { "Kokushu", 0 }, /* heads a province */
425 { "Daimyo", 0 }, /* a samurai lord */
426 { "Kuge", 0 }, /* Noble of the Court */
427 { "Shogun", 0 } }, /* supreme commander, warlord */
428 "_Amaterasu Omikami", "Raijin", "Susanowo", /* Japanese */
430 "the Castle of the Taro Clan",
431 "the Shogun's Castle",
442 ART_TSURUGI_OF_MURAMASA
,
443 MH_HUMAN
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
,
444 /* Str Int Wis Dex Con Cha */
445 { 10, 8, 7, 10, 17, 6 },
446 { 30, 10, 8, 30, 14, 8 },
447 /* Init Lower Higher */
448 { 13, 0, 0, 8, 1, 0 }, /* Hit points */
449 { 1, 0, 0, 1, 0, 1 },
462 { "Excursionist", 0 },
463 { "Peregrinator", "Peregrinatrix" },
468 { "Adventurer", 0 } },
469 "Blind Io", "_The Lady", "Offler", /* Discworld */
472 "the Thieves' Guild Hall",
478 PM_MASTER_OF_THIEVES
,
483 ART_YENDORIAN_EXPRESS_CARD
,
484 MH_HUMAN
| ROLE_MALE
| ROLE_FEMALE
| ROLE_NEUTRAL
,
485 /* Str Int Wis Dex Con Cha */
486 { 7, 10, 6, 7, 7, 10 },
487 { 15, 10, 10, 15, 30, 20 },
488 /* Init Lower Higher */
489 { 8, 0, 0, 8, 0, 0 }, /* Hit points */
490 { 1, 0, 0, 1, 0, 1 },
501 { { "Stripling", 0 },
504 { "Man-at-arms", "Woman-at-arms" },
506 { "Swashbuckler", 0 },
507 { "Hero", "Heroine" },
509 { "Lord", "Lady" } },
510 "Tyr", "Odin", "Loki", /* Norse */
512 "the Shrine of Destiny",
513 "the cave of Surtur",
516 NON_PM
/*PM_WINTER_WOLF_CUB*/,
525 MH_HUMAN
| MH_DWARF
| ROLE_FEMALE
| ROLE_LAWFUL
| ROLE_NEUTRAL
,
526 /* Str Int Wis Dex Con Cha */
527 { 10, 7, 7, 7, 10, 7 },
528 { 30, 6, 7, 20, 30, 7 },
529 /* Init Lower Higher */
530 { 14, 0, 0, 8, 2, 0 }, /* Hit points */
531 { 1, 0, 0, 1, 0, 1 },
544 { "Thaumaturge", 0 },
546 { "Enchanter", "Enchantress" },
547 { "Sorcerer", "Sorceress" },
548 { "Necromancer", 0 },
551 "Ptah", "Thoth", "Anhur", /* Egyptian */
554 "the Tower of Darkness",
558 PM_NEFERET_THE_GREEN
,
565 ART_EYE_OF_THE_AETHIOPICA
,
566 MH_HUMAN
| MH_ELF
| MH_GNOME
| MH_ORC
| ROLE_MALE
| ROLE_FEMALE
567 | ROLE_NEUTRAL
| ROLE_CHAOTIC
,
568 /* Str Int Wis Dex Con Cha */
569 { 7, 10, 7, 7, 7, 7 },
570 { 10, 30, 10, 20, 20, 10 },
571 /* Init Lower Higher */
572 { 10, 0, 0, 8, 1, 0 }, /* Hit points */
573 { 4, 3, 0, 2, 0, 3 },
583 /* Array terminator */
587 /* The player's role, created at runtime from initial
588 * choices. This may be munged in role_init().
590 struct Role urole
= {
592 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
593 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
595 "Xxx", "home", "locate",
596 NON_PM
, NON_PM
, NON_PM
, NON_PM
, NON_PM
, NON_PM
, NON_PM
, NON_PM
,
598 /* Str Int Wis Dex Con Cha */
599 { 7, 7, 7, 7, 7, 7 },
600 { 20, 15, 15, 20, 20, 10 },
601 /* Init Lower Higher */
602 { 10, 0, 0, 8, 1, 0 }, /* Hit points */
603 { 2, 0, 0, 2, 0, 3 },
615 /* Table of all races */
616 const struct Race races
[] = {
627 MH_HUMAN
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
| ROLE_NEUTRAL
632 /* Str Int Wis Dex Con Cha */
633 { 3, 3, 3, 3, 3, 3 },
634 { STR18(100), 18, 18, 18, 18, 18 },
635 /* Init Lower Higher */
636 { 2, 0, 0, 2, 1, 0 }, /* Hit points */
637 { 1, 0, 2, 0, 2, 0 } /* Energy */
649 MH_ELF
| ROLE_MALE
| ROLE_FEMALE
| ROLE_CHAOTIC
,
653 /* Str Int Wis Dex Con Cha */
654 { 3, 3, 3, 3, 3, 3 },
655 { 18, 20, 20, 18, 16, 18 },
656 /* Init Lower Higher */
657 { 1, 0, 0, 1, 1, 0 }, /* Hit points */
658 { 2, 0, 3, 0, 3, 0 } /* Energy */
670 MH_DWARF
| ROLE_MALE
| ROLE_FEMALE
| ROLE_LAWFUL
,
674 /* Str Int Wis Dex Con Cha */
675 { 3, 3, 3, 3, 3, 3 },
676 { STR18(100), 16, 16, 20, 20, 16 },
677 /* Init Lower Higher */
678 { 4, 0, 0, 3, 2, 0 }, /* Hit points */
679 { 0, 0, 0, 0, 0, 0 } /* Energy */
691 MH_GNOME
| ROLE_MALE
| ROLE_FEMALE
| ROLE_NEUTRAL
,
695 /* Str Int Wis Dex Con Cha */
696 { 3, 3, 3, 3, 3, 3 },
697 { STR18(50), 19, 18, 18, 18, 18 },
698 /* Init Lower Higher */
699 { 1, 0, 0, 1, 0, 0 }, /* Hit points */
700 { 2, 0, 2, 0, 2, 0 } /* Energy */
712 MH_ORC
| ROLE_MALE
| ROLE_FEMALE
| ROLE_CHAOTIC
,
715 MH_HUMAN
| MH_ELF
| MH_DWARF
,
716 /* Str Int Wis Dex Con Cha */
717 { 3, 3, 3, 3, 3, 3 },
718 { STR18(50), 16, 16, 18, 18, 16 },
719 /* Init Lower Higher */
720 { 1, 0, 0, 1, 0, 0 }, /* Hit points */
721 { 1, 0, 1, 0, 1, 0 } /* Energy */
723 /* Array terminator */
727 /* The player's race, created at runtime from initial
728 * choices. This may be munged in role_init().
730 struct Race urace
= {
744 /* Str Int Wis Dex Con Cha */
745 { 3, 3, 3, 3, 3, 3 },
746 { STR18(100), 18, 18, 18, 18, 18 },
747 /* Init Lower Higher */
748 { 2, 0, 0, 2, 1, 0 }, /* Hit points */
749 { 1, 0, 2, 0, 2, 0 } /* Energy */
752 /* Table of all genders */
753 const struct Gender genders
[] = {
754 { "male", "he", "him", "his", "Mal", ROLE_MALE
},
755 { "female", "she", "her", "her", "Fem", ROLE_FEMALE
},
756 { "neuter", "it", "it", "its", "Ntr", ROLE_NEUTER
}
759 /* Table of all alignments */
760 const struct Align aligns
[] = {
761 { "law", "lawful", "Law", ROLE_LAWFUL
, A_LAWFUL
},
762 { "balance", "neutral", "Neu", ROLE_NEUTRAL
, A_NEUTRAL
},
763 { "chaos", "chaotic", "Cha", ROLE_CHAOTIC
, A_CHAOTIC
},
764 { "evil", "unaligned", "Una", 0, A_NONE
}
769 boolean roles
[SIZE(roles
)];
773 STATIC_DCL
int NDECL(randrole_filtered
);
774 STATIC_DCL
char *FDECL(promptsep
, (char *, int));
775 STATIC_DCL
int FDECL(role_gendercount
, (int));
776 STATIC_DCL
int FDECL(race_alignmentcount
, (int));
778 /* used by str2XXX() */
779 static char NEARDATA randomstr
[] = "random";
785 return (boolean
) (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1);
791 return rn2(SIZE(roles
) - 1);
797 int i
, n
= 0, set
[SIZE(roles
)];
799 /* this doesn't rule out impossible combinations but attempts to
800 honor all the filter masks */
801 for (i
= 0; i
< SIZE(roles
); ++i
)
802 if (ok_role(i
, ROLE_NONE
, ROLE_NONE
, ROLE_NONE
)
803 && ok_race(i
, ROLE_RANDOM
, ROLE_NONE
, ROLE_NONE
)
804 && ok_gend(i
, ROLE_NONE
, ROLE_RANDOM
, ROLE_NONE
)
805 && ok_align(i
, ROLE_NONE
, ROLE_NONE
, ROLE_RANDOM
))
807 return n
? set
[rn2(n
)] : randrole();
820 /* Match as much of str as is provided */
822 for (i
= 0; roles
[i
].name
.m
; i
++) {
823 /* Does it match the male name? */
824 if (!strncmpi(str
, roles
[i
].name
.m
, len
))
826 /* Or the female name? */
827 if (roles
[i
].name
.f
&& !strncmpi(str
, roles
[i
].name
.f
, len
))
829 /* Or the filecode? */
830 if (!strcmpi(str
, roles
[i
].filecode
))
834 if ((len
== 1 && (*str
== '*' || *str
== '@'))
835 || !strncmpi(str
, randomstr
, len
))
838 /* Couldn't find anything appropriate */
843 validrace(rolenum
, racenum
)
844 int rolenum
, racenum
;
846 /* Assumes validrole */
847 return (boolean
) (racenum
>= 0 && racenum
< SIZE(races
) - 1
848 && (roles
[rolenum
].allow
& races
[racenum
].allow
858 /* Count the number of valid races */
859 for (i
= 0; races
[i
].noun
; i
++)
860 if (roles
[rolenum
].allow
& races
[i
].allow
& ROLE_RACEMASK
)
863 /* Pick a random race */
864 /* Use a factor of 100 in case of bad random number generators */
866 n
= rn2(n
* 100) / 100;
867 for (i
= 0; races
[i
].noun
; i
++)
868 if (roles
[rolenum
].allow
& races
[i
].allow
& ROLE_RACEMASK
) {
875 /* This role has no permitted races? */
876 return rn2(SIZE(races
) - 1);
889 /* Match as much of str as is provided */
891 for (i
= 0; races
[i
].noun
; i
++) {
892 /* Does it match the noun? */
893 if (!strncmpi(str
, races
[i
].noun
, len
))
895 /* Or the filecode? */
896 if (!strcmpi(str
, races
[i
].filecode
))
900 if ((len
== 1 && (*str
== '*' || *str
== '@'))
901 || !strncmpi(str
, randomstr
, len
))
904 /* Couldn't find anything appropriate */
909 validgend(rolenum
, racenum
, gendnum
)
910 int rolenum
, racenum
, gendnum
;
912 /* Assumes validrole and validrace */
913 return (boolean
) (gendnum
>= 0 && gendnum
< ROLE_GENDERS
914 && (roles
[rolenum
].allow
& races
[racenum
].allow
915 & genders
[gendnum
].allow
& ROLE_GENDMASK
));
919 randgend(rolenum
, racenum
)
920 int rolenum
, racenum
;
924 /* Count the number of valid genders */
925 for (i
= 0; i
< ROLE_GENDERS
; i
++)
926 if (roles
[rolenum
].allow
& races
[racenum
].allow
& genders
[i
].allow
930 /* Pick a random gender */
933 for (i
= 0; i
< ROLE_GENDERS
; i
++)
934 if (roles
[rolenum
].allow
& races
[racenum
].allow
& genders
[i
].allow
942 /* This role/race has no permitted genders? */
943 return rn2(ROLE_GENDERS
);
956 /* Match as much of str as is provided */
958 for (i
= 0; i
< ROLE_GENDERS
; i
++) {
959 /* Does it match the adjective? */
960 if (!strncmpi(str
, genders
[i
].adj
, len
))
962 /* Or the filecode? */
963 if (!strcmpi(str
, genders
[i
].filecode
))
966 if ((len
== 1 && (*str
== '*' || *str
== '@'))
967 || !strncmpi(str
, randomstr
, len
))
970 /* Couldn't find anything appropriate */
975 validalign(rolenum
, racenum
, alignnum
)
976 int rolenum
, racenum
, alignnum
;
978 /* Assumes validrole and validrace */
979 return (boolean
) (alignnum
>= 0 && alignnum
< ROLE_ALIGNS
980 && (roles
[rolenum
].allow
& races
[racenum
].allow
981 & aligns
[alignnum
].allow
& ROLE_ALIGNMASK
));
985 randalign(rolenum
, racenum
)
986 int rolenum
, racenum
;
990 /* Count the number of valid alignments */
991 for (i
= 0; i
< ROLE_ALIGNS
; i
++)
992 if (roles
[rolenum
].allow
& races
[racenum
].allow
& aligns
[i
].allow
996 /* Pick a random alignment */
999 for (i
= 0; i
< ROLE_ALIGNS
; i
++)
1000 if (roles
[rolenum
].allow
& races
[racenum
].allow
& aligns
[i
].allow
1008 /* This role/race has no permitted alignments? */
1009 return rn2(ROLE_ALIGNS
);
1019 if (!str
|| !str
[0])
1022 /* Match as much of str as is provided */
1024 for (i
= 0; i
< ROLE_ALIGNS
; i
++) {
1025 /* Does it match the adjective? */
1026 if (!strncmpi(str
, aligns
[i
].adj
, len
))
1028 /* Or the filecode? */
1029 if (!strcmpi(str
, aligns
[i
].filecode
))
1032 if ((len
== 1 && (*str
== '*' || *str
== '@'))
1033 || !strncmpi(str
, randomstr
, len
))
1036 /* Couldn't find anything appropriate */
1040 /* is rolenum compatible with any racenum/gendnum/alignnum constraints? */
1042 ok_role(rolenum
, racenum
, gendnum
, alignnum
)
1043 int rolenum
, racenum
, gendnum
, alignnum
;
1048 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1) {
1049 if (rfilter
.roles
[rolenum
])
1051 allow
= roles
[rolenum
].allow
;
1052 if (racenum
>= 0 && racenum
< SIZE(races
) - 1
1053 && !(allow
& races
[racenum
].allow
& ROLE_RACEMASK
))
1055 if (gendnum
>= 0 && gendnum
< ROLE_GENDERS
1056 && !(allow
& genders
[gendnum
].allow
& ROLE_GENDMASK
))
1058 if (alignnum
>= 0 && alignnum
< ROLE_ALIGNS
1059 && !(allow
& aligns
[alignnum
].allow
& ROLE_ALIGNMASK
))
1063 /* random; check whether any selection is possible */
1064 for (i
= 0; i
< SIZE(roles
) - 1; i
++) {
1065 if (rfilter
.roles
[i
])
1067 allow
= roles
[i
].allow
;
1068 if (racenum
>= 0 && racenum
< SIZE(races
) - 1
1069 && !(allow
& races
[racenum
].allow
& ROLE_RACEMASK
))
1071 if (gendnum
>= 0 && gendnum
< ROLE_GENDERS
1072 && !(allow
& genders
[gendnum
].allow
& ROLE_GENDMASK
))
1074 if (alignnum
>= 0 && alignnum
< ROLE_ALIGNS
1075 && !(allow
& aligns
[alignnum
].allow
& ROLE_ALIGNMASK
))
1083 /* pick a random role subject to any racenum/gendnum/alignnum constraints */
1084 /* If pickhow == PICK_RIGID a role is returned only if there is */
1085 /* a single possibility */
1087 pick_role(racenum
, gendnum
, alignnum
, pickhow
)
1088 int racenum
, gendnum
, alignnum
, pickhow
;
1091 int roles_ok
= 0, set
[SIZE(roles
)];
1093 for (i
= 0; i
< SIZE(roles
) - 1; i
++) {
1094 if (ok_role(i
, racenum
, gendnum
, alignnum
)
1095 && ok_race(i
, (racenum
>= 0) ? racenum
: ROLE_RANDOM
,
1097 && ok_gend(i
, racenum
,
1098 (gendnum
>= 0) ? gendnum
: ROLE_RANDOM
, alignnum
)
1099 && ok_race(i
, racenum
,
1100 gendnum
, (alignnum
>= 0) ? alignnum
: ROLE_RANDOM
))
1101 set
[roles_ok
++] = i
;
1103 if (roles_ok
== 0 || (roles_ok
> 1 && pickhow
== PICK_RIGID
))
1105 return set
[rn2(roles_ok
)];
1108 /* is racenum compatible with any rolenum/gendnum/alignnum constraints? */
1110 ok_race(rolenum
, racenum
, gendnum
, alignnum
)
1111 int rolenum
, racenum
, gendnum
, alignnum
;
1116 if (racenum
>= 0 && racenum
< SIZE(races
) - 1) {
1117 if (rfilter
.mask
& races
[racenum
].selfmask
)
1119 allow
= races
[racenum
].allow
;
1120 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1
1121 && !(allow
& roles
[rolenum
].allow
& ROLE_RACEMASK
))
1123 if (gendnum
>= 0 && gendnum
< ROLE_GENDERS
1124 && !(allow
& genders
[gendnum
].allow
& ROLE_GENDMASK
))
1126 if (alignnum
>= 0 && alignnum
< ROLE_ALIGNS
1127 && !(allow
& aligns
[alignnum
].allow
& ROLE_ALIGNMASK
))
1131 /* random; check whether any selection is possible */
1132 for (i
= 0; i
< SIZE(races
) - 1; i
++) {
1133 if (rfilter
.mask
& races
[i
].selfmask
)
1135 allow
= races
[i
].allow
;
1136 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1
1137 && !(allow
& roles
[rolenum
].allow
& ROLE_RACEMASK
))
1139 if (gendnum
>= 0 && gendnum
< ROLE_GENDERS
1140 && !(allow
& genders
[gendnum
].allow
& ROLE_GENDMASK
))
1142 if (alignnum
>= 0 && alignnum
< ROLE_ALIGNS
1143 && !(allow
& aligns
[alignnum
].allow
& ROLE_ALIGNMASK
))
1151 /* pick a random race subject to any rolenum/gendnum/alignnum constraints */
1152 /* If pickhow == PICK_RIGID a race is returned only if there is */
1153 /* a single possibility */
1155 pick_race(rolenum
, gendnum
, alignnum
, pickhow
)
1156 int rolenum
, gendnum
, alignnum
, pickhow
;
1161 for (i
= 0; i
< SIZE(races
) - 1; i
++) {
1162 if (ok_race(rolenum
, i
, gendnum
, alignnum
))
1165 if (races_ok
== 0 || (races_ok
> 1 && pickhow
== PICK_RIGID
))
1167 races_ok
= rn2(races_ok
);
1168 for (i
= 0; i
< SIZE(races
) - 1; i
++) {
1169 if (ok_race(rolenum
, i
, gendnum
, alignnum
)) {
1179 /* is gendnum compatible with any rolenum/racenum/alignnum constraints? */
1180 /* gender and alignment are not comparable (and also not constrainable) */
1182 ok_gend(rolenum
, racenum
, gendnum
, alignnum
)
1183 int rolenum
, racenum
, gendnum
;
1184 int alignnum UNUSED
;
1189 if (gendnum
>= 0 && gendnum
< ROLE_GENDERS
) {
1190 if (rfilter
.mask
& genders
[gendnum
].allow
)
1192 allow
= genders
[gendnum
].allow
;
1193 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1
1194 && !(allow
& roles
[rolenum
].allow
& ROLE_GENDMASK
))
1196 if (racenum
>= 0 && racenum
< SIZE(races
) - 1
1197 && !(allow
& races
[racenum
].allow
& ROLE_GENDMASK
))
1201 /* random; check whether any selection is possible */
1202 for (i
= 0; i
< ROLE_GENDERS
; i
++) {
1203 if (rfilter
.mask
& genders
[i
].allow
)
1205 allow
= genders
[i
].allow
;
1206 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1
1207 && !(allow
& roles
[rolenum
].allow
& ROLE_GENDMASK
))
1209 if (racenum
>= 0 && racenum
< SIZE(races
) - 1
1210 && !(allow
& races
[racenum
].allow
& ROLE_GENDMASK
))
1218 /* pick a random gender subject to any rolenum/racenum/alignnum constraints */
1219 /* gender and alignment are not comparable (and also not constrainable) */
1220 /* If pickhow == PICK_RIGID a gender is returned only if there is */
1221 /* a single possibility */
1223 pick_gend(rolenum
, racenum
, alignnum
, pickhow
)
1224 int rolenum
, racenum
, alignnum
, pickhow
;
1229 for (i
= 0; i
< ROLE_GENDERS
; i
++) {
1230 if (ok_gend(rolenum
, racenum
, i
, alignnum
))
1233 if (gends_ok
== 0 || (gends_ok
> 1 && pickhow
== PICK_RIGID
))
1235 gends_ok
= rn2(gends_ok
);
1236 for (i
= 0; i
< ROLE_GENDERS
; i
++) {
1237 if (ok_gend(rolenum
, racenum
, i
, alignnum
)) {
1247 /* is alignnum compatible with any rolenum/racenum/gendnum constraints? */
1248 /* alignment and gender are not comparable (and also not constrainable) */
1250 ok_align(rolenum
, racenum
, gendnum
, alignnum
)
1251 int rolenum
, racenum
;
1258 if (alignnum
>= 0 && alignnum
< ROLE_ALIGNS
) {
1259 if (rfilter
.mask
& aligns
[alignnum
].allow
)
1261 allow
= aligns
[alignnum
].allow
;
1262 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1
1263 && !(allow
& roles
[rolenum
].allow
& ROLE_ALIGNMASK
))
1265 if (racenum
>= 0 && racenum
< SIZE(races
) - 1
1266 && !(allow
& races
[racenum
].allow
& ROLE_ALIGNMASK
))
1270 /* random; check whether any selection is possible */
1271 for (i
= 0; i
< ROLE_ALIGNS
; i
++) {
1272 if (rfilter
.mask
& aligns
[i
].allow
)
1274 allow
= aligns
[i
].allow
;
1275 if (rolenum
>= 0 && rolenum
< SIZE(roles
) - 1
1276 && !(allow
& roles
[rolenum
].allow
& ROLE_ALIGNMASK
))
1278 if (racenum
>= 0 && racenum
< SIZE(races
) - 1
1279 && !(allow
& races
[racenum
].allow
& ROLE_ALIGNMASK
))
1287 /* pick a random alignment subject to any rolenum/racenum/gendnum constraints
1289 /* alignment and gender are not comparable (and also not constrainable) */
1290 /* If pickhow == PICK_RIGID an alignment is returned only if there is */
1291 /* a single possibility */
1293 pick_align(rolenum
, racenum
, gendnum
, pickhow
)
1294 int rolenum
, racenum
, gendnum
, pickhow
;
1299 for (i
= 0; i
< ROLE_ALIGNS
; i
++) {
1300 if (ok_align(rolenum
, racenum
, gendnum
, i
))
1303 if (aligns_ok
== 0 || (aligns_ok
> 1 && pickhow
== PICK_RIGID
))
1305 aligns_ok
= rn2(aligns_ok
);
1306 for (i
= 0; i
< ROLE_ALIGNS
; i
++) {
1307 if (ok_align(rolenum
, racenum
, gendnum
, i
)) {
1320 /* Some roles are limited to a single race, alignment, or gender and
1321 * calling this routine prior to XXX_player_selection() will help
1322 * prevent an extraneous prompt that actually doesn't allow
1323 * you to choose anything further. Note the use of PICK_RIGID which
1324 * causes the pick_XX() routine to return a value only if there is one
1325 * single possible selection, otherwise it returns ROLE_NONE.
1328 if (flags
.initrole
== ROLE_RANDOM
) {
1329 /* If the role was explicitly specified as ROLE_RANDOM
1330 * via -uXXXX-@ then choose the role in here to narrow down
1331 * later choices. Pick a random role in this case.
1333 flags
.initrole
= pick_role(flags
.initrace
, flags
.initgend
,
1334 flags
.initalign
, PICK_RANDOM
);
1335 if (flags
.initrole
< 0)
1336 flags
.initrole
= randrole_filtered();
1338 if (flags
.initrole
!= ROLE_NONE
) {
1339 if (flags
.initrace
== ROLE_NONE
)
1340 flags
.initrace
= pick_race(flags
.initrole
, flags
.initgend
,
1341 flags
.initalign
, PICK_RIGID
);
1342 if (flags
.initalign
== ROLE_NONE
)
1343 flags
.initalign
= pick_align(flags
.initrole
, flags
.initrace
,
1344 flags
.initgend
, PICK_RIGID
);
1345 if (flags
.initgend
== ROLE_NONE
)
1346 flags
.initgend
= pick_gend(flags
.initrole
, flags
.initrace
,
1347 flags
.initalign
, PICK_RIGID
);
1356 boolean reslt
= TRUE
;
1358 if ((i
= str2role(bufp
)) != ROLE_NONE
&& i
!= ROLE_RANDOM
)
1359 rfilter
.roles
[i
] = TRUE
;
1360 else if ((i
= str2race(bufp
)) != ROLE_NONE
&& i
!= ROLE_RANDOM
)
1361 rfilter
.mask
|= races
[i
].selfmask
;
1362 else if ((i
= str2gend(bufp
)) != ROLE_NONE
&& i
!= ROLE_RANDOM
)
1363 rfilter
.mask
|= genders
[i
].allow
;
1364 else if ((i
= str2align(bufp
)) != ROLE_NONE
&& i
!= ROLE_RANDOM
)
1365 rfilter
.mask
|= aligns
[i
].allow
;
1378 for (i
= 0; i
< SIZE(roles
); ++i
)
1379 if (rfilter
.roles
[i
])
1389 for (i
= 0; i
< SIZE(roles
); ++i
)
1390 rfilter
.roles
[i
] = FALSE
;
1400 STATIC_VAR
char pa
[NUM_BP
], post_attribs
;
1403 promptsep(buf
, num_post_attribs
)
1405 int num_post_attribs
;
1407 const char *conjuct
= "and ";
1409 if (num_post_attribs
> 1 && post_attribs
< num_post_attribs
1410 && post_attribs
> 1)
1414 if (!post_attribs
&& num_post_attribs
> 1)
1415 Strcat(buf
, conjuct
);
1420 role_gendercount(rolenum
)
1425 if (validrole(rolenum
)) {
1426 if (roles
[rolenum
].allow
& ROLE_MALE
)
1428 if (roles
[rolenum
].allow
& ROLE_FEMALE
)
1430 if (roles
[rolenum
].allow
& ROLE_NEUTER
)
1437 race_alignmentcount(racenum
)
1442 if (racenum
!= ROLE_NONE
&& racenum
!= ROLE_RANDOM
) {
1443 if (races
[racenum
].allow
& ROLE_CHAOTIC
)
1445 if (races
[racenum
].allow
& ROLE_LAWFUL
)
1447 if (races
[racenum
].allow
& ROLE_NEUTRAL
)
1454 root_plselection_prompt(suppliedbuf
, buflen
, rolenum
, racenum
, gendnum
,
1457 int buflen
, rolenum
, racenum
, gendnum
, alignnum
;
1459 int k
, gendercount
= 0, aligncount
= 0;
1461 static char err_ret
[] = " character's";
1462 boolean donefirst
= FALSE
;
1464 if (!suppliedbuf
|| buflen
< 1)
1467 /* initialize these static variables each time this is called */
1469 for (k
= 0; k
< NUM_BP
; ++k
)
1472 *suppliedbuf
= '\0';
1474 /* How many alignments are allowed for the desired race? */
1475 if (racenum
!= ROLE_NONE
&& racenum
!= ROLE_RANDOM
)
1476 aligncount
= race_alignmentcount(racenum
);
1478 if (alignnum
!= ROLE_NONE
&& alignnum
!= ROLE_RANDOM
1479 && ok_align(rolenum
, racenum
, gendnum
, alignnum
)) {
1480 /* if race specified, and multiple choice of alignments for it */
1481 if ((racenum
>= 0) && (aligncount
> 1)) {
1484 Strcat(buf
, aligns
[alignnum
].adj
);
1489 Strcat(buf
, aligns
[alignnum
].adj
);
1493 /* in case we got here by failing the ok_align() test */
1494 if (alignnum
!= ROLE_RANDOM
)
1495 alignnum
= ROLE_NONE
;
1496 /* if alignment not specified, but race is specified
1497 and only one choice of alignment for that race then
1498 don't include it in the later list */
1499 if ((((racenum
!= ROLE_NONE
&& racenum
!= ROLE_RANDOM
)
1500 && ok_race(rolenum
, racenum
, gendnum
, alignnum
))
1501 && (aligncount
> 1))
1502 || (racenum
== ROLE_NONE
|| racenum
== ROLE_RANDOM
)) {
1509 /* How many genders are allowed for the desired role? */
1510 if (validrole(rolenum
))
1511 gendercount
= role_gendercount(rolenum
);
1513 if (gendnum
!= ROLE_NONE
&& gendnum
!= ROLE_RANDOM
) {
1514 if (validrole(rolenum
)) {
1515 /* if role specified, and multiple choice of genders for it,
1516 and name of role itself does not distinguish gender */
1517 if ((rolenum
!= ROLE_NONE
) && (gendercount
> 1)
1518 && !roles
[rolenum
].name
.f
) {
1521 Strcat(buf
, genders
[gendnum
].adj
);
1527 Strcat(buf
, genders
[gendnum
].adj
);
1531 /* if gender not specified, but role is specified
1532 and only one choice of gender then
1533 don't include it in the later list */
1534 if ((validrole(rolenum
) && (gendercount
> 1))
1535 || !validrole(rolenum
)) {
1540 /* <your lawful female> */
1542 if (racenum
!= ROLE_NONE
&& racenum
!= ROLE_RANDOM
) {
1543 if (validrole(rolenum
)
1544 && ok_race(rolenum
, racenum
, gendnum
, alignnum
)) {
1547 Strcat(buf
, (rolenum
== ROLE_NONE
) ? races
[racenum
].noun
1548 : races
[racenum
].adj
);
1550 } else if (!validrole(rolenum
)) {
1553 Strcat(buf
, races
[racenum
].noun
);
1563 /* <your lawful female gnomish> || <your lawful female gnome> */
1565 if (validrole(rolenum
)) {
1568 if (gendnum
!= ROLE_NONE
) {
1569 if (gendnum
== 1 && roles
[rolenum
].name
.f
)
1570 Strcat(buf
, roles
[rolenum
].name
.f
);
1572 Strcat(buf
, roles
[rolenum
].name
.m
);
1574 if (roles
[rolenum
].name
.f
) {
1575 Strcat(buf
, roles
[rolenum
].name
.m
);
1577 Strcat(buf
, roles
[rolenum
].name
.f
);
1579 Strcat(buf
, roles
[rolenum
].name
.m
);
1582 } else if (rolenum
== ROLE_NONE
) {
1587 if ((racenum
== ROLE_NONE
|| racenum
== ROLE_RANDOM
)
1588 && !validrole(rolenum
)) {
1591 Strcat(buf
, "character");
1594 /* <your lawful female gnomish cavewoman> || <your lawful female gnome>
1595 * || <your lawful female character>
1597 if (buflen
> (int) (strlen(buf
) + 1)) {
1598 Strcpy(suppliedbuf
, buf
);
1605 build_plselection_prompt(buf
, buflen
, rolenum
, racenum
, gendnum
, alignnum
)
1607 int buflen
, rolenum
, racenum
, gendnum
, alignnum
;
1609 const char *defprompt
= "Shall I pick a character for you? [ynaq] ";
1610 int num_post_attribs
= 0;
1611 char tmpbuf
[BUFSZ
], *p
;
1613 if (buflen
< QBUFSZ
)
1614 return (char *) defprompt
;
1616 Strcpy(tmpbuf
, "Shall I pick ");
1617 if (racenum
!= ROLE_NONE
|| validrole(rolenum
))
1618 Strcat(tmpbuf
, "your ");
1620 Strcat(tmpbuf
, "a ");
1624 (void) root_plselection_prompt(eos(tmpbuf
), buflen
- strlen(tmpbuf
),
1625 rolenum
, racenum
, gendnum
, alignnum
);
1626 Sprintf(buf
, "%s", s_suffix(tmpbuf
));
1627 /* don't bother splitting caveman/cavewoman or priest/priestess
1628 in order to apply possessive suffix to both halves, but do
1629 change "priest/priestess'" to "priest/priestess's" */
1630 if ((p
= strstri(buf
, "priest/priestess'")) != 0
1631 && p
[sizeof "priest/priestess'" - sizeof ""] == '\0')
1632 strkitten(buf
, 's');
1634 /* buf should now be:
1635 * <your lawful female gnomish cavewoman's>
1636 * || <your lawful female gnome's>
1637 * || <your lawful female character's>
1639 * Now append the post attributes to it
1641 num_post_attribs
= post_attribs
;
1644 (void) promptsep(eos(buf
), num_post_attribs
);
1645 Strcat(buf
, "race");
1648 (void) promptsep(eos(buf
), num_post_attribs
);
1649 Strcat(buf
, "role");
1652 (void) promptsep(eos(buf
), num_post_attribs
);
1653 Strcat(buf
, "gender");
1656 (void) promptsep(eos(buf
), num_post_attribs
);
1657 Strcat(buf
, "alignment");
1660 Strcat(buf
, " for you? [ynaq] ");
1676 #ifdef GENERIC_USERNAMES
1678 /* some generic user names will be ignored in favor of prompting */
1679 const char *uptr
= GENERIC_USERNAMES
;
1681 i
= (int) strlen(plname
);
1682 if ((sptr
= strstri(uptr
, plname
)) != 0
1683 && (sptr
== uptr
|| sptr
[-1] == ' ')
1684 && (sptr
[i
] == ' ' || sptr
[i
] == '\0'))
1685 *plname
= '\0'; /* call askname() */
1691 askname(); /* fill plname[] if necessary */
1693 /* Look for tokens delimited by '-' */
1694 if ((eptr
= index(plname
, '-')) != (char *) 0)
1697 /* Isolate the next token */
1699 if ((eptr
= index(sptr
, '-')) != (char *) 0)
1702 /* Try to match it to something */
1703 if ((i
= str2role(sptr
)) != ROLE_NONE
)
1705 else if ((i
= str2race(sptr
)) != ROLE_NONE
)
1707 else if ((i
= str2gend(sptr
)) != ROLE_NONE
)
1709 else if ((i
= str2align(sptr
)) != ROLE_NONE
)
1710 flags
.initalign
= i
;
1714 /* commas in the plname confuse the record file, convert to spaces */
1715 for (sptr
= plname
; *sptr
; sptr
++) {
1721 /* show current settings for name, role, race, gender, and alignment
1722 in the specified window */
1724 role_selection_prolog(which
, where
)
1728 static const char NEARDATA choosing
[] = " choosing now",
1729 not_yet
[] = " not yet specified",
1730 rand_choice
[] = " random";
1732 int r
, c
, g
, a
, allowmask
;
1737 a
= flags
.initalign
;
1739 allowmask
= roles
[r
].allow
;
1740 if ((allowmask
& ROLE_RACEMASK
) == MH_HUMAN
)
1741 c
= 0; /* races[human] */
1742 else if (c
>= 0 && !(allowmask
& ROLE_RACEMASK
& races
[c
].allow
))
1744 if ((allowmask
& ROLE_GENDMASK
) == ROLE_MALE
)
1745 g
= 0; /* role forces male (hypothetical) */
1746 else if ((allowmask
& ROLE_GENDMASK
) == ROLE_FEMALE
)
1747 g
= 1; /* role forces female (valkyrie) */
1748 if ((allowmask
& ROLE_ALIGNMASK
) == AM_LAWFUL
)
1749 a
= 0; /* aligns[lawful] */
1750 else if ((allowmask
& ROLE_ALIGNMASK
) == AM_NEUTRAL
)
1751 a
= 1; /* aligns[neutral] */
1752 else if ((allowmask
& ROLE_ALIGNMASK
) == AM_CHAOTIC
)
1753 a
= 2; /* alings[chaotic] */
1756 allowmask
= races
[c
].allow
;
1757 if ((allowmask
& ROLE_ALIGNMASK
) == AM_LAWFUL
)
1758 a
= 0; /* aligns[lawful] */
1759 else if ((allowmask
& ROLE_ALIGNMASK
) == AM_NEUTRAL
)
1760 a
= 1; /* aligns[neutral] */
1761 else if ((allowmask
& ROLE_ALIGNMASK
) == AM_CHAOTIC
)
1762 a
= 2; /* alings[chaotic] */
1763 /* [c never forces gender] */
1765 /* [g and a don't constrain anything sufficiently
1766 to narrow something done to a single choice] */
1768 Sprintf(buf
, "%12s ", "name:");
1769 Strcat(buf
, (which
== RS_NAME
) ? choosing
: !*plname
? not_yet
: plname
);
1770 putstr(where
, 0, buf
);
1771 Sprintf(buf
, "%12s ", "role:");
1772 Strcat(buf
, (which
== RS_ROLE
) ? choosing
: (r
== ROLE_NONE
)
1774 : (r
== ROLE_RANDOM
)
1777 if (r
>= 0 && roles
[r
].name
.f
) {
1778 /* distinct female name [caveman/cavewoman, priest/priestess] */
1780 /* female specified; replace male role name with female one */
1781 Sprintf(index(buf
, ':'), ": %s", roles
[r
].name
.f
);
1783 /* gender unspecified; append slash and female role name */
1784 Sprintf(eos(buf
), "/%s", roles
[r
].name
.f
);
1786 putstr(where
, 0, buf
);
1787 Sprintf(buf
, "%12s ", "race:");
1788 Strcat(buf
, (which
== RS_RACE
) ? choosing
: (c
== ROLE_NONE
)
1790 : (c
== ROLE_RANDOM
)
1793 putstr(where
, 0, buf
);
1794 Sprintf(buf
, "%12s ", "gender:");
1795 Strcat(buf
, (which
== RS_GENDER
) ? choosing
: (g
== ROLE_NONE
)
1797 : (g
== ROLE_RANDOM
)
1800 putstr(where
, 0, buf
);
1801 Sprintf(buf
, "%12s ", "alignment:");
1802 Strcat(buf
, (which
== RS_ALGNMNT
) ? choosing
: (a
== ROLE_NONE
)
1804 : (a
== ROLE_RANDOM
)
1807 putstr(where
, 0, buf
);
1810 /* add a "pick alignment first"-type entry to the specified menu */
1812 role_menu_extra(which
, where
, preselect
)
1817 static NEARDATA
const char RS_menu_let
[] = {
1822 '[', /* alignment */
1826 const char *what
= 0, *constrainer
= 0, *forcedvalue
= 0;
1827 int f
= 0, r
, c
, g
, a
, i
, allowmask
;
1838 for (i
= 0; i
< SIZE(roles
); ++i
)
1839 if (i
!= f
&& !rfilter
.roles
[i
])
1841 if (i
== SIZE(roles
)) {
1842 constrainer
= "filter";
1843 forcedvalue
= "role";
1849 c
= ROLE_NONE
; /* override player's setting */
1851 allowmask
= roles
[r
].allow
& ROLE_RACEMASK
;
1852 if (allowmask
== MH_HUMAN
)
1853 c
= 0; /* races[human] */
1855 constrainer
= "role";
1856 forcedvalue
= races
[c
].noun
;
1858 && (allowmask
& ~rfilter
.mask
) == races
[f
].selfmask
) {
1859 /* if there is only one race choice available due to user
1860 options disallowing others, race menu entry is disabled */
1861 constrainer
= "filter";
1862 forcedvalue
= "race";
1871 allowmask
= roles
[r
].allow
& ROLE_GENDMASK
;
1872 if (allowmask
== ROLE_MALE
)
1873 g
= 0; /* genders[male] */
1874 else if (allowmask
== ROLE_FEMALE
)
1875 g
= 1; /* genders[female] */
1877 constrainer
= "role";
1878 forcedvalue
= genders
[g
].adj
;
1880 && (allowmask
& ~rfilter
.mask
) == genders
[f
].allow
) {
1881 /* if there is only one gender choice available due to user
1882 options disallowing other, gender menu entry is disabled */
1883 constrainer
= "filter";
1884 forcedvalue
= "gender";
1890 f
= flags
.initalign
;
1893 allowmask
= roles
[r
].allow
& ROLE_ALIGNMASK
;
1894 if (allowmask
== AM_LAWFUL
)
1895 a
= 0; /* aligns[lawful] */
1896 else if (allowmask
== AM_NEUTRAL
)
1897 a
= 1; /* aligns[neutral] */
1898 else if (allowmask
== AM_CHAOTIC
)
1899 a
= 2; /* aligns[chaotic] */
1901 constrainer
= "role";
1903 if (c
>= 0 && !constrainer
) {
1904 allowmask
= races
[c
].allow
& ROLE_ALIGNMASK
;
1905 if (allowmask
== AM_LAWFUL
)
1906 a
= 0; /* aligns[lawful] */
1907 else if (allowmask
== AM_NEUTRAL
)
1908 a
= 1; /* aligns[neutral] */
1909 else if (allowmask
== AM_CHAOTIC
)
1910 a
= 2; /* aligns[chaotic] */
1912 constrainer
= "race";
1914 if (f
>= 0 && !constrainer
1915 && (ROLE_ALIGNMASK
& ~rfilter
.mask
) == aligns
[f
].allow
) {
1916 /* if there is only one alignment choice available due to user
1917 options disallowing others, algn menu entry is disabled */
1918 constrainer
= "filter";
1919 forcedvalue
= "alignment";
1922 forcedvalue
= aligns
[a
].adj
;
1926 any
= zeroany
; /* zero out all bits */
1929 /* use four spaces of padding to fake a grayed out menu choice */
1930 Sprintf(buf
, "%4s%s forces %s", "", constrainer
, forcedvalue
);
1931 add_menu(where
, NO_GLYPH
, &any
, 0, 0, ATR_NONE
, buf
,
1934 any
.a_int
= RS_menu_arg(which
);
1935 Sprintf(buf
, "Pick%s %s first", (f
>= 0) ? " another" : "", what
);
1936 add_menu(where
, NO_GLYPH
, &any
, RS_menu_let
[which
], 0, ATR_NONE
, buf
,
1938 } else if (which
== RS_filter
) {
1939 any
.a_int
= RS_menu_arg(RS_filter
);
1940 add_menu(where
, NO_GLYPH
, &any
, '~', 0, ATR_NONE
,
1941 "Reset role/race/&c filtering", MENU_UNSELECTED
);
1942 } else if (which
== ROLE_RANDOM
) {
1943 any
.a_int
= ROLE_RANDOM
;
1944 add_menu(where
, NO_GLYPH
, &any
, '*', 0, ATR_NONE
, "Random",
1945 preselect
? MENU_SELECTED
: MENU_UNSELECTED
);
1946 } else if (which
== ROLE_NONE
) {
1947 any
.a_int
= ROLE_NONE
;
1948 add_menu(where
, NO_GLYPH
, &any
, 'q', 0, ATR_NONE
, "Quit",
1949 preselect
? MENU_SELECTED
: MENU_UNSELECTED
);
1951 impossible("role_menu_extra: bad arg (%d)", which
);
1956 * Special setup modifications here:
1958 * Unfortunately, this is going to have to be done
1959 * on each newgame or restore, because you lose the permonst mods
1960 * across a save/restore. :-)
1962 * 1 - The Rogue Leader is the Tourist Nemesis.
1963 * 2 - Priests start with a random alignment - convert the leader and
1965 * 3 - Priests also get their of deities from a randomly chosen role.
1966 * 4 - [obsolete] Elves can have one of two different leaders,
1967 * but can't work it out here because it requires hacking the
1968 * level file data (see sp_lev.c).
1970 * This code also replaces quest_init().
1976 struct permonst
*pm
;
1978 /* Strip the role letter out of the player name.
1979 * This is included for backwards compatibility.
1983 /* Check for a valid role. Try flags.initrole first. */
1984 if (!validrole(flags
.initrole
)) {
1985 /* Try the player letter second */
1986 if ((flags
.initrole
= str2role(pl_character
)) < 0)
1987 /* None specified; pick a random role */
1988 flags
.initrole
= randrole_filtered();
1991 /* We now have a valid role index. Copy the role name back. */
1992 /* This should become OBSOLETE */
1993 Strcpy(pl_character
, roles
[flags
.initrole
].name
.m
);
1994 pl_character
[PL_CSIZ
- 1] = '\0';
1996 /* Check for a valid race */
1997 if (!validrace(flags
.initrole
, flags
.initrace
))
1998 flags
.initrace
= randrace(flags
.initrole
);
2000 /* Check for a valid gender. If new game, check both initgend
2001 * and female. On restore, assume flags.female is correct. */
2002 if (flags
.pantheon
== -1) { /* new game */
2003 if (!validgend(flags
.initrole
, flags
.initrace
, flags
.female
))
2004 flags
.female
= !flags
.female
;
2006 if (!validgend(flags
.initrole
, flags
.initrace
, flags
.initgend
))
2007 /* Note that there is no way to check for an unspecified gender. */
2008 flags
.initgend
= flags
.female
;
2010 /* Check for a valid alignment */
2011 if (!validalign(flags
.initrole
, flags
.initrace
, flags
.initalign
))
2012 /* Pick a random alignment */
2013 flags
.initalign
= randalign(flags
.initrole
, flags
.initrace
);
2014 alignmnt
= aligns
[flags
.initalign
].value
;
2016 /* Initialize urole and urace */
2017 urole
= roles
[flags
.initrole
];
2018 urace
= races
[flags
.initrace
];
2020 /* Fix up the quest leader */
2021 if (urole
.ldrnum
!= NON_PM
) {
2022 pm
= &mons
[urole
.ldrnum
];
2023 pm
->msound
= MS_LEADER
;
2024 pm
->mflags2
|= (M2_PEACEFUL
);
2025 pm
->mflags3
|= M3_CLOSE
;
2026 pm
->maligntyp
= alignmnt
* 3;
2027 /* if gender is random, we choose it now instead of waiting
2028 until the leader monster is created */
2029 quest_status
.ldrgend
=
2030 is_neuter(pm
) ? 2 : is_female(pm
) ? 1 : is_male(pm
)
2035 /* Fix up the quest guardians */
2036 if (urole
.guardnum
!= NON_PM
) {
2037 pm
= &mons
[urole
.guardnum
];
2038 pm
->mflags2
|= (M2_PEACEFUL
);
2039 pm
->maligntyp
= alignmnt
* 3;
2042 /* Fix up the quest nemesis */
2043 if (urole
.neminum
!= NON_PM
) {
2044 pm
= &mons
[urole
.neminum
];
2045 pm
->msound
= MS_NEMESIS
;
2046 pm
->mflags2
&= ~(M2_PEACEFUL
);
2047 pm
->mflags2
|= (M2_NASTY
| M2_STALK
| M2_HOSTILE
);
2048 pm
->mflags3
&= ~(M3_CLOSE
);
2049 pm
->mflags3
|= M3_WANTSARTI
| M3_WAITFORU
;
2050 /* if gender is random, we choose it now instead of waiting
2051 until the nemesis monster is created */
2052 quest_status
.nemgend
= is_neuter(pm
) ? 2 : is_female(pm
) ? 1
2053 : is_male(pm
) ? 0 : (rn2(100) < 50);
2056 /* Fix up the god names */
2057 if (flags
.pantheon
== -1) { /* new game */
2058 flags
.pantheon
= flags
.initrole
; /* use own gods */
2059 while (!roles
[flags
.pantheon
].lgod
) /* unless they're missing */
2060 flags
.pantheon
= randrole();
2063 urole
.lgod
= roles
[flags
.pantheon
].lgod
;
2064 urole
.ngod
= roles
[flags
.pantheon
].ngod
;
2065 urole
.cgod
= roles
[flags
.pantheon
].cgod
;
2067 /* 0 or 1; no gods are neuter, nor is gender randomized */
2068 quest_status
.godgend
= !strcmpi(align_gtitle(alignmnt
), "goddess");
2070 /* Fix up infravision */
2071 if (mons
[urace
.malenum
].mflags3
& M3_INFRAVISION
) {
2072 /* although an infravision intrinsic is possible, infravision
2073 * is purely a property of the physical race. This means that we
2074 * must put the infravision flag in the player's current race
2075 * (either that or have separate permonst entries for
2076 * elven/non-elven members of each class). The side effect is that
2077 * all NPCs of that class will have (probably bogus) infravision,
2078 * but since infravision has no effect for NPCs anyway we can
2081 mons
[urole
.malenum
].mflags3
|= M3_INFRAVISION
;
2082 if (urole
.femalenum
!= NON_PM
)
2083 mons
[urole
.femalenum
].mflags3
|= M3_INFRAVISION
;
2086 /* Artifacts are fixed in hack_artifacts() */
2096 switch (Role_switch
) {
2098 return "Salutations"; /* Olde English */
2100 return (mtmp
&& mtmp
->data
== &mons
[PM_SHOPKEEPER
])
2102 : "Konnichi wa"; /* Japanese */
2104 return "Aloha"; /* Hawaiian */
2108 (mtmp
&& mtmp
->data
== &mons
[PM_MAIL_DAEMON
]) ? "Hallo" :
2110 "Velkommen"; /* Norse */
2119 switch (Role_switch
) {
2121 return "Fare thee well"; /* Olde English */
2123 return "Sayonara"; /* Japanese */
2125 return "Aloha"; /* Hawaiian */
2127 return "Farvel"; /* Norse */