]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/monster.c
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 int dirsub(int *, int *);
120 static void dropsomething(int);
121 static int spattack(int, int, int);
124 * createmonster(monstno) Function to create a monster next to the player
127 * Enter with the monster number (1 to MAXMONST+8)
135 if (mon
< 1 || mon
> MAXMONST
+ 8) { /* check for monster number
138 lprintf("\ncan't createmonst(%ld)\n", (long) mon
);
142 while (monster
[mon
].genocided
&& mon
< MAXMONST
)
143 mon
++; /* genocided? */
144 for (k
= rnd(8), i
= -8; i
< 0; i
++, k
++) { /* choose direction,
147 k
= 1; /* wraparound the diroff arrays */
148 x
= playerx
+ diroffx
[k
];
149 y
= playery
+ diroffy
[k
];
150 if (cgood(x
, y
, 0, 1)) { /* if we can create here */
152 hitp
[x
][y
] = monster
[mon
].hitpoints
;
153 stealth
[x
][y
] = know
[x
][y
] = 0;
166 * int cgood(x,y,itm,monst) Function to check location for emptiness
169 * Routine to return TRUE if a location does not have itm or monst there
170 * returns FALSE (0) otherwise
171 * Enter with itm or monst TRUE or FALSE if checking it
172 * Example: if itm==TRUE check for no item at this location
173 * if monst==TRUE check for no monster at this location
174 * This routine will return FALSE if at a wall or the dungeon exit on level 1
177 cgood(int x
, int y
, int theitem
, int monst
)
180 if ((y
>= 0) && (y
<= MAXY
- 1) && (x
>= 0) && (x
<= MAXX
- 1))
182 if (item
[x
][y
] != OWALL
) /* can't make anything on walls */
183 /* is it free of items? */
184 if (theitem
== 0 || (item
[x
][y
] == 0))
185 /* is it free of monsters? */
186 if (monst
== 0 || (mitem
[x
][y
] == 0))
187 if ((level
!= 1) || (x
!= 33) ||
189 /* not exit to level 1 */
195 * createitem(it,arg) Routine to place an item next to the player
198 * Enter with the item number and its argument (iven[], ivenarg[])
199 * Returns no value, thus we don't know about createitem() failures.
207 return; /* no such object */
208 for (k
= rnd(8), i
= -8; i
< 0; i
++, k
++) { /* choose direction,
211 k
= 1; /* wraparound the diroff arrays */
212 x
= playerx
+ diroffx
[k
];
213 y
= playery
+ diroffy
[k
];
214 if (cgood(x
, y
, 1, 0)) { /* if we can create here */
224 * cast() Subroutine called by parse to cast a spell for the user
226 * No arguments and no return value.
228 static char eys
[] = "\nEnter your spell: ";
234 if (c
[SPELLS
] <= 0) {
235 lprcat("\nYou don't have any spells!");
240 while ((a
= ttgetch()) == 'D') {
246 goto over
; /* to escape casting a spell */
247 if ((b
= ttgetch()) == '\33')
248 goto over
; /* to escape casting a spell */
249 if ((d
= ttgetch()) == '\33') {
250 over
: lprcat(aborted
);
253 } /* to escape casting a spell */
257 for (lprc('\n'), j
= -1, i
= 0; i
< SPNUM
; i
++) /* seq search for his
259 if ((spelcode
[i
][0] == a
) && (spelcode
[i
][1] == b
) && (spelcode
[i
][2] == d
))
266 lprcat(" Nothing Happened ");
271 * speldamage(x) Function to perform spell functions cast by the player
274 * Enter with the spell number, returns no value.
275 * Please insure that there are 2 spaces before all messages here
285 return; /* no such spell */
287 lprcat(" It didn't seem to work");
289 } /* not if time stopped */
291 if ((rnd(23) == 7) || (rnd(18) > c
[INTELLIGENCE
])) {
292 lprcat(" It didn't work!");
295 if (clev
* 3 + 2 < x
) {
296 lprcat(" Nothing happens. You seem inexperienced at this");
300 /* ----- LEVEL 1 SPELLS ----- */
303 if (c
[PROTECTIONTIME
] == 0)
304 c
[MOREDEFENSES
] += 2; /* protection field +2 */
305 c
[PROTECTIONTIME
] += 250;
309 i
= rnd(((clev
+ 1) << 1)) + clev
+ 3;
310 godirect(x
, i
, (clev
>= 2) ? " Your missiles hit the %s" : " Your missile hit the %s", 100, '+'); /* magic missile */
315 if (c
[DEXCOUNT
] == 0)
316 c
[DEXTERITY
] += 3; /* dexterity */
322 direct(x
, fullhit(i
),
323 " While the %s slept, you smashed it %ld times", i
);
326 case 4: /* charm monster */
327 c
[CHARMCOUNT
] += c
[CHARISMA
] << 1;
331 godirect(x
, rnd(10) + 15 + clev
, " The sound damages the %s", 70, '@'); /* sonic spear */
334 /* ----- LEVEL 2 SPELLS ----- */
338 direct(x
, fullhit(i
),
339 " While the %s is entangled, you hit %ld times", i
);
343 if (c
[STRCOUNT
] == 0)
344 c
[STREXTRA
] += 3; /* strength */
345 c
[STRCOUNT
] += 150 + rnd(100);
349 yl
= playery
- 5; /* enlightenment */
354 vxy(&xh
, &yh
); /* check bounds */
355 for (i
= yl
; i
<= yh
; i
++) /* enlightenment */
356 for (j
= xl
; j
<= xh
; j
++)
358 draws(xl
, xh
+ 1, yl
, yh
+ 1);
362 raisehp(20 + (clev
<< 1));
363 return; /* healing */
367 return; /* cure blindness */
370 createmonster(makemonst(level
+ 1) + 8);
374 if (rnd(11) + 7 <= c
[WISDOM
])
375 direct(x
, rnd(20) + 20 + clev
, " The %s believed!", 0);
377 lprcat(" It didn't believe the illusions!");
380 case 13: /* if he has the amulet of invisibility then
382 for (j
= i
= 0; i
< 26; i
++)
383 if (iven
[i
] == OAMULET
)
385 c
[INVISIBILITY
] += (j
<< 7) + 12;
388 /* ----- LEVEL 3 SPELLS ----- */
391 godirect(x
, rnd(25 + clev
) + 25 + clev
, " The fireball hits the %s", 40, '*');
392 return; /* fireball */
395 godirect(x
, rnd(25) + 20 + clev
, " Your cone of cold strikes the %s", 60, 'O'); /* cold */
400 return; /* polymorph */
403 c
[CANCELLATION
] += 5 + clev
;
404 return; /* cancellation */
407 c
[HASTESELF
] += 7 + clev
;
408 return; /* haste self */
411 omnidirect(x
, 30 + rnd(10), " The %s gasps for air"); /* cloud kill */
415 xh
= min(playerx
+ 1, MAXX
- 2);
416 yh
= min(playery
+ 1, MAXY
- 2);
417 for (i
= max(playerx
- 1, 1); i
<= xh
; i
++) /* vaporize rock */
418 for (j
= max(playery
- 1, 1); j
<= yh
; j
++) {
421 switch (*(p
= &item
[i
][j
])) {
423 if (level
< MAXLEVEL
+ MAXVLEVEL
- 1)
428 if (c
[HARDGAME
] < 3) {
439 hitp
[i
][j
] = monster
[GNOMEKING
].hitpoints
;
445 hitp
[i
][j
] = monster
[DEMONPRINCE
].hitpoints
;
452 break; /* Xorn takes damage from vpr */
457 /* ----- LEVEL 4 SPELLS ----- */
460 direct(x
, 100 + clev
, " The %s shrivels up", 0); /* dehydration */
464 godirect(x
, rnd(25) + 20 + (clev
<< 1), " A lightning bolt hits the %s", 1, '~'); /* lightning */
468 i
= min(c
[HP
] - 1, c
[HPMAX
] / 2); /* drain life */
469 direct(x
, i
+ i
, "", 0);
475 c
[MOREDEFENSES
] += 10;
477 loseint(); /* globe of invulnerability */
481 omnidirect(x
, 32 + clev
, " The %s struggles for air in your flood!"); /* flood */
485 if (rnd(151) == 63) {
487 lprcat("\nYour heart stopped!\n");
492 if (c
[WISDOM
] > rnd(10) + 10)
493 direct(x
, 2000, " The %s's heart stopped", 0); /* finger of death */
495 lprcat(" It didn't work");
498 /* ----- LEVEL 5 SPELLS ----- */
501 c
[SCAREMONST
] += rnd(10) + clev
;
502 return; /* scare monster */
505 c
[HOLDMONST
] += rnd(10) + clev
;
506 return; /* hold monster */
509 c
[TIMESTOP
] += rnd(20) + (clev
<< 1);
510 return; /* time stop */
514 return; /* teleport away */
517 omnidirect(x
, 35 + rnd(10) + clev
, " The %s cringes from the flame"); /* magic fire */
520 /* ----- LEVEL 6 SPELLS ----- */
523 if ((rnd(23) == 5) && (wizard
== 0)) { /* sphere of
526 lprcat("\nYou have been enveloped by the zone of nothingness!\n");
534 i
= dirsub(&xl
, &yl
); /* get direction of sphere */
535 newsphere(xl
, yl
, i
, rnd(20) + 11); /* make a sphere */
540 spelknow
[33] = 0; /* genocide */
544 case 34: /* summon demon */
546 direct(x
, 150, " The demon strikes at the %s", 0);
550 lprcat(" Nothing seems to have happened");
553 lprcat(" The demon turned on you and vanished!");
557 losehp(i
); /* must say killed by a demon */
560 case 35: /* walk through walls */
561 c
[WTW
] += rnd(10) + 5;
564 case 36: /* alter reality */
566 struct isave
*save
; /* pointer to item save
569 sc
= 0; /* # items saved */
570 save
= (struct isave
*) malloc(sizeof(struct isave
) * MAXX
* MAXY
* 2);
571 for (j
= 0; j
< MAXY
; j
++)
572 for (i
= 0; i
< MAXX
; i
++) { /* save all items and
575 if (xl
&& xl
!= OWALL
&& xl
!= OANNIHILATION
) {
577 save
[sc
].id
= item
[i
][j
];
578 save
[sc
++].arg
= iarg
[i
][j
];
582 save
[sc
].id
= mitem
[i
][j
];
583 save
[sc
++].arg
= hitp
[i
][j
];
594 item
[33][MAXY
- 1] = 0;
595 for (j
= rnd(MAXY
- 2), i
= 1; i
< MAXX
- 1; i
++)
597 while (sc
> 0) { /* put objects back in level */
599 if (save
[sc
].type
== 0) {
601 for (trys
= 100, i
= j
= 1; --trys
> 0 && item
[i
][j
]; i
= rnd(MAXX
- 1), j
= rnd(MAXY
- 1));
603 item
[i
][j
] = save
[sc
].id
;
604 iarg
[i
][j
] = save
[sc
].arg
;
606 } else { /* put monsters back in */
608 for (trys
= 100, i
= j
= 1; --trys
> 0 && (item
[i
][j
] == OWALL
|| mitem
[i
][j
]); i
= rnd(MAXX
- 1), j
= rnd(MAXY
- 1));
610 mitem
[i
][j
] = save
[sc
].id
;
611 hitp
[i
][j
] = save
[sc
].arg
;
616 draws(0, MAXX
, 0, MAXY
);
624 case 37: /* permanence */
626 spelknow
[37] = 0; /* forget */
631 lprintf(" spell %ld not available!", (long) x
);
638 * loseint() Routine to subtract 1 from your int (intelligence) if > 3
640 * No arguments and no return value
645 if (--c
[INTELLIGENCE
] < 3)
650 * isconfuse() Routine to check to see if player is confused
652 * This routine prints out a message saying "You can't aim your magic!"
653 * returns 0 if not confused, non-zero (time remaining confused) if confused
659 lprcat(" You can't aim your magic!");
666 * nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster
669 * Subroutine to return 1 if the spell can't affect the monster
670 * otherwise returns 0
671 * Enter with the spell number in x, and the monster number in monst.
678 if (x
>= SPNUM
|| monst
>= MAXMONST
+ 8 || monst
< 0 || x
< 0)
679 return (0); /* bad spell or monst */
680 if ((tmp
= spelweird
[monst
- 1][x
]) == 0)
684 lprintf(spelmes
[tmp
], monster
[monst
].name
);
689 * fullhit(xx) Function to return full damage against a monster (aka web)
692 * Function to return hp damage to monster due to a number of full hits
693 * Enter with the number of full hits being done
700 if (xx
< 0 || xx
> 20)
701 return (0); /* fullhits are out of range */
703 return (10000); /* lance of death */
704 i
= xx
* ((c
[WCLASS
] >> 1) + c
[STRENGTH
] + c
[STREXTRA
] - c
[HARDGAME
] - 12 + c
[MOREDAM
]);
705 return ((i
>= 1) ? i
: xx
);
709 * direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir
713 * Routine to ask for a direction to a spell and then hit the monster
714 * Enter with the spell number in spnum, the damage to be done in dam,
715 * lprintf format string in str, and lprintf's argument in arg.
719 direct(spnum
, dam
, str
, arg
)
725 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0)
726 return; /* bad arguments */
731 if (item
[x
][y
] == OMIRROR
) {
732 if (spnum
== 3) { /* sleep */
733 lprcat("You fall asleep! ");
742 } else if (spnum
== 6) { /* web */
743 lprcat("You get stuck in your own web! ");
748 lprintf(str
, "spell caster (that's you)", (long) arg
);
755 lprcat(" There wasn't anything there!");
759 if (nospell(spnum
, m
)) {
764 lprintf(str
, lastmonst
, (long) arg
);
769 * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks
770 * int spnum,dam,delay;
773 * Function to hit in a direction from a missile weapon and have it keep
774 * on going in that direction until its power is exhausted
775 * Enter with the spell number in spnum, the power of the weapon in hp,
776 * lprintf format string in str, the # of milliseconds to delay between
777 * locations in delay, and the character to represent the weapon in cshow.
781 godirect(spnum
, dam
, str
, delay
, cshow
)
782 int spnum
, dam
, delay
;
783 const char *str
, cshow
;
788 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0 || delay
< 0)
789 return; /* bad args */
802 if ((x
> MAXX
- 1) || (y
> MAXY
- 1) || (x
< 0) || (y
< 0)) {
804 break; /* out of bounds */
806 if ((x
== playerx
) && (y
== playery
)) { /* if energy hits player */
808 lprcat("\nYou are hit by your own magic!");
814 if (c
[BLINDCOUNT
] == 0) { /* if not blind show effect */
815 cursor(x
+ 1, y
+ 1);
820 if ((m
= mitem
[x
][y
])) { /* is there a monster there? */
822 if (nospell(spnum
, m
)) {
829 lprintf(str
, lastmonst
);
830 dam
-= hitm(x
, y
, dam
);
836 switch (*(p
= &item
[x
][y
])) {
840 lprintf(str
, "wall");
841 if (dam
>= 50 + c
[HARDGAME
]) /* enough damage? */
842 if (level
< MAXLEVEL
+ MAXVLEVEL
- 1) /* not on V3 */
843 if ((x
< MAXX
- 1) && (y
< MAXY
- 1) && (x
) && (y
)) {
844 lprcat(" The wall crumbles");
855 lprintf(str
, "door");
857 lprcat(" The door is blasted apart");
865 lprintf(str
, "statue");
868 lprcat(" The statue crumbles");
878 lprintf(str
, "throne");
880 mitem
[x
][y
] = GNOMEKING
;
881 hitp
[x
][y
] = monster
[GNOMEKING
].hitpoints
;
892 dam
-= 3 + (c
[HARDGAME
] >> 1);
897 * ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt
900 * Subroutine to copy the word "monster" into lastmonst if the player is blind
901 * Enter with the coordinates (x,y) of the monster
905 ifblind(int x
, int y
)
909 vxy(&x
, &y
); /* verify correct x,y coordinates */
914 lastnum
= mitem
[x
][y
];
915 p
= monster
[lastnum
].name
;
917 strcpy(lastmonst
, p
);
921 * tdirect(spnum) Routine to teleport away a monster
924 * Routine to ask for a direction to a spell and then teleport away monster
925 * Enter with the spell number that wants to teleport away
934 if (spnum
< 0 || spnum
>= SPNUM
)
935 return; /* bad args */
939 if ((m
= mitem
[x
][y
]) == 0) {
940 lprcat(" There wasn't anything there!");
944 if (nospell(spnum
, m
)) {
950 mitem
[x
][y
] = know
[x
][y
] = 0;
954 * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player
958 * Routine to cast a spell and then hit the monster in all directions
959 * Enter with the spell number in sp, the damage done to wach square in dam,
960 * and the lprintf string to identify the spell in str.
964 omnidirect(int spnum
, int dam
, const char *str
)
968 if (spnum
< 0 || spnum
>= SPNUM
|| str
== 0)
969 return; /* bad args */
970 for (x
= playerx
- 1; x
< playerx
+ 2; x
++)
971 for (y
= playery
- 1; y
< playery
+ 2; y
++) {
972 if ((m
= mitem
[x
][y
]) != 0) {
973 if (nospell(spnum
, m
) == 0) {
977 lprintf(str
, lastmonst
);
989 * static dirsub(x,y) Routine to ask for direction, then modify x,y for it
992 * Function to ask for a direction and modify an x,y for that direction
993 * Enter with the origination coordinates in (x,y).
994 * Returns index into diroffx[] (0-8).
1001 lprcat("\nIn What Direction? ");
1003 switch (ttgetch()) {
1023 *x
= playerx
+ diroffx
[i
];
1024 *y
= playery
+ diroffy
[i
];
1030 * vxy(x,y) Routine to verify/fix coordinates for being within bounds
1033 * Function to verify x & y are within the bounds for a level
1034 * If *x or *y is not within the absolute bounds for a level, fix them so that
1035 * they are on the level.
1036 * Returns TRUE if it was out of bounds, and the *x & *y in the calling
1037 * routine are affected.
1064 * dirpoly(spnum) Routine to ask for a direction and polymorph a monst
1067 * Subroutine to polymorph a monster and ask for the direction its in
1068 * Enter with the spell number in spmun.
1076 if (spnum
< 0 || spnum
>= SPNUM
)
1077 return; /* bad args */
1079 return; /* if he is confused, he can't aim his magic */
1081 if (mitem
[x
][y
] == 0) {
1082 lprcat(" There wasn't anything there!");
1086 if (nospell(spnum
, mitem
[x
][y
])) {
1091 while (monster
[m
= mitem
[x
][y
] = rnd(MAXMONST
+ 7)].genocided
);
1092 hitp
[x
][y
] = monster
[m
].hitpoints
;
1093 show1cell(x
, y
); /* show the new monster */
1097 * hitmonster(x,y) Function to hit a monster at the designated coordinates
1100 * This routine is used for a bash & slash type attack on a monster
1101 * Enter with the coordinates of the monster in (x,y).
1108 int tmp
, monst
, damag
= 0, flag
;
1110 return; /* not if time stopped */
1111 vxy(&x
, &y
); /* verify coordinates are within range */
1112 if ((monst
= mitem
[x
][y
]) == 0)
1116 tmp
= monster
[monst
].armorclass
+ c
[LEVEL
] + c
[DEXTERITY
] +
1119 /* need at least random chance to hit */
1120 if ((rnd(20) < tmp
- c
[HARDGAME
]) || (rnd(71) < 5)) {
1121 lprcat("\nYou hit");
1125 damag
= rnd(damag
) + 1;
1127 lprcat("\nYou missed");
1132 if (flag
) /* if the monster was hit */
1133 if ((monst
== RUSTMONSTER
) || (monst
== DISENCHANTRESS
) || (monst
== CUBE
))
1135 if (ivenarg
[c
[WIELD
]] > -10) {
1136 lprintf("\nYour weapon is dulled by the %s", lastmonst
);
1138 --ivenarg
[c
[WIELD
]];
1142 if (monst
== VAMPIRE
)
1143 if (hitp
[x
][y
] < 25) {
1150 * hitm(x,y,amt) Function to just hit a monster at a given coordinates
1153 * Returns the number of hitpoints the monster absorbed
1154 * This routine is used to specifically damage a monster at a location (x,y)
1155 * Called by hitmonster(x,y)
1164 vxy(&x
, &y
); /* verify coordinates are within range */
1165 amt2
= amt
; /* save initial damage so we can return it */
1166 monst
= mitem
[x
][y
];
1168 amt
>>= 1; /* if half damage curse adjust damage points */
1173 stealth
[x
][y
] = 1; /* make sure hitting monst breaks stealth
1175 c
[HOLDMONST
] = 0; /* hit a monster breaks hold monster spell */
1176 switch (monst
) { /* if a dragon and orb(s) of dragon slaying */
1181 case PLATINUMDRAGON
:
1183 amt
*= 1 + (c
[SLAYING
] << 1);
1186 /* invincible monster fix is here */
1187 if (hitp
[x
][y
] > monster
[monst
].hitpoints
)
1188 hitp
[x
][y
] = monster
[monst
].hitpoints
;
1189 if ((hpoints
= hitp
[x
][y
]) <= amt
) {
1193 lprintf("\nThe %s died!", lastmonst
);
1194 raiseexperience((long) monster
[monst
].experience
);
1195 amt
= monster
[monst
].gold
;
1197 dropgold(rnd(amt
) + amt
);
1198 dropsomething(monst
);
1203 hitp
[x
][y
] = hpoints
- amt
;
1208 * hitplayer(x,y) Function for the monster to hit the player from (x,y)
1211 * Function for the monster to hit the player with monster at location x,y
1212 * Returns nothing of value.
1218 int dam
, tmp
, mster
, bias
;
1219 vxy(&x
, &y
); /* verify coordinates are within range */
1220 lastnum
= mster
= mitem
[x
][y
];
1222 * spirit nagas and poltergeists do nothing if scarab of negate
1225 if (c
[NEGATESPIRIT
] || c
[SPIRITPRO
])
1226 if ((mster
== POLTERGEIST
) || (mster
== SPIRITNAGA
))
1228 /* if undead and cube of undead control */
1229 if (c
[CUBEofUNDEAD
] || c
[UNDEADPRO
])
1230 if ((mster
== VAMPIRE
) || (mster
== WRAITH
) || (mster
== ZOMBIE
))
1232 if ((know
[x
][y
] & 1) == 0) {
1236 bias
= (c
[HARDGAME
]) + 1;
1237 hitflag
= hit2flag
= hit3flag
= 1;
1241 if (c
[INVISIBILITY
])
1243 lprintf("\nThe %s misses wildly", lastmonst
);
1247 if (rnd(30) + 5 * monster
[mster
].level
- c
[CHARISMA
] < 30) {
1248 lprintf("\nThe %s is awestruck at your magnificence!", lastmonst
);
1254 dam
= monster
[mster
].damage
;
1255 dam
+= rnd((int) ((dam
< 1) ? 1 : dam
)) + monster
[mster
].level
;
1258 if (monster
[mster
].attack
> 0)
1259 if (((dam
+ bias
+ 8) > c
[AC
]) || (rnd((int) ((c
[AC
] > 0) ? c
[AC
] : 1)) == 1)) {
1260 if (spattack(monster
[mster
].attack
, x
, y
)) {
1268 if (((dam
+ bias
) > c
[AC
]) || (rnd((int) ((c
[AC
] > 0) ? c
[AC
] : 1)) == 1)) {
1269 lprintf("\n The %s hit you ", lastmonst
);
1271 if ((dam
-= c
[AC
]) < 0)
1280 lprintf("\n The %s missed ", lastmonst
);
1284 * dropsomething(monst) Function to create an object when a monster dies
1287 * Function to create an object near the player when certain monsters are killed
1288 * Enter with the monster number
1289 * Returns nothing of value.
1292 dropsomething(monst
)
1303 case PLATINUMDRAGON
:
1313 dropsomething(LEPRECHAUN
);
1319 * dropgold(amount) Function to drop some gold around player
1322 * Enter with the number of gold pieces to drop
1323 * Returns nothing of value.
1330 createitem(OMAXGOLD
, amount
/ 100);
1332 createitem(OGOLDPILE
, amount
);
1336 * something(level) Function to create a random item around player
1339 * Function to create an item from a designed probability around player
1340 * Enter with the cave level on which something is to be dropped
1341 * Returns nothing of value.
1344 something(int cavelevel
)
1348 if (cavelevel
< 0 || cavelevel
> MAXLEVEL
+ MAXVLEVEL
)
1349 return; /* correct level? */
1351 something(cavelevel
); /* possibly more than one item */
1352 j
= newobject(cavelevel
, &i
);
1357 * newobject(lev,i) Routine to return a randomly selected new object
1360 * Routine to return a randomly selected object to be created
1361 * Returns the object number created, and sets *i for its argument
1362 * Enter with the cave level and a pointer to the items arg
1364 static char nobjtab
[] = {
1365 0, OSCROLL
, OSCROLL
, OSCROLL
, OSCROLL
, OPOTION
, OPOTION
,
1366 OPOTION
, OPOTION
, OGOLDPILE
, OGOLDPILE
, OGOLDPILE
, OGOLDPILE
,
1367 OBOOK
, OBOOK
, OBOOK
, OBOOK
, ODAGGER
, ODAGGER
, ODAGGER
,
1368 OLEATHER
, OLEATHER
, OLEATHER
, OREGENRING
, OPROTRING
,
1369 OENERGYRING
, ODEXRING
, OSTRRING
, OSPEAR
, OBELT
, ORING
,
1370 OSTUDLEATHER
, OSHIELD
, OFLAIL
, OCHAIN
, O2SWORD
, OPLATE
,
1378 if (level
< 0 || level
> MAXLEVEL
+ MAXVLEVEL
)
1379 return (0); /* correct level? */
1384 j
= nobjtab
[tmp
= rnd(tmp
)]; /* the object type */
1402 *i
= rnd((lev
+ 1) * 10) + lev
* 10 + 10;
1413 if (!(*i
= newdagger()))
1419 if (!(*i
= newleather()))
1425 *i
= rund(lev
/ 3 + 1);
1429 *i
= rnd(lev
/ 4 + 1);
1432 *i
= rund(lev
/ 4 + 1);
1435 *i
= rnd(lev
/ 2 + 1);
1439 *i
= rund(lev
/ 2 + 1);
1442 *i
= rund(lev
/ 3 + 1);
1448 *i
= rund(lev
/ 2 + 1);
1466 * spattack(atckno,xx,yy) Function to process special attacks from monsters
1469 * Enter with the special attack number, and the coordinates (xx,yy)
1470 * of the monster that is special attacking
1471 * Returns 1 if must do a show1cell(xx,yy) upon return, 0 otherwise
1473 * atckno monster effect
1474 * ---------------------------------------------------
1476 * 1 rust monster eat armor
1477 * 2 hell hound breathe light fire
1478 * 3 dragon breathe fire
1479 * 4 giant centipede weakening sing
1480 * 5 white dragon cold breath
1481 * 6 wraith drain level
1482 * 7 waterlord water gusher
1483 * 8 leprechaun steal gold
1484 * 9 disenchantress disenchant weapon or armor
1485 * 10 ice lizard hits with barbed tail
1486 * 11 umber hulk confusion
1487 * 12 spirit naga cast spells taken from special attacks
1488 * 13 platinum dragon psionics
1489 * 14 nymph steal objects
1493 * char rustarm[ARMORTYPES][2];
1494 * special array for maximum rust damage to armor from rustmonster
1495 * format is: { armor type , minimum attribute
1497 #define ARMORTYPES 6
1498 static char rustarm
[ARMORTYPES
][2] = {
1499 { OSTUDLEATHER
, -2 },
1506 static char spsel
[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14};
1512 const char *p
= NULL
;
1514 if (c
[CANCELLATION
])
1516 vxy(&xx
, &yy
); /* verify x & y coordinates */
1518 case 1: /* rust your armor, j=1 when rusting has occurred */
1520 if ((i
= c
[SHIELD
]) != -1) {
1521 if (--ivenarg
[i
] < -1)
1526 if ((j
== 0) && (k
!= -1)) {
1528 for (i
= 0; i
< ARMORTYPES
; i
++)
1529 /* find his armor in table */
1530 if (m
== rustarm
[i
][0]) {
1531 if (--ivenarg
[k
] < rustarm
[i
][1])
1532 ivenarg
[k
] = rustarm
[i
][1];
1538 if (j
== 0) /* if rusting did not occur */
1541 p
= "\nThe %s hit you -- You're lucky you have leather on";
1544 p
= "\nThe %s hit you -- You're fortunate to have stainless steel armor!";
1549 p
= "\nThe %s hit you -- your armor feels weaker";
1554 i
= rnd(15) + 8 - c
[AC
];
1555 spout
: p
= "\nThe %s breathes fire at you!";
1556 if (c
[FIRERESISTANCE
])
1557 p
= "\nThe %s's flame doesn't faze you!";
1560 lprintf(p
, lastmonst
);
1567 i
= rnd(20) + 25 - c
[AC
];
1571 if (c
[STRENGTH
] > 3) {
1572 p
= "\nThe %s stung you! You feel weaker";
1576 p
= "\nThe %s stung you!";
1580 p
= "\nThe %s blasts you with his cold breath";
1581 i
= rnd(15) + 18 - c
[AC
];
1585 lprintf("\nThe %s drains you of your life energy!", lastmonst
);
1591 p
= "\nThe %s got you with a gusher!";
1592 i
= rnd(15) + 25 - c
[AC
];
1597 return (0); /* he has a device of no theft */
1599 p
= "\nThe %s hit you -- Your purse feels lighter";
1600 if (c
[GOLD
] > 32767)
1603 c
[GOLD
] -= rnd((int) (1 + (c
[GOLD
] >> 1)));
1607 p
= "\nThe %s couldn't find any gold to steal";
1608 lprintf(p
, lastmonst
);
1615 for (j
= 50;;) {/* disenchant */
1617 m
= iven
[i
]; /* randomly select item */
1618 if (m
> 0 && ivenarg
[i
] > 0 && m
!= OSCROLL
&& m
!= OPOTION
) {
1619 if ((ivenarg
[i
] -= 3) < 0)
1621 lprintf("\nThe %s hits you -- you feel a sense of loss", lastmonst
);
1629 p
= "\nThe %s nearly misses";
1637 p
= "\nThe %s hit you with his barbed tail";
1638 i
= rnd(25) - c
[AC
];
1642 p
= "\nThe %s has confused you";
1644 c
[CONFUSE
] += 10 + rnd(10);
1647 case 12: /* performs any number of other special
1649 return (spattack(spsel
[rund(10)], xx
, yy
));
1652 p
= "\nThe %s flattens you with his psionics!";
1653 i
= rnd(15) + 30 - c
[AC
];
1658 return (0); /* he has device of no theft */
1659 if (emptyhanded() == 1) {
1660 p
= "\nThe %s couldn't find anything to steal";
1663 lprintf("\nThe %s picks your pocket and takes:", lastmonst
);
1665 if (stealsomething() == 0)
1672 i
= rnd(10) + 5 - c
[AC
];
1673 spout3
: p
= "\nThe %s bit you!";
1677 i
= rnd(15) + 10 - c
[AC
];
1681 lprintf(p
, lastmonst
);
1688 * checkloss(x) Routine to subtract hp from user and flag bottomline display
1691 * Routine to subtract hitpoints from the user and flag the bottomline display
1692 * Enter with the number of hit points to lose
1693 * Note: if x > c[HP] this routine could kill the player!
1706 * annihilate() Routine to annihilate all monsters around player (playerx,playery)
1708 * Gives player experience, but no dropped objects
1709 * Returns the experience gained from all monsters killed
1717 for (k
= 0, i
= playerx
- 1; i
<= playerx
+ 1; i
++)
1718 for (j
= playery
- 1; j
<= playery
+ 1; j
++)
1719 if (!vxy(&i
, &j
)) { /* if not out of bounds */
1720 if (*(p
= &mitem
[i
][j
])) { /* if a monster there */
1721 if (*p
< DEMONLORD
+ 2) {
1722 k
+= monster
[*p
].experience
;
1723 *p
= know
[i
][j
] = 0;
1725 lprintf("\nThe %s barely escapes being annihilated!", monster
[*p
].name
);
1726 hitp
[i
][j
] = (hitp
[i
][j
] >> 1) + 1; /* lose half hit points */
1731 lprcat("\nYou hear loud screams of agony!");
1732 raiseexperience((long) k
);
1738 * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation
1739 * int x,y,dir,lifetime;
1741 * Enter with the coordinates of the sphere in x,y
1742 * the direction (0-8 diroffx format) in dir, and the lifespan of the
1743 * sphere in lifetime (in turns)
1744 * Returns the number of spheres currently in existence
1747 newsphere(x
, y
, dir
, life
)
1748 int x
, y
, dir
, life
;
1752 if (((sp
= (struct sphere
*) malloc(sizeof(struct sphere
)))) == 0)
1753 return (c
[SPHCAST
]); /* can't malloc, therefore failure */
1755 dir
= 0; /* no movement if direction not found */
1757 vxy(&x
, &y
); /* don't go out of bounds */
1768 if ((m
= mitem
[x
][y
]) >= DEMONLORD
+ 4) { /* demons dispel spheres */
1770 show1cell(x
, y
);/* show the demon (ha ha) */
1772 lprintf("\nThe %s dispels the sphere!", monster
[m
].name
);
1774 rmsphere(x
, y
); /* remove any spheres that are here */
1776 return (c
[SPHCAST
]);
1778 if (m
== DISENCHANTRESS
) { /* disenchantress cancels spheres */
1780 lprintf("\nThe %s causes cancellation of the sphere!", monster
[m
].name
);
1782 boom
: sphboom(x
, y
); /* blow up stuff around sphere */
1783 rmsphere(x
, y
); /* remove any spheres that are here */
1785 return (c
[SPHCAST
]);
1787 if (c
[CANCELLATION
]) { /* cancellation cancels spheres */
1789 lprcat("\nAs the cancellation takes effect, you hear a great earth shaking blast!");
1793 if (item
[x
][y
] == OANNIHILATION
) { /* collision of spheres
1794 * detonates spheres */
1796 lprcat("\nTwo spheres of annihilation collide! You hear a great earth shaking blast!");
1801 if (playerx
== x
&& playery
== y
) { /* collision of sphere and
1804 lprcat("\nYou have been enveloped by the zone of nothingness!\n");
1806 rmsphere(x
, y
); /* remove any spheres that are here */
1810 item
[x
][y
] = OANNIHILATION
;
1813 show1cell(x
, y
); /* show the new sphere */
1818 sp
->lifetime
= life
;
1821 spheres
= sp
; /* if first node in the sphere list */
1822 else { /* add sphere to beginning of linked list */
1826 return (++c
[SPHCAST
]); /* one more sphere in the world */
1830 * rmsphere(x,y) Function to delete a sphere of annihilation from list
1833 * Enter with the coordinates of the sphere (on current level)
1834 * Returns the number of spheres currently in existence
1840 struct sphere
*sp
, *sp2
= 0;
1841 for (sp
= spheres
; sp
; sp2
= sp
, sp
= sp
->p
)
1842 if (level
== sp
->lev
) /* is sphere on this level? */
1843 if ((x
== sp
->x
) && (y
== sp
->y
)) { /* locate sphere at this
1845 item
[x
][y
] = mitem
[x
][y
] = 0;
1847 show1cell(x
, y
); /* show the now missing
1850 if (sp
== spheres
) {
1861 return (c
[SPHCAST
]); /* return number of spheres in the world */
1865 * sphboom(x,y) Function to perform the effects of a sphere detonation
1868 * Enter with the coordinates of the blast, Returns no value
1877 if (c
[CANCELLATION
])
1878 c
[CANCELLATION
] = 1;
1879 for (j
= max(1, x
- 2); j
< min(x
+ 3, MAXX
- 1); j
++)
1880 for (i
= max(1, y
- 2); i
< min(y
+ 3, MAXY
- 1); i
++) {
1881 item
[j
][i
] = mitem
[j
][i
] = 0;
1883 if (playerx
== j
&& playery
== i
) {
1886 lprcat("\nYou were too close to the sphere!");
1888 died(283); /* player killed in explosion */
1894 * genmonst() Function to ask for monster and genocide from game
1896 * This is done by setting a flag in the monster[] structure
1903 lprcat("\nGenocide what monster? ");
1904 for (i
= 0; (!isalpha(i
)) && (i
!= ' '); i
= ttgetch());
1906 for (j
= 0; j
< MAXMONST
; j
++) /* search for the monster type */
1907 if (monstnamelist
[j
] == i
) { /* have we found it? */
1908 monster
[j
].genocided
= 1; /* genocided from game */
1909 lprintf(" There will be no more %s's", monster
[j
].name
);
1910 /* now wipe out monsters on this level */
1911 newcavelevel(level
);
1912 draws(0, MAXX
, 0, MAXY
);
1916 lprcat(" You sense failure!");