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 $ */
9 #define Strcpy (void) strcpy
10 #define Strcat (void) strcat
12 #define UNDEF_SPE '\177'
13 extern struct obj *addinv();
18 char pl_character[PL_CSIZ];
19 char *(roles[]) = { /* must all have distinct first letter */
20 /* roles[4] may be changed to -man */
21 "Tourist", "Speleologist", "Fighter", "Knight",
24 #define NR_OF_ROLES SIZE(roles)
25 char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
36 struct trobj Extra_objs[] = {
42 struct trobj Cave_man[] = {
43 { MACE, 1, WEAPON_SYM, 1, 1 },
44 { BOW, 1, WEAPON_SYM, 1, 1 },
45 { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */
46 { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
50 struct trobj Fighter[] = {
51 { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
52 { RING_MAIL, 0, ARMOR_SYM, 1, 1 },
56 struct trobj Knight[] = {
57 { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
58 { SPEAR, 2, WEAPON_SYM, 1, 1 },
59 { RING_MAIL, 1, ARMOR_SYM, 1, 1 },
60 { HELMET, 0, ARMOR_SYM, 1, 1 },
61 { SHIELD, 0, ARMOR_SYM, 1, 1 },
62 { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 },
66 struct trobj Speleologist[] = {
67 { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
68 { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
69 { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
70 { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 },
71 { ICE_BOX, 0, TOOL_SYM, 1, 0 },
75 struct trobj Tinopener[] = {
76 { CAN_OPENER, 0, TOOL_SYM, 1, 1 },
80 struct trobj Tourist[] = {
81 { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
82 { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
83 { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
84 { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */
88 struct trobj Wizard[] = {
89 { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 },
90 { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
91 { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
92 { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
93 { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
100 extern char readchar();
101 if(flags.female) /* should have been set in HACKOPTIONS */
102 roles[4] = "Cave-woman";
103 for(i = 0; i < NR_OF_ROLES; i++)
104 rolesyms[i] = roles[i][0];
107 if(pc = pl_character[0]) {
108 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
109 if((i = role_index(pc)) >= 0)
110 goto got_suffix; /* implies experienced */
111 printf("\nUnknown role: %c\n", pc);
112 pl_character[0] = pc = 0;
115 printf("\nAre you an experienced player? [ny] ");
117 while(!index("ynYN \n\004", (exper = readchar())))
119 if(exper == '\004') /* Give him an opportunity to get out */
121 printf("%c\n", exper); /* echo */
122 if(index("Nn \n", exper)) {
127 printf("\nTell me what kind of character you are:\n");
129 for(i = 0; i < NR_OF_ROLES; i++) {
130 printf(" a %s", roles[i]);
133 else if(i < NR_OF_ROLES - 2)
135 else if(i == NR_OF_ROLES - 2)
138 printf("? [%s] ", rolesyms);
140 while(pc = readchar()) {
141 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
142 if((i = role_index(pc)) >= 0) {
143 printf("%c\n", pc); /* echo */
144 (void) fflush(stdout); /* should be seen */
149 if(pc == '\004') /* Give him the opportunity to get out */
158 printf("\nI'll choose a character for you.\n");
159 i = rn2(NR_OF_ROLES);
161 printf("This game you will be a%s %s.\n",
162 exper ? "n experienced" : "",
165 /* give him some feedback in case mklev takes much time */
166 (void) putchar('\n');
167 (void) fflush(stdout);
175 (void) strncpy(pl_character, roles[i], PL_CSIZ-1);
176 pl_character[PL_CSIZ-1] = 0;
185 uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
191 Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
192 u.uhp = u.uhpmax = 16;
193 u.ustr = u.ustrmax = 18;
198 Tourist[3].trquan = 20 + rnd(20);
199 u.ugold = u.ugold0 = rnd(1000);
200 u.uhp = u.uhpmax = 10;
201 u.ustr = u.ustrmax = 8;
203 if(!rn2(25)) ini_inv(Tinopener);
207 for(i=1; i<=4; i++) if(!rn2(5))
208 Wizard[i].trquan += rn2(3) - 1;
209 u.uhp = u.uhpmax = 15;
210 u.ustr = u.ustrmax = 16;
217 u.uhp = u.uhpmax = 12;
218 u.ustr = u.ustrmax = 10;
219 ini_inv(Speleologist);
220 if(!rn2(10)) ini_inv(Tinopener);
224 u.uhp = u.uhpmax = 12;
225 u.ustr = u.ustrmax = 10;
230 u.uhp = u.uhpmax = 14;
231 u.ustr = u.ustrmax = 17;
234 default: /* impossible */
235 u.uhp = u.uhpmax = 12;
236 u.ustr = u.ustrmax = 16;
240 int d = rn2(7) - 2; /* biased variation */
246 if(wizard) wiz_inv();
249 /* make sure he can carry all he has - especially for T's */
250 while(inv_weight() > 0 && u.ustr < 118)
251 u.ustr++, u.ustrmax++;
254 ini_inv(trop) struct trobj *trop; {
256 extern struct obj *mkobj();
257 while(trop->trolet) {
258 obj = mkobj(trop->trolet);
259 obj->known = trop->trknown;
260 /* not obj->dknown = 1; - let him look at it at least once */
262 if(obj->olet == WEAPON_SYM){
263 obj->quan = trop->trquan;
266 if(trop->trspe != UNDEF_SPE)
267 obj->spe = trop->trspe;
268 if(trop->trotyp != UNDEF_TYP)
269 obj->otyp = trop->trotyp;
271 if(obj->otyp == WAN_WISHING) /* gitpyr!robert */
272 obj->otyp = WAN_DEATH;
273 obj->owt = weight(obj); /* defined after setting otyp+quan */
275 if(obj->olet == ARMOR_SYM){
278 if(!uarms) setworn(obj, W_ARMS);
281 if(!uarmh) setworn(obj, W_ARMH);
284 if(!uarmg) setworn(obj, W_ARMG);
291 if(!uarm) setworn(obj, W_ARM);
294 if(obj->olet == WEAPON_SYM)
295 if(!uwep) setuwep(obj);
297 if(--trop->trquan) continue; /* make a similar object */
299 if(trop->trquan) { /* check if zero first */
302 continue; /* make a similar object */
311 struct trobj *trop = &Extra_objs[0];
312 char *ep = getenv("INVENT");
317 if(ep) while(*ep == ',' || *ep == ' ') ep++;
318 if(type <= 0 || type > NROFOBJECTS) continue;
320 trop->trolet = objects[type].oc_olet;
326 /* give him a wand of wishing by default */
327 trop->trotyp = WAN_WISHING;
328 trop->trolet = WAND_SYM;
338 if(p = rindex(plname, '-')) {
340 pl_character[0] = p[1];
351 { /* must be called only from u_init() */
352 /* so that rolesyms[] is defined */
355 if(cp = index(rolesyms, pc))
356 return(cp - rolesyms);