]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/monster.c
2b691569ffac8a0079f31eaa1430b9a1be848c89
1 /* $NetBSD: monster.c,v 1.14 2008/02/03 19:20:42 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.14 2008/02/03 19:20:42 dholland Exp $");
104 #endif /* not lint */
111 struct isave
{ /* used for altar reality */
112 char type
; /* 0=item, 1=monster */
113 char id
; /* item number or monster number */
114 short arg
; /* the type of item or hitpoints of monster */
117 static int cgood(int, int, int, int);
118 static int dirsub(int *, int *);
119 static void dropsomething(int);
120 static int spattack(int, int, int);
123 * createmonster(monstno) Function to create a monster next to the player
126 * Enter with the monster number (1 to MAXMONST+8)
134 if (mon
< 1 || mon
> MAXMONST
+ 8) { /* check for monster number
137 lprintf("\ncan't createmonst(%ld)\n", (long) mon
);
141 while (monster
[mon
].genocided
&& mon
< MAXMONST
)
142 mon
++; /* genocided? */
143 for (k
= rnd(8), i
= -8; i
< 0; i
++, k
++) { /* choose direction,
146 k
= 1; /* wraparound the diroff arrays */
147 x
= playerx
+ diroffx
[k
];
148 y
= playery
+ diroffy
[k
];
149 if (cgood(x
, y
, 0, 1)) { /* if we can create here */
151 hitp
[x
][y
] = monster
[mon
].hitpoints
;
152 stealth
[x
][y
] = know
[x
][y
] = 0;
165 * int cgood(x,y,itm,monst) Function to check location for emptiness
168 * Routine to return TRUE if a location does not have itm or monst there
169 * returns FALSE (0) otherwise
170 * Enter with itm or monst TRUE or FALSE if checking it
171 * Example: if itm==TRUE check for no item at this location
172 * if monst==TRUE check for no monster at this location
173 * This routine will return FALSE if at a wall or the dungeon exit on level 1
176 cgood(int x
, int y
, int theitem
, int monst
)
179 if ((y
>= 0) && (y
<= MAXY
- 1) && (x
>= 0) && (x
<= MAXX
- 1))
181 if (item
[x
][y
] != OWALL
) /* can't make anything on walls */
182 /* is it free of items? */
183 if (theitem
== 0 || (item
[x
][y
] == 0))
184 /* is it free of monsters? */
185 if (monst
== 0 || (mitem
[x
][y
] == 0))
186 if ((level
!= 1) || (x
!= 33) ||
188 /* not exit to level 1 */
194 * createitem(it,arg) Routine to place an item next to the player
197 * Enter with the item number and its argument (iven[], ivenarg[])
198 * Returns no value, thus we don't know about createitem() failures.
206 return; /* no such object */
207 for (k
= rnd(8), i
= -8; i
< 0; i
++, k
++) { /* choose direction,
210 k
= 1; /* wraparound the diroff arrays */
211 x
= playerx
+ diroffx
[k
];
212 y
= playery
+ diroffy
[k
];
213 if (cgood(x
, y
, 1, 0)) { /* if we can create here */
223 * cast() Subroutine called by parse to cast a spell for the user
225 * No arguments and no return value.
227 static char eys
[] = "\nEnter your spell: ";
233 if (c
[SPELLS
] <= 0) {
234 lprcat("\nYou don't have any spells!");
239 while ((a
= lgetchar()) == 'D') {
245 goto over
; /* to escape casting a spell */
246 if ((b
= lgetchar()) == '\33')
247 goto over
; /* to escape casting a spell */
248 if ((d
= lgetchar()) == '\33') {
249 over
: lprcat(aborted
);
252 } /* to escape casting a spell */
256 for (lprc('\n'), j
= -1, i
= 0; i
< SPNUM
; i
++) /* seq search for his
258 if ((spelcode
[i
][0] == a
) && (spelcode
[i
][1] == b
) && (spelcode
[i
][2] == d
))
265 lprcat(" Nothing Happened ");
270 * speldamage(x) Function to perform spell functions cast by the player
273 * Enter with the spell number, returns no value.
274 * Please insure that there are 2 spaces before all messages here
284 return; /* no such spell */
286 lprcat(" It didn't seem to work");
288 } /* not if time stopped */
290 if ((rnd(23) == 7) || (rnd(18) > c
[INTELLIGENCE
])) {
291 lprcat(" It didn't work!");
294 if (clev
* 3 + 2 < x
) {
295 lprcat(" Nothing happens. You seem inexperienced at this");
299 /* ----- LEVEL 1 SPELLS ----- */
302 if (c
[PROTECTIONTIME
] == 0)
303 c
[MOREDEFENSES
] += 2; /* protection field +2 */
304 c
[PROTECTIONTIME
] += 250;
308 i
= rnd(((clev
+ 1) << 1)) + clev
+ 3;
309 godirect(x
, i
, (clev
>= 2) ? " Your missiles hit the %s" : " Your missile hit the %s", 100, '+'); /* magic missile */
314 if (c
[DEXCOUNT
] == 0)
315 c
[DEXTERITY
] += 3; /* dexterity */
321 direct(x
, fullhit(i
),
322 " While the %s slept, you smashed it %ld times", i
);
325 case 4: /* charm monster */
326 c
[CHARMCOUNT
] += c
[CHARISMA
] << 1;
330 godirect(x
, rnd(10) + 15 + clev
, " The sound damages the %s", 70, '@'); /* sonic spear */
333 /* ----- LEVEL 2 SPELLS ----- */
337 direct(x
, fullhit(i
),
338 " While the %s is entangled, you hit %ld times", i
);
342 if (c
[STRCOUNT
] == 0)
343 c
[STREXTRA
] += 3; /* strength */
344 c
[STRCOUNT
] += 150 + rnd(100);
348 yl
= playery
- 5; /* enlightenment */
353 vxy(&xh
, &yh
); /* check bounds */
354 for (i
= yl
; i
<= yh
; i
++) /* enlightenment */
355 for (j
= xl
; j
<= xh
; j
++)
357 draws(xl
, xh
+ 1, yl
, yh
+ 1);
361 raisehp(20 + (clev
<< 1));
362 return; /* healing */
366 return; /* cure blindness */
369 createmonster(makemonst(level
+ 1) + 8);
373 if (rnd(11) + 7 <= c
[WISDOM
])
374 direct(x
, rnd(20) + 20 + clev
, " The %s believed!", 0);
376 lprcat(" It didn't believe the illusions!");
379 case 13: /* if he has the amulet of invisibility then
381 for (j
= i
= 0; i
< 26; i
++)
382 if (iven
[i
] == OAMULET
)
384 c
[INVISIBILITY
] += (j
<< 7) + 12;
387 /* ----- LEVEL 3 SPELLS ----- */
390 godirect(x
, rnd(25 + clev
) + 25 + clev
, " The fireball hits the %s", 40, '*');
391 return; /* fireball */
394 godirect(x
, rnd(25) + 20 + clev
, " Your cone of cold strikes the %s", 60, 'O'); /* cold */
399 return; /* polymorph */
402 c
[CANCELLATION
] += 5 + clev
;
403 return; /* cancellation */
406 c
[HASTESELF
] += 7 + clev
;
407 return; /* haste self */
410 omnidirect(x
, 30 + rnd(10), " The %s gasps for air"); /* cloud kill */
414 xh
= min(playerx
+ 1, MAXX
- 2);
415 yh
= min(playery
+ 1, MAXY
- 2);
416 for (i
= max(playerx
- 1, 1); i
<= xh
; i
++) /* vaporize rock */
417 for (j
= max(playery
- 1, 1); j
<= yh
; j
++) {
420 switch (*(p
= &item
[i
][j
])) {
422 if (level
< MAXLEVEL
+ MAXVLEVEL
- 1)
427 if (c
[HARDGAME
] < 3) {
438 hitp
[i
][j
] = monster
[GNOMEKING
].hitpoints
;
444 hitp
[i
][j
] = monster
[DEMONPRINCE
].hitpoints
;
451 break; /* Xorn takes damage from vpr */
456 /* ----- LEVEL 4 SPELLS ----- */
459 direct(x
, 100 + clev
, " The %s shrivels up", 0); /* dehydration */
463 godirect(x
, rnd(25) + 20 + (clev
<< 1), " A lightning bolt hits the %s", 1, '~'); /* lightning */
467 i
= min(c
[HP
] - 1, c
[HPMAX
] / 2); /* drain life */
468 direct(x
, i
+ i
, "", 0);
474 c
[MOREDEFENSES
] += 10;
476 loseint(); /* globe of invulnerability */
480 omnidirect(x
, 32 + clev
, " The %s struggles for air in your flood!"); /* flood */
484 if (rnd(151) == 63) {
486 lprcat("\nYour heart stopped!\n");
491 if (c
[WISDOM
] > rnd(10) + 10)
492 direct(x
, 2000, " The %s's heart stopped", 0); /* finger of death */
494 lprcat(" It didn't work");
497 /* ----- LEVEL 5 SPELLS ----- */
500 c
[SCAREMONST
] += rnd(10) + clev
;
501 return; /* scare monster */
504 c
[HOLDMONST
] += rnd(10) + clev
;
505 return; /* hold monster */
508 c
[TIMESTOP
] += rnd(20) + (clev
<< 1);
509 return; /* time stop */
513 return; /* teleport away */
516 omnidirect(x
, 35 + rnd(10) + clev
, " The %s cringes from the flame"); /* magic fire */
519 /* ----- LEVEL 6 SPELLS ----- */
522 if ((rnd(23) == 5) && (wizard
== 0)) { /* sphere of
525 lprcat("\nYou have been enveloped by the zone of nothingness!\n");
533 i
= dirsub(&xl
, &yl
); /* get direction of sphere */
534 newsphere(xl
, yl
, i
, rnd(20) + 11); /* make a sphere */
539 spelknow
[33] = 0; /* genocide */
543 case 34: /* summon demon */
545 direct(x
, 150, " The demon strikes at the %s", 0);
549 lprcat(" Nothing seems to have happened");
552 lprcat(" The demon turned on you and vanished!");
556 losehp(i
); /* must say killed by a demon */
559 case 35: /* walk through walls */
560 c
[WTW
] += rnd(10) + 5;
563 case 36: /* alter reality */
565 struct isave
*save
; /* pointer to item save
568 sc
= 0; /* # items saved */
569 save
= (struct isave
*) malloc(sizeof(struct isave
) * MAXX
* MAXY
* 2);
570 for (j
= 0; j
< MAXY
; j
++)
571 for (i
= 0; i
< MAXX
; i
++) { /* save all items and
574 if (xl
&& xl
!= OWALL
&& xl
!= OANNIHILATION
) {
576 save
[sc
].id
= item
[i
][j
];
577 save
[sc
++].arg
= iarg
[i
][j
];
581 save
[sc
].id
= mitem
[i
][j
];
582 save
[sc
++].arg
= hitp
[i
][j
];
593 item
[33][MAXY
- 1] = 0;
594 for (j
= rnd(MAXY
- 2), i
= 1; i
< MAXX
- 1; i
++)
596 while (sc
> 0) { /* put objects back in level */
598 if (save
[sc
].type
== 0) {
600 for (trys
= 100, i
= j
= 1; --trys
> 0 && item
[i
][j
]; i
= rnd(MAXX
- 1), j
= rnd(MAXY
- 1));
602 item
[i
][j
] = save
[sc
].id
;
603 iarg
[i
][j
] = save
[sc
].arg
;
605 } else { /* put monsters back in */
607 for (trys
= 100, i
= j
= 1; --trys
> 0 && (item
[i
][j
] == OWALL
|| mitem
[i
][j
]); i
= rnd(MAXX
- 1), j
= rnd(MAXY
- 1));
609 mitem
[i
][j
] = save
[sc
].id
;
610 hitp
[i
][j
] = save
[sc
].arg
;
615 draws(0, MAXX
, 0, MAXY
);
623 case 37: /* permanence */
625 spelknow
[37] = 0; /* forget */
630 lprintf(" spell %ld not available!", (long) x
);
637 * loseint() Routine to subtract 1 from your int (intelligence) if > 3
639 * No arguments and no return value
644 if (--c
[INTELLIGENCE
] < 3)
649 * isconfuse() Routine to check to see if player is confused
651 * This routine prints out a message saying "You can't aim your magic!"
652 * returns 0 if not confused, non-zero (time remaining confused) if confused
658 lprcat(" You can't aim your magic!");
665 * nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster
668 * Subroutine to return 1 if the spell can't affect the monster
669 * otherwise returns 0
670 * Enter with the spell number in x, and the monster number in monst.
677 if (x
>= SPNUM
|| monst
>= MAXMONST
+ 8 || monst
< 0 || x
< 0)
678 return (0); /* bad spell or monst */
679 if ((tmp
= spelweird
[monst
- 1][x
]) == 0)
683 lprintf(spelmes
[tmp
], monster
[monst
].name
);
688 * fullhit(xx) Function to return full damage against a monster (aka web)
691 * Function to return hp damage to monster due to a number of full hits
692 * Enter with the number of full hits being done
699 if (xx
< 0 || xx
> 20)
700 return (0); /* fullhits are out of range */
702 return (10000); /* lance of death */
703 i
= xx
* ((c
[WCLASS
] >> 1) + c
[STRENGTH
] + c
[STREXTRA
] - c
[HARDGAME
] - 12 + c
[MOREDAM
]);
704 return ((i
>= 1) ? i
: xx
);
708 * direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir
712 * Routine to ask for a direction to a spell and then hit the monster
713 * Enter with the spell number in spnum, the damage to be done in dam,
714 * lprintf format string in str, and lprintf's argument in arg.
718 direct(spnum
, dam
, str
, arg
)
724 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0)
725 return; /* bad arguments */
730 if (item
[x
][y
] == OMIRROR
) {
731 if (spnum
== 3) { /* sleep */
732 lprcat("You fall asleep! ");
741 } else if (spnum
== 6) { /* web */
742 lprcat("You get stuck in your own web! ");
747 lprintf(str
, "spell caster (that's you)", (long) arg
);
754 lprcat(" There wasn't anything there!");
758 if (nospell(spnum
, m
)) {
763 lprintf(str
, lastmonst
, (long) arg
);
768 * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks
769 * int spnum,dam,delay;
772 * Function to hit in a direction from a missile weapon and have it keep
773 * on going in that direction until its power is exhausted
774 * Enter with the spell number in spnum, the power of the weapon in hp,
775 * lprintf format string in str, the # of milliseconds to delay between
776 * locations in delay, and the character to represent the weapon in cshow.
780 godirect(spnum
, dam
, str
, delay
, cshow
)
781 int spnum
, dam
, delay
;
782 const char *str
, cshow
;
787 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0 || delay
< 0)
788 return; /* bad args */
801 if ((x
> MAXX
- 1) || (y
> MAXY
- 1) || (x
< 0) || (y
< 0)) {
803 break; /* out of bounds */
805 if ((x
== playerx
) && (y
== playery
)) { /* if energy hits player */
807 lprcat("\nYou are hit by your own magic!");
813 if (c
[BLINDCOUNT
] == 0) { /* if not blind show effect */
814 cursor(x
+ 1, y
+ 1);
819 if ((m
= mitem
[x
][y
])) { /* is there a monster there? */
821 if (nospell(spnum
, m
)) {
828 lprintf(str
, lastmonst
);
829 dam
-= hitm(x
, y
, dam
);
835 switch (*(p
= &item
[x
][y
])) {
839 lprintf(str
, "wall");
840 if (dam
>= 50 + c
[HARDGAME
]) /* enough damage? */
841 if (level
< MAXLEVEL
+ MAXVLEVEL
- 1) /* not on V3 */
842 if ((x
< MAXX
- 1) && (y
< MAXY
- 1) && (x
) && (y
)) {
843 lprcat(" The wall crumbles");
854 lprintf(str
, "door");
856 lprcat(" The door is blasted apart");
864 lprintf(str
, "statue");
867 lprcat(" The statue crumbles");
877 lprintf(str
, "throne");
879 mitem
[x
][y
] = GNOMEKING
;
880 hitp
[x
][y
] = monster
[GNOMEKING
].hitpoints
;
891 dam
-= 3 + (c
[HARDGAME
] >> 1);
896 * ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt
899 * Subroutine to copy the word "monster" into lastmonst if the player is blind
900 * Enter with the coordinates (x,y) of the monster
904 ifblind(int x
, int y
)
908 vxy(&x
, &y
); /* verify correct x,y coordinates */
913 lastnum
= mitem
[x
][y
];
914 p
= monster
[lastnum
].name
;
916 strcpy(lastmonst
, p
);
920 * tdirect(spnum) Routine to teleport away a monster
923 * Routine to ask for a direction to a spell and then teleport away monster
924 * Enter with the spell number that wants to teleport away
933 if (spnum
< 0 || spnum
>= SPNUM
)
934 return; /* bad args */
938 if ((m
= mitem
[x
][y
]) == 0) {
939 lprcat(" There wasn't anything there!");
943 if (nospell(spnum
, m
)) {
949 mitem
[x
][y
] = know
[x
][y
] = 0;
953 * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player
957 * Routine to cast a spell and then hit the monster in all directions
958 * Enter with the spell number in sp, the damage done to wach square in dam,
959 * and the lprintf string to identify the spell in str.
963 omnidirect(int spnum
, int dam
, const char *str
)
967 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0)
968 return; /* bad args */
969 for (x
= playerx
- 1; x
< playerx
+ 2; x
++)
970 for (y
= playery
- 1; y
< playery
+ 2; y
++) {
971 if ((m
= mitem
[x
][y
]) != 0) {
972 if (nospell(spnum
, m
) == 0) {
976 lprintf(str
, lastmonst
);
988 * static dirsub(x,y) Routine to ask for direction, then modify x,y for it
991 * Function to ask for a direction and modify an x,y for that direction
992 * Enter with the origination coordinates in (x,y).
993 * Returns index into diroffx[] (0-8).
1000 lprcat("\nIn What Direction? ");
1002 switch (lgetchar()) {
1022 *x
= playerx
+ diroffx
[i
];
1023 *y
= playery
+ diroffy
[i
];
1029 * vxy(x,y) Routine to verify/fix coordinates for being within bounds
1032 * Function to verify x & y are within the bounds for a level
1033 * If *x or *y is not within the absolute bounds for a level, fix them so that
1034 * they are on the level.
1035 * Returns TRUE if it was out of bounds, and the *x & *y in the calling
1036 * routine are affected.
1063 * dirpoly(spnum) Routine to ask for a direction and polymorph a monst
1066 * Subroutine to polymorph a monster and ask for the direction its in
1067 * Enter with the spell number in spmun.
1075 if (spnum
< 0 || spnum
>= SPNUM
)
1076 return; /* bad args */
1078 return; /* if he is confused, he can't aim his magic */
1080 if (mitem
[x
][y
] == 0) {
1081 lprcat(" There wasn't anything there!");
1085 if (nospell(spnum
, mitem
[x
][y
])) {
1090 while (monster
[m
= mitem
[x
][y
] = rnd(MAXMONST
+ 7)].genocided
);
1091 hitp
[x
][y
] = monster
[m
].hitpoints
;
1092 show1cell(x
, y
); /* show the new monster */
1096 * hitmonster(x,y) Function to hit a monster at the designated coordinates
1099 * This routine is used for a bash & slash type attack on a monster
1100 * Enter with the coordinates of the monster in (x,y).
1107 int tmp
, monst
, damag
= 0, flag
;
1109 return; /* not if time stopped */
1110 vxy(&x
, &y
); /* verify coordinates are within range */
1111 if ((monst
= mitem
[x
][y
]) == 0)
1115 tmp
= monster
[monst
].armorclass
+ c
[LEVEL
] + c
[DEXTERITY
] +
1118 /* need at least random chance to hit */
1119 if ((rnd(20) < tmp
- c
[HARDGAME
]) || (rnd(71) < 5)) {
1120 lprcat("\nYou hit");
1124 damag
= rnd(damag
) + 1;
1126 lprcat("\nYou missed");
1131 if (flag
) /* if the monster was hit */
1132 if ((monst
== RUSTMONSTER
) || (monst
== DISENCHANTRESS
) || (monst
== CUBE
))
1134 if (ivenarg
[c
[WIELD
]] > -10) {
1135 lprintf("\nYour weapon is dulled by the %s", lastmonst
);
1137 --ivenarg
[c
[WIELD
]];
1141 if (monst
== VAMPIRE
)
1142 if (hitp
[x
][y
] < 25) {
1149 * hitm(x,y,amt) Function to just hit a monster at a given coordinates
1152 * Returns the number of hitpoints the monster absorbed
1153 * This routine is used to specifically damage a monster at a location (x,y)
1154 * Called by hitmonster(x,y)
1163 vxy(&x
, &y
); /* verify coordinates are within range */
1164 amt2
= amt
; /* save initial damage so we can return it */
1165 monst
= mitem
[x
][y
];
1167 amt
>>= 1; /* if half damage curse adjust damage points */
1172 stealth
[x
][y
] = 1; /* make sure hitting monst breaks stealth
1174 c
[HOLDMONST
] = 0; /* hit a monster breaks hold monster spell */
1175 switch (monst
) { /* if a dragon and orb(s) of dragon slaying */
1180 case PLATINUMDRAGON
:
1182 amt
*= 1 + (c
[SLAYING
] << 1);
1185 /* invincible monster fix is here */
1186 if (hitp
[x
][y
] > monster
[monst
].hitpoints
)
1187 hitp
[x
][y
] = monster
[monst
].hitpoints
;
1188 if ((hpoints
= hitp
[x
][y
]) <= amt
) {
1192 lprintf("\nThe %s died!", lastmonst
);
1193 raiseexperience((long) monster
[monst
].experience
);
1194 amt
= monster
[monst
].gold
;
1196 dropgold(rnd(amt
) + amt
);
1197 dropsomething(monst
);
1202 hitp
[x
][y
] = hpoints
- amt
;
1207 * hitplayer(x,y) Function for the monster to hit the player from (x,y)
1210 * Function for the monster to hit the player with monster at location x,y
1211 * Returns nothing of value.
1217 int dam
, tmp
, mster
, bias
;
1218 vxy(&x
, &y
); /* verify coordinates are within range */
1219 lastnum
= mster
= mitem
[x
][y
];
1221 * spirit nagas and poltergeists do nothing if scarab of negate
1224 if (c
[NEGATESPIRIT
] || c
[SPIRITPRO
])
1225 if ((mster
== POLTERGEIST
) || (mster
== SPIRITNAGA
))
1227 /* if undead and cube of undead control */
1228 if (c
[CUBEofUNDEAD
] || c
[UNDEADPRO
])
1229 if ((mster
== VAMPIRE
) || (mster
== WRAITH
) || (mster
== ZOMBIE
))
1231 if ((know
[x
][y
] & 1) == 0) {
1235 bias
= (c
[HARDGAME
]) + 1;
1236 hitflag
= hit2flag
= hit3flag
= 1;
1240 if (c
[INVISIBILITY
])
1242 lprintf("\nThe %s misses wildly", lastmonst
);
1246 if (rnd(30) + 5 * monster
[mster
].level
- c
[CHARISMA
] < 30) {
1247 lprintf("\nThe %s is awestruck at your magnificence!", lastmonst
);
1253 dam
= monster
[mster
].damage
;
1254 dam
+= rnd((int) ((dam
< 1) ? 1 : dam
)) + monster
[mster
].level
;
1257 if (monster
[mster
].attack
> 0)
1258 if (((dam
+ bias
+ 8) > c
[AC
]) || (rnd((int) ((c
[AC
] > 0) ? c
[AC
] : 1)) == 1)) {
1259 if (spattack(monster
[mster
].attack
, x
, y
)) {
1267 if (((dam
+ bias
) > c
[AC
]) || (rnd((int) ((c
[AC
] > 0) ? c
[AC
] : 1)) == 1)) {
1268 lprintf("\n The %s hit you ", lastmonst
);
1270 if ((dam
-= c
[AC
]) < 0)
1279 lprintf("\n The %s missed ", lastmonst
);
1283 * dropsomething(monst) Function to create an object when a monster dies
1286 * Function to create an object near the player when certain monsters are killed
1287 * Enter with the monster number
1288 * Returns nothing of value.
1291 dropsomething(monst
)
1302 case PLATINUMDRAGON
:
1312 dropsomething(LEPRECHAUN
);
1318 * dropgold(amount) Function to drop some gold around player
1321 * Enter with the number of gold pieces to drop
1322 * Returns nothing of value.
1329 createitem(OMAXGOLD
, amount
/ 100);
1331 createitem(OGOLDPILE
, amount
);
1335 * something(level) Function to create a random item around player
1338 * Function to create an item from a designed probability around player
1339 * Enter with the cave level on which something is to be dropped
1340 * Returns nothing of value.
1343 something(int cavelevel
)
1347 if (cavelevel
< 0 || cavelevel
> MAXLEVEL
+ MAXVLEVEL
)
1348 return; /* correct level? */
1350 something(cavelevel
); /* possibly more than one item */
1351 j
= newobject(cavelevel
, &i
);
1356 * newobject(lev,i) Routine to return a randomly selected new object
1359 * Routine to return a randomly selected object to be created
1360 * Returns the object number created, and sets *i for its argument
1361 * Enter with the cave level and a pointer to the items arg
1363 static char nobjtab
[] = {
1364 0, OSCROLL
, OSCROLL
, OSCROLL
, OSCROLL
, OPOTION
, OPOTION
,
1365 OPOTION
, OPOTION
, OGOLDPILE
, OGOLDPILE
, OGOLDPILE
, OGOLDPILE
,
1366 OBOOK
, OBOOK
, OBOOK
, OBOOK
, ODAGGER
, ODAGGER
, ODAGGER
,
1367 OLEATHER
, OLEATHER
, OLEATHER
, OREGENRING
, OPROTRING
,
1368 OENERGYRING
, ODEXRING
, OSTRRING
, OSPEAR
, OBELT
, ORING
,
1369 OSTUDLEATHER
, OSHIELD
, OFLAIL
, OCHAIN
, O2SWORD
, OPLATE
,
1377 if (level
< 0 || level
> MAXLEVEL
+ MAXVLEVEL
)
1378 return (0); /* correct level? */
1383 j
= nobjtab
[tmp
= rnd(tmp
)]; /* the object type */
1401 *i
= rnd((lev
+ 1) * 10) + lev
* 10 + 10;
1412 if (!(*i
= newdagger()))
1418 if (!(*i
= newleather()))
1424 *i
= rund(lev
/ 3 + 1);
1428 *i
= rnd(lev
/ 4 + 1);
1431 *i
= rund(lev
/ 4 + 1);
1434 *i
= rnd(lev
/ 2 + 1);
1438 *i
= rund(lev
/ 2 + 1);
1441 *i
= rund(lev
/ 3 + 1);
1447 *i
= rund(lev
/ 2 + 1);
1465 * spattack(atckno,xx,yy) Function to process special attacks from monsters
1468 * Enter with the special attack number, and the coordinates (xx,yy)
1469 * of the monster that is special attacking
1470 * Returns 1 if must do a show1cell(xx,yy) upon return, 0 otherwise
1472 * atckno monster effect
1473 * ---------------------------------------------------
1475 * 1 rust monster eat armor
1476 * 2 hell hound breathe light fire
1477 * 3 dragon breathe fire
1478 * 4 giant centipede weakening sing
1479 * 5 white dragon cold breath
1480 * 6 wraith drain level
1481 * 7 waterlord water gusher
1482 * 8 leprechaun steal gold
1483 * 9 disenchantress disenchant weapon or armor
1484 * 10 ice lizard hits with barbed tail
1485 * 11 umber hulk confusion
1486 * 12 spirit naga cast spells taken from special attacks
1487 * 13 platinum dragon psionics
1488 * 14 nymph steal objects
1492 * char rustarm[ARMORTYPES][2];
1493 * special array for maximum rust damage to armor from rustmonster
1494 * format is: { armor type , minimum attribute
1496 #define ARMORTYPES 6
1497 static char rustarm
[ARMORTYPES
][2] = {
1498 { OSTUDLEATHER
, -2 },
1505 static char spsel
[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14};
1511 const char *p
= NULL
;
1513 if (c
[CANCELLATION
])
1515 vxy(&xx
, &yy
); /* verify x & y coordinates */
1517 case 1: /* rust your armor, j=1 when rusting has occurred */
1519 if ((i
= c
[SHIELD
]) != -1) {
1520 if (--ivenarg
[i
] < -1)
1525 if ((j
== 0) && (k
!= -1)) {
1527 for (i
= 0; i
< ARMORTYPES
; i
++)
1528 /* find his armor in table */
1529 if (m
== rustarm
[i
][0]) {
1530 if (--ivenarg
[k
] < rustarm
[i
][1])
1531 ivenarg
[k
] = rustarm
[i
][1];
1537 if (j
== 0) /* if rusting did not occur */
1540 p
= "\nThe %s hit you -- You're lucky you have leather on";
1543 p
= "\nThe %s hit you -- You're fortunate to have stainless steel armor!";
1548 p
= "\nThe %s hit you -- your armor feels weaker";
1553 i
= rnd(15) + 8 - c
[AC
];
1554 spout
: p
= "\nThe %s breathes fire at you!";
1555 if (c
[FIRERESISTANCE
])
1556 p
= "\nThe %s's flame doesn't faze you!";
1559 lprintf(p
, lastmonst
);
1566 i
= rnd(20) + 25 - c
[AC
];
1570 if (c
[STRENGTH
] > 3) {
1571 p
= "\nThe %s stung you! You feel weaker";
1575 p
= "\nThe %s stung you!";
1579 p
= "\nThe %s blasts you with his cold breath";
1580 i
= rnd(15) + 18 - c
[AC
];
1584 lprintf("\nThe %s drains you of your life energy!", lastmonst
);
1590 p
= "\nThe %s got you with a gusher!";
1591 i
= rnd(15) + 25 - c
[AC
];
1596 return (0); /* he has a device of no theft */
1598 p
= "\nThe %s hit you -- Your purse feels lighter";
1599 if (c
[GOLD
] > 32767)
1602 c
[GOLD
] -= rnd((int) (1 + (c
[GOLD
] >> 1)));
1606 p
= "\nThe %s couldn't find any gold to steal";
1607 lprintf(p
, lastmonst
);
1614 for (j
= 50;;) {/* disenchant */
1616 m
= iven
[i
]; /* randomly select item */
1617 if (m
> 0 && ivenarg
[i
] > 0 && m
!= OSCROLL
&& m
!= OPOTION
) {
1618 if ((ivenarg
[i
] -= 3) < 0)
1620 lprintf("\nThe %s hits you -- you feel a sense of loss", lastmonst
);
1628 p
= "\nThe %s nearly misses";
1636 p
= "\nThe %s hit you with his barbed tail";
1637 i
= rnd(25) - c
[AC
];
1641 p
= "\nThe %s has confused you";
1643 c
[CONFUSE
] += 10 + rnd(10);
1646 case 12: /* performs any number of other special
1648 return (spattack(spsel
[rund(10)], xx
, yy
));
1651 p
= "\nThe %s flattens you with his psionics!";
1652 i
= rnd(15) + 30 - c
[AC
];
1657 return (0); /* he has device of no theft */
1658 if (emptyhanded() == 1) {
1659 p
= "\nThe %s couldn't find anything to steal";
1662 lprintf("\nThe %s picks your pocket and takes:", lastmonst
);
1664 if (stealsomething() == 0)
1671 i
= rnd(10) + 5 - c
[AC
];
1672 spout3
: p
= "\nThe %s bit you!";
1676 i
= rnd(15) + 10 - c
[AC
];
1680 lprintf(p
, lastmonst
);
1687 * checkloss(x) Routine to subtract hp from user and flag bottomline display
1690 * Routine to subtract hitpoints from the user and flag the bottomline display
1691 * Enter with the number of hit points to lose
1692 * Note: if x > c[HP] this routine could kill the player!
1705 * annihilate() Routine to annihilate all monsters around player (playerx,playery)
1707 * Gives player experience, but no dropped objects
1708 * Returns the experience gained from all monsters killed
1716 for (k
= 0, i
= playerx
- 1; i
<= playerx
+ 1; i
++)
1717 for (j
= playery
- 1; j
<= playery
+ 1; j
++)
1718 if (!vxy(&i
, &j
)) { /* if not out of bounds */
1719 if (*(p
= &mitem
[i
][j
])) { /* if a monster there */
1720 if (*p
< DEMONLORD
+ 2) {
1721 k
+= monster
[*p
].experience
;
1722 *p
= know
[i
][j
] = 0;
1724 lprintf("\nThe %s barely escapes being annihilated!", monster
[*p
].name
);
1725 hitp
[i
][j
] = (hitp
[i
][j
] >> 1) + 1; /* lose half hit points */
1730 lprcat("\nYou hear loud screams of agony!");
1731 raiseexperience((long) k
);
1737 * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation
1738 * int x,y,dir,lifetime;
1740 * Enter with the coordinates of the sphere in x,y
1741 * the direction (0-8 diroffx format) in dir, and the lifespan of the
1742 * sphere in lifetime (in turns)
1743 * Returns the number of spheres currently in existence
1746 newsphere(x
, y
, dir
, life
)
1747 int x
, y
, dir
, life
;
1751 if (((sp
= (struct sphere
*) malloc(sizeof(struct sphere
)))) == 0)
1752 return (c
[SPHCAST
]); /* can't malloc, therefore failure */
1754 dir
= 0; /* no movement if direction not found */
1756 vxy(&x
, &y
); /* don't go out of bounds */
1767 if ((m
= mitem
[x
][y
]) >= DEMONLORD
+ 4) { /* demons dispel spheres */
1769 show1cell(x
, y
);/* show the demon (ha ha) */
1771 lprintf("\nThe %s dispels the sphere!", monster
[m
].name
);
1773 rmsphere(x
, y
); /* remove any spheres that are here */
1775 return (c
[SPHCAST
]);
1777 if (m
== DISENCHANTRESS
) { /* disenchantress cancels spheres */
1779 lprintf("\nThe %s causes cancellation of the sphere!", monster
[m
].name
);
1781 boom
: sphboom(x
, y
); /* blow up stuff around sphere */
1782 rmsphere(x
, y
); /* remove any spheres that are here */
1784 return (c
[SPHCAST
]);
1786 if (c
[CANCELLATION
]) { /* cancellation cancels spheres */
1788 lprcat("\nAs the cancellation takes effect, you hear a great earth shaking blast!");
1792 if (item
[x
][y
] == OANNIHILATION
) { /* collision of spheres
1793 * detonates spheres */
1795 lprcat("\nTwo spheres of annihilation collide! You hear a great earth shaking blast!");
1800 if (playerx
== x
&& playery
== y
) { /* collision of sphere and
1803 lprcat("\nYou have been enveloped by the zone of nothingness!\n");
1805 rmsphere(x
, y
); /* remove any spheres that are here */
1809 item
[x
][y
] = OANNIHILATION
;
1812 show1cell(x
, y
); /* show the new sphere */
1817 sp
->lifetime
= life
;
1820 spheres
= sp
; /* if first node in the sphere list */
1821 else { /* add sphere to beginning of linked list */
1825 return (++c
[SPHCAST
]); /* one more sphere in the world */
1829 * rmsphere(x,y) Function to delete a sphere of annihilation from list
1832 * Enter with the coordinates of the sphere (on current level)
1833 * Returns the number of spheres currently in existence
1839 struct sphere
*sp
, *sp2
= 0;
1840 for (sp
= spheres
; sp
; sp2
= sp
, sp
= sp
->p
)
1841 if (level
== sp
->lev
) /* is sphere on this level? */
1842 if ((x
== sp
->x
) && (y
== sp
->y
)) { /* locate sphere at this
1844 item
[x
][y
] = mitem
[x
][y
] = 0;
1846 show1cell(x
, y
); /* show the now missing
1849 if (sp
== spheres
) {
1860 return (c
[SPHCAST
]); /* return number of spheres in the world */
1864 * sphboom(x,y) Function to perform the effects of a sphere detonation
1867 * Enter with the coordinates of the blast, Returns no value
1876 if (c
[CANCELLATION
])
1877 c
[CANCELLATION
] = 1;
1878 for (j
= max(1, x
- 2); j
< min(x
+ 3, MAXX
- 1); j
++)
1879 for (i
= max(1, y
- 2); i
< min(y
+ 3, MAXY
- 1); i
++) {
1880 item
[j
][i
] = mitem
[j
][i
] = 0;
1882 if (playerx
== j
&& playery
== i
) {
1885 lprcat("\nYou were too close to the sphere!");
1887 died(283); /* player killed in explosion */
1893 * genmonst() Function to ask for monster and genocide from game
1895 * This is done by setting a flag in the monster[] structure
1902 lprcat("\nGenocide what monster? ");
1903 for (i
= 0; (!isalpha(i
)) && (i
!= ' '); i
= lgetchar());
1905 for (j
= 0; j
< MAXMONST
; j
++) /* search for the monster type */
1906 if (monstnamelist
[j
] == i
) { /* have we found it? */
1907 monster
[j
].genocided
= 1; /* genocided from game */
1908 lprintf(" There will be no more %s's", monster
[j
].name
);
1909 /* now wipe out monsters on this level */
1910 newcavelevel(level
);
1911 draws(0, MAXX
, 0, MAXY
);
1915 lprcat(" You sense failure!");