-+-+-+-+-+-+-+-+ START OF PART 10 -+-+-+-+-+-+-+-+ X nlines = lines; X X /* get memory for array of pointers to each fortune */ X if ((flines=(char**)malloc(nlines*sizeof(char*))) == 0) `7B X free((char*)base); X fd= -1; X return(0); /* malloc() failure */ X `7D X X /* now assign each pointer to a line */ X for (p=base,tmp=0; tmp 2) /* if we have a database to look at */ X return(flines`5Brund((nlines<=0)?1:nlines)`5D); X else X return(0); X`7D X# endif $ CALL UNPACK FORTUNE.C;1 961360194 $ create 'f' X/* global.c X * X * raiselevel() subroutine to raise the player one level X * loselevel() subroutine to lower the player by one level X * raiseexperience(x) subroutine to increase experience points X * loseexperience(x) subroutine to lose experience points X * losehp(x) subroutine to remove hit points from the player X * losemhp(x) subroutine to remove max # hit points from the playe Vr X * raisehp(x) subroutine to gain hit points X * raisemhp(x) subroutine to gain maximum hit points X * losemspells(x) subroutine to lose maximum spells X * raisemspells(x) subroutine to gain maximum spells X * makemonst(lev) function to return monster number for a randomly sel Vected monster X * positionplayer() function to be sure player is not in a wall X * recalc() function to recalculate the armor class of the playe Vr X * quit() subroutine to ask if the player really wants to quit X * more() X * take() X * drop_object() X * enchantarmor() X * enchweapon() X * pocketfull() X * nearbymonst() X * stealsomething() X * emptyhanded() X * creategem() X * adjustcvalues() X * gettokstr() X * getpassword() X * getyn() X * packweight() X */ X X#include X#include "header.h" X#include "larndefs.h" X#include "monsters.h" X#include "objects.h" X#include "player.h" X Xextern int score`5B`5D,dropflag; Xextern short playerx,playery,lastnum; Xextern char cheat,level,monstnamelist`5B`5D; Xextern char lastmonst`5B`5D,*what`5B`5D,*who`5B`5D;`20 Xextern char winner`5B`5D; Xextern char logname`5B`5D,monstlevel`5B`5D; Xextern char sciv`5BSCORESIZE+1`5D`5B26`5D`5B2`5D,*potionname`5B`5D,*scrollna Vme`5B`5D; X X#ifdef __STDC__ Xextern void show3( int ); X#else Xextern void show3(); X#endif X X/* X raiselevel() X X subroutine to raise the player one level X uses the skill`5B`5D array to find level boundarys X uses c`5BEXPERIENCE`5D c`5BLEVEL`5D X */ Xraiselevel() X `7B X if (c`5BLEVEL`5D < MAXPLEVEL) raiseexperience((long)(skill`5Bc`5BLEVEL`5 VD`5D-c`5BEXPERIENCE`5D)); X `7D X X/* X loselevel() X X subroutine to lower the players character level by one X */ Xloselevel() X `7B X if (c`5BLEVEL`5D > 1) loseexperience((long)(c`5BEXPERIENCE`5D - skill`5B Vc`5BLEVEL`5D-1`5D + 1)); X `7D X X/* X raiseexperience(x) X X subroutine to increase experience points X */ Xraiseexperience(x) X register long x; X `7B X register int i,tmp; X i=c`5BLEVEL`5D; c`5BEXPERIENCE`5D+=x; X while (c`5BEXPERIENCE`5D >= skill`5Bc`5BLEVEL`5D`5D && (c`5BLEVEL`5D < M VAXPLEVEL)) X `7B X tmp = (c`5BCONSTITUTION`5D-c`5BHARDGAME`5D)>>1; X c`5BLEVEL`5D++; raisemhp((int)(rnd(3)+rnd((tmp>0)?tmp:1))); X raisemspells((int)rund(3)); X if (c`5BLEVEL`5D < 7-c`5BHARDGAME`5D) raisemhp((int)(c`5BCONSTITUTIO VN`5D>>2)); X `7D X if (c`5BLEVEL`5D != i) X `7B X cursors(); X beep(); lprintf("\nWelcome to level %d",(long)c`5BLEVEL`5D); /* i Vf we changed levels */ X `7D X bottomline(); X `7D X X/* X loseexperience(x) X X subroutine to lose experience points X */ Xloseexperience(x) X register long x; X `7B X register int i,tmp; X i=c`5BLEVEL`5D; c`5BEXPERIENCE`5D-=x; X if (c`5BEXPERIENCE`5D < 0) c`5BEXPERIENCE`5D=0; X while (c`5BEXPERIENCE`5D < skill`5Bc`5BLEVEL`5D-1`5D) X `7B X if (--c`5BLEVEL`5D <= 1) c`5BLEVEL`5D=1; /* down one level V */ X tmp = (c`5BCONSTITUTION`5D-c`5BHARDGAME`5D)>>1; /* lose hpoints */ X losemhp((int)rnd((tmp>0)?tmp:1)); /* lose hpoints */ X if (c`5BLEVEL`5D < 7-c`5BHARDGAME`5D) losemhp((int)(c`5BCONSTITUTION V`5D>>2)); X losemspells((int)rund(3)); /* lose spells */ X `7D X if (i!=c`5BLEVEL`5D) X `7B X cursors(); X beep(); lprintf("\nYou went down to level %d!",(long)c`5BLEVEL`5D); X `7D X bottomline(); X `7D X X/* X losehp(x) X losemhp(x) X X subroutine to remove hit points from the player X warning -- will kill player if hp goes to zero X */ Xlosehp(x) X register int x; X `7B X if ((c`5BHP`5D -= x) <= 0) X `7B X beep(); lprcat("\n"); nap(3000); died(lastnum); X `7D X `7D X Xlosemhp(x) X register int x; X `7B X c`5BHP`5D -= x; if (c`5BHP`5D < 1) c`5BHP`5D=1; X c`5BHPMAX`5D -= x; if (c`5BHPMAX`5D < 1) c`5BHPMAX`5D=1; X `7D X X/* X raisehp(x) X raisemhp(x) X X subroutine to gain maximum hit points X */ Xraisehp(x) X register int x; X `7B X if ((c`5BHP`5D += x) > c`5BHPMAX`5D) c`5BHP`5D = c`5BHPMAX`5D; X `7D X Xraisemhp(x) X register int x; X `7B X c`5BHPMAX`5D += x; c`5BHP`5D += x; X `7D X X/* X raisemspells(x) X X subroutine to gain maximum spells X*/ Xraisemspells(x) X register int x; X `7B X c`5BSPELLMAX`5D+=x; c`5BSPELLS`5D+=x; X `7D X X/* X losemspells(x) X X subroutine to lose maximum spells X*/ Xlosemspells(x) X register int x; X `7B X if ((c`5BSPELLMAX`5D -= x) < 0) c`5BSPELLMAX`5D=0; X if ((c`5BSPELLS`5D -= x) < 0) c`5BSPELLS`5D=0; X `7D X X/* X makemonst(lev) X int lev; X X function to return monster number for a randomly selected monster X for the given cave level `20 X */ Xmakemonst(lev) X register int lev; X `7B X register int tmp,x; X if (lev < 1) X lev = 1; X if (lev > 12) X lev = 12; X if (lev < 5) X tmp=rnd((x=monstlevel`5Blev-1`5D)?x:1); X else X tmp=rnd((x=monstlevel`5Blev-1`5D-monstlevel`5Blev-4`5D)?x:1)+monstle Vvel`5Blev-4`5D; X X while (monster`5Btmp`5D.genocided && tmp= MAXX-1) X `7B X playerx = 1; X if (++playery >= MAXY-1) X `7B X playery = 1; X try--; X `7D X `7D X `7D X while (try); X X /* no spot found. X */ X lprcat("Failure in positionplayer\n"); X `7D X X/* X recalc() function to recalculate the armor class of the player X */ Xrecalc() X `7B X register int i,j,k; X c`5BAC`5D = c`5BMOREDEFENSES`5D; X if (c`5BWEAR`5D >= 0) `20 X switch(iven`5Bc`5BWEAR`5D`5D) X `7B X case OSHIELD: c`5BAC`5D += 2 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case OLEATHER: c`5BAC`5D += 2 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case OSTUDLEATHER: c`5BAC`5D += 3 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case ORING: c`5BAC`5D += 5 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case OCHAIN: c`5BAC`5D += 6 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case OSPLINT: c`5BAC`5D += 7 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case OPLATE: c`5BAC`5D += 9 + ivenarg`5Bc`5BWEAR`5D`5D; b Vreak; X case OPLATEARMOR: c`5BAC`5D += 10 + ivenarg`5Bc`5BWEAR`5D`5D; V break; X case OSSPLATE: c`5BAC`5D += 12 + ivenarg`5Bc`5BWEAR`5D`5D; V break; X `7D X X if (c`5BSHIELD`5D >= 0) if (iven`5Bc`5BSHIELD`5D`5D == OSHIELD) c`5BAC`5 VD += 2 + ivenarg`5Bc`5BSHIELD`5D`5D; X if (c`5BWIELD`5D < 0) c`5BWCLASS`5D = 0; else X `7B X i = ivenarg`5Bc`5BWIELD`5D`5D; X switch(iven`5Bc`5BWIELD`5D`5D) X `7B X case ODAGGER: c`5BWCLASS`5D = 3 + i; break; X case OBELT: c`5BWCLASS`5D = 7 + i; break; X case OSHIELD: c`5BWCLASS`5D = 8 + i; break; X case OSPEAR: c`5BWCLASS`5D = 10 + i; break; X case OFLAIL: c`5BWCLASS`5D = 14 + i; break; X case OBATTLEAXE: c`5BWCLASS`5D = 17 + i; break; X case OLANCE: c`5BWCLASS`5D = 19 + i; break; X case OLONGSWORD: c`5BWCLASS`5D = 22 + i; break; X case O2SWORD: c`5BWCLASS`5D = 26 + i; break; X case OSWORD: c`5BWCLASS`5D = 32 + i; break; X case OSWORDofSLASHING: c`5BWCLASS`5D = 30 + i; break; X case OHAMMER: c`5BWCLASS`5D = 35 + i; break; X default: c`5BWCLASS`5D = 0; X `7D X `7D X c`5BWCLASS`5D += c`5BMOREDAM`5D; X X/* now for regeneration abilities based on rings */ X c`5BREGEN`5D=1; c`5BENERGY`5D=0; X j=0; for (k=25; k>0; k--) if (iven`5Bk`5D) `7Bj=k; k=0; `7D X for (i=0; i<=j; i++) X `7B X switch(iven`5Bi`5D) X `7B X case OPROTRING: c`5BAC`5D += ivenarg`5Bi`5D + 1; break; X case ODAMRING: c`5BWCLASS`5D += ivenarg`5Bi`5D + 1; break; X case OBELT: c`5BWCLASS`5D += ((ivenarg`5Bi`5D<<1)) + 2; brea Vk; X X case OREGENRING: c`5BREGEN`5D += ivenarg`5Bi`5D + 1; brea Vk; X case ORINGOFEXTRA: c`5BREGEN`5D += 5 * (ivenarg`5Bi`5D+1); bre Vak; X case OENERGYRING: c`5BENERGY`5D += ivenarg`5Bi`5D + 1; brea Vk; X `7D X `7D X `7D X X X/* X quit() X X subroutine to ask if the player really wants to quit X */ Xquit() X `7B X register int i; X cursors(); strcpy(lastmonst,""); X lprcat("\n\nDo you really want to quit?"); X while (1) X `7B X i=ttgetch(); X if ((i == 'y') `7C`7C (i == 'Y')) `20 X `7B`20 X died(300);`20 X return;`20 X `7D X if ((i == 'n') `7C`7C (i == 'N') `7C`7C (i == '\33'))`20 X `7B`20 X lprcat(" no");`20 X lflush();`20 X return;`20 X `7D X lprcat("\n"); `20 X setbold(); lprcat("Yes"); resetbold(); `20 X lprcat(" or "); X setbold(); lprcat("No"); resetbold(); `20 X lprcat(" please? Do you want to quit? "); X `7D `20 X `7D X X/* X function to ask --more--. If the user enters a space, returns 0. If use Vr X enters Escape, returns 1. If user enters alphabetic, then returns that X value. X */ Xmore(select_allowed) Xchar select_allowed; X `7B X register int i; X X lprcat("\n --- press "); standout("space"); lprcat(" to continue --- V "); X if (select_allowed) X lprcat("letter to select --- "); X X while (TRUE) X `7B X if ((i=ttgetch()) == ' ' `7C`7C i == '\n') X return 0 ; X if (i== '\x1B') X return 1 ; X`09if (select_allowed) X`09 `7B X`09 if (isupper(i)) X`09`09i = tolower(i); X`09 if ( i >= 'a' && i <= 'z' `7C`7C i == '.' ) X`09`09return i; X`09 `7D X `7D X `7D X X/* X function to enchant armor player is currently wearing X */ Xenchantarmor() X `7B X register int tmp; X if (c`5BWEAR`5D<0) `7B if (c`5BSHIELD`5D < 0) X `7B cursors(); beep(); lprcat("\nYou feel a sense of loss"); return; V `7D X else `7B tmp=iven`5Bc`5BSHIELD`5D`5D; if (tmp != OSCROLL V) if (tmp != OPOTION) `7B ivenarg`5Bc`5BSHIELD`5D`5D++; bottomline(); `7D `7 VD `7D X tmp = iven`5Bc`5BWEAR`5D`5D; X if (tmp!=OSCROLL) if (tmp!=OPOTION) `7B ivenarg`5Bc`5BWEAR`5D`5D++; bo Vttomline(); `7D X `7D X X/* X function to enchant a weapon presently being wielded X */ Xenchweapon() X `7B X register int tmp; X if (c`5BWIELD`5D<0) X `7B cursors(); beep(); lprcat("\nYou feel a sense of loss"); return; V `7D X tmp = iven`5Bc`5BWIELD`5D`5D; X if (tmp!=OSCROLL) if (tmp!=OPOTION) X `7B ivenarg`5Bc`5BWIELD`5D`5D++; X if (tmp==OCLEVERRING) c`5BINTELLIGENCE`5D++; else X if (tmp==OSTRRING) c`5BSTREXTRA`5D++; else X if (tmp==ODEXRING) c`5BDEXTERITY`5D++; bottomline(); `7D X `7D X X/* X function to return 1 if a monster is next to the player else returns 0 X */ Xnearbymonst() X `7B X register int tmp,tmp2; X for (tmp=playerx-1; tmp