]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/monster.c
1 /* $NetBSD: monster.c,v 1.11 2006/03/30 04:10:04 jnemeth 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)monster.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: monster.c,v 1.11 2006/03/30 04:10:04 jnemeth Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
58 object level_monsters
;
59 boolean mon_disappeared
;
61 const char *const m_names
[] = {
90 object mon_tab
[MONSTERS
] = {
91 {(ASLEEP
|WAKENS
|WANDERS
|RUSTS
),"0d0",25,'A',20,9,18,100,0,0,0,0,0},
92 {(ASLEEP
|WANDERS
|FLITS
|FLIES
),"1d3",10,'B',2,1,8,60,0,0,0,0,0},
93 {(ASLEEP
|WANDERS
),"3d3/2d5",32,'C',15,7,16,85,0,10,0,0,0},
94 {(ASLEEP
|WAKENS
|FLAMES
),"4d6/4d9",145,'D',5000,21,126,100,0,90,0,0,0},
95 {(ASLEEP
|WAKENS
),"1d3",11,'E',2,1,7,65,0,0,0,0,0},
96 {(HOLDS
|STATIONARY
),"5d5",73,'F',91,12,126,80,0,0,0,0,0},
97 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"5d5/5d5",115,'G',
98 2000,20,126,85,0,10,0,0,0},
99 {(ASLEEP
|WAKENS
|WANDERS
),"1d3/1d2",15,'H',3,1,10,67,0,0,0,0,0},
100 {(ASLEEP
|FREEZES
),"0d0",15,'I',5,2,11,68,0,0,0,0,0},
101 {(ASLEEP
|WANDERS
),"3d10/4d5",132,'J',3000,21,126,100,0,0,0,0,0},
102 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"1d4",10,'K',2,1,6,60,0,0,0,0,0},
103 {(ASLEEP
|STEALS_GOLD
),"0d0",25,'L',21,6,16,75,0,0,0,0,0},
104 {(ASLEEP
|WAKENS
|WANDERS
|CONFUSES
),"4d4/3d7",97,'M',
105 250,18,126,85,0,25,0,0,0},
106 {(ASLEEP
|STEALS_ITEM
),"0d0",25,'N',39,10,19,75,0,100,0,0,0},
107 {(ASLEEP
|WANDERS
|WAKENS
|SEEKS_GOLD
),"1d6",25,'O',5,4,13,70,0,10,0,0,0},
108 {(ASLEEP
|INVISIBLE
|WANDERS
|FLITS
),"5d4",76,'P',120,15,24,80,0,50,0,0,0},
109 {(ASLEEP
|WAKENS
|WANDERS
),"3d5",30,'Q',20,8,17,78,0,20,0,0,0},
110 {(ASLEEP
|WAKENS
|WANDERS
|STINGS
),"2d5",19,'R',10,3,12,70,0,0,0,0,0},
111 {(ASLEEP
|WAKENS
|WANDERS
),"1d3",8,'S',2,1,9,50,0,0,0,0,0},
112 {(ASLEEP
|WAKENS
|WANDERS
),"4d6/1d4",75,'T',125,13,22,75,0,33,0,0,0},
113 {(ASLEEP
|WAKENS
|WANDERS
),"4d10",90,'U',
114 200,17,26,85,0,33,0,0,0},
115 {(ASLEEP
|WAKENS
|WANDERS
|DRAINS_LIFE
),"1d14/1d4",55,'V',
116 350,19,126,85,0,18,0,0,0},
117 {(ASLEEP
|WANDERS
|DROPS_LEVEL
),"2d8",45,'W',55,14,23,75,0,0,0,0,0},
118 {(ASLEEP
|IMITATES
),"4d6",42,'X',110,16,25,75,0,0,0,0,0},
119 {(ASLEEP
|WANDERS
),"3d6",35,'Y',50,11,20,80,0,20,0,0,0},
120 {(ASLEEP
|WAKENS
|WANDERS
),"1d7",21,'Z',8,5,14,69,0,0,0,0,0}
133 for (i
= 0; i
< n
; i
++) {
134 monster
= gr_monster((object
*) 0, 0);
135 if ((monster
->m_flags
& WANDERS
) && coin_toss()) {
138 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
139 put_m_at(row
, col
, monster
);
144 gr_monster(monster
, mn
)
149 monster
= alloc_object();
152 mn
= get_rand(0, MONSTERS
-1);
153 if ((cur_level
>= mon_tab
[mn
].first_level
) &&
154 (cur_level
<= mon_tab
[mn
].last_level
)) {
159 *monster
= mon_tab
[mn
];
160 if (monster
->m_flags
& IMITATES
) {
161 monster
->disguise
= gr_obj_char();
163 if (cur_level
> (AMULET_LEVEL
+ 2)) {
164 monster
->m_flags
|= HASTED
;
166 monster
->trow
= NO_ROOM
;
173 object
*monster
, *next_monster
, *test_mons
;
176 if (haste_self
% 2) {
180 monster
= level_monsters
.next_monster
;
183 next_monster
= monster
->next_monster
;
185 if (monster
->m_flags
& HASTED
) {
186 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
187 if (mon_disappeared
) {
190 } else if (monster
->m_flags
& SLOWED
) {
191 monster
->slowed_toggle
= !monster
->slowed_toggle
;
192 if (monster
->slowed_toggle
) {
196 if ((monster
->m_flags
& CONFUSED
) && move_confused(monster
)) {
200 if ( (monster
->m_flags
& FLIES
) &&
201 !(monster
->m_flags
& NAPPING
) &&
202 !mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
204 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
205 if (mon_disappeared
) {
209 if (!(flew
&& mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
210 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
212 NM
: test_mons
= level_monsters
.next_monster
;
216 if (next_monster
== test_mons
)
218 monster
= next_monster
;
221 test_mons
= test_mons
-> next_monster
;
227 party_monsters(rn
, n
)
238 for (i
= 0; i
< MONSTERS
; i
++) {
239 mon_tab
[i
].first_level
-= (cur_level
% 3);
241 for (i
= 0; i
< n
; i
++) {
242 if (no_room_for_monster(rn
)) {
245 for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
246 row
= get_rand(rooms
[rn
].top_row
+1,
247 rooms
[rn
].bottom_row
-1);
248 col
= get_rand(rooms
[rn
].left_col
+1,
249 rooms
[rn
].right_col
-1);
250 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
251 (dungeon
[row
][col
] & (FLOOR
| TUNNEL
))) {
256 monster
= gr_monster((object
*) 0, 0);
257 if (!(monster
->m_flags
& IMITATES
)) {
258 monster
->m_flags
|= WAKENS
;
260 put_m_at(row
, col
, monster
);
263 for (i
= 0; i
< MONSTERS
; i
++) {
264 mon_tab
[i
].first_level
+= (cur_level
% 3);
269 gmc_row_col(row
, col
)
274 if ((monster
= object_at(&level_monsters
, row
, col
)) != NULL
) {
275 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
276 (monster
->m_flags
& INVISIBLE
)) || blind
) {
277 return(monster
->trail_char
);
279 if (monster
->m_flags
& IMITATES
) {
280 return(monster
->disguise
);
282 return(monster
->m_char
);
284 return('&'); /* BUG if this ever happens */
292 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
293 (monster
->m_flags
& INVISIBLE
))
295 return(monster
->trail_char
);
297 if (monster
->m_flags
& IMITATES
) {
298 return(monster
->disguise
);
300 return(monster
->m_char
);
304 mv_1_monster(monster
, row
, col
)
311 if (monster
->m_flags
& ASLEEP
) {
312 if (monster
->m_flags
& NAPPING
) {
313 if (--monster
->nap_length
<= 0) {
314 monster
->m_flags
&= (~(NAPPING
| ASLEEP
));
318 if ((monster
->m_flags
& WAKENS
) &&
319 rogue_is_around(monster
->row
, monster
->col
) &&
320 rand_percent(((stealthy
> 0) ?
321 (WAKE_PERCENT
/ (STEALTH_FACTOR
+ stealthy
)) :
326 } else if (monster
->m_flags
& ALREADY_MOVED
) {
327 monster
->m_flags
&= (~ALREADY_MOVED
);
330 if ((monster
->m_flags
& FLITS
) && flit(monster
)) {
333 if ((monster
->m_flags
& STATIONARY
) &&
334 (!mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
337 if (monster
->m_flags
& FREEZING_ROGUE
) {
340 if ((monster
->m_flags
& CONFUSES
) && m_confuse(monster
)) {
343 if (mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
347 if ((monster
->m_flags
& FLAMES
) && flame_broil(monster
)) {
350 if ((monster
->m_flags
& SEEKS_GOLD
) && seek_gold(monster
)) {
353 if ((monster
->trow
== monster
->row
) &&
354 (monster
->tcol
== monster
->col
)) {
355 monster
->trow
= NO_ROOM
;
356 } else if (monster
->trow
!= NO_ROOM
) {
360 if (monster
->row
> row
) {
361 row
= monster
->row
- 1;
362 } else if (monster
->row
< row
) {
363 row
= monster
->row
+ 1;
365 if ((dungeon
[row
][monster
->col
] & DOOR
) &&
366 mtry(monster
, row
, monster
->col
)) {
369 if (monster
->col
> col
) {
370 col
= monster
->col
- 1;
371 } else if (monster
->col
< col
) {
372 col
= monster
->col
+ 1;
374 if ((dungeon
[monster
->row
][col
] & DOOR
) &&
375 mtry(monster
, monster
->row
, col
)) {
378 if (mtry(monster
, row
, col
)) {
382 for (i
= 0; i
<= 5; i
++) tried
[i
] = 0;
384 for (i
= 0; i
< 6; i
++) {
385 NEXT_TRY
: n
= get_rand(0, 5);
388 if (!tried
[n
] && mtry(monster
, row
, monster
->col
-1)) {
393 if (!tried
[n
] && mtry(monster
, row
, monster
->col
)) {
398 if (!tried
[n
] && mtry(monster
, row
, monster
->col
+1)) {
403 if (!tried
[n
] && mtry(monster
, monster
->row
-1, col
)) {
408 if (!tried
[n
] && mtry(monster
, monster
->row
, col
)) {
413 if (!tried
[n
] && mtry(monster
, monster
->row
+1, col
)) {
425 if ((monster
->row
== monster
->o_row
) && (monster
->col
== monster
->o_col
)) {
426 if (++(monster
->o
) > 4) {
427 if ((monster
->trow
== NO_ROOM
) &&
428 (!mon_sees(monster
, rogue
.row
, rogue
.col
))) {
429 monster
->trow
= get_rand(1, (DROWS
- 2));
430 monster
->tcol
= get_rand(0, (DCOLS
- 1));
432 monster
->trow
= NO_ROOM
;
437 monster
->o_row
= monster
->row
;
438 monster
->o_col
= monster
->col
;
444 mtry(monster
, row
, col
)
448 if (mon_can_go(monster
, row
, col
)) {
449 move_mon_to(monster
, row
, col
);
456 move_mon_to(monster
, row
, col
)
466 dungeon
[mrow
][mcol
] &= ~MONSTER
;
467 dungeon
[row
][col
] |= MONSTER
;
469 c
= mvinch(mrow
, mcol
);
471 if ((c
>= 'A') && (c
<= 'Z')) {
472 if (!detect_monster
) {
473 mvaddch(mrow
, mcol
, monster
->trail_char
);
475 if (rogue_can_see(mrow
, mcol
)) {
476 mvaddch(mrow
, mcol
, monster
->trail_char
);
478 if (monster
->trail_char
== '.') {
479 monster
->trail_char
= ' ';
481 mvaddch(mrow
, mcol
, monster
->trail_char
);
485 monster
->trail_char
= mvinch(row
, col
);
486 if (!blind
&& (detect_monster
|| rogue_can_see(row
, col
))) {
487 if ((!(monster
->m_flags
& INVISIBLE
) ||
488 (detect_monster
|| see_invisible
|| r_see_invisible
))) {
489 mvaddch(row
, col
, gmc(monster
));
492 if ((dungeon
[row
][col
] & DOOR
) &&
493 (get_room_number(row
, col
) != cur_room
) &&
494 (dungeon
[mrow
][mcol
] == FLOOR
) && !blind
) {
495 mvaddch(mrow
, mcol
, ' ');
497 if (dungeon
[row
][col
] & DOOR
) {
498 dr_course(monster
, ((dungeon
[mrow
][mcol
] & TUNNEL
) ? 1 : 0),
507 mon_can_go(monster
, row
, col
)
508 const object
*monster
;
514 dr
= monster
->row
- row
; /* check if move distance > 1 */
515 if ((dr
>= 2) || (dr
<= -2)) {
518 dc
= monster
->col
- col
;
519 if ((dc
>= 2) || (dc
<= -2)) {
522 if ((!dungeon
[monster
->row
][col
]) || (!dungeon
[row
][monster
->col
])) {
525 if ((!is_passable(row
, col
)) || (dungeon
[row
][col
] & MONSTER
)) {
528 if ((monster
->row
!=row
)&&(monster
->col
!=col
)&&((dungeon
[row
][col
]&DOOR
) ||
529 (dungeon
[monster
->row
][monster
->col
]&DOOR
))) {
532 if (!(monster
->m_flags
& (FLITS
| CONFUSED
| CAN_FLIT
)) &&
533 (monster
->trow
== NO_ROOM
)) {
534 if ((monster
->row
< rogue
.row
) && (row
< monster
->row
)) return(0);
535 if ((monster
->row
> rogue
.row
) && (row
> monster
->row
)) return(0);
536 if ((monster
->col
< rogue
.col
) && (col
< monster
->col
)) return(0);
537 if ((monster
->col
> rogue
.col
) && (col
> monster
->col
)) return(0);
539 if (dungeon
[row
][col
] & OBJECT
) {
540 obj
= object_at(&level_objects
, row
, col
);
541 if ((obj
->what_is
== SCROL
) && (obj
->which_kind
== SCARE_MONSTER
)) {
552 if (!(monster
->m_flags
& NAPPING
)) {
553 monster
->m_flags
&= (~(ASLEEP
| IMITATES
| WAKENS
));
558 wake_room(rn
, entering
, row
, col
)
567 wake_percent
= (rn
== party_room
) ? PARTY_WAKE_PERCENT
: WAKE_PERCENT
;
569 wake_percent
/= (STEALTH_FACTOR
+ stealthy
);
572 monster
= level_monsters
.next_monster
;
575 in_room
= (rn
== get_room_number(monster
->row
, monster
->col
));
578 monster
->trow
= NO_ROOM
;
584 if ((monster
->m_flags
& WAKENS
) &&
585 (rn
== get_room_number(monster
->row
, monster
->col
))) {
586 if (rand_percent(wake_percent
)) {
590 monster
= monster
->next_monster
;
596 const object
*monster
;
600 if (blind
|| ((monster
->m_flags
& INVISIBLE
) &&
601 !(detect_monster
|| see_invisible
|| r_see_invisible
))) {
605 ch
= get_rand('A', 'Z') - 'A';
608 ch
= monster
->m_char
- 'A';
613 rogue_is_around(row
, col
)
616 short rdif
, cdif
, retval
;
618 rdif
= row
- rogue
.row
;
619 cdif
= col
- rogue
.col
;
621 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
632 monster
= NULL
; /* XXXGCC -Wuninitialized [powerpc] */
634 for (i
= 0; ((i
< 15) && (!found
)); i
++) {
635 monster
= gr_monster((object
*) 0, 0);
636 if (!(monster
->m_flags
& (WAKENS
| WANDERS
))) {
637 free_object(monster
);
645 for (i
= 0; ((i
< 25) && (!found
)); i
++) {
646 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
647 if (!rogue_can_see(row
, col
)) {
648 put_m_at(row
, col
, monster
);
653 free_object(monster
);
668 monster
= level_monsters
.next_monster
;
671 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
672 if (monster
->m_flags
& IMITATES
) {
673 monster
->m_flags
&= (~IMITATES
);
674 monster
->m_flags
|= WAKENS
;
676 monster
= monster
->next_monster
;
691 for (i
= 0; i
< 9; i
++) {
692 rand_around(i
, &row
, &col
);
693 if (((row
== rogue
.row
) && (col
= rogue
.col
)) ||
694 (row
< MIN_ROW
) || (row
> (DROWS
-2)) ||
695 (col
< 0) || (col
> (DCOLS
-1))) {
698 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
699 (dungeon
[row
][col
] & (FLOOR
|TUNNEL
|STAIRS
|DOOR
))) {
705 monster
= gr_monster((object
*) 0, 0);
706 put_m_at(row
, col
, monster
);
707 mvaddch(row
, col
, gmc(monster
));
708 if (monster
->m_flags
& (WANDERS
| WAKENS
)) {
712 message("you hear a faint cry of anguish in the distance", 0);
717 put_m_at(row
, col
, monster
)
723 dungeon
[row
][col
] |= MONSTER
;
724 monster
->trail_char
= mvinch(row
, col
);
725 (void) add_to_pack(monster
, &level_monsters
, 0);
726 aim_monster(monster
);
735 rn
= get_room_number(monster
->row
, monster
->col
);
737 clean_up("aim_monster: monster not in room");
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
;