]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/monster.c
2 * Copyright (c) 1988 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid
[] = "@(#)monster.c 5.3 (Berkeley) 6/1/90";
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
55 object level_monsters
;
56 boolean mon_disappeared
;
87 object mon_tab
[MONSTERS
] = {
88 {(ASLEEP
|WAKENS
|WANDERS
|RUSTS
),"0d0",25,'A',20,9,18,100,0,0,0,0,0},
89 {(ASLEEP
|WANDERS
|FLITS
|FLIES
),"1d3",10,'B',2,1,8,60,0,0,0,0,0},
90 {(ASLEEP
|WANDERS
),"3d3/2d5",32,'C',15,7,16,85,0,10,0,0,0},
91 {(ASLEEP
|WAKENS
|FLAMES
),"4d6/4d9",145,'D',5000,21,126,100,0,90,0,0,0},
92 {(ASLEEP
|WAKENS
),"1d3",11,'E',2,1,7,65,0,0,0,0,0},
93 {(HOLDS
|STATIONARY
),"5d5",73,'F',91,12,126,80,0,0,0,0,0},
94 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"5d5/5d5",115,'G',
95 2000,20,126,85,0,10,0,0,0},
96 {(ASLEEP
|WAKENS
|WANDERS
),"1d3/1d2",15,'H',3,1,10,67,0,0,0,0,0},
97 {(ASLEEP
|FREEZES
),"0d0",15,'I',5,2,11,68,0,0,0,0,0},
98 {(ASLEEP
|WANDERS
),"3d10/4d5",132,'J',3000,21,126,100,0,0,0,0,0},
99 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"1d4",10,'K',2,1,6,60,0,0,0,0,0},
100 {(ASLEEP
|STEALS_GOLD
),"0d0",25,'L',21,6,16,75,0,0,0,0,0},
101 {(ASLEEP
|WAKENS
|WANDERS
|CONFUSES
),"4d4/3d7",97,'M',
102 250,18,126,85,0,25,0,0,0},
103 {(ASLEEP
|STEALS_ITEM
),"0d0",25,'N',39,10,19,75,0,100,0,0,0},
104 {(ASLEEP
|WANDERS
|WAKENS
|SEEKS_GOLD
),"1d6",25,'O',5,4,13,70,0,10,0,0,0},
105 {(ASLEEP
|INVISIBLE
|WANDERS
|FLITS
),"5d4",76,'P',120,15,24,80,0,50,0,0,0},
106 {(ASLEEP
|WAKENS
|WANDERS
),"3d5",30,'Q',20,8,17,78,0,20,0,0,0},
107 {(ASLEEP
|WAKENS
|WANDERS
|STINGS
),"2d5",19,'R',10,3,12,70,0,0,0,0,0},
108 {(ASLEEP
|WAKENS
|WANDERS
),"1d3",8,'S',2,1,9,50,0,0,0,0,0},
109 {(ASLEEP
|WAKENS
|WANDERS
),"4d6/1d4",75,'T',125,13,22,75,0,33,0,0,0},
110 {(ASLEEP
|WAKENS
|WANDERS
),"4d10",90,'U',
111 200,17,26,85,0,33,0,0,0},
112 {(ASLEEP
|WAKENS
|WANDERS
|DRAINS_LIFE
),"1d14/1d4",55,'V',
113 350,19,126,85,0,18,0,0,0},
114 {(ASLEEP
|WANDERS
|DROPS_LEVEL
),"2d8",45,'W',55,14,23,75,0,0,0,0,0},
115 {(ASLEEP
|IMITATES
),"4d6",42,'X',110,16,25,75,0,0,0,0,0},
116 {(ASLEEP
|WANDERS
),"3d6",35,'Y',50,11,20,80,0,20,0,0,0},
117 {(ASLEEP
|WAKENS
|WANDERS
),"1d7",21,'Z',8,5,14,69,0,0,0,0,0}
120 extern short cur_level
;
121 extern short cur_room
, party_room
;
122 extern short blind
, halluc
, haste_self
;
123 extern boolean detect_monster
, see_invisible
, r_see_invisible
;
124 extern short stealthy
;
135 for (i
= 0; i
< n
; i
++) {
136 monster
= gr_monster((object
*) 0, 0);
137 if ((monster
->m_flags
& WANDERS
) && coin_toss()) {
140 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
141 put_m_at(row
, col
, monster
);
146 gr_monster(monster
, mn
)
147 register object
*monster
;
151 monster
= alloc_object();
154 mn
= get_rand(0, MONSTERS
-1);
155 if ((cur_level
>= mon_tab
[mn
].first_level
) &&
156 (cur_level
<= mon_tab
[mn
].last_level
)) {
161 *monster
= mon_tab
[mn
];
162 if (monster
->m_flags
& IMITATES
) {
163 monster
->disguise
= gr_obj_char();
165 if (cur_level
> (AMULET_LEVEL
+ 2)) {
166 monster
->m_flags
|= HASTED
;
168 monster
->trow
= NO_ROOM
;
174 register object
*monster
, *next_monster
;
177 if (haste_self
% 2) {
181 monster
= level_monsters
.next_monster
;
184 next_monster
= monster
->next_monster
;
186 if (monster
->m_flags
& HASTED
) {
187 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
188 if (mon_disappeared
) {
191 } else if (monster
->m_flags
& SLOWED
) {
192 monster
->slowed_toggle
= !monster
->slowed_toggle
;
193 if (monster
->slowed_toggle
) {
197 if ((monster
->m_flags
& CONFUSED
) && move_confused(monster
)) {
201 if ( (monster
->m_flags
& FLIES
) &&
202 !(monster
->m_flags
& NAPPING
) &&
203 !mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
205 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
206 if (mon_disappeared
) {
210 if (!(flew
&& mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
211 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
213 NM
: monster
= next_monster
;
217 party_monsters(rn
, n
)
227 for (i
= 0; i
< MONSTERS
; i
++) {
228 mon_tab
[i
].first_level
-= (cur_level
% 3);
230 for (i
= 0; i
< n
; i
++) {
231 if (no_room_for_monster(rn
)) {
234 for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
235 row
= get_rand(rooms
[rn
].top_row
+1,
236 rooms
[rn
].bottom_row
-1);
237 col
= get_rand(rooms
[rn
].left_col
+1,
238 rooms
[rn
].right_col
-1);
239 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
240 (dungeon
[row
][col
] & (FLOOR
| TUNNEL
))) {
245 monster
= gr_monster((object
*) 0, 0);
246 if (!(monster
->m_flags
& IMITATES
)) {
247 monster
->m_flags
|= WAKENS
;
249 put_m_at(row
, col
, monster
);
252 for (i
= 0; i
< MONSTERS
; i
++) {
253 mon_tab
[i
].first_level
+= (cur_level
% 3);
257 gmc_row_col(row
, col
)
260 register object
*monster
;
262 if (monster
= object_at(&level_monsters
, row
, col
)) {
263 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
264 (monster
->m_flags
& INVISIBLE
)) || blind
) {
265 return(monster
->trail_char
);
267 if (monster
->m_flags
& IMITATES
) {
268 return(monster
->disguise
);
270 return(monster
->m_char
);
272 return('&'); /* BUG if this ever happens */
279 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
280 (monster
->m_flags
& INVISIBLE
))
282 return(monster
->trail_char
);
284 if (monster
->m_flags
& IMITATES
) {
285 return(monster
->disguise
);
287 return(monster
->m_char
);
290 mv_1_monster(monster
, row
, col
)
291 register object
*monster
;
297 if (monster
->m_flags
& ASLEEP
) {
298 if (monster
->m_flags
& NAPPING
) {
299 if (--monster
->nap_length
<= 0) {
300 monster
->m_flags
&= (~(NAPPING
| ASLEEP
));
304 if ((monster
->m_flags
& WAKENS
) &&
305 rogue_is_around(monster
->row
, monster
->col
) &&
306 rand_percent(((stealthy
> 0) ?
307 (WAKE_PERCENT
/ (STEALTH_FACTOR
+ stealthy
)) :
312 } else if (monster
->m_flags
& ALREADY_MOVED
) {
313 monster
->m_flags
&= (~ALREADY_MOVED
);
316 if ((monster
->m_flags
& FLITS
) && flit(monster
)) {
319 if ((monster
->m_flags
& STATIONARY
) &&
320 (!mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
323 if (monster
->m_flags
& FREEZING_ROGUE
) {
326 if ((monster
->m_flags
& CONFUSES
) && m_confuse(monster
)) {
329 if (mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
333 if ((monster
->m_flags
& FLAMES
) && flame_broil(monster
)) {
336 if ((monster
->m_flags
& SEEKS_GOLD
) && seek_gold(monster
)) {
339 if ((monster
->trow
== monster
->row
) &&
340 (monster
->tcol
== monster
->col
)) {
341 monster
->trow
= NO_ROOM
;
342 } else if (monster
->trow
!= NO_ROOM
) {
346 if (monster
->row
> row
) {
347 row
= monster
->row
- 1;
348 } else if (monster
->row
< row
) {
349 row
= monster
->row
+ 1;
351 if ((dungeon
[row
][monster
->col
] & DOOR
) &&
352 mtry(monster
, row
, monster
->col
)) {
355 if (monster
->col
> col
) {
356 col
= monster
->col
- 1;
357 } else if (monster
->col
< col
) {
358 col
= monster
->col
+ 1;
360 if ((dungeon
[monster
->row
][col
] & DOOR
) &&
361 mtry(monster
, monster
->row
, col
)) {
364 if (mtry(monster
, row
, col
)) {
368 for (i
= 0; i
<= 5; i
++) tried
[i
] = 0;
370 for (i
= 0; i
< 6; i
++) {
371 NEXT_TRY
: n
= get_rand(0, 5);
374 if (!tried
[n
] && mtry(monster
, row
, monster
->col
-1)) {
379 if (!tried
[n
] && mtry(monster
, row
, monster
->col
)) {
384 if (!tried
[n
] && mtry(monster
, row
, monster
->col
+1)) {
389 if (!tried
[n
] && mtry(monster
, monster
->row
-1, col
)) {
394 if (!tried
[n
] && mtry(monster
, monster
->row
, col
)) {
399 if (!tried
[n
] && mtry(monster
, monster
->row
+1, col
)) {
411 if ((monster
->row
== monster
->o_row
) && (monster
->col
== monster
->o_col
)) {
412 if (++(monster
->o
) > 4) {
413 if ((monster
->trow
== NO_ROOM
) &&
414 (!mon_sees(monster
, rogue
.row
, rogue
.col
))) {
415 monster
->trow
= get_rand(1, (DROWS
- 2));
416 monster
->tcol
= get_rand(0, (DCOLS
- 1));
418 monster
->trow
= NO_ROOM
;
423 monster
->o_row
= monster
->row
;
424 monster
->o_col
= monster
->col
;
429 mtry(monster
, row
, col
)
430 register object
*monster
;
431 register short row
, col
;
433 if (mon_can_go(monster
, row
, col
)) {
434 move_mon_to(monster
, row
, col
);
440 move_mon_to(monster
, row
, col
)
441 register object
*monster
;
442 register short row
, col
;
450 dungeon
[mrow
][mcol
] &= ~MONSTER
;
451 dungeon
[row
][col
] |= MONSTER
;
453 c
= mvinch(mrow
, mcol
);
455 if ((c
>= 'A') && (c
<= 'Z')) {
456 if (!detect_monster
) {
457 mvaddch(mrow
, mcol
, monster
->trail_char
);
459 if (rogue_can_see(mrow
, mcol
)) {
460 mvaddch(mrow
, mcol
, monster
->trail_char
);
462 if (monster
->trail_char
== '.') {
463 monster
->trail_char
= ' ';
465 mvaddch(mrow
, mcol
, monster
->trail_char
);
469 monster
->trail_char
= mvinch(row
, col
);
470 if (!blind
&& (detect_monster
|| rogue_can_see(row
, col
))) {
471 if ((!(monster
->m_flags
& INVISIBLE
) ||
472 (detect_monster
|| see_invisible
|| r_see_invisible
))) {
473 mvaddch(row
, col
, gmc(monster
));
476 if ((dungeon
[row
][col
] & DOOR
) &&
477 (get_room_number(row
, col
) != cur_room
) &&
478 (dungeon
[mrow
][mcol
] == FLOOR
) && !blind
) {
479 mvaddch(mrow
, mcol
, ' ');
481 if (dungeon
[row
][col
] & DOOR
) {
482 dr_course(monster
, ((dungeon
[mrow
][mcol
] & TUNNEL
) ? 1 : 0),
490 mon_can_go(monster
, row
, col
)
491 register object
*monster
;
492 register short row
, col
;
497 dr
= monster
->row
- row
; /* check if move distance > 1 */
498 if ((dr
>= 2) || (dr
<= -2)) {
501 dc
= monster
->col
- col
;
502 if ((dc
>= 2) || (dc
<= -2)) {
505 if ((!dungeon
[monster
->row
][col
]) || (!dungeon
[row
][monster
->col
])) {
508 if ((!is_passable(row
, col
)) || (dungeon
[row
][col
] & MONSTER
)) {
511 if ((monster
->row
!=row
)&&(monster
->col
!=col
)&&((dungeon
[row
][col
]&DOOR
) ||
512 (dungeon
[monster
->row
][monster
->col
]&DOOR
))) {
515 if (!(monster
->m_flags
& (FLITS
| CONFUSED
| CAN_FLIT
)) &&
516 (monster
->trow
== NO_ROOM
)) {
517 if ((monster
->row
< rogue
.row
) && (row
< monster
->row
)) return(0);
518 if ((monster
->row
> rogue
.row
) && (row
> monster
->row
)) return(0);
519 if ((monster
->col
< rogue
.col
) && (col
< monster
->col
)) return(0);
520 if ((monster
->col
> rogue
.col
) && (col
> monster
->col
)) return(0);
522 if (dungeon
[row
][col
] & OBJECT
) {
523 obj
= object_at(&level_objects
, row
, col
);
524 if ((obj
->what_is
== SCROL
) && (obj
->which_kind
== SCARE_MONSTER
)) {
534 if (!(monster
->m_flags
& NAPPING
)) {
535 monster
->m_flags
&= (~(ASLEEP
| IMITATES
| WAKENS
));
539 wake_room(rn
, entering
, row
, col
)
548 wake_percent
= (rn
== party_room
) ? PARTY_WAKE_PERCENT
: WAKE_PERCENT
;
550 wake_percent
/= (STEALTH_FACTOR
+ stealthy
);
553 monster
= level_monsters
.next_monster
;
556 in_room
= (rn
== get_room_number(monster
->row
, monster
->col
));
559 monster
->trow
= NO_ROOM
;
565 if ((monster
->m_flags
& WAKENS
) &&
566 (rn
== get_room_number(monster
->row
, monster
->col
))) {
567 if (rand_percent(wake_percent
)) {
571 monster
= monster
->next_monster
;
581 if (blind
|| ((monster
->m_flags
& INVISIBLE
) &&
582 !(detect_monster
|| see_invisible
|| r_see_invisible
))) {
586 ch
= get_rand('A', 'Z') - 'A';
589 ch
= monster
->m_char
- 'A';
593 rogue_is_around(row
, col
)
596 short rdif
, cdif
, retval
;
598 rdif
= row
- rogue
.row
;
599 cdif
= col
- rogue
.col
;
601 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
611 for (i
= 0; ((i
< 15) && (!found
)); i
++) {
612 monster
= gr_monster((object
*) 0, 0);
613 if (!(monster
->m_flags
& (WAKENS
| WANDERS
))) {
614 free_object(monster
);
622 for (i
= 0; ((i
< 25) && (!found
)); i
++) {
623 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
624 if (!rogue_can_see(row
, col
)) {
625 put_m_at(row
, col
, monster
);
630 free_object(monster
);
644 monster
= level_monsters
.next_monster
;
647 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
648 if (monster
->m_flags
& IMITATES
) {
649 monster
->m_flags
&= (~IMITATES
);
650 monster
->m_flags
|= WAKENS
;
652 monster
= monster
->next_monster
;
666 for (i
= 0; i
< 9; i
++) {
667 rand_around(i
, &row
, &col
);
668 if (((row
== rogue
.row
) && (col
= rogue
.col
)) ||
669 (row
< MIN_ROW
) || (row
> (DROWS
-2)) ||
670 (col
< 0) || (col
> (DCOLS
-1))) {
673 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
674 (dungeon
[row
][col
] & (FLOOR
|TUNNEL
|STAIRS
|DOOR
))) {
680 monster
= gr_monster((object
*) 0, 0);
681 put_m_at(row
, col
, monster
);
682 mvaddch(row
, col
, gmc(monster
));
683 if (monster
->m_flags
& (WANDERS
| WAKENS
)) {
687 message("you hear a faint cry of anguish in the distance", 0);
691 put_m_at(row
, col
, monster
)
697 dungeon
[row
][col
] |= MONSTER
;
698 monster
->trail_char
= mvinch(row
, col
);
699 (void) add_to_pack(monster
, &level_monsters
, 0);
700 aim_monster(monster
);
708 rn
= get_room_number(monster
->row
, monster
->col
);
711 for (i
= 0; i
< 4; i
++) {
713 if (rooms
[rn
].doors
[d
].oth_room
!= NO_ROOM
) {
714 monster
->trow
= rooms
[rn
].doors
[d
].door_row
;
715 monster
->tcol
= rooms
[rn
].doors
[d
].door_col
;
721 rogue_can_see(row
, col
)
727 (((get_room_number(row
, col
) == cur_room
) &&
728 !(rooms
[cur_room
].is_room
& R_MAZE
)) ||
729 rogue_is_around(row
, col
));
734 move_confused(monster
)
739 if (!(monster
->m_flags
& ASLEEP
)) {
740 if (--monster
->moves_confused
<= 0) {
741 monster
->m_flags
&= (~CONFUSED
);
743 if (monster
->m_flags
& STATIONARY
) {
744 return(coin_toss() ? 1 : 0);
745 } else if (rand_percent(15)) {
751 for (i
= 0; i
< 9; i
++) {
752 rand_around(i
, &row
, &col
);
753 if ((row
== rogue
.row
) && (col
== rogue
.col
)) {
756 if (mtry(monster
, row
, col
)) {
769 if (!rand_percent(FLIT_PERCENT
+ ((monster
->m_flags
& FLIES
) ? 20 : 0))) {
772 if (rand_percent(10)) {
778 for (i
= 0; i
< 9; i
++) {
779 rand_around(i
, &row
, &col
);
780 if ((row
== rogue
.row
) && (col
== rogue
.col
)) {
783 if (mtry(monster
, row
, col
)) {
793 char *rs
= "%!?]=/):*";
800 no_room_for_monster(rn
)
805 for (i
= rooms
[rn
].top_row
+1; i
< rooms
[rn
].bottom_row
; i
++) {
806 for (j
= rooms
[rn
].left_col
+1; j
< rooms
[rn
].right_col
; j
++) {
807 if (!(dungeon
[i
][j
] & MONSTER
)) {
819 message("you hear a high pitched humming noise", 0);
821 monster
= level_monsters
.next_monster
;
825 monster
->m_flags
&= (~IMITATES
);
826 if (rogue_can_see(monster
->row
, monster
->col
)) {
827 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
829 monster
= monster
->next_monster
;
834 mon_sees(monster
, row
, col
)
837 short rn
, rdif
, cdif
, retval
;
839 rn
= get_room_number(row
, col
);
841 if ( (rn
!= NO_ROOM
) &&
842 (rn
== get_room_number(monster
->row
, monster
->col
)) &&
843 !(rooms
[rn
].is_room
& R_MAZE
)) {
846 rdif
= row
- monster
->row
;
847 cdif
= col
- monster
->col
;
849 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
857 monster
= level_monsters
.next_monster
;
860 if ((monster
->m_char
== 'A') &&
861 mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
862 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
863 monster
->m_flags
|= ALREADY_MOVED
;
865 monster
= monster
->next_monster
;