From c015d2f9aa4fbe23c4e9e50742dcebee298b0287 Mon Sep 17 00:00:00 2001 From: dholland Date: Mon, 4 Feb 2008 01:07:01 +0000 Subject: More assorted cleanup merged from larn 12.2. --- larn/extern.h | 4 +- larn/global.c | 52 ++------------------ larn/moreobj.c | 21 ++------ larn/object.c | 26 ++-------- larn/tok.c | 150 +++++++++++++++++++++++++-------------------------------- 5 files changed, 78 insertions(+), 175 deletions(-) (limited to 'larn') diff --git a/larn/extern.h b/larn/extern.h index dba6a213..97b697bc 100644 --- a/larn/extern.h +++ b/larn/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.10 2008/02/03 21:24:58 dholland Exp $ */ +/* $NetBSD: extern.h,v 1.11 2008/02/04 01:07:01 dholland Exp $ */ /* * Copyright (c) 1997 Christos Zoulas. All rights reserved. @@ -76,9 +76,7 @@ void losehp(int); void losemhp(int); void raisehp(int); void raisemhp(int); -void raisespells(int); void raisemspells(int); -void losespells(int); void losemspells(int); int makemonst(int); void positionplayer(void); diff --git a/larn/global.c b/larn/global.c index 678ae639..bade6a23 100644 --- a/larn/global.c +++ b/larn/global.c @@ -1,4 +1,4 @@ -/* $NetBSD: global.c,v 1.11 2008/02/03 21:24:58 dholland Exp $ */ +/* $NetBSD: global.c,v 1.12 2008/02/04 01:07:01 dholland Exp $ */ /* * global.c Larn is copyrighted 1986 by Noah Morgan. @@ -11,19 +11,17 @@ * losemhp(x) subroutine to remove max # hit points from the player * raisehp(x) subroutine to gain hit points * raisemhp(x) subroutine to gain maximum hit points - * losespells(x) subroutine to lose spells * losemspells(x) subroutine to lose maximum spells - * raisespells(x) subroutine to gain spells * raisemspells(x) subroutine to gain maximum spells - * recalc() function to recalculate the armor class of the player * makemonst(lev) function to return monster number for a randomly * selected monster * positionplayer() function to be sure player is not in a wall + * recalc() function to recalculate the armor class of the player * quit() subroutine to ask if the player really wants to quit */ #include #ifndef lint -__RCSID("$NetBSD: global.c,v 1.11 2008/02/03 21:24:58 dholland Exp $"); +__RCSID("$NetBSD: global.c,v 1.12 2008/02/04 01:07:01 dholland Exp $"); #endif /* not lint */ #include @@ -37,9 +35,6 @@ extern char sciv[SCORESIZE + 1][26][2]; extern char *password; /* - *********** - RAISE LEVEL - *********** raiselevel() subroutine to raise the player one level @@ -54,9 +49,6 @@ raiselevel() } /* - *********** - LOOSE LEVEL - *********** loselevel() subroutine to lower the players character level by one @@ -69,9 +61,6 @@ loselevel() } /* - **************** - RAISE EXPERIENCE - **************** raiseexperience(x) subroutine to increase experience points @@ -100,9 +89,6 @@ raiseexperience(x) } /* - **************** - LOOSE EXPERIENCE - **************** loseexperience(x) subroutine to lose experience points @@ -134,9 +120,6 @@ loseexperience(x) } /* - ******** - LOOSE HP - ******** losehp(x) losemhp(x) @@ -168,9 +151,6 @@ losemhp(x) } /* - ******** - RAISE HP - ******** raisehp(x) raisemhp(x) @@ -193,22 +173,10 @@ raisemhp(x) } /* - ************ - RAISE SPELLS - ************ - raisespells(x) raisemspells(x) subroutine to gain maximum spells */ -void -raisespells(x) - int x; -{ - if ((c[SPELLS] += x) > c[SPELLMAX]) - c[SPELLS] = c[SPELLMAX]; -} - void raisemspells(x) int x; @@ -218,22 +186,10 @@ raisemspells(x) } /* - ************ - LOOSE SPELLS - ************ - losespells(x) losemspells(x) subroutine to lose maximum spells */ -void -losespells(x) - int x; -{ - if ((c[SPELLS] -= x) < 0) - c[SPELLS] = 0; -} - void losemspells(x) int x; @@ -809,7 +765,7 @@ getpassword() lflush(); i = strlen(password); for (j = 0; j < i; j++) - read(0, gpwp++, 1); + *gpwp++ = ttgetch(); gpwbuf[i] = 0; sncbr(); /* system("stty echo -cbreak"); */ if (strcmp(gpwbuf, password) != 0) { diff --git a/larn/moreobj.c b/larn/moreobj.c index 7854cf7d..b515fbff 100644 --- a/larn/moreobj.c +++ b/larn/moreobj.c @@ -1,4 +1,4 @@ -/* $NetBSD: moreobj.c,v 1.9 2008/02/03 21:24:58 dholland Exp $ */ +/* $NetBSD: moreobj.c,v 1.10 2008/02/04 01:07:01 dholland Exp $ */ /* * moreobj.c Larn is copyrighted 1986 by Noah Morgan. @@ -9,7 +9,7 @@ */ #include #ifndef lint -__RCSID("$NetBSD: moreobj.c,v 1.9 2008/02/03 21:24:58 dholland Exp $"); +__RCSID("$NetBSD: moreobj.c,v 1.10 2008/02/04 01:07:01 dholland Exp $"); #endif /* not lint */ #include #include @@ -20,10 +20,6 @@ static void ohear(void); static void fch(int, long *); /* - * ****** - * OALTAR - * ****** - * * subroutine to process an altar object */ void @@ -137,10 +133,6 @@ ohear() } /* - ******* - OTHRONE - ******* - subroutine to process a throne object */ void @@ -224,10 +216,6 @@ odeadthrone() } /* - ****** - OCHEST - ****** - subroutine to process a throne object */ void @@ -294,11 +282,8 @@ ochest() } /* - ********* - OFOUNTAIN - ********* + process a fountain object */ - void ofountain() { diff --git a/larn/object.c b/larn/object.c index 691f9780..74b4d97b 100644 --- a/larn/object.c +++ b/larn/object.c @@ -1,18 +1,16 @@ -/* $NetBSD: object.c,v 1.13 2008/02/03 21:24:59 dholland Exp $ */ +/* $NetBSD: object.c,v 1.14 2008/02/04 01:07:01 dholland Exp $ */ /* object.c Larn is copyrighted 1986 by Noah Morgan. */ #include #ifndef lint -__RCSID("$NetBSD: object.c,v 1.13 2008/02/03 21:24:59 dholland Exp $"); +__RCSID("$NetBSD: object.c,v 1.14 2008/02/04 01:07:01 dholland Exp $"); #endif /* not lint */ #include "header.h" #include "extern.h" /* - *************** - LOOK_FOR_OBJECT - *************** + lookforobject subroutine to look for an object and give the player his options if an object was found. @@ -22,7 +20,7 @@ lookforobject() { int i, j; if (c[TIMESTOP]) - return; /* can't find objects is time is stopped */ + return; /* can't find objects if time is stopped */ i = item[playerx][playery]; if (i == 0) return; @@ -537,10 +535,6 @@ finditem(int theitem) /* - ******* - OSTAIRS - ******* - subroutine to process the stair cases if dir > 0 the up else down */ @@ -608,10 +602,6 @@ ostairs(dir) /* - ********* - OTELEPORTER - ********* - subroutine to handle a teleport trap +/- 1 level maximum */ void @@ -649,10 +639,6 @@ oteleport(err) /* - ******* - OPOTION - ******* - function to process a potion */ void @@ -862,10 +848,6 @@ quaffpotion(pot) /* - ******* - OSCROLL - ******* - function to process a magic scroll */ void diff --git a/larn/tok.c b/larn/tok.c index 6ca1f672..1a9b8bca 100644 --- a/larn/tok.c +++ b/larn/tok.c @@ -1,9 +1,9 @@ -/* $NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $ */ +/* $NetBSD: tok.c,v 1.10 2008/02/04 01:07:01 dholland Exp $ */ /* tok.c Larn is copyrighted 1986 by Noah Morgan. */ #include #ifndef lint -__RCSID("$NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $"); +__RCSID("$NetBSD: tok.c,v 1.10 2008/02/04 01:07:01 dholland Exp $"); #endif /* not lint */ #include @@ -16,6 +16,9 @@ __RCSID("$NetBSD: tok.c,v 1.9 2008/02/03 20:11:05 dholland Exp $"); #include "header.h" #include "extern.h" +/* Keystrokes (roughly) between checkpoints */ +#define CHECKPOINT_INTERVAL 400 + static char lastok = 0; int yrepcount = 0; #ifndef FLUSHNO @@ -53,9 +56,9 @@ yylex() lflush(); while (1) { c[BYTESIN]++; + /* check for periodic checkpointing */ if (ckpflag) - if ((c[BYTESIN] % 400) == 0) { /* check for periodic - * checkpointing */ + if ((c[BYTESIN] % CHECKPOINT_INTERVAL) == 0) { #ifndef DOCHECKPOINTS savegame(ckpfile); #else @@ -133,6 +136,8 @@ sethard(hard) int hard; { int j, k, i; + struct monst *mp; + j = c[HARDGAME]; hashewon(); if (restorflag == 0) { /* don't set c[HARDGAME] if restoring game */ @@ -144,16 +149,17 @@ sethard(hard) if ((k = c[HARDGAME]) != 0) for (j = 0; j <= MAXMONST + 8; j++) { - i = ((6 + k) * monster[j].hitpoints + 1) / 6; - monster[j].hitpoints = (i < 0) ? 32767 : i; - i = ((6 + k) * monster[j].damage + 1) / 5; - monster[j].damage = (i > 127) ? 127 : i; - i = (10 * monster[j].gold) / (10 + k); - monster[j].gold = (i > 32767) ? 32767 : i; - i = monster[j].armorclass - k; - monster[j].armorclass = (i < -127) ? -127 : i; - i = (7 * monster[j].experience) / (7 + k) + 1; - monster[j].experience = (i <= 0) ? 1 : i; + mp = &monster[j]; + i = ((6 + k) * mp->hitpoints + 1) / 6; + mp->hitpoints = (i < 0) ? 32767 : i; + i = ((6 + k) * mp->damage + 1) / 5; + mp->damage = (i > 127) ? 127 : i; + i = (10 * mp->gold) / (10 + k); + mp->gold = (i > 32767) ? 32767 : i; + i = mp->armorclass - k; + mp->armorclass = (i < -127) ? -127 : i; + i = (7 * mp->experience) / (7 + k) + 1; + mp->experience = (i <= 0) ? 1 : i; } } @@ -166,8 +172,9 @@ readopts() const char *i; int j, k; int flag; - flag = 1; /* set to 0 if he specifies a name for his - * character */ + + flag = 1; /* set to 0 if a name is specified */ + if (lopen(optsfile) < 0) { strcpy(logname, loginname); return; /* user name if no character name */ @@ -178,76 +185,51 @@ readopts() break; /* check for EOF */ while ((*i == ' ') || (*i == '\t')) i++; /* eat leading whitespace */ - switch (*i) { - case 'b': - if (strcmp(i, "bold-objects") == 0) - boldon = 1; - break; - - case 'e': - if (strcmp(i, "enable-checkpointing") == 0) - ckpflag = 1; - break; - - case 'i': - if (strcmp(i, "inverse-objects") == 0) - boldon = 0; - break; - - case 'f': - if (strcmp(i, "female") == 0) - sex = 0; /* male or female */ - break; - case 'm': - if (strcmp(i, "monster:") == 0) { /* name favorite monster */ - if ((i = lgetw()) == 0) - break; - strlcpy(usermonster[usermpoint], i, MAXMNAME); - if (usermpoint >= MAXUM) - break; /* defined all of em */ - if (isalpha(j = usermonster[usermpoint][0])) { - for (k = 1; k < MAXMONST + 8; k++) /* find monster */ - if (monstnamelist[k] == j) { - monster[k].name = &usermonster[usermpoint++][0]; - break; - } - } - } else if (strcmp(i, "male") == 0) - sex = 1; - break; - - case 'n': - if (strcmp(i, "name:") == 0) { /* defining players name */ - if ((i = lgetw()) == 0) - break; - strlcpy(logname, i, LOGNAMESIZE); - flag = 0; - } else if (strcmp(i, "no-introduction") == 0) - nowelcome = 1; - else if (strcmp(i, "no-beep") == 0) - nobeep = 1; - break; - - case 'p': - if (strcmp(i, "process-name:") == 0) { - if ((i = lgetw()) == 0) - break; - strlcpy(psname, i, PSNAMESIZE); - } else if (strcmp(i, "play-day-play") == 0) { - /* bypass time restrictions: ignored */ + if (strcmp(i, "bold-objects") == 0) + boldon = 1; + else if (strcmp(i, "enable-checkpointing") == 0) + ckpflag = 1; + else if (strcmp(i, "inverse-objects") == 0) + boldon = 0; + else if (strcmp(i, "female") == 0) + sex = 0; /* male or female */ + else if (strcmp(i, "monster:") == 0) { /* name favorite monster */ + if ((i = lgetw()) == 0) + break; + strlcpy(usermonster[usermpoint], i, MAXMNAME); + if (usermpoint >= MAXUM) + continue; /* defined all of em */ + if (isalpha(j = usermonster[usermpoint][0])) { + for (k = 1; k < MAXMONST + 8; k++) /* find monster */ + if (monstnamelist[k] == j) { + monster[k].name = &usermonster[usermpoint++][0]; + break; + } } - break; - - case 's': - if (strcmp(i, "savefile:") == 0) { /* defining savefilename */ - if ((i = lgetw()) == 0) - break; - strcpy(savefilename, i); - flag = 0; - } - break; - }; + } else if (strcmp(i, "male") == 0) + sex = 1; + else if (strcmp(i, "name:") == 0) { /* defining players name */ + if ((i = lgetw()) == 0) + break; + strlcpy(logname, i, LOGNAMESIZE); + flag = 0; + } else if (strcmp(i, "no-introduction") == 0) + nowelcome = 1; + else if (strcmp(i, "no-beep") == 0) + nobeep = 1; + else if (strcmp(i, "process-name:") == 0) { + if ((i = lgetw()) == 0) + break; + strlcpy(psname, i, PSNAMESIZE); + } else if (strcmp(i, "play-day-play") == 0) { + /* bypass time restrictions: ignored */ + } else if (strcmp(i, "savefile:") == 0) { /* defining savefilename */ + if ((i = lgetw()) == 0) + break; + strcpy(savefilename, i); + flag = 0; + } } if (flag) strcpy(logname, loginname); -- cgit v1.2.3-56-ge451