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.2 2003/06/17 04:25:24 dillon 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];
20 char *(roles[]) = { /* must all have distinct first letter */
21 /* roles[4] may be changed to -man */
22 "Tourist", "Speleologist", "Fighter", "Knight",
25 #define NR_OF_ROLES SIZE(roles)
26 char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
37 struct trobj Extra_objs[] = {
43 struct trobj Cave_man[] = {
44 { MACE, 1, WEAPON_SYM, 1, 1 },
45 { BOW, 1, WEAPON_SYM, 1, 1 },
46 { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */
47 { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
51 struct trobj Fighter[] = {
52 { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
53 { RING_MAIL, 0, ARMOR_SYM, 1, 1 },
57 struct trobj Knight[] = {
58 { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
59 { SPEAR, 2, WEAPON_SYM, 1, 1 },
60 { RING_MAIL, 1, ARMOR_SYM, 1, 1 },
61 { HELMET, 0, ARMOR_SYM, 1, 1 },
62 { SHIELD, 0, ARMOR_SYM, 1, 1 },
63 { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 },
67 struct trobj Speleologist[] = {
68 { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
69 { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
70 { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
71 { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 },
72 { ICE_BOX, 0, TOOL_SYM, 1, 0 },
76 struct trobj Tinopener[] = {
77 { CAN_OPENER, 0, TOOL_SYM, 1, 1 },
81 struct trobj Tourist[] = {
82 { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
83 { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
84 { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
85 { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */
89 struct trobj Wizard[] = {
90 { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 },
91 { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
92 { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
93 { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
94 { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
100 char exper = 'y', pc;
101 extern char readchar();
102 if(flags.female) /* should have been set in HACKOPTIONS */
103 roles[4] = "Cave-woman";
104 for(i = 0; i < NR_OF_ROLES; i++)
105 rolesyms[i] = roles[i][0];
108 if(pc = pl_character[0]) {
109 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
110 if((i = role_index(pc)) >= 0)
111 goto got_suffix; /* implies experienced */
112 printf("\nUnknown role: %c\n", pc);
113 pl_character[0] = pc = 0;
116 printf("\nAre you an experienced player? [ny] ");
118 while(!index("ynYN \n\004", (exper = readchar())))
120 if(exper == '\004') /* Give him an opportunity to get out */
122 printf("%c\n", exper); /* echo */
123 if(index("Nn \n", exper)) {
128 printf("\nTell me what kind of character you are:\n");
130 for(i = 0; i < NR_OF_ROLES; i++) {
131 printf(" a %s", roles[i]);
134 else if(i < NR_OF_ROLES - 2)
136 else if(i == NR_OF_ROLES - 2)
139 printf("? [%s] ", rolesyms);
141 while(pc = readchar()) {
142 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
143 if((i = role_index(pc)) >= 0) {
144 printf("%c\n", pc); /* echo */
145 (void) fflush(stdout); /* should be seen */
150 if(pc == '\004') /* Give him the opportunity to get out */
159 printf("\nI'll choose a character for you.\n");
160 i = rn2(NR_OF_ROLES);
162 printf("This game you will be a%s %s.\n",
163 exper ? "n experienced" : "",
166 /* give him some feedback in case mklev takes much time */
167 (void) putchar('\n');
168 (void) fflush(stdout);
176 (void) strncpy(pl_character, roles[i], PL_CSIZ-1);
177 pl_character[PL_CSIZ-1] = 0;
186 uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
192 Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
193 u.uhp = u.uhpmax = 16;
194 u.ustr = u.ustrmax = 18;
199 Tourist[3].trquan = 20 + rnd(20);
200 u.ugold = u.ugold0 = rnd(1000);
201 u.uhp = u.uhpmax = 10;
202 u.ustr = u.ustrmax = 8;
204 if(!rn2(25)) ini_inv(Tinopener);
208 for(i=1; i<=4; i++) if(!rn2(5))
209 Wizard[i].trquan += rn2(3) - 1;
210 u.uhp = u.uhpmax = 15;
211 u.ustr = u.ustrmax = 16;
218 u.uhp = u.uhpmax = 12;
219 u.ustr = u.ustrmax = 10;
220 ini_inv(Speleologist);
221 if(!rn2(10)) ini_inv(Tinopener);
225 u.uhp = u.uhpmax = 12;
226 u.ustr = u.ustrmax = 10;
231 u.uhp = u.uhpmax = 14;
232 u.ustr = u.ustrmax = 17;
235 default: /* impossible */
236 u.uhp = u.uhpmax = 12;
237 u.ustr = u.ustrmax = 16;
241 int d = rn2(7) - 2; /* biased variation */
247 if(wizard) wiz_inv();
250 /* make sure he can carry all he has - especially for T's */
251 while(inv_weight() > 0 && u.ustr < 118)
252 u.ustr++, u.ustrmax++;
255 ini_inv(trop) struct trobj *trop; {
257 extern struct obj *mkobj();
258 while(trop->trolet) {
259 obj = mkobj(trop->trolet);
260 obj->known = trop->trknown;
261 /* not obj->dknown = 1; - let him look at it at least once */
263 if(obj->olet == WEAPON_SYM){
264 obj->quan = trop->trquan;
267 if(trop->trspe != UNDEF_SPE)
268 obj->spe = trop->trspe;
269 if(trop->trotyp != UNDEF_TYP)
270 obj->otyp = trop->trotyp;
272 if(obj->otyp == WAN_WISHING) /* gitpyr!robert */
273 obj->otyp = WAN_DEATH;
274 obj->owt = weight(obj); /* defined after setting otyp+quan */
276 if(obj->olet == ARMOR_SYM){
279 if(!uarms) setworn(obj, W_ARMS);
282 if(!uarmh) setworn(obj, W_ARMH);
285 if(!uarmg) setworn(obj, W_ARMG);
292 if(!uarm) setworn(obj, W_ARM);
295 if(obj->olet == WEAPON_SYM)
296 if(!uwep) setuwep(obj);
298 if(--trop->trquan) continue; /* make a similar object */
300 if(trop->trquan) { /* check if zero first */
303 continue; /* make a similar object */
312 struct trobj *trop = &Extra_objs[0];
313 char *ep = getenv("INVENT");
318 if(ep) while(*ep == ',' || *ep == ' ') ep++;
319 if(type <= 0 || type > NROFOBJECTS) continue;
321 trop->trolet = objects[type].oc_olet;
327 /* give him a wand of wishing by default */
328 trop->trotyp = WAN_WISHING;
329 trop->trolet = WAND_SYM;
339 if(p = rindex(plname, '-')) {
341 pl_character[0] = p[1];
352 { /* must be called only from u_init() */
353 /* so that rolesyms[] is defined */
356 if(cp = index(rolesyms, pc))
357 return(cp - rolesyms);