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 UNDEF_SPE '\177'
12 char pl_character
[PL_CSIZ
];
14 * must all have distinct first letter
15 * roles[4] may be changed to -man
17 char roles
[][12 + 1] = {
18 "Tourist", "Speleologist", "Fighter", "Knight",
21 #define NR_OF_ROLES SIZE(roles)
22 char rolesyms
[NR_OF_ROLES
+ 1]; /* filled by u_init() */
33 struct trobj Extra_objs
[] = {
39 struct trobj Cave_man
[] = {
40 { MACE
, 1, WEAPON_SYM
, 1, 1 },
41 { BOW
, 1, WEAPON_SYM
, 1, 1 },
42 { ARROW
, 0, WEAPON_SYM
, 25, 1 }, /* quan is variable */
43 { LEATHER_ARMOR
, 0, ARMOR_SYM
, 1, 1 },
47 struct trobj Fighter
[] = {
48 { TWO_HANDED_SWORD
, 0, WEAPON_SYM
, 1, 1 },
49 { RING_MAIL
, 0, ARMOR_SYM
, 1, 1 },
53 struct trobj Knight
[] = {
54 { LONG_SWORD
, 0, WEAPON_SYM
, 1, 1 },
55 { SPEAR
, 2, WEAPON_SYM
, 1, 1 },
56 { RING_MAIL
, 1, ARMOR_SYM
, 1, 1 },
57 { HELMET
, 0, ARMOR_SYM
, 1, 1 },
58 { SHIELD
, 0, ARMOR_SYM
, 1, 1 },
59 { PAIR_OF_GLOVES
, 0, ARMOR_SYM
, 1, 1 },
63 struct trobj Speleologist
[] = {
64 { STUDDED_LEATHER_ARMOR
, 0, ARMOR_SYM
, 1, 1 },
65 { UNDEF_TYP
, 0, POTION_SYM
, 2, 0 },
66 { FOOD_RATION
, 0, FOOD_SYM
, 3, 1 },
67 { PICK_AXE
, UNDEF_SPE
, TOOL_SYM
, 1, 0 },
68 { ICE_BOX
, 0, TOOL_SYM
, 1, 0 },
72 struct trobj Tinopener
[] = {
73 { CAN_OPENER
, 0, TOOL_SYM
, 1, 1 },
77 struct trobj Tourist
[] = {
78 { UNDEF_TYP
, 0, FOOD_SYM
, 10, 1 },
79 { POT_EXTRA_HEALING
, 0, POTION_SYM
, 2, 0 },
80 { EXPENSIVE_CAMERA
, 0, TOOL_SYM
, 1, 1 },
81 { DART
, 2, WEAPON_SYM
, 25, 1 }, /* quan is variable */
85 struct trobj Wizard
[] = {
86 { ELVEN_CLOAK
, 0, ARMOR_SYM
, 1, 1 },
87 { UNDEF_TYP
, UNDEF_SPE
, WAND_SYM
, 2, 0 },
88 { UNDEF_TYP
, UNDEF_SPE
, RING_SYM
, 2, 0 },
89 { UNDEF_TYP
, UNDEF_SPE
, POTION_SYM
, 2, 0 },
90 { UNDEF_TYP
, UNDEF_SPE
, SCROLL_SYM
, 3, 0 },
94 static void ini_inv(struct trobj
*);
96 static void wiz_inv(void);
98 static int role_index(char);
104 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]) != '\0') {
113 if ('a' <= pc
&& pc
<= 'z')
115 if ((i
= role_index(pc
)) >= 0)
116 goto got_suffix
; /* implies experienced */
117 printf("\nUnknown role: %c\n", pc
);
118 pl_character
[0] = pc
= 0;
121 printf("\nAre you an experienced player? [ny] ");
123 while (!strchr("ynYN \n\004", (exper
= readchar())))
125 if (exper
== '\004') /* Give him an opportunity to get out */
127 printf("%c\n", exper
); /* echo */
128 if (strchr("Nn \n", exper
)) {
133 printf("\nTell me what kind of character you are:\n");
135 for (i
= 0; i
< NR_OF_ROLES
; i
++) {
136 printf(" a %s", roles
[i
]);
139 else if (i
< NR_OF_ROLES
- 2)
141 else if (i
== NR_OF_ROLES
- 2)
144 printf("? [%s] ", rolesyms
);
146 while ((pc
= readchar()) != '\0') {
147 if ('a' <= pc
&& pc
<= 'z')
149 if ((i
= role_index(pc
)) >= 0) {
150 printf("%c\n", pc
); /* echo */
151 fflush(stdout
); /* should be seen */
156 if (pc
== '\004') /* Give him the opportunity to get out */
165 printf("\nI'll choose a character for you.\n");
166 i
= rn2(NR_OF_ROLES
);
168 printf("This game you will be a%s %s.\n",
169 exper
? "n experienced" : "",
172 /* give him some feedback in case mklev takes much time */
181 strncpy(pl_character
, roles
[i
], PL_CSIZ
- 1);
182 pl_character
[PL_CSIZ
- 1] = 0;
191 uarm
= uarm2
= uarmh
= uarms
= uarmg
= uwep
= uball
= uchain
=
197 Cave_man
[2].trquan
= 12 + rnd(9) * rnd(9);
198 u
.uhp
= u
.uhpmax
= 16;
199 u
.ustr
= u
.ustrmax
= 18;
204 Tourist
[3].trquan
= 20 + rnd(20);
205 u
.ugold
= u
.ugold0
= rnd(1000);
206 u
.uhp
= u
.uhpmax
= 10;
207 u
.ustr
= u
.ustrmax
= 8;
214 for (i
= 1; i
<= 4; i
++)
216 Wizard
[i
].trquan
+= rn2(3) - 1;
217 u
.uhp
= u
.uhpmax
= 15;
218 u
.ustr
= u
.ustrmax
= 16;
225 u
.uhp
= u
.uhpmax
= 12;
226 u
.ustr
= u
.ustrmax
= 10;
227 ini_inv(Speleologist
);
233 u
.uhp
= u
.uhpmax
= 12;
234 u
.ustr
= u
.ustrmax
= 10;
239 u
.uhp
= u
.uhpmax
= 14;
240 u
.ustr
= u
.ustrmax
= 17;
243 default: /* impossible */
244 u
.uhp
= u
.uhpmax
= 12;
245 u
.ustr
= u
.ustrmax
= 16;
249 int d1
= rn2(7) - 2; /* biased variation */
259 /* make sure he can carry all he has - especially for T's */
260 while (inv_weight() > 0 && u
.ustr
< 118)
261 u
.ustr
++, u
.ustrmax
++;
265 ini_inv(struct trobj
*trop
)
269 while (trop
->trolet
) {
270 obj
= mkobj(trop
->trolet
);
271 obj
->known
= trop
->trknown
;
272 /* not obj->dknown = 1; - let him look at it at least once */
274 if (obj
->olet
== WEAPON_SYM
) {
275 obj
->quan
= trop
->trquan
;
278 if (trop
->trspe
!= UNDEF_SPE
)
279 obj
->spe
= trop
->trspe
;
280 if (trop
->trotyp
!= UNDEF_TYP
)
281 obj
->otyp
= trop
->trotyp
;
282 else if (obj
->otyp
== WAN_WISHING
) /* gitpyr!robert */
283 obj
->otyp
= WAN_DEATH
;
284 obj
->owt
= weight(obj
); /* defined after setting otyp+quan */
286 if (obj
->olet
== ARMOR_SYM
) {
290 setworn(obj
, W_ARMS
);
294 setworn(obj
, W_ARMH
);
298 setworn(obj
, W_ARMG
);
309 if (obj
->olet
== WEAPON_SYM
)
313 if (--trop
->trquan
) /* make a similar object */
316 if (trop
->trquan
) { /* check if zero first */
319 continue; /* make a similar object */
321 #endif /* PYRAMID_BUG */
330 struct trobj
*trop
= &Extra_objs
[0];
331 char *ep
= getenv("INVENT");
336 ep
= strchr(ep
, ',');
338 while (*ep
== ',' || *ep
== ' ')
340 if (type
<= 0 || type
> NROFOBJECTS
)
343 trop
->trolet
= objects
[type
].oc_olet
;
349 /* give him a wand of wishing by default */
350 trop
->trotyp
= WAN_WISHING
;
351 trop
->trolet
= WAND_SYM
;
364 if ((p
= strrchr(plname
, '-')) != NULL
) {
366 pl_character
[0] = p
[1];
377 { /* must be called only from u_init() */
378 /* so that rolesyms[] is defined */
381 if ((cp
= strchr(rolesyms
, pc
)) != NULL
)
382 return (cp
- rolesyms
);