Path: news.larc.nasa.gov!amiga-request
From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
Subject: v91i155: Larn 12.3 - dungeon type adventure game, Part11/17
Reply-To: Sie <S.Raybould@fulcrum.bt.co.uk>
Newsgroups: comp.sources.amiga
Message-ID: <comp.sources.amiga.v91i155@ab20.larc.nasa.gov>
References: <comp.sources.amiga.v91i145@ab20.larc.nasa.gov>
Date: 29 Aug 91 10:10:46 GMT
Approved: tadguy@uunet.UU.NET (Tad Guy)
X-Mail-Submissions-To: amiga@uunet.uu.net
X-Post-Discussions-To: comp.sys.amiga.misc

Submitted-by: Sie <S.Raybould@fulcrum.bt.co.uk>
Posting-number: Volume 91, Issue 155
Archive-name: games/larn-12.3/part11

#!/bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 11 (of 17)."
# Contents:  spells.c
# Wrapped by tadguy@ab20 on Mon Aug 26 21:51:54 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'spells.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'spells.c'\"
else
echo shar: Extracting \"'spells.c'\" \(27345 characters\)
sed "s/^X//" >'spells.c' <<'END_OF_FILE'
X/*
X  cast()             Subroutine called by parse to cast a spell for the user
X  speldamage(x)      Function to perform spell functions cast by the player
X  loseint()          Routine to decrement your int (intelligence) if > 3
X  isconfuse()        Routine to check to see if player is confused
X  nospell(x,monst)   Routine to return 1 if a spell doesn't affect a monster
X  fullhit(xx)        Function to return full damage against a monst (aka web)
X  direct(spnum,dam,str,arg)   Routine to direct spell damage 1 square in 1 dir
X  godirect(spnum,dam,str,delay,cshow)     Function to perform missile attacks
X  ifblind(x,y)       Routine to put "monster" or the monster name into lastmosnt
X  tdirect(spnum)     Routine to teleport away a monster
X  omnidirect(sp,dam,str)  Routine to damage all monsters 1 square from player
X  dirsub(x,y)        Routine to ask for direction, then modify x,y for it
X  dirpoly(spnum)     Routine to ask for a direction and polymorph a monst
X  annihilate()   Routine to annihilate monsters around player, playerx,playery
X  genmonst()         Function to ask for monster and genocide from game
X*/
X
X#include "header.h"
X#include "larndefs.h"
X#include "objects.h"
X#include "monsters.h"
X#include "player.h"
X#include <ctype.h>
X
X#define min(x,y) (((x)>(y))?(y):(x))
X#define max(x,y) (((x)>(y))?(x):(y))
X
Xstruct isave    /* used for altar reality */
X    {
X    char type;  /* 0=item,  1=monster */
X    char id;    /* item number or monster number */
X    short arg;  /* the type of item or hitpoints of monster */
X    };
X
X/* Forward declarations
X*/
Xstatic void create_guardian();
Xextern hitm();
Xextern char spelweird[MAXMONST+8][SPNUM];
X
X/*
X *  cast()      Subroutine called by parse to cast a spell for the user
X *
X *  No arguments and no return value.
X */
Xstatic char eys[] = "\nEnter your spell: ";
Xcast()
X    {
X    register int i,j,a,b,d;
X    cursors();
X    if (c[SPELLS]<=0) 
X        {   
X        lprcat("\nYou don't have any spells!"); 
X        return; 
X        }
X    lprcat(eys);
X    --c[SPELLS];
X    while ((a=ttgetch())=='I')
X        { 
X        seemagic(-1); 
X        cursors();  
X        lprcat(eys);
X        }
X    if (a=='\33') 
X        goto over;                  /*  to escape casting a spell   */
X    if ((b=ttgetch())=='\33') 
X        goto over;                  /*  to escape casting a spell   */
X    if ((d=ttgetch())=='\33')
X        { 
Xover: 
X        lprcat(aborted); 
X        c[SPELLS]++; 
X        return;
X        }                           /*  to escape casting a spell   */
X#ifdef EXTRA
X    c[SPELLSCAST]++;
X#endif
X    for (lprc('\n'),j= -1,i=0; i<SPNUM; i++) /*seq search for his spell, hash?*/
X        if ((spelcode[i][0]==a) && (spelcode[i][1]==b) && (spelcode[i][2]==d))
X            if (spelknow[i])
X                {  speldamage(i);  j = 1;  i=SPNUM; }
X
X    if (j == -1) lprcat("  Nothing Happened ");
X    bottomline();
X    }
X
X/*
X *  speldamage(x)       Function to perform spell functions cast by the player
X *      int x;
X *
X *  Enter with the spell number, returns no value.
X *  Please insure that there are 2 spaces before all messages here
X */
Xstatic speldamage(x)
X    int x;
X    {
X    register int i,j,clev;
X    int xl,xh,yl,yh;
X    register char *p,*kn,*pm;
X
X    if (x>=SPNUM) return;   /* no such spell */
X    if (c[TIMESTOP])  { lprcat("  It didn't seem to work"); return; }  /* not if time stopped */
X    clev = c[LEVEL];
X    if ((rnd(23)==7) || (rnd(18) > c[INTELLIGENCE]))
X        { lprcat("  It didn't work!");  return; }
X    if (clev*3+2 < x)
X    {
X    lprcat("  Nothing happens.  You seem inexperienced at this");
X    return;
X    }
X
X    switch(x)
X        {
X/* ----- LEVEL 1 SPELLS ----- */
X
X        case 0: if (c[PROTECTIONTIME]==0)   c[MOREDEFENSES]+=2; /* protection field +2 */
X                c[PROTECTIONTIME] += 250;   return;
X
X        case 1: i = rnd(((clev+1)<<1)) + clev + 3;
X                godirect(x,i,(clev>=2)?"  Your missiles hit the %s":"  Your missile hit the %s",100,'+'); /* magic missile */
X
X                return;
X
X        case 2: if (c[DEXCOUNT]==0) c[DEXTERITY]+=3; /* dexterity   */
X                c[DEXCOUNT] += 400;     return;
X
X        case 3: i=rnd(3)+1;
X                p="  While the %s slept, you smashed it %d times";
X            ws: direct(x,fullhit(i),p,i); /*    sleep   */  return;
X
X        case 4: /*  charm monster   */  c[CHARMCOUNT] += c[CHARISMA]<<1;    return;
X
X        case 5: godirect(x,rnd(10)+15+clev,"  The sound damages the %s",70,'@'); /* sonic spear */
X                return;
X
X/* ----- LEVEL 2 SPELLS ----- */
X
X        case 6: i=rnd(3)+2; p="  While the %s is entangled, you hit %d times";
X                goto ws; /* web */
X
X        case 7: if (c[STRCOUNT]==0) c[STREXTRA]+=3; /*  strength    */
X                c[STRCOUNT] += 150+rnd(100);    return;
X
X        case 8: yl = playery-5;     /* enlightenment */
X                yh = playery+6;   xl = playerx-15;   xh = playerx+16;
X                vxy(&xl,&yl);   vxy(&xh,&yh); /* check bounds */
X                for (i=yl; i<=yh; i++) /* enlightenment */
X                    for (j=xl; j<=xh; j++)
X                        know[j][i]=KNOWALL;
X                draws(xl,xh+1,yl,yh+1); return;
X
X        case 9: raisehp(20+(clev<<1));  return;  /* healing */
X
X        case 10:    c[BLINDCOUNT]=0;    return; /* cure blindness   */
X
X        case 11:    createmonster(makemonst(level+1)+8);  return;
X
X        case 12:    if (rnd(11)+7 <= c[WISDOM]) direct(x,rnd(20)+20+clev,"  The %s believed!",0);
X                    else lprcat("  It didn't believe the illusions!");
X                    return;
X
X        case 13:    /* if he has the amulet of invisibility then add more time */
X                    for (j=i=0; i<26; i++)
X                        if (iven[i]==OAMULET) j+= 1+ivenarg[i];
X                    c[INVISIBILITY] += (j<<7)+12;   return;
X
X/* ----- LEVEL 3 SPELLS ----- */
X
X        case 14:    godirect(x,rnd(25+clev)+25+clev,"  The fireball hits the %s",40,'*'); return; /*    fireball */
X
X        case 15:    godirect(x,rnd(25)+20+clev,"  Your cone of cold strikes the %s",60,'O');    /*  cold */
X                    return;
X
X        case 16:    dirpoly(x);  return;    /*  polymorph */
X
X        case 17:    c[CANCELLATION]+= 5+clev;   return; /*  cancellation    */
X
X        case 18:    c[HASTESELF]+= 7+clev;  return;  /* haste self  */
X
X        case 19:    omnidirect(x,30+rnd(10),"  The %s gasps for air");  /* cloud kill */
X                    return;
X
X        case 20:    xh = min(playerx+1,MAXX-2);     yh = min(playery+1,MAXY-2);
X                    for (i=max(playerx-1,1); i<=xh; i++) /* vaporize rock */
X                      for (j=max(playery-1,1); j<=yh; j++)
X                        {
X                        kn = &know[i][j];
X                            pm = &mitem[i][j];
X                        switch(*(p= &item[i][j]))
X                          {
X                          case OWALL: if (level < MAXLEVEL+MAXVLEVEL-1)
X                                            *p = *kn = 0;
X                                        break;
X
X                          case OSTATUE: if (c[HARDGAME]<3)
X                                             {
X                                             *p=OBOOK; iarg[i][j]=level;  *kn=0;
X                                             }
X                                        break;
X
X              case OTHRONE:
X                  *p= OTHRONE2;
X                  create_guardian( GNOMEKING, i, j );
X                  break;
X
X              case OALTAR:
X                  create_guardian( DEMONPRINCE, i, j );
X                  break;
X
X              case OFOUNTAIN:
X                  create_guardian( WATERLORD, i, j );
X                  break;
X              };
X                        switch(*pm)
X                            {
X                            case XORN:  ifblind(i,j);  hitm(i,j,200); break; /* Xorn takes damage from vpr */
X                            }
X                        }
X                    return;
X
X/* ----- LEVEL 4 SPELLS ----- */
X
X        case 21:    direct(x,100+clev,"  The %s shrivels up",0); /* dehydration */
X                    return;
X
X        case 22:    godirect(x,rnd(25)+20+(clev<<1),"  A lightning bolt hits the %s",1,'~');    /*  lightning */
X                    return;
X
X        case 23:    i=min(c[HP]-1,c[HPMAX]/2);  /* drain life */
X                    direct(x,i+i,"",0); c[HP] -= i;     return;
X
X        case 24:    if (c[GLOBE]==0) c[MOREDEFENSES] += 10;
X                    c[GLOBE] += 200;  loseint();  /* globe of invulnerability */
X                    return;
X
X        case 25:    omnidirect(x,32+clev,"  The %s struggles for air in your flood!"); /* flood */
X                    return;
X
X        case 26:    if (rnd(151)==63) { beep(); lprcat("\nYour heart stopped!\n"); nap(4000);  died(270); return; }
X                    if (c[WISDOM]>rnd(10)+10) direct(x,2000,"  The %s's heart stopped",0); /* finger of death */
X                    else lprcat("  It didn't work"); return;
X
X/* ----- LEVEL 5 SPELLS ----- */
X
X        case 27:    c[SCAREMONST] += rnd(10)+clev;  return;  /* scare monster */
X
X        case 28:    c[HOLDMONST] += rnd(10)+clev;  return;  /* hold monster */
X
X        case 29:    c[TIMESTOP] += rnd(20)+(clev<<1);  return;  /* time stop */
X
X        case 30:    tdirect(x);  return;  /* teleport away */
X
X        case 31:    omnidirect(x,35+rnd(10)+clev,"  The %s cringes from the flame"); /* magic fire */
X                    return;
X
X/* ----- LEVEL 6 SPELLS ----- */
X
X        case 32:    if ((rnd(23)==5) && (wizard==0)) /* sphere of annihilation */
X                        {
X                        beep(); lprcat("\nYou have been enveloped by the zone of nothingness!\n");
X                        nap(4000);  died(258); return;
X                        }
X                    xl=playerx; yl=playery;
X                    loseint();
X                    i=dirsub(&xl,&yl); /* get direction of sphere */
X                    newsphere(xl,yl,i,rnd(20)+11);  /* make a sphere */
X                    return;
X
X        case 33:    genmonst();  spelknow[33]=0;  /* genocide */
X                    loseint();
X                    return;
X
X        case 34:    /* summon demon */
X                    if (rnd(100) > 30) { direct(x,150,"  The demon strikes at the %s",0);  return; }
X                    if (rnd(100) > 15) { lprcat("  Nothing seems to have happened");  return; }
X                    lprcat("  The demon turned on you and vanished!"); beep();
X                    i=rnd(40)+30;  lastnum=277;
X                    losehp(i); /* must say killed by a demon */ return;
X
X        case 35:    /* walk through walls */
X                    c[WTW] += rnd(10)+5;    return;
X
X        case 36:    /* alter reality */
X                    {
X                    struct isave *save; /* pointer to item save structure */
X                    int sc; sc=0;   /* # items saved */
X                    save = (struct isave *)malloc(sizeof(struct isave)*MAXX*MAXY*2);
X            if (save == NULL)
X            {
X            lprcat("\nPolinneaus won't let you mess with his dungeon!");
X            return;
X            }
X            for (j=0; j<MAXY; j++)
X                        for (i=0; i<MAXX; i++) /* save all items and monsters */
X                            {
X                            xl = item[i][j];
X                            if (xl && xl!=OWALL && xl!=OANNIHILATION) 
X                                {
X                                save[sc].type=0;  save[sc].id=item[i][j];
X                                save[sc++].arg=iarg[i][j];
X                                }
X                            if (mitem[i][j]) 
X                                {
X                                save[sc].type=1;  save[sc].id=mitem[i][j];
X                                save[sc++].arg=hitp[i][j];
X                                }
X                            item[i][j]=OWALL;   mitem[i][j]=0;
X                        if (wizard)
X                            know[i][j]=KNOWALL;
X                        else
X                            know[i][j]=0;
X                            }
X                    eat(1,1);   if (level==1) item[33][MAXY-1]=OENTRANCE;
X                    for (j=rnd(MAXY-2), i=1; i<MAXX-1; i++) item[i][j]=0;
X                    while (sc>0) /* put objects back in level */
X                        {
X                        --sc;
X                        if (save[sc].type == 0)
X                            {
X                            int trys;
X                            for (trys=100, i=j=1; --trys>0 && item[i][j]; i=rnd(MAXX-1), j=rnd(MAXY-1));
X                            if (trys) { item[i][j]=save[sc].id; iarg[i][j]=save[sc].arg; }
X                            }
X                        else
X                            { /* put monsters back in */
X                            int trys;
X                            for (trys=100, i=j=1; --trys>0 && (item[i][j]==OWALL || mitem[i][j]); i=rnd(MAXX-1), j=rnd(MAXY-1));
X                            if (trys) { mitem[i][j]=save[sc].id; hitp[i][j]=save[sc].arg; }
X                            }
X                        }
X                    loseint();
X                    draws(0,MAXX,0,MAXY);  if (wizard==0) spelknow[36]=0;
X                    free((char*)save);   positionplayer();  return;
X                    }
X
X        case 37:    /* permanence */ adjtime(-99999L);  spelknow[37]=0; /* forget */
X                    loseint();
X                    return;
X
X        default:    lprintf("  spell %d not available!",(long)x); beep();  return;
X        };
X    }
X
X/*
X    Create a guardian for a throne/altar/fountain, as a result of the player
X    using a VPR spell or pulverization scroll on it.
X*/
Xstatic void create_guardian( monst, x, y )
Xint monst;  /* monster code for the guardian */
Xint x, y;   /* coords of the object being guarded */
X    {
X    int k ;
X
X    /* prevent the guardian from being created on top of the player
X    */
X    if ((x == playerx) && (y == playery))
X    {
X    k = rnd(8);
X    x += diroffx[k];
X    y += diroffy[k];
X    }
X    know[x][y] = 0;
X    mitem[x][y] = monst ;
X    hitp[x][y]  = monster[monst].hitpoints;
X    }
X
X/*
X *  loseint()       Routine to subtract 1 from your int (intelligence) if > 3
X *
X *  No arguments and no return value
X */
Xstatic loseint()
X    {
X    if (--c[INTELLIGENCE]<3)  c[INTELLIGENCE]=3;
X    }
X
X/*
X *  isconfuse()         Routine to check to see if player is confused
X *
X *  This routine prints out a message saying "You can't aim your magic!"
X *  returns 0 if not confused, non-zero (time remaining confused) if confused
X */
Xstatic isconfuse()
X    {
X    if (c[CONFUSE]) { lprcat(" You can't aim your magic!"); beep(); }
X    return(c[CONFUSE]);
X    }
X
X/*
X *  nospell(x,monst)    Routine to return 1 if a spell doesn't affect a monster
X *      int x,monst;
X *
X *  Subroutine to return 1 if the spell can't affect the monster
X *    otherwise returns 0
X *  Enter with the spell number in x, and the monster number in monst.
X */
Xstatic nospell(x,monst)
X    int x,monst;
X    {
X    register int tmp;
X    if (x>=SPNUM || monst>=MAXMONST+8 || monst<0 || x<0) return(0); /* bad spell or monst */
X    if ((tmp=spelweird[monst-1][x])==0) return(0);
X    cursors();  lprc('\n');  lprintf(spelmes[tmp],monster[monst].name);  return(1);
X    }
X
X/*
X *  fullhit(xx)     Function to return full damage against a monster (aka web)
X *      int xx;
X *
X *  Function to return hp damage to monster due to a number of full hits
X *  Enter with the number of full hits being done
X */
Xfullhit(xx)
X    int xx;
X    {
X    register int i;
X    if (xx<0 || xx>20) return(0);   /* fullhits are out of range */
X    if (c[LANCEDEATH]) return(10000);   /* lance of death */
X    i = xx * ((c[WCLASS]>>1)+c[STRENGTH]+c[STREXTRA]-c[HARDGAME]-12+c[MOREDAM]);
X    return( (i>=1) ? i : xx );
X    }
X
X/*
X *  direct(spnum,dam,str,arg)   Routine to direct spell damage 1 square in 1 dir
X *      int spnum,dam,arg;
X *      char *str;
X *
X *  Routine to ask for a direction to a spell and then hit the monster
X *  Enter with the spell number in spnum, the damage to be done in dam,
X *    lprintf format string in str, and lprintf's argument in arg.
X *  Returns no value.
X */
Xstatic direct(spnum,dam,str,arg)
X    int spnum,dam,arg;
X    char *str;
X    {
X    extern char lastmonst[];
X    int x,y;
X    register int m;
X    if (spnum<0 || spnum>=SPNUM || str==0) return; /* bad arguments */
X    if (isconfuse()) return;
X    dirsub(&x,&y);
X    m = mitem[x][y];
X    if (item[x][y]==OMIRROR)
X        {
X        if (spnum==3) /* sleep */
X            {
X            lprcat("You fall asleep! "); beep();
X        fool:
X            arg += 2;
X            while (arg-- > 0) { parse2(); nap(1000); }
X            return;
X            }
X        else if (spnum==6) /* web */
X            {
X            lprcat("You get stuck in your own web! "); beep();
X            goto fool;
X            }
X        else
X            {
X            lastnum=278; 
X            lprintf(str,"spell caster (thats you)",(long)arg);
X            beep(); losehp(dam); return;
X            }
X        }
X    if (m==0)
X        {   lprcat("  There wasn't anything there!");   return;  }
X    ifblind(x,y);
X    if (nospell(spnum,m)) { lasthx=x;  lasthy=y; return; }
X    lprintf(str,lastmonst,(long)arg);       hitm(x,y,dam);
X    }
X
X/*
X *  godirect(spnum,dam,str,delay,cshow)     Function to perform missile attacks
X *      int spnum,dam,delay;
X *      char *str,cshow;
X *
X *  Function to hit in a direction from a missile weapon and have it keep
X *  on going in that direction until its power is exhausted
X *  Enter with the spell number in spnum, the power of the weapon in hp,
X *    lprintf format string in str, the # of milliseconds to delay between 
X *    locations in delay, and the character to represent the weapon in cshow.
X *  Returns no value.
X */
Xgodirect(spnum,dam,str,delay,cshow)
X    int spnum,dam,delay;
X    char *str,cshow;
X    {
X    extern char lastmonst[] ;
X    register char *p;
X    register int x,y,m;
X    int dx,dy;
X    if (spnum<0 || spnum>=SPNUM || str==0 || delay<0) return; /* bad args */
X    if (isconfuse()) return;
X    dirsub(&dx,&dy);    x=dx;   y=dy;
X    dx = x-playerx;     dy = y-playery;     x = playerx;    y = playery;
X    while (dam>0)
X        {
X        x += dx;    y += dy;
X        if ((x > MAXX-1) || (y > MAXY-1) || (x < 0) || (y < 0))
X            {
X            dam=0;  break;  /* out of bounds */
X            }
X        if ((x==playerx) && (y==playery)) /* if energy hits player */
X            {
X            cursors(); lprcat("\nYou are hit my your own magic!"); beep();
X            lastnum=278;  losehp(dam);  return;
X            }
X        if (c[BLINDCOUNT]==0) /* if not blind show effect */
X            {
X            cursor(x+1,y+1); lprc(cshow); nap(delay); show1cell(x,y);
X            }
X        if ((m=mitem[x][y]))    /* is there a monster there? */
X            {
X            ifblind(x,y);
X            if (nospell(spnum,m)) { lasthx=x;  lasthy=y; return; }
X            cursors(); lprc('\n');
X            lprintf(str,lastmonst);     dam -= hitm(x,y,dam);
X            show1cell(x,y);  nap(1000);     x -= dx;    y -= dy;
X            }
X        else switch (*(p= &item[x][y]))
X            {
X        case OWALL:
X        cursors();
X        lprc('\n');
X        lprintf(str,"wall");
X        if (dam>=50+c[HARDGAME]) /* enough damage? */
X            if (level<MAXLEVEL+MAXVLEVEL-1) /* not on V3 */
X            if ((x<MAXX-1) && (y<MAXY-1) && (x) && (y))
X                            {
X                            lprcat("  The wall crumbles");
X                *p=0;
X                know[x][y]=0;
X                            show1cell(x,y);
X                            }
X        dam = 0;
X        break;
X
X        case OCLOSEDDOOR:
X        cursors();
X        lprc('\n');
X        lprintf(str,"door");
X        if (dam>=40)
X            {
X            lprcat("  The door is blasted apart");
X            *p = 0;
X            know[x][y] = 0;
X            show1cell( x, y );
X            }
X        dam = 0 ;
X        break;
X
X        case OSTATUE:
X        cursors();
X        lprc('\n');
X        lprintf(str,"statue");
X        if (c[HARDGAME]<3)
X            if (dam>44)
X            {
X            lprcat("  The statue crumbles");
X            *p=OBOOK;
X            iarg[x][y]=level;
X            know[x][y] = 0;
X            show1cell( x, y );
X            }
X        dam = 0 ;
X        break;
X
X        case OTHRONE:
X        cursors();
X        lprc('\n');
X        lprintf(str,"throne");
X        if (dam>39)
X            {
X            *p = OTHRONE2;
X            create_guardian( GNOMEKING, x, y );
X            show1cell( x, y );
X            }
X        dam = 0;
X        break;
X
X        case OALTAR:
X        cursors();
X        lprc('\n');
X        lprintf(str, "altar");
X        if ( dam > 75 - ( c[HARDGAME] >> 2 ))
X            {
X            create_guardian( DEMONPRINCE, x, y );
X            show1cell( x, y );
X            }
X        dam = 0 ;
X        break;
X
X        case OFOUNTAIN:
X        cursors();
X        lprc('\n');
X        lprintf(str, "fountain");
X        if ( dam > 55 )
X            {
X            create_guardian( WATERLORD, x, y );
X            show1cell( x, y );
X            }
X        dam = 0 ;
X        break;
X
X        case OMIRROR:
X    {
X    int bounce = FALSE, odx=dx, ody=dy ;
X        /* spells may bounce directly back or off at an angle
X        */
X        if (rnd(100) < 50 )
X        {
X        bounce = TRUE ;
X        dx *= -1;
X        }
X        if (rnd(100) < 50 )
X        {
X        bounce = TRUE ;
X        dy *= -1;
X        }
X    if (!bounce || ((odx==dx) && (ody==dy)))    /* guarentee a bounce */
X        {
X    dx = -odx;
X    dy = -ody;
X        }
X        }
X        break;
X            };
X        dam -= 3 + (c[HARDGAME]>>1);
X        }
X    }
X
X/*
X *  ifblind(x,y)    Routine to put "monster" or the monster name into lastmosnt
X *      int x,y;
X *
X *  Subroutine to copy the word "monster" into lastmonst if the player is blind
X *  Enter with the coordinates (x,y) of the monster
X *  Returns no value.
X */
Xifblind(x,y)
X    int x,y;
X    {
X    extern char lastmonst[] ;
X    char *p;
X    vxy(&x,&y); /* verify correct x,y coordinates */
X    if (c[BLINDCOUNT]) { lastnum=279;  p="monster"; }
X        else { lastnum=mitem[x][y];  p=monster[lastnum].name; }
X    strcpy(lastmonst,p);
X    }
X
X/*
X *  tdirect(spnum)      Routine to teleport away a monster
X *      int spnum;
X *
X *  Routine to ask for a direction to a spell and then teleport away monster
X *  Enter with the spell number that wants to teleport away
X *  Returns no value.
X */
Xstatic tdirect(spnum)
X    int spnum;
X    {
X    int x,y;
X    register int m;
X    if (spnum<0 || spnum>=SPNUM) return; /* bad args */
X    if (isconfuse()) return;
X    dirsub(&x,&y);
X    if ((m=mitem[x][y])==0)
X        {   lprcat("  There wasn't anything there!");   return;  }
X    ifblind(x,y);
X    if (nospell(spnum,m)) { lasthx=x;  lasthy=y; return; }
X    fillmonst(m);  mitem[x][y]=0; know[x][y] &= ~KNOWHERE;
X    }
X
X/*
X *  omnidirect(sp,dam,str)   Routine to damage all monsters 1 square from player
X *      int sp,dam;
X *      char *str;
X *
X *  Routine to cast a spell and then hit the monster in all directions
X *  Enter with the spell number in sp, the damage done to wach square in dam,
X *    and the lprintf string to identify the spell in str.
X *  Returns no value.
X */
Xstatic omnidirect(spnum,dam,str)
X    int spnum,dam;
X    char *str;
X    {
X    extern char lastmonst[] ;
X    register int x,y,m;
X    if (spnum<0 || spnum>=SPNUM || str==0) return; /* bad args */
X    for (x=playerx-1; x<playerx+2; x++)
X        for (y=playery-1; y<playery+2; y++)
X            {
X            if (m=mitem[x][y])
X                if (nospell(spnum,m) == 0)
X                    {
X                    ifblind(x,y);
X                    cursors(); lprc('\n'); lprintf(str,lastmonst);
X                    hitm(x,y,dam);  nap(800);
X                    }
X                else  { lasthx=x;  lasthy=y; }
X            }
X    }
X
X/*
X *  dirsub(x,y)      Routine to ask for direction, then modify playerx,
X *                   playery for it
X *      int *x,*y;
X *
X *  Function to ask for a direction and modify an x,y for that direction
X *  Enter with the coordinate destination (x,y).
X *  Returns index into diroffx[] (0-8).
X */
Xdirsub(x,y)
X    int *x,*y;
X    {
X    register int i;
X    lprcat("\nIn What Direction? ");
X    for (i=0; ; )
X        switch(ttgetch())
X            {
X            case 'b':   i++;
X            case 'n':   i++;
X            case 'y':   i++;
X            case 'u':   i++;
X            case 'h':   i++;
X            case 'k':   i++;
X            case 'l':   i++;
X            case 'j':   i++;        goto out;
X            };
Xout:
X    *x = playerx+diroffx[i];        *y = playery+diroffy[i];
X    vxy(x,y);  return(i);
X    }
X
X/*
X *  dirpoly(spnum)      Routine to ask for a direction and polymorph a monst
X *      int spnum;
X *
X *  Subroutine to polymorph a monster and ask for the direction its in
X *  Enter with the spell number in spmun.
X *  Returns no value.
X */
Xstatic dirpoly(spnum)
X    int spnum;
X    {
X    int x,y,m;
X    if (spnum<0 || spnum>=SPNUM) return; /* bad args */
X    if (isconfuse()) return;    /* if he is confused, he can't aim his magic */
X    dirsub(&x,&y);
X    if (mitem[x][y]==0)
X        {   lprcat("  There wasn't anything there!");   return;  }
X    ifblind(x,y);
X    if (nospell(spnum,mitem[x][y])) { lasthx=x;  lasthy=y; return; }
X# ifdef MSDOS
X    do {
X        m = rnd(MAXMONST+7);
X        mitem[x][y] = m;
X    } while ( monster[m].genocided );
X# else
X    while ( monster[m = mitem[x][y] = rnd(MAXMONST+7)].genocided );
X# endif
X    hitp[x][y] = monster[m].hitpoints;
X    show1cell(x,y);  /* show the new monster */
X    }
X
X/*
X *  annihilate()    Routine to annihilate all monsters around player (playerx,playery)
X *
X *  Gives player experience, but no dropped objects
X *  Returns the experience gained from all monsters killed
X */
Xannihilate()
X    {
X    int i,j;
X    register long k;
X    register char *p;
X    for (k=0, i=playerx-1; i<=playerx+1; i++)
X      for (j=playery-1; j<=playery+1; j++)
X        if (!vxy(&i,&j)) /* if not out of bounds */
X            if (*(p= &mitem[i][j])) /* if a monster there */
X                if (*p<DEMONLORD+2)
X                    {
X                    k += monster[*p].experience;    *p=know[i][j] &= ~KNOWHERE;
X                    }
X                else
X                    {
X                    lprintf("\nThe %s barely escapes being annihilated!",monster[*p].name);
X                    hitp[i][j] = (hitp[i][j]>>1) + 1; /* lose half hit points*/
X                    }
X    if (k>0)
X        {
X        lprcat("\nYou hear loud screams of agony!");    raiseexperience((long)k);
X        }
X    return(k);
X    }
X
X/*
X *  genmonst()      Function to ask for monster and genocide from game
X *
X *  This is done by setting a flag in the monster[] structure
X */
Xstatic genmonst()
X    {
X    register int i,j;
X    cursors();  lprcat("\nGenocide what monster? ");
X    for (i=0; (!isalpha(i)) && (i!=' '); i=ttgetch());
X    lprc(i);
X    for (j=0; j<MAXMONST; j++)  /* search for the monster type */
X        if (monstnamelist[j]==i)    /* have we found it? */
X            {
X            monster[j].genocided=1; /* genocided from game */
X            lprintf("  There will be no more %s's",monster[j].name);
X            /* now wipe out monsters on this level */
X            newcavelevel(level); draws(0,MAXX,0,MAXY); bot_linex();
X            return;
X            }
X    lprcat("  You sense failure!");
X    }
END_OF_FILE
if test 27345 -ne `wc -c <'spells.c'`; then
    echo shar: \"'spells.c'\" unpacked with wrong size!
fi
# end of 'spells.c'
fi
echo shar: End of archive 11 \(of 17\).
cp /dev/null ark11isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 17 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.misc.
