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
;
107 if (flags
.female
) /* should have been set in HACKOPTIONS */
108 strlcpy(roles
[4], "Cave-woman", sizeof(roles
[4]));
109 for (i
= 0; i
< NR_OF_ROLES
; i
++)
110 rolesyms
[i
] = roles
[i
][0];
113 if ((pc
= pl_character
[0]) != '\0') {
114 if ('a' <= pc
&& pc
<= 'z')
116 if ((i
= role_index(pc
)) >= 0)
117 goto got_suffix
; /* implies experienced */
118 printf("\nUnknown role: %c\n", pc
);
119 pl_character
[0] = pc
= 0;
122 printf("\nAre you an experienced player? [ny] ");
124 while (!strchr("ynYN \n\004", (exper
= readchar())))
126 if (exper
== '\004') /* Give him an opportunity to get out */
128 printf("%c\n", exper
); /* echo */
129 if (strchr("Nn \n", exper
)) {
134 printf("\nTell me what kind of character you are:\n");
136 for (i
= 0; i
< NR_OF_ROLES
; i
++) {
137 printf(" a %s", roles
[i
]);
140 else if (i
< NR_OF_ROLES
- 2)
142 else if (i
== NR_OF_ROLES
- 2)
145 printf("? [%s] ", rolesyms
);
147 while ((pc
= readchar()) != '\0') {
148 if ('a' <= pc
&& pc
<= 'z')
150 if ((i
= role_index(pc
)) >= 0) {
151 printf("%c\n", pc
); /* echo */
152 fflush(stdout
); /* should be seen */
157 if (pc
== '\004') /* Give him the opportunity to get out */
166 printf("\nI'll choose a character for you.\n");
167 i
= rn2(NR_OF_ROLES
);
169 printf("This game you will be a%s %s.\n",
170 exper
? "n experienced" : "",
173 /* give him some feedback in case mklev takes much time */
182 strncpy(pl_character
, roles
[i
], PL_CSIZ
- 1);
183 pl_character
[PL_CSIZ
- 1] = 0;
192 uarm
= uarm2
= uarmh
= uarms
= uarmg
= uwep
= uball
= uchain
=
198 Cave_man
[2].trquan
= 12 + rnd(9) * rnd(9);
199 u
.uhp
= u
.uhpmax
= 16;
200 u
.ustr
= u
.ustrmax
= 18;
205 Tourist
[3].trquan
= 20 + rnd(20);
206 u
.ugold
= u
.ugold0
= rnd(1000);
207 u
.uhp
= u
.uhpmax
= 10;
208 u
.ustr
= u
.ustrmax
= 8;
215 for (i
= 1; i
<= 4; i
++)
217 Wizard
[i
].trquan
+= rn2(3) - 1;
218 u
.uhp
= u
.uhpmax
= 15;
219 u
.ustr
= u
.ustrmax
= 16;
226 u
.uhp
= u
.uhpmax
= 12;
227 u
.ustr
= u
.ustrmax
= 10;
228 ini_inv(Speleologist
);
234 u
.uhp
= u
.uhpmax
= 12;
235 u
.ustr
= u
.ustrmax
= 10;
240 u
.uhp
= u
.uhpmax
= 14;
241 u
.ustr
= u
.ustrmax
= 17;
244 default: /* impossible */
245 u
.uhp
= u
.uhpmax
= 12;
246 u
.ustr
= u
.ustrmax
= 16;
250 int d1
= rn2(7) - 2; /* biased variation */
260 /* make sure he can carry all he has - especially for T's */
261 while (inv_weight() > 0 && u
.ustr
< 118)
262 u
.ustr
++, u
.ustrmax
++;
266 ini_inv(struct trobj
*trop
)
270 while (trop
->trolet
) {
271 obj
= mkobj(trop
->trolet
);
272 obj
->known
= trop
->trknown
;
273 /* not obj->dknown = 1; - let him look at it at least once */
275 if (obj
->olet
== WEAPON_SYM
) {
276 obj
->quan
= trop
->trquan
;
279 if (trop
->trspe
!= UNDEF_SPE
)
280 obj
->spe
= trop
->trspe
;
281 if (trop
->trotyp
!= UNDEF_TYP
)
282 obj
->otyp
= trop
->trotyp
;
283 else if (obj
->otyp
== WAN_WISHING
) /* gitpyr!robert */
284 obj
->otyp
= WAN_DEATH
;
285 obj
->owt
= weight(obj
); /* defined after setting otyp+quan */
287 if (obj
->olet
== ARMOR_SYM
) {
291 setworn(obj
, W_ARMS
);
295 setworn(obj
, W_ARMH
);
299 setworn(obj
, W_ARMG
);
310 if (obj
->olet
== WEAPON_SYM
)
314 if (--trop
->trquan
) /* make a similar object */
317 if (trop
->trquan
) { /* check if zero first */
320 continue; /* make a similar object */
322 #endif /* PYRAMID_BUG */
331 struct trobj
*trop
= &Extra_objs
[0];
332 char *ep
= getenv("INVENT");
337 ep
= strchr(ep
, ',');
339 while (*ep
== ',' || *ep
== ' ')
341 if (type
<= 0 || type
> NROFOBJECTS
)
344 trop
->trolet
= objects
[type
].oc_olet
;
350 /* give him a wand of wishing by default */
351 trop
->trotyp
= WAN_WISHING
;
352 trop
->trolet
= WAND_SYM
;
365 if ((p
= strrchr(plname
, '-')) != NULL
) {
367 pl_character
[0] = p
[1];
378 { /* must be called only from u_init() */
379 /* so that rolesyms[] is defined */
382 if ((cp
= strchr(rolesyms
, pc
)) != NULL
)
383 return (cp
- rolesyms
);