1 /* $NetBSD: monster.c,v 1.16 2008/02/03 21:24:58 dholland Exp $ */
4 * monster.c Larn is copyrighted 1986 by Noah Morgan.
6 * This file contains the following functions:
7 * ----------------------------------------------------------------------------
9 * createmonster(monstno) Function to create a monster next to the player
12 * int cgood(x,y,itm,monst)Function to check location for emptiness
15 * createitem(it,arg) Routine to place an item next to the player
18 * cast() Subroutine called by parse to cast a spell for the user
20 * speldamage(x) Function to perform spell functions cast by the player
23 * loseint() Routine to decrement your int (intelligence) if > 3
25 * isconfuse() Routine to check to see if player is confused
27 * nospell(x,monst)Routine to return 1 if a spell doesn't affect a monster
30 * fullhit(xx) Function to return full damage against a monst (aka web)
33 * direct(spnum,dam,str,arg)Routine to direct spell damage 1 square in 1 dir
37 * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks
38 * int spnum,dam,delay;
41 * ifblind(x,y)Routine to put "monster" or the monster name into lastmosnt
44 * tdirect(spnum) Routine to teleport away a monster
47 * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player
51 * dirsub(x,y) Routine to ask for direction, then modify x,y for it
54 * vxy(x,y) Routine to verify/fix (*x,*y) for being within bounds
57 * dirpoly(spnum) Routine to ask for a direction and polymorph a monst
60 * hitmonster(x,y) Function to hit a monster at the designated coordinates
63 * hitm(x,y,amt) Function to just hit a monster at a given coordinates
66 * hitplayer(x,y) Function for the monster to hit the player from (x,y)
69 * dropsomething(monst) Function to create an object when a monster dies
72 * dropgold(amount) Function to drop some gold around player
75 * something(level) Function to create a random item around player
78 * newobject(lev,i) Routine to return a randomly selected new object
81 * spattack(atckno,xx,yy) Function to process special attacks from monsters
84 * checkloss(x) Routine to subtract hp from user and flag bottomline display
87 * annihilate() Routine to annihilate monsters around player, playerx,playery
89 * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation
90 * int x,y,dir,lifetime;
92 * rmsphere(x,y) Function to delete a sphere of annihilation from list
95 * sphboom(x,y) Function to perform the effects of a sphere detonation
98 * genmonst() Function to ask for monster and genocide from game
101 #include <sys/cdefs.h>
103 __RCSID("$NetBSD: monster.c,v 1.16 2008/02/03 21:24:58 dholland Exp $");
104 #endif /* not lint */
112 struct isave
{ /* used for altar reality */
113 char type
; /* 0=item, 1=monster */
114 char id
; /* item number or monster number */
115 short arg
; /* the type of item or hitpoints of monster */
118 static int cgood(int, int, int, int);
119 static void speldamage(int);
120 static void loseint(void);
121 static int isconfuse(void);
122 static int nospell(int, int);
123 static int fullhit(int);
124 static void direct(int, int, const char *, int);
125 static void ifblind(int, int);
126 static void tdirect(int);
127 static void omnidirect(int, int, const char *);
128 static int dirsub(int *, int *);
129 static void dirpoly(int);
130 static int hitm(int, int, int);
131 static void dropsomething(int);
132 static int spattack(int, int, int);
133 static void sphboom(int, int);
134 static void genmonst(void);
137 * createmonster(monstno) Function to create a monster next to the player
140 * Enter with the monster number (1 to MAXMONST+8)
148 if (mon
< 1 || mon
> MAXMONST
+ 8) { /* check for monster number
151 lprintf("\ncan't createmonst(%ld)\n", (long) mon
);
155 while (monster
[mon
].genocided
&& mon
< MAXMONST
)
156 mon
++; /* genocided? */
157 for (k
= rnd(8), i
= -8; i
< 0; i
++, k
++) { /* choose direction,
160 k
= 1; /* wraparound the diroff arrays */
161 x
= playerx
+ diroffx
[k
];
162 y
= playery
+ diroffy
[k
];
163 if (cgood(x
, y
, 0, 1)) { /* if we can create here */
165 hitp
[x
][y
] = monster
[mon
].hitpoints
;
166 stealth
[x
][y
] = know
[x
][y
] = 0;
179 * int cgood(x,y,itm,monst) Function to check location for emptiness
182 * Routine to return TRUE if a location does not have itm or monst there
183 * returns FALSE (0) otherwise
184 * Enter with itm or monst TRUE or FALSE if checking it
185 * Example: if itm==TRUE check for no item at this location
186 * if monst==TRUE check for no monster at this location
187 * This routine will return FALSE if at a wall or the dungeon exit on level 1
190 cgood(int x
, int y
, int theitem
, int monst
)
193 if ((y
>= 0) && (y
<= MAXY
- 1) && (x
>= 0) && (x
<= MAXX
- 1))
195 if (item
[x
][y
] != OWALL
) /* can't make anything on walls */
196 /* is it free of items? */
197 if (theitem
== 0 || (item
[x
][y
] == 0))
198 /* is it free of monsters? */
199 if (monst
== 0 || (mitem
[x
][y
] == 0))
200 if ((level
!= 1) || (x
!= 33) ||
202 /* not exit to level 1 */
208 * createitem(it,arg) Routine to place an item next to the player
211 * Enter with the item number and its argument (iven[], ivenarg[])
212 * Returns no value, thus we don't know about createitem() failures.
220 return; /* no such object */
221 for (k
= rnd(8), i
= -8; i
< 0; i
++, k
++) { /* choose direction,
224 k
= 1; /* wraparound the diroff arrays */
225 x
= playerx
+ diroffx
[k
];
226 y
= playery
+ diroffy
[k
];
227 if (cgood(x
, y
, 1, 0)) { /* if we can create here */
237 * cast() Subroutine called by parse to cast a spell for the user
239 * No arguments and no return value.
241 static char eys
[] = "\nEnter your spell: ";
247 if (c
[SPELLS
] <= 0) {
248 lprcat("\nYou don't have any spells!");
253 while ((a
= ttgetch()) == 'D') {
259 goto over
; /* to escape casting a spell */
260 if ((b
= ttgetch()) == '\33')
261 goto over
; /* to escape casting a spell */
262 if ((d
= ttgetch()) == '\33') {
263 over
: lprcat(aborted
);
266 } /* to escape casting a spell */
270 for (lprc('\n'), j
= -1, i
= 0; i
< SPNUM
; i
++) /* seq search for his
272 if ((spelcode
[i
][0] == a
) && (spelcode
[i
][1] == b
) && (spelcode
[i
][2] == d
))
279 lprcat(" Nothing Happened ");
284 * speldamage(x) Function to perform spell functions cast by the player
287 * Enter with the spell number, returns no value.
288 * Please insure that there are 2 spaces before all messages here
298 return; /* no such spell */
300 lprcat(" It didn't seem to work");
302 } /* not if time stopped */
304 if ((rnd(23) == 7) || (rnd(18) > c
[INTELLIGENCE
])) {
305 lprcat(" It didn't work!");
308 if (clev
* 3 + 2 < x
) {
309 lprcat(" Nothing happens. You seem inexperienced at this");
313 /* ----- LEVEL 1 SPELLS ----- */
316 if (c
[PROTECTIONTIME
] == 0)
317 c
[MOREDEFENSES
] += 2; /* protection field +2 */
318 c
[PROTECTIONTIME
] += 250;
322 i
= rnd(((clev
+ 1) << 1)) + clev
+ 3;
323 godirect(x
, i
, (clev
>= 2) ? " Your missiles hit the %s" : " Your missile hit the %s", 100, '+'); /* magic missile */
328 if (c
[DEXCOUNT
] == 0)
329 c
[DEXTERITY
] += 3; /* dexterity */
335 direct(x
, fullhit(i
),
336 " While the %s slept, you smashed it %ld times", i
);
339 case 4: /* charm monster */
340 c
[CHARMCOUNT
] += c
[CHARISMA
] << 1;
344 godirect(x
, rnd(10) + 15 + clev
, " The sound damages the %s", 70, '@'); /* sonic spear */
347 /* ----- LEVEL 2 SPELLS ----- */
351 direct(x
, fullhit(i
),
352 " While the %s is entangled, you hit %ld times", i
);
356 if (c
[STRCOUNT
] == 0)
357 c
[STREXTRA
] += 3; /* strength */
358 c
[STRCOUNT
] += 150 + rnd(100);
362 yl
= playery
- 5; /* enlightenment */
367 vxy(&xh
, &yh
); /* check bounds */
368 for (i
= yl
; i
<= yh
; i
++) /* enlightenment */
369 for (j
= xl
; j
<= xh
; j
++)
371 draws(xl
, xh
+ 1, yl
, yh
+ 1);
375 raisehp(20 + (clev
<< 1));
376 return; /* healing */
380 return; /* cure blindness */
383 createmonster(makemonst(level
+ 1) + 8);
387 if (rnd(11) + 7 <= c
[WISDOM
])
388 direct(x
, rnd(20) + 20 + clev
, " The %s believed!", 0);
390 lprcat(" It didn't believe the illusions!");
393 case 13: /* if he has the amulet of invisibility then
395 for (j
= i
= 0; i
< 26; i
++)
396 if (iven
[i
] == OAMULET
)
398 c
[INVISIBILITY
] += (j
<< 7) + 12;
401 /* ----- LEVEL 3 SPELLS ----- */
404 godirect(x
, rnd(25 + clev
) + 25 + clev
, " The fireball hits the %s", 40, '*');
405 return; /* fireball */
408 godirect(x
, rnd(25) + 20 + clev
, " Your cone of cold strikes the %s", 60, 'O'); /* cold */
413 return; /* polymorph */
416 c
[CANCELLATION
] += 5 + clev
;
417 return; /* cancellation */
420 c
[HASTESELF
] += 7 + clev
;
421 return; /* haste self */
424 omnidirect(x
, 30 + rnd(10), " The %s gasps for air"); /* cloud kill */
428 xh
= min(playerx
+ 1, MAXX
- 2);
429 yh
= min(playery
+ 1, MAXY
- 2);
430 for (i
= max(playerx
- 1, 1); i
<= xh
; i
++) /* vaporize rock */
431 for (j
= max(playery
- 1, 1); j
<= yh
; j
++) {
434 switch (*(p
= &item
[i
][j
])) {
436 if (level
< MAXLEVEL
+ MAXVLEVEL
- 1)
441 if (c
[HARDGAME
] < 3) {
452 hitp
[i
][j
] = monster
[GNOMEKING
].hitpoints
;
458 hitp
[i
][j
] = monster
[DEMONPRINCE
].hitpoints
;
465 break; /* Xorn takes damage from vpr */
470 /* ----- LEVEL 4 SPELLS ----- */
473 direct(x
, 100 + clev
, " The %s shrivels up", 0); /* dehydration */
477 godirect(x
, rnd(25) + 20 + (clev
<< 1), " A lightning bolt hits the %s", 1, '~'); /* lightning */
481 i
= min(c
[HP
] - 1, c
[HPMAX
] / 2); /* drain life */
482 direct(x
, i
+ i
, "", 0);
488 c
[MOREDEFENSES
] += 10;
490 loseint(); /* globe of invulnerability */
494 omnidirect(x
, 32 + clev
, " The %s struggles for air in your flood!"); /* flood */
498 if (rnd(151) == 63) {
500 lprcat("\nYour heart stopped!\n");
505 if (c
[WISDOM
] > rnd(10) + 10)
506 direct(x
, 2000, " The %s's heart stopped", 0); /* finger of death */
508 lprcat(" It didn't work");
511 /* ----- LEVEL 5 SPELLS ----- */
514 c
[SCAREMONST
] += rnd(10) + clev
;
515 return; /* scare monster */
518 c
[HOLDMONST
] += rnd(10) + clev
;
519 return; /* hold monster */
522 c
[TIMESTOP
] += rnd(20) + (clev
<< 1);
523 return; /* time stop */
527 return; /* teleport away */
530 omnidirect(x
, 35 + rnd(10) + clev
, " The %s cringes from the flame"); /* magic fire */
533 /* ----- LEVEL 6 SPELLS ----- */
536 if ((rnd(23) == 5) && (wizard
== 0)) { /* sphere of
539 lprcat("\nYou have been enveloped by the zone of nothingness!\n");
547 i
= dirsub(&xl
, &yl
); /* get direction of sphere */
548 newsphere(xl
, yl
, i
, rnd(20) + 11); /* make a sphere */
553 spelknow
[33] = 0; /* genocide */
557 case 34: /* summon demon */
559 direct(x
, 150, " The demon strikes at the %s", 0);
563 lprcat(" Nothing seems to have happened");
566 lprcat(" The demon turned on you and vanished!");
570 losehp(i
); /* must say killed by a demon */
573 case 35: /* walk through walls */
574 c
[WTW
] += rnd(10) + 5;
577 case 36: /* alter reality */
579 struct isave
*save
; /* pointer to item save
582 sc
= 0; /* # items saved */
583 save
= (struct isave
*) malloc(sizeof(struct isave
) * MAXX
* MAXY
* 2);
584 for (j
= 0; j
< MAXY
; j
++)
585 for (i
= 0; i
< MAXX
; i
++) { /* save all items and
588 if (xl
&& xl
!= OWALL
&& xl
!= OANNIHILATION
) {
590 save
[sc
].id
= item
[i
][j
];
591 save
[sc
++].arg
= iarg
[i
][j
];
595 save
[sc
].id
= mitem
[i
][j
];
596 save
[sc
++].arg
= hitp
[i
][j
];
607 item
[33][MAXY
- 1] = 0;
608 for (j
= rnd(MAXY
- 2), i
= 1; i
< MAXX
- 1; i
++)
610 while (sc
> 0) { /* put objects back in level */
612 if (save
[sc
].type
== 0) {
614 for (trys
= 100, i
= j
= 1; --trys
> 0 && item
[i
][j
]; i
= rnd(MAXX
- 1), j
= rnd(MAXY
- 1));
616 item
[i
][j
] = save
[sc
].id
;
617 iarg
[i
][j
] = save
[sc
].arg
;
619 } else { /* put monsters back in */
621 for (trys
= 100, i
= j
= 1; --trys
> 0 && (item
[i
][j
] == OWALL
|| mitem
[i
][j
]); i
= rnd(MAXX
- 1), j
= rnd(MAXY
- 1));
623 mitem
[i
][j
] = save
[sc
].id
;
624 hitp
[i
][j
] = save
[sc
].arg
;
629 draws(0, MAXX
, 0, MAXY
);
637 case 37: /* permanence */
639 spelknow
[37] = 0; /* forget */
644 lprintf(" spell %ld not available!", (long) x
);
651 * loseint() Routine to subtract 1 from your int (intelligence) if > 3
653 * No arguments and no return value
658 if (--c
[INTELLIGENCE
] < 3)
663 * isconfuse() Routine to check to see if player is confused
665 * This routine prints out a message saying "You can't aim your magic!"
666 * returns 0 if not confused, non-zero (time remaining confused) if confused
672 lprcat(" You can't aim your magic!");
679 * nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster
682 * Subroutine to return 1 if the spell can't affect the monster
683 * otherwise returns 0
684 * Enter with the spell number in x, and the monster number in monst.
691 if (x
>= SPNUM
|| monst
>= MAXMONST
+ 8 || monst
< 0 || x
< 0)
692 return (0); /* bad spell or monst */
693 if ((tmp
= spelweird
[monst
- 1][x
]) == 0)
697 lprintf(spelmes
[tmp
], monster
[monst
].name
);
702 * fullhit(xx) Function to return full damage against a monster (aka web)
705 * Function to return hp damage to monster due to a number of full hits
706 * Enter with the number of full hits being done
713 if (xx
< 0 || xx
> 20)
714 return (0); /* fullhits are out of range */
716 return (10000); /* lance of death */
717 i
= xx
* ((c
[WCLASS
] >> 1) + c
[STRENGTH
] + c
[STREXTRA
] - c
[HARDGAME
] - 12 + c
[MOREDAM
]);
718 return ((i
>= 1) ? i
: xx
);
722 * direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir
726 * Routine to ask for a direction to a spell and then hit the monster
727 * Enter with the spell number in spnum, the damage to be done in dam,
728 * lprintf format string in str, and lprintf's argument in arg.
732 direct(spnum
, dam
, str
, arg
)
738 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0)
739 return; /* bad arguments */
744 if (item
[x
][y
] == OMIRROR
) {
745 if (spnum
== 3) { /* sleep */
746 lprcat("You fall asleep! ");
755 } else if (spnum
== 6) { /* web */
756 lprcat("You get stuck in your own web! ");
761 lprintf(str
, "spell caster (that's you)", (long) arg
);
768 lprcat(" There wasn't anything there!");
772 if (nospell(spnum
, m
)) {
777 lprintf(str
, lastmonst
, (long) arg
);
782 * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks
783 * int spnum,dam,delay;
786 * Function to hit in a direction from a missile weapon and have it keep
787 * on going in that direction until its power is exhausted
788 * Enter with the spell number in spnum, the power of the weapon in hp,
789 * lprintf format string in str, the # of milliseconds to delay between
790 * locations in delay, and the character to represent the weapon in cshow.
794 godirect(spnum
, dam
, str
, delay
, cshow
)
795 int spnum
, dam
, delay
;
796 const char *str
, cshow
;
801 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0 || delay
< 0)
802 return; /* bad args */
815 if ((x
> MAXX
- 1) || (y
> MAXY
- 1) || (x
< 0) || (y
< 0)) {
817 break; /* out of bounds */
819 if ((x
== playerx
) && (y
== playery
)) { /* if energy hits player */
821 lprcat("\nYou are hit by your own magic!");
827 if (c
[BLINDCOUNT
] == 0) { /* if not blind show effect */
828 cursor(x
+ 1, y
+ 1);
833 if ((m
= mitem
[x
][y
])) { /* is there a monster there? */
835 if (nospell(spnum
, m
)) {
842 lprintf(str
, lastmonst
);
843 dam
-= hitm(x
, y
, dam
);
849 switch (*(p
= &item
[x
][y
])) {
853 lprintf(str
, "wall");
854 if (dam
>= 50 + c
[HARDGAME
]) /* enough damage? */
855 if (level
< MAXLEVEL
+ MAXVLEVEL
- 1) /* not on V3 */
856 if ((x
< MAXX
- 1) && (y
< MAXY
- 1) && (x
) && (y
)) {
857 lprcat(" The wall crumbles");
868 lprintf(str
, "door");
870 lprcat(" The door is blasted apart");
878 lprintf(str
, "statue");
881 lprcat(" The statue crumbles");
891 lprintf(str
, "throne");
893 mitem
[x
][y
] = GNOMEKING
;
894 hitp
[x
][y
] = monster
[GNOMEKING
].hitpoints
;
905 dam
-= 3 + (c
[HARDGAME
] >> 1);
910 * ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt
913 * Subroutine to copy the word "monster" into lastmonst if the player is blind
914 * Enter with the coordinates (x,y) of the monster
918 ifblind(int x
, int y
)
922 vxy(&x
, &y
); /* verify correct x,y coordinates */
927 lastnum
= mitem
[x
][y
];
928 p
= monster
[lastnum
].name
;
930 strcpy(lastmonst
, p
);
934 * tdirect(spnum) Routine to teleport away a monster
937 * Routine to ask for a direction to a spell and then teleport away monster
938 * Enter with the spell number that wants to teleport away
947 if (spnum
< 0 || spnum
>= SPNUM
)
948 return; /* bad args */
952 if ((m
= mitem
[x
][y
]) == 0) {
953 lprcat(" There wasn't anything there!");
957 if (nospell(spnum
, m
)) {
963 mitem
[x
][y
] = know
[x
][y
] = 0;
967 * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player
971 * Routine to cast a spell and then hit the monster in all directions
972 * Enter with the spell number in sp, the damage done to wach square in dam,
973 * and the lprintf string to identify the spell in str.
977 omnidirect(int spnum
, int dam
, const char *str
)
981 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0)
982 return; /* bad args */
983 for (x
= playerx
- 1; x
< playerx
+ 2; x
++)
984 for (y
= playery
- 1; y
< playery
+ 2; y
++) {
985 if ((m
= mitem
[x
][y
]) != 0) {
986 if (nospell(spnum
, m
) == 0) {
990 lprintf(str
, lastmonst
);
1002 * static dirsub(x,y) Routine to ask for direction, then modify x,y for it
1005 * Function to ask for a direction and modify an x,y for that direction
1006 * Enter with the origination coordinates in (x,y).
1007 * Returns index into diroffx[] (0-8).
1014 lprcat("\nIn What Direction? ");
1016 switch (ttgetch()) {
1036 *x
= playerx
+ diroffx
[i
];
1037 *y
= playery
+ diroffy
[i
];
1043 * vxy(x,y) Routine to verify/fix coordinates for being within bounds
1046 * Function to verify x & y are within the bounds for a level
1047 * If *x or *y is not within the absolute bounds for a level, fix them so that
1048 * they are on the level.
1049 * Returns TRUE if it was out of bounds, and the *x & *y in the calling
1050 * routine are affected.
1077 * dirpoly(spnum) Routine to ask for a direction and polymorph a monst
1080 * Subroutine to polymorph a monster and ask for the direction its in
1081 * Enter with the spell number in spmun.
1089 if (spnum
< 0 || spnum
>= SPNUM
)
1090 return; /* bad args */
1092 return; /* if he is confused, he can't aim his magic */
1094 if (mitem
[x
][y
] == 0) {
1095 lprcat(" There wasn't anything there!");
1099 if (nospell(spnum
, mitem
[x
][y
])) {
1104 while (monster
[m
= mitem
[x
][y
] = rnd(MAXMONST
+ 7)].genocided
);
1105 hitp
[x
][y
] = monster
[m
].hitpoints
;
1106 show1cell(x
, y
); /* show the new monster */
1110 * hitmonster(x,y) Function to hit a monster at the designated coordinates
1113 * This routine is used for a bash & slash type attack on a monster
1114 * Enter with the coordinates of the monster in (x,y).
1121 int tmp
, monst
, damag
= 0, flag
;
1123 return; /* not if time stopped */
1124 vxy(&x
, &y
); /* verify coordinates are within range */
1125 if ((monst
= mitem
[x
][y
]) == 0)
1129 tmp
= monster
[monst
].armorclass
+ c
[LEVEL
] + c
[DEXTERITY
] +
1132 /* need at least random chance to hit */
1133 if ((rnd(20) < tmp
- c
[HARDGAME
]) || (rnd(71) < 5)) {
1134 lprcat("\nYou hit");
1138 damag
= rnd(damag
) + 1;
1140 lprcat("\nYou missed");
1145 if (flag
) /* if the monster was hit */
1146 if ((monst
== RUSTMONSTER
) || (monst
== DISENCHANTRESS
) || (monst
== CUBE
))
1148 if (ivenarg
[c
[WIELD
]] > -10) {
1149 lprintf("\nYour weapon is dulled by the %s", lastmonst
);
1151 --ivenarg
[c
[WIELD
]];
1155 if (monst
== VAMPIRE
)
1156 if (hitp
[x
][y
] < 25) {
1163 * hitm(x,y,amt) Function to just hit a monster at a given coordinates
1166 * Returns the number of hitpoints the monster absorbed
1167 * This routine is used to specifically damage a monster at a location (x,y)
1168 * Called by hitmonster(x,y)
1177 vxy(&x
, &y
); /* verify coordinates are within range */
1178 amt2
= amt
; /* save initial damage so we can return it */
1179 monst
= mitem
[x
][y
];
1181 amt
>>= 1; /* if half damage curse adjust damage points */
1186 stealth
[x
][y
] = 1; /* make sure hitting monst breaks stealth
1188 c
[HOLDMONST
] = 0; /* hit a monster breaks hold monster spell */
1189 switch (monst
) { /* if a dragon and orb(s) of dragon slaying */
1194 case PLATINUMDRAGON
:
1196 amt
*= 1 + (c
[SLAYING
] << 1);
1199 /* invincible monster fix is here */
1200 if (hitp
[x
][y
] > monster
[monst
].hitpoints
)
1201 hitp
[x
][y
] = monster
[monst
].hitpoints
;
1202 if ((hpoints
= hitp
[x
][y
]) <= amt
) {
1206 lprintf("\nThe %s died!", lastmonst
);
1207 raiseexperience((long) monster
[monst
].experience
);
1208 amt
= monster
[monst
].gold
;
1210 dropgold(rnd(amt
) + amt
);
1211 dropsomething(monst
);
1216 hitp
[x
][y
] = hpoints
- amt
;
1221 * hitplayer(x,y) Function for the monster to hit the player from (x,y)
1224 * Function for the monster to hit the player with monster at location x,y
1225 * Returns nothing of value.
1231 int dam
, tmp
, mster
, bias
;
1232 vxy(&x
, &y
); /* verify coordinates are within range */
1233 lastnum
= mster
= mitem
[x
][y
];
1235 * spirit nagas and poltergeists do nothing if scarab of negate
1238 if (c
[NEGATESPIRIT
] || c
[SPIRITPRO
])
1239 if ((mster
== POLTERGEIST
) || (mster
== SPIRITNAGA
))
1241 /* if undead and cube of undead control */
1242 if (c
[CUBEofUNDEAD
] || c
[UNDEADPRO
])
1243 if ((mster
== VAMPIRE
) || (mster
== WRAITH
) || (mster
== ZOMBIE
))
1245 if ((know
[x
][y
] & 1) == 0) {
1249 bias
= (c
[HARDGAME
]) + 1;
1250 hitflag
= hit2flag
= hit3flag
= 1;
1254 if (c
[INVISIBILITY
])
1256 lprintf("\nThe %s misses wildly", lastmonst
);
1260 if (rnd(30) + 5 * monster
[mster
].level
- c
[CHARISMA
] < 30) {
1261 lprintf("\nThe %s is awestruck at your magnificence!", lastmonst
);
1267 dam
= monster
[mster
].damage
;
1268 dam
+= rnd((int) ((dam
< 1) ? 1 : dam
)) + monster
[mster
].level
;
1271 if (monster
[mster
].attack
> 0)
1272 if (((dam
+ bias
+ 8) > c
[AC
]) || (rnd((int) ((c
[AC
] > 0) ? c
[AC
] : 1)) == 1)) {
1273 if (spattack(monster
[mster
].attack
, x
, y
)) {
1281 if (((dam
+ bias
) > c
[AC
]) || (rnd((int) ((c
[AC
] > 0) ? c
[AC
] : 1)) == 1)) {
1282 lprintf("\n The %s hit you ", lastmonst
);
1284 if ((dam
-= c
[AC
]) < 0)
1293 lprintf("\n The %s missed ", lastmonst
);
1297 * dropsomething(monst) Function to create an object when a monster dies
1300 * Function to create an object near the player when certain monsters are killed
1301 * Enter with the monster number
1302 * Returns nothing of value.
1305 dropsomething(monst
)
1316 case PLATINUMDRAGON
:
1326 dropsomething(LEPRECHAUN
);
1332 * dropgold(amount) Function to drop some gold around player
1335 * Enter with the number of gold pieces to drop
1336 * Returns nothing of value.
1343 createitem(OMAXGOLD
, amount
/ 100);
1345 createitem(OGOLDPILE
, amount
);
1349 * something(level) Function to create a random item around player
1352 * Function to create an item from a designed probability around player
1353 * Enter with the cave level on which something is to be dropped
1354 * Returns nothing of value.
1357 something(int cavelevel
)
1361 if (cavelevel
< 0 || cavelevel
> MAXLEVEL
+ MAXVLEVEL
)
1362 return; /* correct level? */
1364 something(cavelevel
); /* possibly more than one item */
1365 j
= newobject(cavelevel
, &i
);
1370 * newobject(lev,i) Routine to return a randomly selected new object
1373 * Routine to return a randomly selected object to be created
1374 * Returns the object number created, and sets *i for its argument
1375 * Enter with the cave level and a pointer to the items arg
1377 static char nobjtab
[] = {
1378 0, OSCROLL
, OSCROLL
, OSCROLL
, OSCROLL
, OPOTION
, OPOTION
,
1379 OPOTION
, OPOTION
, OGOLDPILE
, OGOLDPILE
, OGOLDPILE
, OGOLDPILE
,
1380 OBOOK
, OBOOK
, OBOOK
, OBOOK
, ODAGGER
, ODAGGER
, ODAGGER
,
1381 OLEATHER
, OLEATHER
, OLEATHER
, OREGENRING
, OPROTRING
,
1382 OENERGYRING
, ODEXRING
, OSTRRING
, OSPEAR
, OBELT
, ORING
,
1383 OSTUDLEATHER
, OSHIELD
, OFLAIL
, OCHAIN
, O2SWORD
, OPLATE
,
1391 if (level
< 0 || level
> MAXLEVEL
+ MAXVLEVEL
)
1392 return (0); /* correct level? */
1397 j
= nobjtab
[tmp
= rnd(tmp
)]; /* the object type */
1415 *i
= rnd((lev
+ 1) * 10) + lev
* 10 + 10;
1426 if (!(*i
= newdagger()))
1432 if (!(*i
= newleather()))
1438 *i
= rund(lev
/ 3 + 1);
1442 *i
= rnd(lev
/ 4 + 1);
1445 *i
= rund(lev
/ 4 + 1);
1448 *i
= rnd(lev
/ 2 + 1);
1452 *i
= rund(lev
/ 2 + 1);
1455 *i
= rund(lev
/ 3 + 1);
1461 *i
= rund(lev
/ 2 + 1);
1479 * spattack(atckno,xx,yy) Function to process special attacks from monsters
1482 * Enter with the special attack number, and the coordinates (xx,yy)
1483 * of the monster that is special attacking
1484 * Returns 1 if must do a show1cell(xx,yy) upon return, 0 otherwise
1486 * atckno monster effect
1487 * ---------------------------------------------------
1489 * 1 rust monster eat armor
1490 * 2 hell hound breathe light fire
1491 * 3 dragon breathe fire
1492 * 4 giant centipede weakening sing
1493 * 5 white dragon cold breath
1494 * 6 wraith drain level
1495 * 7 waterlord water gusher
1496 * 8 leprechaun steal gold
1497 * 9 disenchantress disenchant weapon or armor
1498 * 10 ice lizard hits with barbed tail
1499 * 11 umber hulk confusion
1500 * 12 spirit naga cast spells taken from special attacks
1501 * 13 platinum dragon psionics
1502 * 14 nymph steal objects
1506 * char rustarm[ARMORTYPES][2];
1507 * special array for maximum rust damage to armor from rustmonster
1508 * format is: { armor type , minimum attribute
1510 #define ARMORTYPES 6
1511 static char rustarm
[ARMORTYPES
][2] = {
1512 { OSTUDLEATHER
, -2 },
1519 static char spsel
[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14};
1525 const char *p
= NULL
;
1527 if (c
[CANCELLATION
])
1529 vxy(&xx
, &yy
); /* verify x & y coordinates */
1531 case 1: /* rust your armor, j=1 when rusting has occurred */
1533 if ((i
= c
[SHIELD
]) != -1) {
1534 if (--ivenarg
[i
] < -1)
1539 if ((j
== 0) && (k
!= -1)) {
1541 for (i
= 0; i
< ARMORTYPES
; i
++)
1542 /* find his armor in table */
1543 if (m
== rustarm
[i
][0]) {
1544 if (--ivenarg
[k
] < rustarm
[i
][1])
1545 ivenarg
[k
] = rustarm
[i
][1];
1551 if (j
== 0) /* if rusting did not occur */
1554 p
= "\nThe %s hit you -- You're lucky you have leather on";
1557 p
= "\nThe %s hit you -- You're fortunate to have stainless steel armor!";
1562 p
= "\nThe %s hit you -- your armor feels weaker";
1567 i
= rnd(15) + 8 - c
[AC
];
1568 spout
: p
= "\nThe %s breathes fire at you!";
1569 if (c
[FIRERESISTANCE
])
1570 p
= "\nThe %s's flame doesn't faze you!";
1573 lprintf(p
, lastmonst
);
1580 i
= rnd(20) + 25 - c
[AC
];
1584 if (c
[STRENGTH
] > 3) {
1585 p
= "\nThe %s stung you! You feel weaker";
1589 p
= "\nThe %s stung you!";
1593 p
= "\nThe %s blasts you with his cold breath";
1594 i
= rnd(15) + 18 - c
[AC
];
1598 lprintf("\nThe %s drains you of your life energy!", lastmonst
);
1604 p
= "\nThe %s got you with a gusher!";
1605 i
= rnd(15) + 25 - c
[AC
];
1610 return (0); /* he has a device of no theft */
1612 p
= "\nThe %s hit you -- Your purse feels lighter";
1613 if (c
[GOLD
] > 32767)
1616 c
[GOLD
] -= rnd((int) (1 + (c
[GOLD
] >> 1)));
1620 p
= "\nThe %s couldn't find any gold to steal";
1621 lprintf(p
, lastmonst
);
1628 for (j
= 50;;) {/* disenchant */
1630 m
= iven
[i
]; /* randomly select item */
1631 if (m
> 0 && ivenarg
[i
] > 0 && m
!= OSCROLL
&& m
!= OPOTION
) {
1632 if ((ivenarg
[i
] -= 3) < 0)
1634 lprintf("\nThe %s hits you -- you feel a sense of loss", lastmonst
);
1642 p
= "\nThe %s nearly misses";
1650 p
= "\nThe %s hit you with his barbed tail";
1651 i
= rnd(25) - c
[AC
];
1655 p
= "\nThe %s has confused you";
1657 c
[CONFUSE
] += 10 + rnd(10);
1660 case 12: /* performs any number of other special
1662 return (spattack(spsel
[rund(10)], xx
, yy
));
1665 p
= "\nThe %s flattens you with his psionics!";
1666 i
= rnd(15) + 30 - c
[AC
];
1671 return (0); /* he has device of no theft */
1672 if (emptyhanded() == 1) {
1673 p
= "\nThe %s couldn't find anything to steal";
1676 lprintf("\nThe %s picks your pocket and takes:", lastmonst
);
1678 if (stealsomething() == 0)
1685 i
= rnd(10) + 5 - c
[AC
];
1686 spout3
: p
= "\nThe %s bit you!";
1690 i
= rnd(15) + 10 - c
[AC
];
1694 lprintf(p
, lastmonst
);
1701 * checkloss(x) Routine to subtract hp from user and flag bottomline display
1704 * Routine to subtract hitpoints from the user and flag the bottomline display
1705 * Enter with the number of hit points to lose
1706 * Note: if x > c[HP] this routine could kill the player!
1719 * annihilate() Routine to annihilate all monsters around player (playerx,playery)
1721 * Gives player experience, but no dropped objects
1722 * Returns the experience gained from all monsters killed
1730 for (k
= 0, i
= playerx
- 1; i
<= playerx
+ 1; i
++)
1731 for (j
= playery
- 1; j
<= playery
+ 1; j
++)
1732 if (!vxy(&i
, &j
)) { /* if not out of bounds */
1733 if (*(p
= &mitem
[i
][j
])) { /* if a monster there */
1734 if (*p
< DEMONLORD
+ 2) {
1735 k
+= monster
[*p
].experience
;
1736 *p
= know
[i
][j
] = 0;
1738 lprintf("\nThe %s barely escapes being annihilated!", monster
[*p
].name
);
1739 hitp
[i
][j
] = (hitp
[i
][j
] >> 1) + 1; /* lose half hit points */
1744 lprcat("\nYou hear loud screams of agony!");
1745 raiseexperience((long) k
);
1751 * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation
1752 * int x,y,dir,lifetime;
1754 * Enter with the coordinates of the sphere in x,y
1755 * the direction (0-8 diroffx format) in dir, and the lifespan of the
1756 * sphere in lifetime (in turns)
1757 * Returns the number of spheres currently in existence
1760 newsphere(x
, y
, dir
, life
)
1761 int x
, y
, dir
, life
;
1765 if (((sp
= (struct sphere
*) malloc(sizeof(struct sphere
)))) == 0)
1766 return (c
[SPHCAST
]); /* can't malloc, therefore failure */
1768 dir
= 0; /* no movement if direction not found */
1770 vxy(&x
, &y
); /* don't go out of bounds */
1781 if ((m
= mitem
[x
][y
]) >= DEMONLORD
+ 4) { /* demons dispel spheres */
1783 show1cell(x
, y
);/* show the demon (ha ha) */
1785 lprintf("\nThe %s dispels the sphere!", monster
[m
].name
);
1787 rmsphere(x
, y
); /* remove any spheres that are here */
1789 return (c
[SPHCAST
]);
1791 if (m
== DISENCHANTRESS
) { /* disenchantress cancels spheres */
1793 lprintf("\nThe %s causes cancellation of the sphere!", monster
[m
].name
);
1795 boom
: sphboom(x
, y
); /* blow up stuff around sphere */
1796 rmsphere(x
, y
); /* remove any spheres that are here */
1798 return (c
[SPHCAST
]);
1800 if (c
[CANCELLATION
]) { /* cancellation cancels spheres */
1802 lprcat("\nAs the cancellation takes effect, you hear a great earth shaking blast!");
1806 if (item
[x
][y
] == OANNIHILATION
) { /* collision of spheres
1807 * detonates spheres */
1809 lprcat("\nTwo spheres of annihilation collide! You hear a great earth shaking blast!");
1814 if (playerx
== x
&& playery
== y
) { /* collision of sphere and
1817 lprcat("\nYou have been enveloped by the zone of nothingness!\n");
1819 rmsphere(x
, y
); /* remove any spheres that are here */
1823 item
[x
][y
] = OANNIHILATION
;
1826 show1cell(x
, y
); /* show the new sphere */
1831 sp
->lifetime
= life
;
1834 spheres
= sp
; /* if first node in the sphere list */
1835 else { /* add sphere to beginning of linked list */
1839 return (++c
[SPHCAST
]); /* one more sphere in the world */
1843 * rmsphere(x,y) Function to delete a sphere of annihilation from list
1846 * Enter with the coordinates of the sphere (on current level)
1847 * Returns the number of spheres currently in existence
1853 struct sphere
*sp
, *sp2
= 0;
1854 for (sp
= spheres
; sp
; sp2
= sp
, sp
= sp
->p
)
1855 if (level
== sp
->lev
) /* is sphere on this level? */
1856 if ((x
== sp
->x
) && (y
== sp
->y
)) { /* locate sphere at this
1858 item
[x
][y
] = mitem
[x
][y
] = 0;
1860 show1cell(x
, y
); /* show the now missing
1863 if (sp
== spheres
) {
1874 return (c
[SPHCAST
]); /* return number of spheres in the world */
1878 * sphboom(x,y) Function to perform the effects of a sphere detonation
1881 * Enter with the coordinates of the blast, Returns no value
1890 if (c
[CANCELLATION
])
1891 c
[CANCELLATION
] = 1;
1892 for (j
= max(1, x
- 2); j
< min(x
+ 3, MAXX
- 1); j
++)
1893 for (i
= max(1, y
- 2); i
< min(y
+ 3, MAXY
- 1); i
++) {
1894 item
[j
][i
] = mitem
[j
][i
] = 0;
1896 if (playerx
== j
&& playery
== i
) {
1899 lprcat("\nYou were too close to the sphere!");
1901 died(283); /* player killed in explosion */
1907 * genmonst() Function to ask for monster and genocide from game
1909 * This is done by setting a flag in the monster[] structure
1916 lprcat("\nGenocide what monster? ");
1917 for (i
= 0; (!isalpha(i
)) && (i
!= ' '); i
= ttgetch());
1919 for (j
= 0; j
< MAXMONST
; j
++) /* search for the monster type */
1920 if (monstnamelist
[j
] == i
) { /* have we found it? */
1921 monster
[j
].genocided
= 1; /* genocided from game */
1922 lprintf(" There will be no more %s's", monster
[j
].name
);
1923 /* now wipe out monsters on this level */
1924 newcavelevel(level
);
1925 draws(0, MAXX
, 0, MAXY
);
1929 lprcat(" You sense failure!");