]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.u_init.c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.u_init.c - version 1.0.3 */
7 #define Strcpy (void) strcpy
8 #define Strcat (void) strcat
10 #define UNDEF_SPE '\177'
11 extern struct obj
*addinv();
16 char pl_character
[PL_CSIZ
];
17 char *(roles
[]) = { /* must all have distinct first letter */
18 /* roles[4] may be changed to -woman */
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 },
98 extern char readchar();
99 if(flags
.female
) /* should have been set in HACKOPTIONS */
100 roles
[4] = "Cave-woman";
101 for(i
= 0; i
< NR_OF_ROLES
; i
++)
102 rolesyms
[i
] = roles
[i
][0];
105 if(pc
= pl_character
[0]) {
106 if(islower(pc
)) pc
= toupper(pc
);
107 if((i
= role_index(pc
)) >= 0)
108 goto got_suffix
; /* implies experienced */
109 printf("\nUnknown role: %c\n", pc
);
110 pl_character
[0] = pc
= 0;
113 printf("\nAre you an experienced player? [ny] ");
115 while(!index("ynYN \n\004", (exper
= readchar())))
117 if(exper
== '\004') /* Give him an opportunity to get out */
119 printf("%c\n", exper
); /* echo */
120 if(index("Nn \n", exper
)) {
125 printf("\nTell me what kind of character you are:\n");
127 for(i
= 0; i
< NR_OF_ROLES
; i
++) {
128 printf(" a %s", roles
[i
]);
131 else if(i
< NR_OF_ROLES
- 2)
133 else if(i
== NR_OF_ROLES
- 2)
136 printf("? [%s] ", rolesyms
);
138 while(pc
= readchar()) {
139 if(islower(pc
)) pc
= toupper(pc
);
140 if((i
= role_index(pc
)) >= 0) {
141 printf("%c\n", pc
); /* echo */
142 (void) fflush(stdout
); /* should be seen */
147 if(pc
== '\004') /* Give him the opportunity to get out */
156 printf("\nI'll choose a character for you.\n");
157 i
= rn2(NR_OF_ROLES
);
159 printf("This game you will be a%s %s.\n",
160 exper
? "n experienced" : "",
163 /* give him some feedback in case mklev takes much time */
164 (void) putchar('\n');
165 (void) fflush(stdout
);
168 /* Given the above code, I can't see why this would ever change
169 anything; it does core pretty well, though. - cmh 4/20/93 */
177 (void) strncpy(pl_character
, roles
[i
], PL_CSIZ
-1);
178 pl_character
[PL_CSIZ
-1] = 0;
187 uarm
= uarm2
= uarmh
= uarms
= uarmg
= uwep
= uball
= uchain
=
193 Cave_man
[2].trquan
= 12 + rnd(9)*rnd(9);
194 u
.uhp
= u
.uhpmax
= 16;
195 u
.ustr
= u
.ustrmax
= 18;
200 Tourist
[3].trquan
= 20 + rnd(20);
201 u
.ugold
= u
.ugold0
= rnd(1000);
202 u
.uhp
= u
.uhpmax
= 10;
203 u
.ustr
= u
.ustrmax
= 8;
205 if(!rn2(25)) ini_inv(Tinopener
);
209 for(i
=1; i
<=4; i
++) if(!rn2(5))
210 Wizard
[i
].trquan
+= rn2(3) - 1;
211 u
.uhp
= u
.uhpmax
= 15;
212 u
.ustr
= u
.ustrmax
= 16;
219 u
.uhp
= u
.uhpmax
= 12;
220 u
.ustr
= u
.ustrmax
= 10;
221 ini_inv(Speleologist
);
222 if(!rn2(10)) ini_inv(Tinopener
);
226 u
.uhp
= u
.uhpmax
= 12;
227 u
.ustr
= u
.ustrmax
= 10;
232 u
.uhp
= u
.uhpmax
= 14;
233 u
.ustr
= u
.ustrmax
= 17;
236 default: /* impossible */
237 u
.uhp
= u
.uhpmax
= 12;
238 u
.ustr
= u
.ustrmax
= 16;
242 register int d
= rn2(7) - 2; /* biased variation */
248 if(wizard
) wiz_inv();
251 /* make sure he can carry all he has - especially for T's */
252 while(inv_weight() > 0 && u
.ustr
< 118)
253 u
.ustr
++, u
.ustrmax
++;
256 ini_inv(trop
) register struct trobj
*trop
; {
257 register struct obj
*obj
;
258 extern struct obj
*mkobj();
259 while(trop
->trolet
) {
260 obj
= mkobj(trop
->trolet
);
261 obj
->known
= trop
->trknown
;
262 /* not obj->dknown = 1; - let him look at it at least once */
264 if(obj
->olet
== WEAPON_SYM
){
265 obj
->quan
= trop
->trquan
;
268 if(trop
->trspe
!= UNDEF_SPE
)
269 obj
->spe
= trop
->trspe
;
270 if(trop
->trotyp
!= UNDEF_TYP
)
271 obj
->otyp
= trop
->trotyp
;
273 if(obj
->otyp
== WAN_WISHING
) /* gitpyr!robert */
274 obj
->otyp
= WAN_DEATH
;
275 obj
->owt
= weight(obj
); /* defined after setting otyp+quan */
277 if(obj
->olet
== ARMOR_SYM
){
280 if(!uarms
) setworn(obj
, W_ARMS
);
283 if(!uarmh
) setworn(obj
, W_ARMH
);
286 if(!uarmg
) setworn(obj
, W_ARMG
);
293 if(!uarm
) setworn(obj
, W_ARM
);
296 if(obj
->olet
== WEAPON_SYM
)
297 if(!uwep
) setuwep(obj
);
299 if(--trop
->trquan
) continue; /* make a similar object */
301 if(trop
->trquan
) { /* check if zero first */
304 continue; /* make a similar object */
313 register struct trobj
*trop
= &Extra_objs
[0];
314 extern char *getenv();
315 register char *ep
= getenv("INVENT");
320 if(ep
) while(*ep
== ',' || *ep
== ' ') ep
++;
321 if(type
<= 0 || type
> NROFOBJECTS
) continue;
323 trop
->trolet
= objects
[type
].oc_olet
;
329 /* give him a wand of wishing by default */
330 trop
->trotyp
= WAN_WISHING
;
331 trop
->trolet
= WAND_SYM
;
341 if(p
= rindex(plname
, '-')) {
343 pl_character
[0] = p
[1];
354 { /* must be called only from u_init() */
355 /* so that rolesyms[] is defined */
358 if(cp
= index(rolesyms
, pc
))
359 return(cp
- rolesyms
);