summaryrefslogtreecommitdiffstats
path: root/hack/hack.u_init.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>1997-10-19 16:56:41 +0000
committerchristos <christos@NetBSD.org>1997-10-19 16:56:41 +0000
commit84e7d0704483ce39bbdeacd5e676168db6fa664f (patch)
treef9ffeffa1a4342e749494bc3f5618552435839af /hack/hack.u_init.c
parentf73f1009084e75624e3bc00fef9cf4749de80dcc (diff)
downloadbsdgames-darwin-84e7d0704483ce39bbdeacd5e676168db6fa664f.tar.gz
bsdgames-darwin-84e7d0704483ce39bbdeacd5e676168db6fa664f.tar.zst
bsdgames-darwin-84e7d0704483ce39bbdeacd5e676168db6fa664f.zip
WARNsify...
Diffstat (limited to 'hack/hack.u_init.c')
-rw-r--r--hack/hack.u_init.c332
1 files changed, 178 insertions, 154 deletions
diff --git a/hack/hack.u_init.c b/hack/hack.u_init.c
index f61899d0..9f7ba082 100644
--- a/hack/hack.u_init.c
+++ b/hack/hack.u_init.c
@@ -1,186 +1,193 @@
+/* $NetBSD: hack.u_init.c,v 1.5 1997/10/19 16:59:19 christos Exp $ */
+
/*
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char rcsid[] = "$NetBSD: hack.u_init.c,v 1.4 1995/03/23 08:31:51 cgd Exp $";
-#endif /* not lint */
+__RCSID("$NetBSD: hack.u_init.c,v 1.5 1997/10/19 16:59:19 christos Exp $");
+#endif /* not lint */
-#include "hack.h"
-#include <stdio.h>
+#include <ctype.h>
#include <signal.h>
+#include <stdlib.h>
+#include "hack.h"
+#include "extern.h"
+
#define Strcpy (void) strcpy
#define Strcat (void) strcat
#define UNDEF_TYP 0
#define UNDEF_SPE '\177'
-extern struct obj *addinv();
-extern char *eos();
-extern char plname[];
-struct you zerou;
-char pl_character[PL_CSIZ];
-char *(roles[]) = { /* must all have distinct first letter */
- /* roles[4] may be changed to -woman */
+struct you zerou;
+char pl_character[PL_CSIZ];
+char *(roles[]) = { /* must all have distinct first letter */
+ /* roles[4] may be changed to -woman */
"Tourist", "Speleologist", "Fighter", "Knight",
"Cave-man", "Wizard"
};
#define NR_OF_ROLES SIZE(roles)
-char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
+char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
struct trobj {
- uchar trotyp;
- schar trspe;
- char trolet;
- Bitfield(trquan,6);
- Bitfield(trknown,1);
+ uchar trotyp;
+ schar trspe;
+ char trolet;
+ Bitfield(trquan, 6);
+ Bitfield(trknown, 1);
};
#ifdef WIZARD
-struct trobj Extra_objs[] = {
- { 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0 }
+struct trobj Extra_objs[] = {
+ {0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0}
};
-#endif WIZARD
+#endif /* WIZARD */
-struct trobj Cave_man[] = {
- { MACE, 1, WEAPON_SYM, 1, 1 },
- { BOW, 1, WEAPON_SYM, 1, 1 },
- { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */
- { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
- { 0, 0, 0, 0, 0}
+struct trobj Cave_man[] = {
+ {MACE, 1, WEAPON_SYM, 1, 1},
+ {BOW, 1, WEAPON_SYM, 1, 1},
+ {ARROW, 0, WEAPON_SYM, 25, 1}, /* quan is variable */
+ {LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1},
+ {0, 0, 0, 0, 0}
};
-struct trobj Fighter[] = {
- { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
- { RING_MAIL, 0, ARMOR_SYM, 1, 1 },
- { 0, 0, 0, 0, 0 }
+struct trobj Fighter[] = {
+ {TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1},
+ {RING_MAIL, 0, ARMOR_SYM, 1, 1},
+ {0, 0, 0, 0, 0}
};
-struct trobj Knight[] = {
- { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
- { SPEAR, 2, WEAPON_SYM, 1, 1 },
- { RING_MAIL, 1, ARMOR_SYM, 1, 1 },
- { HELMET, 0, ARMOR_SYM, 1, 1 },
- { SHIELD, 0, ARMOR_SYM, 1, 1 },
- { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 },
- { 0, 0, 0, 0, 0 }
+struct trobj Knight[] = {
+ {LONG_SWORD, 0, WEAPON_SYM, 1, 1},
+ {SPEAR, 2, WEAPON_SYM, 1, 1},
+ {RING_MAIL, 1, ARMOR_SYM, 1, 1},
+ {HELMET, 0, ARMOR_SYM, 1, 1},
+ {SHIELD, 0, ARMOR_SYM, 1, 1},
+ {PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1},
+ {0, 0, 0, 0, 0}
};
-struct trobj Speleologist[] = {
- { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 },
- { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
- { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
- { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 },
- { ICE_BOX, 0, TOOL_SYM, 1, 0 },
- { 0, 0, 0, 0, 0}
+struct trobj Speleologist[] = {
+ {STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1},
+ {UNDEF_TYP, 0, POTION_SYM, 2, 0},
+ {FOOD_RATION, 0, FOOD_SYM, 3, 1},
+ {PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0},
+ {ICE_BOX, 0, TOOL_SYM, 1, 0},
+ {0, 0, 0, 0, 0}
};
-struct trobj Tinopener[] = {
- { CAN_OPENER, 0, TOOL_SYM, 1, 1 },
- { 0, 0, 0, 0, 0 }
+struct trobj Tinopener[] = {
+ {CAN_OPENER, 0, TOOL_SYM, 1, 1},
+ {0, 0, 0, 0, 0}
};
-struct trobj Tourist[] = {
- { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
- { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
- { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
- { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */
- { 0, 0, 0, 0, 0 }
+struct trobj Tourist[] = {
+ {UNDEF_TYP, 0, FOOD_SYM, 10, 1},
+ {POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0},
+ {EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1},
+ {DART, 2, WEAPON_SYM, 25, 1}, /* quan is variable */
+ {0, 0, 0, 0, 0}
};
-struct trobj Wizard[] = {
- { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 },
- { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
- { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
- { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
- { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
- { 0, 0, 0, 0, 0 }
+struct trobj Wizard[] = {
+ {ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1},
+ {UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0},
+ {UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0},
+ {UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0},
+ {UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0},
+ {0, 0, 0, 0, 0}
};
-u_init(){
-register int i;
-char exper = 'y', pc;
-extern char readchar();
- if(flags.female) /* should have been set in HACKOPTIONS */
+void
+u_init()
+{
+ int i;
+ char exper = 'y', pc;
+ if (flags.female) /* should have been set in HACKOPTIONS */
roles[4] = "Cave-woman";
- for(i = 0; i < NR_OF_ROLES; i++)
+ for (i = 0; i < NR_OF_ROLES; i++)
rolesyms[i] = roles[i][0];
rolesyms[i] = 0;
- if(pc = pl_character[0]) {
- if(islower(pc)) pc = toupper(pc);
- if((i = role_index(pc)) >= 0)
+ if ((pc = pl_character[0]) != '\0') {
+ if (islower(pc))
+ pc = toupper(pc);
+ if ((i = role_index(pc)) >= 0)
goto got_suffix; /* implies experienced */
printf("\nUnknown role: %c\n", pc);
pl_character[0] = pc = 0;
}
-
printf("\nAre you an experienced player? [ny] ");
- while(!index("ynYN \n\004", (exper = readchar())))
+ while (!strchr("ynYN \n\004", (exper = readchar())))
bell();
- if(exper == '\004') /* Give him an opportunity to get out */
+ if (exper == '\004') /* Give him an opportunity to get out */
end_of_input();
- printf("%c\n", exper); /* echo */
- if(index("Nn \n", exper)) {
+ printf("%c\n", exper); /* echo */
+ if (strchr("Nn \n", exper)) {
exper = 0;
goto beginner;
}
-
printf("\nTell me what kind of character you are:\n");
printf("Are you");
- for(i = 0; i < NR_OF_ROLES; i++) {
+ for (i = 0; i < NR_OF_ROLES; i++) {
printf(" a %s", roles[i]);
- if(i == 2) /* %% */
+ if (i == 2) /* %% */
printf(",\n\t");
- else if(i < NR_OF_ROLES - 2)
+ else if (i < NR_OF_ROLES - 2)
printf(",");
- else if(i == NR_OF_ROLES - 2)
+ else if (i == NR_OF_ROLES - 2)
printf(" or");
}
printf("? [%s] ", rolesyms);
- while(pc = readchar()) {
- if(islower(pc)) pc = toupper(pc);
- if((i = role_index(pc)) >= 0) {
+ while ((pc = readchar()) != '\0') {
+ if (islower(pc))
+ pc = toupper(pc);
+ if ((i = role_index(pc)) >= 0) {
printf("%c\n", pc); /* echo */
(void) fflush(stdout); /* should be seen */
break;
}
- if(pc == '\n')
+ if (pc == '\n')
break;
- if(pc == '\004') /* Give him the opportunity to get out */
+ if (pc == '\004') /* Give him the opportunity to get
+ * out */
end_of_input();
bell();
}
- if(pc == '\n')
+ if (pc == '\n')
pc = 0;
beginner:
- if(!pc) {
+ if (!pc) {
printf("\nI'll choose a character for you.\n");
i = rn2(NR_OF_ROLES);
pc = rolesyms[i];
printf("This game you will be a%s %s.\n",
- exper ? "n experienced" : "",
- roles[i]);
+ exper ? "n experienced" : "",
+ roles[i]);
getret();
/* give him some feedback in case mklev takes much time */
(void) putchar('\n');
(void) fflush(stdout);
}
#if 0
- /* Given the above code, I can't see why this would ever change
- anything; it does core pretty well, though. - cmh 4/20/93 */
- if(exper) {
+ /*
+ * Given the above code, I can't see why this would ever change
+ * anything; it does core pretty well, though. - cmh 4/20/93
+ */
+ if (exper) {
roles[i][0] = pc;
}
#endif
got_suffix:
- (void) strncpy(pl_character, roles[i], PL_CSIZ-1);
- pl_character[PL_CSIZ-1] = 0;
+ (void) strncpy(pl_character, roles[i], PL_CSIZ - 1);
+ pl_character[PL_CSIZ - 1] = 0;
flags.beginner = 1;
u = zerou;
u.usym = '@';
@@ -188,14 +195,14 @@ got_suffix:
init_uhunger();
#ifdef QUEST
u.uhorizon = 6;
-#endif QUEST
+#endif /* QUEST */
uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
- uleft = uright = 0;
+ uleft = uright = 0;
- switch(pc) {
+ switch (pc) {
case 'c':
case 'C':
- Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
+ Cave_man[2].trquan = 12 + rnd(9) * rnd(9);
u.uhp = u.uhpmax = 16;
u.ustr = u.ustrmax = 18;
ini_inv(Cave_man);
@@ -207,12 +214,14 @@ got_suffix:
u.uhp = u.uhpmax = 10;
u.ustr = u.ustrmax = 8;
ini_inv(Tourist);
- if(!rn2(25)) ini_inv(Tinopener);
+ if (!rn2(25))
+ ini_inv(Tinopener);
break;
case 'w':
case 'W':
- for(i=1; i<=4; i++) if(!rn2(5))
- Wizard[i].trquan += rn2(3) - 1;
+ for (i = 1; i <= 4; i++)
+ if (!rn2(5))
+ Wizard[i].trquan += rn2(3) - 1;
u.uhp = u.uhpmax = 15;
u.ustr = u.ustrmax = 16;
ini_inv(Wizard);
@@ -224,7 +233,8 @@ got_suffix:
u.uhp = u.uhpmax = 12;
u.ustr = u.ustrmax = 10;
ini_inv(Speleologist);
- if(!rn2(10)) ini_inv(Tinopener);
+ if (!rn2(10))
+ ini_inv(Tinopener);
break;
case 'k':
case 'K':
@@ -238,92 +248,103 @@ got_suffix:
u.ustr = u.ustrmax = 17;
ini_inv(Fighter);
break;
- default: /* impossible */
+ default: /* impossible */
u.uhp = u.uhpmax = 12;
u.ustr = u.ustrmax = 16;
}
find_ac();
- if(!rn2(20)) {
- register int d = rn2(7) - 2; /* biased variation */
+ if (!rn2(20)) {
+ int d = rn2(7) - 2; /* biased variation */
u.ustr += d;
u.ustrmax += d;
}
-
#ifdef WIZARD
- if(wizard) wiz_inv();
-#endif WIZARD
+ if (wizard)
+ wiz_inv();
+#endif /* WIZARD */
/* make sure he can carry all he has - especially for T's */
- while(inv_weight() > 0 && u.ustr < 118)
+ while (inv_weight() > 0 && u.ustr < 118)
u.ustr++, u.ustrmax++;
}
-ini_inv(trop) register struct trobj *trop; {
-register struct obj *obj;
-extern struct obj *mkobj();
- while(trop->trolet) {
+void
+ini_inv(trop)
+ struct trobj *trop;
+{
+ struct obj *obj;
+ while (trop->trolet) {
obj = mkobj(trop->trolet);
obj->known = trop->trknown;
/* not obj->dknown = 1; - let him look at it at least once */
obj->cursed = 0;
- if(obj->olet == WEAPON_SYM){
+ if (obj->olet == WEAPON_SYM) {
obj->quan = trop->trquan;
trop->trquan = 1;
}
- if(trop->trspe != UNDEF_SPE)
+ if (trop->trspe != UNDEF_SPE)
obj->spe = trop->trspe;
- if(trop->trotyp != UNDEF_TYP)
+ if (trop->trotyp != UNDEF_TYP)
obj->otyp = trop->trotyp;
- else
- if(obj->otyp == WAN_WISHING) /* gitpyr!robert */
- obj->otyp = WAN_DEATH;
+ else if (obj->otyp == WAN_WISHING) /* gitpyr!robert */
+ obj->otyp = WAN_DEATH;
obj->owt = weight(obj); /* defined after setting otyp+quan */
obj = addinv(obj);
- if(obj->olet == ARMOR_SYM){
- switch(obj->otyp){
+ if (obj->olet == ARMOR_SYM) {
+ switch (obj->otyp) {
case SHIELD:
- if(!uarms) setworn(obj, W_ARMS);
+ if (!uarms)
+ setworn(obj, W_ARMS);
break;
case HELMET:
- if(!uarmh) setworn(obj, W_ARMH);
+ if (!uarmh)
+ setworn(obj, W_ARMH);
break;
case PAIR_OF_GLOVES:
- if(!uarmg) setworn(obj, W_ARMG);
+ if (!uarmg)
+ setworn(obj, W_ARMG);
break;
case ELVEN_CLOAK:
- if(!uarm2)
+ if (!uarm2)
setworn(obj, W_ARM);
break;
default:
- if(!uarm) setworn(obj, W_ARM);
+ if (!uarm)
+ setworn(obj, W_ARM);
}
}
- if(obj->olet == WEAPON_SYM)
- if(!uwep) setuwep(obj);
+ if (obj->olet == WEAPON_SYM)
+ if (!uwep)
+ setuwep(obj);
#ifndef PYRAMID_BUG
- if(--trop->trquan) continue; /* make a similar object */
+ if (--trop->trquan)
+ continue; /* make a similar object */
#else
- if(trop->trquan) { /* check if zero first */
+ if (trop->trquan) { /* check if zero first */
--trop->trquan;
- if(trop->trquan)
+ if (trop->trquan)
continue; /* make a similar object */
}
-#endif PYRAMID_BUG
+#endif /* PYRAMID_BUG */
trop++;
}
}
#ifdef WIZARD
-wiz_inv(){
-register struct trobj *trop = &Extra_objs[0];
-extern char *getenv();
-register char *ep = getenv("INVENT");
-register int type;
- while(ep && *ep) {
+void
+wiz_inv()
+{
+ struct trobj *trop = &Extra_objs[0];
+ char *ep = getenv("INVENT");
+ int type;
+ while (ep && *ep) {
type = atoi(ep);
- ep = index(ep, ',');
- if(ep) while(*ep == ',' || *ep == ' ') ep++;
- if(type <= 0 || type > NROFOBJECTS) continue;
+ ep = strchr(ep, ',');
+ if (ep)
+ while (*ep == ',' || *ep == ' ')
+ ep++;
+ if (type <= 0 || type > NROFOBJECTS)
+ continue;
trop->trotyp = type;
trop->trolet = objects[type].oc_olet;
trop->trspe = 4;
@@ -339,28 +360,31 @@ register int type;
trop->trquan = 1;
ini_inv(trop);
}
-#endif WIZARD
+#endif /* WIZARD */
-plnamesuffix() {
-register char *p;
- if(p = rindex(plname, '-')) {
+void
+plnamesuffix()
+{
+ char *p;
+ if ((p = strrchr(plname, '-')) != NULL) {
*p = 0;
pl_character[0] = p[1];
pl_character[1] = 0;
- if(!plname[0]) {
+ if (!plname[0]) {
askname();
plnamesuffix();
}
}
}
+int
role_index(pc)
-char pc;
-{ /* must be called only from u_init() */
- /* so that rolesyms[] is defined */
- register char *cp;
+ char pc;
+{ /* must be called only from u_init() */
+ /* so that rolesyms[] is defined */
+ char *cp;
- if(cp = index(rolesyms, pc))
- return(cp - rolesyms);
- return(-1);
+ if ((cp = strchr(rolesyms, pc)) != NULL)
+ return (cp - rolesyms);
+ return (-1);
}