1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.u_init.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.u_init.c,v 1.4 1999/11/16 02:57:13 billf Exp $ */
4 /* $DragonFly: src/games/hack/hack.u_init.c,v 1.4 2005/05/22 01:28:15 y0netan1 Exp $ */
10 #define Strcpy (void) strcpy
11 #define Strcat (void) strcat
13 #define UNDEF_SPE '\177'
14 extern struct obj *addinv();
19 char pl_character[PL_CSIZ];
21 * must all have distinct first letter
22 * roles[4] may be changed to -man
24 char roles[][12 + 1] = {
25 "Tourist", "Speleologist", "Fighter", "Knight",
28 #define NR_OF_ROLES SIZE(roles)
29 char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
40 struct trobj Extra_objs[] = {
46 struct trobj Cave_man[] = {
47 { MACE, 1, WEAPON_SYM, 1, 1 },
48 { BOW, 1, WEAPON_SYM, 1, 1 },
49 { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */
50 { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
54 struct trobj Fighter[] = {
55 { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
56 { RING_MAIL, 0, ARMOR_SYM, 1, 1 },
60 struct trobj Knight[] = {
61 { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
62 { SPEAR, 2, WEAPON_SYM, 1, 1 },
63 { RING_MAIL, 1, ARMOR_SYM, 1, 1 },
64 { HELMET, 0, ARMOR_SYM, 1, 1 },
65 { SHIELD, 0, ARMOR_SYM, 1, 1 },
66 { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 },
70 struct trobj Speleologist[] = {
71 { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
72 { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
73 { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
74 { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 },
75 { ICE_BOX, 0, TOOL_SYM, 1, 0 },
79 struct trobj Tinopener[] = {
80 { CAN_OPENER, 0, TOOL_SYM, 1, 1 },
84 struct trobj Tourist[] = {
85 { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
86 { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
87 { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
88 { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */
92 struct trobj Wizard[] = {
93 { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 },
94 { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
95 { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
96 { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
97 { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
103 char exper = 'y', pc;
104 extern char readchar();
105 if(flags.female) /* should have been set in HACKOPTIONS */
106 strlcpy(roles[4], "Cave-woman", sizeof(roles[4]));
107 for(i = 0; i < NR_OF_ROLES; i++)
108 rolesyms[i] = roles[i][0];
111 if(pc = pl_character[0]) {
112 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
113 if((i = role_index(pc)) >= 0)
114 goto got_suffix; /* implies experienced */
115 printf("\nUnknown role: %c\n", pc);
116 pl_character[0] = pc = 0;
119 printf("\nAre you an experienced player? [ny] ");
121 while(!index("ynYN \n\004", (exper = readchar())))
123 if(exper == '\004') /* Give him an opportunity to get out */
125 printf("%c\n", exper); /* echo */
126 if(index("Nn \n", exper)) {
131 printf("\nTell me what kind of character you are:\n");
133 for(i = 0; i < NR_OF_ROLES; i++) {
134 printf(" a %s", roles[i]);
137 else if(i < NR_OF_ROLES - 2)
139 else if(i == NR_OF_ROLES - 2)
142 printf("? [%s] ", rolesyms);
144 while(pc = readchar()) {
145 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
146 if((i = role_index(pc)) >= 0) {
147 printf("%c\n", pc); /* echo */
148 (void) fflush(stdout); /* should be seen */
153 if(pc == '\004') /* Give him the opportunity to get out */
162 printf("\nI'll choose a character for you.\n");
163 i = rn2(NR_OF_ROLES);
165 printf("This game you will be a%s %s.\n",
166 exper ? "n experienced" : "",
169 /* give him some feedback in case mklev takes much time */
170 (void) putchar('\n');
171 (void) fflush(stdout);
179 (void) strncpy(pl_character, roles[i], PL_CSIZ-1);
180 pl_character[PL_CSIZ-1] = 0;
189 uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
195 Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
196 u.uhp = u.uhpmax = 16;
197 u.ustr = u.ustrmax = 18;
202 Tourist[3].trquan = 20 + rnd(20);
203 u.ugold = u.ugold0 = rnd(1000);
204 u.uhp = u.uhpmax = 10;
205 u.ustr = u.ustrmax = 8;
207 if(!rn2(25)) ini_inv(Tinopener);
211 for(i=1; i<=4; i++) if(!rn2(5))
212 Wizard[i].trquan += rn2(3) - 1;
213 u.uhp = u.uhpmax = 15;
214 u.ustr = u.ustrmax = 16;
221 u.uhp = u.uhpmax = 12;
222 u.ustr = u.ustrmax = 10;
223 ini_inv(Speleologist);
224 if(!rn2(10)) ini_inv(Tinopener);
228 u.uhp = u.uhpmax = 12;
229 u.ustr = u.ustrmax = 10;
234 u.uhp = u.uhpmax = 14;
235 u.ustr = u.ustrmax = 17;
238 default: /* impossible */
239 u.uhp = u.uhpmax = 12;
240 u.ustr = u.ustrmax = 16;
244 int d = rn2(7) - 2; /* biased variation */
250 if(wizard) wiz_inv();
253 /* make sure he can carry all he has - especially for T's */
254 while(inv_weight() > 0 && u.ustr < 118)
255 u.ustr++, u.ustrmax++;
258 ini_inv(trop) struct trobj *trop; {
260 extern struct obj *mkobj();
261 while(trop->trolet) {
262 obj = mkobj(trop->trolet);
263 obj->known = trop->trknown;
264 /* not obj->dknown = 1; - let him look at it at least once */
266 if(obj->olet == WEAPON_SYM){
267 obj->quan = trop->trquan;
270 if(trop->trspe != UNDEF_SPE)
271 obj->spe = trop->trspe;
272 if(trop->trotyp != UNDEF_TYP)
273 obj->otyp = trop->trotyp;
275 if(obj->otyp == WAN_WISHING) /* gitpyr!robert */
276 obj->otyp = WAN_DEATH;
277 obj->owt = weight(obj); /* defined after setting otyp+quan */
279 if(obj->olet == ARMOR_SYM){
282 if(!uarms) setworn(obj, W_ARMS);
285 if(!uarmh) setworn(obj, W_ARMH);
288 if(!uarmg) setworn(obj, W_ARMG);
295 if(!uarm) setworn(obj, W_ARM);
298 if(obj->olet == WEAPON_SYM)
299 if(!uwep) setuwep(obj);
301 if(--trop->trquan) continue; /* make a similar object */
303 if(trop->trquan) { /* check if zero first */
306 continue; /* make a similar object */
308 #endif /* PYRAMID_BUG */
315 struct trobj *trop = &Extra_objs[0];
316 char *ep = getenv("INVENT");
321 if(ep) while(*ep == ',' || *ep == ' ') ep++;
322 if(type <= 0 || type > NROFOBJECTS) continue;
324 trop->trolet = objects[type].oc_olet;
330 /* give him a wand of wishing by default */
331 trop->trotyp = WAN_WISHING;
332 trop->trolet = WAND_SYM;
342 if(p = rindex(plname, '-')) {
344 pl_character[0] = p[1];
355 { /* must be called only from u_init() */
356 /* so that rolesyms[] is defined */
359 if(cp = index(rolesyms, pc))
360 return(cp - rolesyms);