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.5 2006/08/21 19:45:32 pavalos Exp $ */
7 #define Strcpy (void) strcpy
8 #define Strcat (void) strcat
10 #define UNDEF_SPE '\177'
13 char pl_character[PL_CSIZ];
15 * must all have distinct first letter
16 * roles[4] may be changed to -man
18 char roles[][12 + 1] = {
19 "Tourist", "Speleologist", "Fighter", "Knight",
22 #define NR_OF_ROLES SIZE(roles)
23 char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
34 struct trobj Extra_objs[] = {
40 struct trobj Cave_man[] = {
41 { MACE, 1, WEAPON_SYM, 1, 1 },
42 { BOW, 1, WEAPON_SYM, 1, 1 },
43 { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */
44 { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
48 struct trobj Fighter[] = {
49 { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
50 { RING_MAIL, 0, ARMOR_SYM, 1, 1 },
54 struct trobj Knight[] = {
55 { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
56 { SPEAR, 2, WEAPON_SYM, 1, 1 },
57 { RING_MAIL, 1, ARMOR_SYM, 1, 1 },
58 { HELMET, 0, ARMOR_SYM, 1, 1 },
59 { SHIELD, 0, ARMOR_SYM, 1, 1 },
60 { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 },
64 struct trobj Speleologist[] = {
65 { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
66 { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
67 { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
68 { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 },
69 { ICE_BOX, 0, TOOL_SYM, 1, 0 },
73 struct trobj Tinopener[] = {
74 { CAN_OPENER, 0, TOOL_SYM, 1, 1 },
78 struct trobj Tourist[] = {
79 { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
80 { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
81 { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
82 { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */
86 struct trobj Wizard[] = {
87 { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 },
88 { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
89 { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
90 { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
91 { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
95 static void ini_inv(struct trobj *);
97 static void wiz_inv(void);
99 static int role_index(char);
105 char exper = 'y', pc;
106 if(flags.female) /* should have been set in HACKOPTIONS */
107 strlcpy(roles[4], "Cave-woman", sizeof(roles[4]));
108 for(i = 0; i < NR_OF_ROLES; i++)
109 rolesyms[i] = roles[i][0];
112 if((pc = pl_character[0])) {
113 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
114 if((i = role_index(pc)) >= 0)
115 goto got_suffix; /* implies experienced */
116 printf("\nUnknown role: %c\n", pc);
117 pl_character[0] = pc = 0;
120 printf("\nAre you an experienced player? [ny] ");
122 while(!index("ynYN \n\004", (exper = readchar())))
124 if(exper == '\004') /* Give him an opportunity to get out */
126 printf("%c\n", exper); /* echo */
127 if(index("Nn \n", exper)) {
132 printf("\nTell me what kind of character you are:\n");
134 for(i = 0; i < NR_OF_ROLES; i++) {
135 printf(" a %s", roles[i]);
138 else if(i < NR_OF_ROLES - 2)
140 else if(i == NR_OF_ROLES - 2)
143 printf("? [%s] ", rolesyms);
145 while((pc = readchar())) {
146 if('a' <= pc && pc <= 'z') pc += 'A'-'a';
147 if((i = role_index(pc)) >= 0) {
148 printf("%c\n", pc); /* echo */
149 fflush(stdout); /* should be seen */
154 if(pc == '\004') /* Give him the opportunity to get out */
163 printf("\nI'll choose a character for you.\n");
164 i = rn2(NR_OF_ROLES);
166 printf("This game you will be a%s %s.\n",
167 exper ? "n experienced" : "",
170 /* give him some feedback in case mklev takes much time */
180 strncpy(pl_character, roles[i], PL_CSIZ-1);
181 pl_character[PL_CSIZ-1] = 0;
190 uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
196 Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
197 u.uhp = u.uhpmax = 16;
198 u.ustr = u.ustrmax = 18;
203 Tourist[3].trquan = 20 + rnd(20);
204 u.ugold = u.ugold0 = rnd(1000);
205 u.uhp = u.uhpmax = 10;
206 u.ustr = u.ustrmax = 8;
208 if(!rn2(25)) ini_inv(Tinopener);
212 for(i=1; i<=4; i++) if(!rn2(5))
213 Wizard[i].trquan += rn2(3) - 1;
214 u.uhp = u.uhpmax = 15;
215 u.ustr = u.ustrmax = 16;
222 u.uhp = u.uhpmax = 12;
223 u.ustr = u.ustrmax = 10;
224 ini_inv(Speleologist);
225 if(!rn2(10)) ini_inv(Tinopener);
229 u.uhp = u.uhpmax = 12;
230 u.ustr = u.ustrmax = 10;
235 u.uhp = u.uhpmax = 14;
236 u.ustr = u.ustrmax = 17;
239 default: /* impossible */
240 u.uhp = u.uhpmax = 12;
241 u.ustr = u.ustrmax = 16;
245 int d1 = rn2(7) - 2; /* biased variation */
251 if(wizard) wiz_inv();
254 /* make sure he can carry all he has - especially for T's */
255 while(inv_weight() > 0 && u.ustr < 118)
256 u.ustr++, u.ustrmax++;
260 ini_inv(struct trobj *trop)
263 while(trop->trolet) {
264 obj = mkobj(trop->trolet);
265 obj->known = trop->trknown;
266 /* not obj->dknown = 1; - let him look at it at least once */
268 if(obj->olet == WEAPON_SYM){
269 obj->quan = trop->trquan;
272 if(trop->trspe != UNDEF_SPE)
273 obj->spe = trop->trspe;
274 if(trop->trotyp != UNDEF_TYP)
275 obj->otyp = trop->trotyp;
277 if(obj->otyp == WAN_WISHING) /* gitpyr!robert */
278 obj->otyp = WAN_DEATH;
279 obj->owt = weight(obj); /* defined after setting otyp+quan */
281 if(obj->olet == ARMOR_SYM){
284 if(!uarms) setworn(obj, W_ARMS);
287 if(!uarmh) setworn(obj, W_ARMH);
290 if(!uarmg) setworn(obj, W_ARMG);
297 if(!uarm) setworn(obj, W_ARM);
300 if(obj->olet == WEAPON_SYM)
301 if(!uwep) setuwep(obj);
303 if(--trop->trquan) continue; /* make a similar object */
305 if(trop->trquan) { /* check if zero first */
308 continue; /* make a similar object */
310 #endif /* PYRAMID_BUG */
319 struct trobj *trop = &Extra_objs[0];
320 char *ep = getenv("INVENT");
325 if(ep) while(*ep == ',' || *ep == ' ') ep++;
326 if(type <= 0 || type > NROFOBJECTS) continue;
328 trop->trolet = objects[type].oc_olet;
334 /* give him a wand of wishing by default */
335 trop->trotyp = WAN_WISHING;
336 trop->trolet = WAND_SYM;
348 if((p = rindex(plname, '-'))) {
350 pl_character[0] = p[1];
361 { /* must be called only from u_init() */
362 /* so that rolesyms[] is defined */
365 if((cp = index(rolesyms, pc)))
366 return(cp - rolesyms);