]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/monster.c
1 /* $NetBSD: monster.c,v 1.7 1998/11/10 13:01:32 hubertf Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)monster.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: monster.c,v 1.7 1998/11/10 13:01:32 hubertf Exp $");
51 * This source herein may be modified and/or distributed by anybody who
52 * so desires, with the following restrictions:
53 * 1.) No portion of this notice shall be removed.
54 * 2.) Credit shall not be taken for the creation of this source.
55 * 3.) This code is not to be traded, sold, or used for personal
62 object level_monsters
;
63 boolean mon_disappeared
;
65 const char *const m_names
[] = {
94 object mon_tab
[MONSTERS
] = {
95 {(ASLEEP
|WAKENS
|WANDERS
|RUSTS
),"0d0",25,'A',20,9,18,100,0,0,0,0,0},
96 {(ASLEEP
|WANDERS
|FLITS
|FLIES
),"1d3",10,'B',2,1,8,60,0,0,0,0,0},
97 {(ASLEEP
|WANDERS
),"3d3/2d5",32,'C',15,7,16,85,0,10,0,0,0},
98 {(ASLEEP
|WAKENS
|FLAMES
),"4d6/4d9",145,'D',5000,21,126,100,0,90,0,0,0},
99 {(ASLEEP
|WAKENS
),"1d3",11,'E',2,1,7,65,0,0,0,0,0},
100 {(HOLDS
|STATIONARY
),"5d5",73,'F',91,12,126,80,0,0,0,0,0},
101 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"5d5/5d5",115,'G',
102 2000,20,126,85,0,10,0,0,0},
103 {(ASLEEP
|WAKENS
|WANDERS
),"1d3/1d2",15,'H',3,1,10,67,0,0,0,0,0},
104 {(ASLEEP
|FREEZES
),"0d0",15,'I',5,2,11,68,0,0,0,0,0},
105 {(ASLEEP
|WANDERS
),"3d10/4d5",132,'J',3000,21,126,100,0,0,0,0,0},
106 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"1d4",10,'K',2,1,6,60,0,0,0,0,0},
107 {(ASLEEP
|STEALS_GOLD
),"0d0",25,'L',21,6,16,75,0,0,0,0,0},
108 {(ASLEEP
|WAKENS
|WANDERS
|CONFUSES
),"4d4/3d7",97,'M',
109 250,18,126,85,0,25,0,0,0},
110 {(ASLEEP
|STEALS_ITEM
),"0d0",25,'N',39,10,19,75,0,100,0,0,0},
111 {(ASLEEP
|WANDERS
|WAKENS
|SEEKS_GOLD
),"1d6",25,'O',5,4,13,70,0,10,0,0,0},
112 {(ASLEEP
|INVISIBLE
|WANDERS
|FLITS
),"5d4",76,'P',120,15,24,80,0,50,0,0,0},
113 {(ASLEEP
|WAKENS
|WANDERS
),"3d5",30,'Q',20,8,17,78,0,20,0,0,0},
114 {(ASLEEP
|WAKENS
|WANDERS
|STINGS
),"2d5",19,'R',10,3,12,70,0,0,0,0,0},
115 {(ASLEEP
|WAKENS
|WANDERS
),"1d3",8,'S',2,1,9,50,0,0,0,0,0},
116 {(ASLEEP
|WAKENS
|WANDERS
),"4d6/1d4",75,'T',125,13,22,75,0,33,0,0,0},
117 {(ASLEEP
|WAKENS
|WANDERS
),"4d10",90,'U',
118 200,17,26,85,0,33,0,0,0},
119 {(ASLEEP
|WAKENS
|WANDERS
|DRAINS_LIFE
),"1d14/1d4",55,'V',
120 350,19,126,85,0,18,0,0,0},
121 {(ASLEEP
|WANDERS
|DROPS_LEVEL
),"2d8",45,'W',55,14,23,75,0,0,0,0,0},
122 {(ASLEEP
|IMITATES
),"4d6",42,'X',110,16,25,75,0,0,0,0,0},
123 {(ASLEEP
|WANDERS
),"3d6",35,'Y',50,11,20,80,0,20,0,0,0},
124 {(ASLEEP
|WAKENS
|WANDERS
),"1d7",21,'Z',8,5,14,69,0,0,0,0,0}
137 for (i
= 0; i
< n
; i
++) {
138 monster
= gr_monster((object
*) 0, 0);
139 if ((monster
->m_flags
& WANDERS
) && coin_toss()) {
142 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
143 put_m_at(row
, col
, monster
);
148 gr_monster(monster
, mn
)
153 monster
= alloc_object();
156 mn
= get_rand(0, MONSTERS
-1);
157 if ((cur_level
>= mon_tab
[mn
].first_level
) &&
158 (cur_level
<= mon_tab
[mn
].last_level
)) {
163 *monster
= mon_tab
[mn
];
164 if (monster
->m_flags
& IMITATES
) {
165 monster
->disguise
= gr_obj_char();
167 if (cur_level
> (AMULET_LEVEL
+ 2)) {
168 monster
->m_flags
|= HASTED
;
170 monster
->trow
= NO_ROOM
;
177 object
*monster
, *next_monster
, *test_mons
;
180 if (haste_self
% 2) {
184 monster
= level_monsters
.next_monster
;
187 next_monster
= monster
->next_monster
;
189 if (monster
->m_flags
& HASTED
) {
190 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
191 if (mon_disappeared
) {
194 } else if (monster
->m_flags
& SLOWED
) {
195 monster
->slowed_toggle
= !monster
->slowed_toggle
;
196 if (monster
->slowed_toggle
) {
200 if ((monster
->m_flags
& CONFUSED
) && move_confused(monster
)) {
204 if ( (monster
->m_flags
& FLIES
) &&
205 !(monster
->m_flags
& NAPPING
) &&
206 !mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
208 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
209 if (mon_disappeared
) {
213 if (!(flew
&& mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
214 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
216 NM
: test_mons
= level_monsters
.next_monster
;
220 if (next_monster
== test_mons
)
222 monster
= next_monster
;
225 test_mons
= test_mons
-> next_monster
;
231 party_monsters(rn
, n
)
242 for (i
= 0; i
< MONSTERS
; i
++) {
243 mon_tab
[i
].first_level
-= (cur_level
% 3);
245 for (i
= 0; i
< n
; i
++) {
246 if (no_room_for_monster(rn
)) {
249 for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
250 row
= get_rand(rooms
[rn
].top_row
+1,
251 rooms
[rn
].bottom_row
-1);
252 col
= get_rand(rooms
[rn
].left_col
+1,
253 rooms
[rn
].right_col
-1);
254 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
255 (dungeon
[row
][col
] & (FLOOR
| TUNNEL
))) {
260 monster
= gr_monster((object
*) 0, 0);
261 if (!(monster
->m_flags
& IMITATES
)) {
262 monster
->m_flags
|= WAKENS
;
264 put_m_at(row
, col
, monster
);
267 for (i
= 0; i
< MONSTERS
; i
++) {
268 mon_tab
[i
].first_level
+= (cur_level
% 3);
273 gmc_row_col(row
, col
)
278 if ((monster
= object_at(&level_monsters
, row
, col
)) != NULL
) {
279 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
280 (monster
->m_flags
& INVISIBLE
)) || blind
) {
281 return(monster
->trail_char
);
283 if (monster
->m_flags
& IMITATES
) {
284 return(monster
->disguise
);
286 return(monster
->m_char
);
288 return('&'); /* BUG if this ever happens */
296 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
297 (monster
->m_flags
& INVISIBLE
))
299 return(monster
->trail_char
);
301 if (monster
->m_flags
& IMITATES
) {
302 return(monster
->disguise
);
304 return(monster
->m_char
);
308 mv_1_monster(monster
, row
, col
)
315 if (monster
->m_flags
& ASLEEP
) {
316 if (monster
->m_flags
& NAPPING
) {
317 if (--monster
->nap_length
<= 0) {
318 monster
->m_flags
&= (~(NAPPING
| ASLEEP
));
322 if ((monster
->m_flags
& WAKENS
) &&
323 rogue_is_around(monster
->row
, monster
->col
) &&
324 rand_percent(((stealthy
> 0) ?
325 (WAKE_PERCENT
/ (STEALTH_FACTOR
+ stealthy
)) :
330 } else if (monster
->m_flags
& ALREADY_MOVED
) {
331 monster
->m_flags
&= (~ALREADY_MOVED
);
334 if ((monster
->m_flags
& FLITS
) && flit(monster
)) {
337 if ((monster
->m_flags
& STATIONARY
) &&
338 (!mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
341 if (monster
->m_flags
& FREEZING_ROGUE
) {
344 if ((monster
->m_flags
& CONFUSES
) && m_confuse(monster
)) {
347 if (mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
351 if ((monster
->m_flags
& FLAMES
) && flame_broil(monster
)) {
354 if ((monster
->m_flags
& SEEKS_GOLD
) && seek_gold(monster
)) {
357 if ((monster
->trow
== monster
->row
) &&
358 (monster
->tcol
== monster
->col
)) {
359 monster
->trow
= NO_ROOM
;
360 } else if (monster
->trow
!= NO_ROOM
) {
364 if (monster
->row
> row
) {
365 row
= monster
->row
- 1;
366 } else if (monster
->row
< row
) {
367 row
= monster
->row
+ 1;
369 if ((dungeon
[row
][monster
->col
] & DOOR
) &&
370 mtry(monster
, row
, monster
->col
)) {
373 if (monster
->col
> col
) {
374 col
= monster
->col
- 1;
375 } else if (monster
->col
< col
) {
376 col
= monster
->col
+ 1;
378 if ((dungeon
[monster
->row
][col
] & DOOR
) &&
379 mtry(monster
, monster
->row
, col
)) {
382 if (mtry(monster
, row
, col
)) {
386 for (i
= 0; i
<= 5; i
++) tried
[i
] = 0;
388 for (i
= 0; i
< 6; i
++) {
389 NEXT_TRY
: n
= get_rand(0, 5);
392 if (!tried
[n
] && mtry(monster
, row
, monster
->col
-1)) {
397 if (!tried
[n
] && mtry(monster
, row
, monster
->col
)) {
402 if (!tried
[n
] && mtry(monster
, row
, monster
->col
+1)) {
407 if (!tried
[n
] && mtry(monster
, monster
->row
-1, col
)) {
412 if (!tried
[n
] && mtry(monster
, monster
->row
, col
)) {
417 if (!tried
[n
] && mtry(monster
, monster
->row
+1, col
)) {
429 if ((monster
->row
== monster
->o_row
) && (monster
->col
== monster
->o_col
)) {
430 if (++(monster
->o
) > 4) {
431 if ((monster
->trow
== NO_ROOM
) &&
432 (!mon_sees(monster
, rogue
.row
, rogue
.col
))) {
433 monster
->trow
= get_rand(1, (DROWS
- 2));
434 monster
->tcol
= get_rand(0, (DCOLS
- 1));
436 monster
->trow
= NO_ROOM
;
441 monster
->o_row
= monster
->row
;
442 monster
->o_col
= monster
->col
;
448 mtry(monster
, row
, col
)
452 if (mon_can_go(monster
, row
, col
)) {
453 move_mon_to(monster
, row
, col
);
460 move_mon_to(monster
, row
, col
)
470 dungeon
[mrow
][mcol
] &= ~MONSTER
;
471 dungeon
[row
][col
] |= MONSTER
;
473 c
= mvinch(mrow
, mcol
);
475 if ((c
>= 'A') && (c
<= 'Z')) {
476 if (!detect_monster
) {
477 mvaddch(mrow
, mcol
, monster
->trail_char
);
479 if (rogue_can_see(mrow
, mcol
)) {
480 mvaddch(mrow
, mcol
, monster
->trail_char
);
482 if (monster
->trail_char
== '.') {
483 monster
->trail_char
= ' ';
485 mvaddch(mrow
, mcol
, monster
->trail_char
);
489 monster
->trail_char
= mvinch(row
, col
);
490 if (!blind
&& (detect_monster
|| rogue_can_see(row
, col
))) {
491 if ((!(monster
->m_flags
& INVISIBLE
) ||
492 (detect_monster
|| see_invisible
|| r_see_invisible
))) {
493 mvaddch(row
, col
, gmc(monster
));
496 if ((dungeon
[row
][col
] & DOOR
) &&
497 (get_room_number(row
, col
) != cur_room
) &&
498 (dungeon
[mrow
][mcol
] == FLOOR
) && !blind
) {
499 mvaddch(mrow
, mcol
, ' ');
501 if (dungeon
[row
][col
] & DOOR
) {
502 dr_course(monster
, ((dungeon
[mrow
][mcol
] & TUNNEL
) ? 1 : 0),
511 mon_can_go(monster
, row
, col
)
512 const object
*monster
;
518 dr
= monster
->row
- row
; /* check if move distance > 1 */
519 if ((dr
>= 2) || (dr
<= -2)) {
522 dc
= monster
->col
- col
;
523 if ((dc
>= 2) || (dc
<= -2)) {
526 if ((!dungeon
[monster
->row
][col
]) || (!dungeon
[row
][monster
->col
])) {
529 if ((!is_passable(row
, col
)) || (dungeon
[row
][col
] & MONSTER
)) {
532 if ((monster
->row
!=row
)&&(monster
->col
!=col
)&&((dungeon
[row
][col
]&DOOR
) ||
533 (dungeon
[monster
->row
][monster
->col
]&DOOR
))) {
536 if (!(monster
->m_flags
& (FLITS
| CONFUSED
| CAN_FLIT
)) &&
537 (monster
->trow
== NO_ROOM
)) {
538 if ((monster
->row
< rogue
.row
) && (row
< monster
->row
)) return(0);
539 if ((monster
->row
> rogue
.row
) && (row
> monster
->row
)) return(0);
540 if ((monster
->col
< rogue
.col
) && (col
< monster
->col
)) return(0);
541 if ((monster
->col
> rogue
.col
) && (col
> monster
->col
)) return(0);
543 if (dungeon
[row
][col
] & OBJECT
) {
544 obj
= object_at(&level_objects
, row
, col
);
545 if ((obj
->what_is
== SCROL
) && (obj
->which_kind
== SCARE_MONSTER
)) {
556 if (!(monster
->m_flags
& NAPPING
)) {
557 monster
->m_flags
&= (~(ASLEEP
| IMITATES
| WAKENS
));
562 wake_room(rn
, entering
, row
, col
)
571 wake_percent
= (rn
== party_room
) ? PARTY_WAKE_PERCENT
: WAKE_PERCENT
;
573 wake_percent
/= (STEALTH_FACTOR
+ stealthy
);
576 monster
= level_monsters
.next_monster
;
579 in_room
= (rn
== get_room_number(monster
->row
, monster
->col
));
582 monster
->trow
= NO_ROOM
;
588 if ((monster
->m_flags
& WAKENS
) &&
589 (rn
== get_room_number(monster
->row
, monster
->col
))) {
590 if (rand_percent(wake_percent
)) {
594 monster
= monster
->next_monster
;
600 const object
*monster
;
604 if (blind
|| ((monster
->m_flags
& INVISIBLE
) &&
605 !(detect_monster
|| see_invisible
|| r_see_invisible
))) {
609 ch
= get_rand('A', 'Z') - 'A';
612 ch
= monster
->m_char
- 'A';
617 rogue_is_around(row
, col
)
620 short rdif
, cdif
, retval
;
622 rdif
= row
- rogue
.row
;
623 cdif
= col
- rogue
.col
;
625 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
636 for (i
= 0; ((i
< 15) && (!found
)); i
++) {
637 monster
= gr_monster((object
*) 0, 0);
638 if (!(monster
->m_flags
& (WAKENS
| WANDERS
))) {
639 free_object(monster
);
647 for (i
= 0; ((i
< 25) && (!found
)); i
++) {
648 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
649 if (!rogue_can_see(row
, col
)) {
650 put_m_at(row
, col
, monster
);
655 free_object(monster
);
670 monster
= level_monsters
.next_monster
;
673 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
674 if (monster
->m_flags
& IMITATES
) {
675 monster
->m_flags
&= (~IMITATES
);
676 monster
->m_flags
|= WAKENS
;
678 monster
= monster
->next_monster
;
693 for (i
= 0; i
< 9; i
++) {
694 rand_around(i
, &row
, &col
);
695 if (((row
== rogue
.row
) && (col
= rogue
.col
)) ||
696 (row
< MIN_ROW
) || (row
> (DROWS
-2)) ||
697 (col
< 0) || (col
> (DCOLS
-1))) {
700 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
701 (dungeon
[row
][col
] & (FLOOR
|TUNNEL
|STAIRS
|DOOR
))) {
707 monster
= gr_monster((object
*) 0, 0);
708 put_m_at(row
, col
, monster
);
709 mvaddch(row
, col
, gmc(monster
));
710 if (monster
->m_flags
& (WANDERS
| WAKENS
)) {
714 message("you hear a faint cry of anguish in the distance", 0);
719 put_m_at(row
, col
, monster
)
725 dungeon
[row
][col
] |= MONSTER
;
726 monster
->trail_char
= mvinch(row
, col
);
727 (void) add_to_pack(monster
, &level_monsters
, 0);
728 aim_monster(monster
);
737 rn
= get_room_number(monster
->row
, monster
->col
);
740 for (i
= 0; i
< 4; i
++) {
742 if (rooms
[rn
].doors
[d
].oth_room
!= NO_ROOM
) {
743 monster
->trow
= rooms
[rn
].doors
[d
].door_row
;
744 monster
->tcol
= rooms
[rn
].doors
[d
].door_col
;
751 rogue_can_see(row
, col
)
757 (((get_room_number(row
, col
) == cur_room
) &&
758 !(rooms
[cur_room
].is_room
& R_MAZE
)) ||
759 rogue_is_around(row
, col
));
765 move_confused(monster
)
770 if (!(monster
->m_flags
& ASLEEP
)) {
771 if (--monster
->moves_confused
<= 0) {
772 monster
->m_flags
&= (~CONFUSED
);
774 if (monster
->m_flags
& STATIONARY
) {
775 return(coin_toss() ? 1 : 0);
776 } else if (rand_percent(15)) {
782 for (i
= 0; i
< 9; i
++) {
783 rand_around(i
, &row
, &col
);
784 if ((row
== rogue
.row
) && (col
== rogue
.col
)) {
787 if (mtry(monster
, row
, col
)) {
801 if (!rand_percent(FLIT_PERCENT
+ ((monster
->m_flags
& FLIES
) ? 20 : 0))) {
804 if (rand_percent(10)) {
810 for (i
= 0; i
< 9; i
++) {
811 rand_around(i
, &row
, &col
);
812 if ((row
== rogue
.row
) && (col
== rogue
.col
)) {
815 if (mtry(monster
, row
, col
)) {
826 const char *rs
= "%!?]=/):*";
834 no_room_for_monster(rn
)
839 for (i
= rooms
[rn
].top_row
+1; i
< rooms
[rn
].bottom_row
; i
++) {
840 for (j
= rooms
[rn
].left_col
+1; j
< rooms
[rn
].right_col
; j
++) {
841 if (!(dungeon
[i
][j
] & MONSTER
)) {
854 message("you hear a high pitched humming noise", 0);
856 monster
= level_monsters
.next_monster
;
860 monster
->m_flags
&= (~IMITATES
);
861 if (rogue_can_see(monster
->row
, monster
->col
)) {
862 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
864 monster
= monster
->next_monster
;
869 mon_sees(monster
, row
, col
)
870 const object
*monster
;
873 short rn
, rdif
, cdif
, retval
;
875 rn
= get_room_number(row
, col
);
877 if ( (rn
!= NO_ROOM
) &&
878 (rn
== get_room_number(monster
->row
, monster
->col
)) &&
879 !(rooms
[rn
].is_room
& R_MAZE
)) {
882 rdif
= row
- monster
->row
;
883 cdif
= col
- monster
->col
;
885 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
894 monster
= level_monsters
.next_monster
;
897 if ((monster
->m_char
== 'A') &&
898 mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
899 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
900 monster
->m_flags
|= ALREADY_MOVED
;
902 monster
= monster
->next_monster
;