]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/monster.c
1 /* $NetBSD: monster.c,v 1.3 1995/04/22 10:27:45 cgd 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
41 static char sccsid
[] = "@(#)monster.c 8.1 (Berkeley) 5/31/93";
43 static char rcsid
[] = "$NetBSD: monster.c,v 1.3 1995/04/22 10:27:45 cgd Exp $";
50 * This source herein may be modified and/or distributed by anybody who
51 * so desires, with the following restrictions:
52 * 1.) No portion of this notice shall be removed.
53 * 2.) Credit shall not be taken for the creation of this source.
54 * 3.) This code is not to be traded, sold, or used for personal
61 object level_monsters
;
62 boolean mon_disappeared
;
93 object mon_tab
[MONSTERS
] = {
94 {(ASLEEP
|WAKENS
|WANDERS
|RUSTS
),"0d0",25,'A',20,9,18,100,0,0,0,0,0},
95 {(ASLEEP
|WANDERS
|FLITS
|FLIES
),"1d3",10,'B',2,1,8,60,0,0,0,0,0},
96 {(ASLEEP
|WANDERS
),"3d3/2d5",32,'C',15,7,16,85,0,10,0,0,0},
97 {(ASLEEP
|WAKENS
|FLAMES
),"4d6/4d9",145,'D',5000,21,126,100,0,90,0,0,0},
98 {(ASLEEP
|WAKENS
),"1d3",11,'E',2,1,7,65,0,0,0,0,0},
99 {(HOLDS
|STATIONARY
),"5d5",73,'F',91,12,126,80,0,0,0,0,0},
100 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"5d5/5d5",115,'G',
101 2000,20,126,85,0,10,0,0,0},
102 {(ASLEEP
|WAKENS
|WANDERS
),"1d3/1d2",15,'H',3,1,10,67,0,0,0,0,0},
103 {(ASLEEP
|FREEZES
),"0d0",15,'I',5,2,11,68,0,0,0,0,0},
104 {(ASLEEP
|WANDERS
),"3d10/4d5",132,'J',3000,21,126,100,0,0,0,0,0},
105 {(ASLEEP
|WAKENS
|WANDERS
|FLIES
),"1d4",10,'K',2,1,6,60,0,0,0,0,0},
106 {(ASLEEP
|STEALS_GOLD
),"0d0",25,'L',21,6,16,75,0,0,0,0,0},
107 {(ASLEEP
|WAKENS
|WANDERS
|CONFUSES
),"4d4/3d7",97,'M',
108 250,18,126,85,0,25,0,0,0},
109 {(ASLEEP
|STEALS_ITEM
),"0d0",25,'N',39,10,19,75,0,100,0,0,0},
110 {(ASLEEP
|WANDERS
|WAKENS
|SEEKS_GOLD
),"1d6",25,'O',5,4,13,70,0,10,0,0,0},
111 {(ASLEEP
|INVISIBLE
|WANDERS
|FLITS
),"5d4",76,'P',120,15,24,80,0,50,0,0,0},
112 {(ASLEEP
|WAKENS
|WANDERS
),"3d5",30,'Q',20,8,17,78,0,20,0,0,0},
113 {(ASLEEP
|WAKENS
|WANDERS
|STINGS
),"2d5",19,'R',10,3,12,70,0,0,0,0,0},
114 {(ASLEEP
|WAKENS
|WANDERS
),"1d3",8,'S',2,1,9,50,0,0,0,0,0},
115 {(ASLEEP
|WAKENS
|WANDERS
),"4d6/1d4",75,'T',125,13,22,75,0,33,0,0,0},
116 {(ASLEEP
|WAKENS
|WANDERS
),"4d10",90,'U',
117 200,17,26,85,0,33,0,0,0},
118 {(ASLEEP
|WAKENS
|WANDERS
|DRAINS_LIFE
),"1d14/1d4",55,'V',
119 350,19,126,85,0,18,0,0,0},
120 {(ASLEEP
|WANDERS
|DROPS_LEVEL
),"2d8",45,'W',55,14,23,75,0,0,0,0,0},
121 {(ASLEEP
|IMITATES
),"4d6",42,'X',110,16,25,75,0,0,0,0,0},
122 {(ASLEEP
|WANDERS
),"3d6",35,'Y',50,11,20,80,0,20,0,0,0},
123 {(ASLEEP
|WAKENS
|WANDERS
),"1d7",21,'Z',8,5,14,69,0,0,0,0,0}
126 extern short cur_level
;
127 extern short cur_room
, party_room
;
128 extern short blind
, halluc
, haste_self
;
129 extern boolean detect_monster
, see_invisible
, r_see_invisible
;
130 extern short stealthy
;
141 for (i
= 0; i
< n
; i
++) {
142 monster
= gr_monster((object
*) 0, 0);
143 if ((monster
->m_flags
& WANDERS
) && coin_toss()) {
146 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
147 put_m_at(row
, col
, monster
);
152 gr_monster(monster
, mn
)
153 register object
*monster
;
157 monster
= alloc_object();
160 mn
= get_rand(0, MONSTERS
-1);
161 if ((cur_level
>= mon_tab
[mn
].first_level
) &&
162 (cur_level
<= mon_tab
[mn
].last_level
)) {
167 *monster
= mon_tab
[mn
];
168 if (monster
->m_flags
& IMITATES
) {
169 monster
->disguise
= gr_obj_char();
171 if (cur_level
> (AMULET_LEVEL
+ 2)) {
172 monster
->m_flags
|= HASTED
;
174 monster
->trow
= NO_ROOM
;
180 register object
*monster
, *next_monster
;
183 if (haste_self
% 2) {
187 monster
= level_monsters
.next_monster
;
190 next_monster
= monster
->next_monster
;
192 if (monster
->m_flags
& HASTED
) {
193 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
194 if (mon_disappeared
) {
197 } else if (monster
->m_flags
& SLOWED
) {
198 monster
->slowed_toggle
= !monster
->slowed_toggle
;
199 if (monster
->slowed_toggle
) {
203 if ((monster
->m_flags
& CONFUSED
) && move_confused(monster
)) {
207 if ( (monster
->m_flags
& FLIES
) &&
208 !(monster
->m_flags
& NAPPING
) &&
209 !mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
211 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
212 if (mon_disappeared
) {
216 if (!(flew
&& mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
217 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
219 NM
: monster
= next_monster
;
223 party_monsters(rn
, n
)
233 for (i
= 0; i
< MONSTERS
; i
++) {
234 mon_tab
[i
].first_level
-= (cur_level
% 3);
236 for (i
= 0; i
< n
; i
++) {
237 if (no_room_for_monster(rn
)) {
240 for (j
= found
= 0; ((!found
) && (j
< 250)); j
++) {
241 row
= get_rand(rooms
[rn
].top_row
+1,
242 rooms
[rn
].bottom_row
-1);
243 col
= get_rand(rooms
[rn
].left_col
+1,
244 rooms
[rn
].right_col
-1);
245 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
246 (dungeon
[row
][col
] & (FLOOR
| TUNNEL
))) {
251 monster
= gr_monster((object
*) 0, 0);
252 if (!(monster
->m_flags
& IMITATES
)) {
253 monster
->m_flags
|= WAKENS
;
255 put_m_at(row
, col
, monster
);
258 for (i
= 0; i
< MONSTERS
; i
++) {
259 mon_tab
[i
].first_level
+= (cur_level
% 3);
263 gmc_row_col(row
, col
)
266 register object
*monster
;
268 if (monster
= object_at(&level_monsters
, row
, col
)) {
269 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
270 (monster
->m_flags
& INVISIBLE
)) || blind
) {
271 return(monster
->trail_char
);
273 if (monster
->m_flags
& IMITATES
) {
274 return(monster
->disguise
);
276 return(monster
->m_char
);
278 return('&'); /* BUG if this ever happens */
285 if ((!(detect_monster
|| see_invisible
|| r_see_invisible
) &&
286 (monster
->m_flags
& INVISIBLE
))
288 return(monster
->trail_char
);
290 if (monster
->m_flags
& IMITATES
) {
291 return(monster
->disguise
);
293 return(monster
->m_char
);
296 mv_1_monster(monster
, row
, col
)
297 register object
*monster
;
303 if (monster
->m_flags
& ASLEEP
) {
304 if (monster
->m_flags
& NAPPING
) {
305 if (--monster
->nap_length
<= 0) {
306 monster
->m_flags
&= (~(NAPPING
| ASLEEP
));
310 if ((monster
->m_flags
& WAKENS
) &&
311 rogue_is_around(monster
->row
, monster
->col
) &&
312 rand_percent(((stealthy
> 0) ?
313 (WAKE_PERCENT
/ (STEALTH_FACTOR
+ stealthy
)) :
318 } else if (monster
->m_flags
& ALREADY_MOVED
) {
319 monster
->m_flags
&= (~ALREADY_MOVED
);
322 if ((monster
->m_flags
& FLITS
) && flit(monster
)) {
325 if ((monster
->m_flags
& STATIONARY
) &&
326 (!mon_can_go(monster
, rogue
.row
, rogue
.col
))) {
329 if (monster
->m_flags
& FREEZING_ROGUE
) {
332 if ((monster
->m_flags
& CONFUSES
) && m_confuse(monster
)) {
335 if (mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
339 if ((monster
->m_flags
& FLAMES
) && flame_broil(monster
)) {
342 if ((monster
->m_flags
& SEEKS_GOLD
) && seek_gold(monster
)) {
345 if ((monster
->trow
== monster
->row
) &&
346 (monster
->tcol
== monster
->col
)) {
347 monster
->trow
= NO_ROOM
;
348 } else if (monster
->trow
!= NO_ROOM
) {
352 if (monster
->row
> row
) {
353 row
= monster
->row
- 1;
354 } else if (monster
->row
< row
) {
355 row
= monster
->row
+ 1;
357 if ((dungeon
[row
][monster
->col
] & DOOR
) &&
358 mtry(monster
, row
, monster
->col
)) {
361 if (monster
->col
> col
) {
362 col
= monster
->col
- 1;
363 } else if (monster
->col
< col
) {
364 col
= monster
->col
+ 1;
366 if ((dungeon
[monster
->row
][col
] & DOOR
) &&
367 mtry(monster
, monster
->row
, col
)) {
370 if (mtry(monster
, row
, col
)) {
374 for (i
= 0; i
<= 5; i
++) tried
[i
] = 0;
376 for (i
= 0; i
< 6; i
++) {
377 NEXT_TRY
: n
= get_rand(0, 5);
380 if (!tried
[n
] && mtry(monster
, row
, monster
->col
-1)) {
385 if (!tried
[n
] && mtry(monster
, row
, monster
->col
)) {
390 if (!tried
[n
] && mtry(monster
, row
, monster
->col
+1)) {
395 if (!tried
[n
] && mtry(monster
, monster
->row
-1, col
)) {
400 if (!tried
[n
] && mtry(monster
, monster
->row
, col
)) {
405 if (!tried
[n
] && mtry(monster
, monster
->row
+1, col
)) {
417 if ((monster
->row
== monster
->o_row
) && (monster
->col
== monster
->o_col
)) {
418 if (++(monster
->o
) > 4) {
419 if ((monster
->trow
== NO_ROOM
) &&
420 (!mon_sees(monster
, rogue
.row
, rogue
.col
))) {
421 monster
->trow
= get_rand(1, (DROWS
- 2));
422 monster
->tcol
= get_rand(0, (DCOLS
- 1));
424 monster
->trow
= NO_ROOM
;
429 monster
->o_row
= monster
->row
;
430 monster
->o_col
= monster
->col
;
435 mtry(monster
, row
, col
)
436 register object
*monster
;
437 register short row
, col
;
439 if (mon_can_go(monster
, row
, col
)) {
440 move_mon_to(monster
, row
, col
);
446 move_mon_to(monster
, row
, col
)
447 register object
*monster
;
448 register short row
, col
;
456 dungeon
[mrow
][mcol
] &= ~MONSTER
;
457 dungeon
[row
][col
] |= MONSTER
;
459 c
= mvinch(mrow
, mcol
);
461 if ((c
>= 'A') && (c
<= 'Z')) {
462 if (!detect_monster
) {
463 mvaddch(mrow
, mcol
, monster
->trail_char
);
465 if (rogue_can_see(mrow
, mcol
)) {
466 mvaddch(mrow
, mcol
, monster
->trail_char
);
468 if (monster
->trail_char
== '.') {
469 monster
->trail_char
= ' ';
471 mvaddch(mrow
, mcol
, monster
->trail_char
);
475 monster
->trail_char
= mvinch(row
, col
);
476 if (!blind
&& (detect_monster
|| rogue_can_see(row
, col
))) {
477 if ((!(monster
->m_flags
& INVISIBLE
) ||
478 (detect_monster
|| see_invisible
|| r_see_invisible
))) {
479 mvaddch(row
, col
, gmc(monster
));
482 if ((dungeon
[row
][col
] & DOOR
) &&
483 (get_room_number(row
, col
) != cur_room
) &&
484 (dungeon
[mrow
][mcol
] == FLOOR
) && !blind
) {
485 mvaddch(mrow
, mcol
, ' ');
487 if (dungeon
[row
][col
] & DOOR
) {
488 dr_course(monster
, ((dungeon
[mrow
][mcol
] & TUNNEL
) ? 1 : 0),
496 mon_can_go(monster
, row
, col
)
497 register object
*monster
;
498 register short row
, col
;
503 dr
= monster
->row
- row
; /* check if move distance > 1 */
504 if ((dr
>= 2) || (dr
<= -2)) {
507 dc
= monster
->col
- col
;
508 if ((dc
>= 2) || (dc
<= -2)) {
511 if ((!dungeon
[monster
->row
][col
]) || (!dungeon
[row
][monster
->col
])) {
514 if ((!is_passable(row
, col
)) || (dungeon
[row
][col
] & MONSTER
)) {
517 if ((monster
->row
!=row
)&&(monster
->col
!=col
)&&((dungeon
[row
][col
]&DOOR
) ||
518 (dungeon
[monster
->row
][monster
->col
]&DOOR
))) {
521 if (!(monster
->m_flags
& (FLITS
| CONFUSED
| CAN_FLIT
)) &&
522 (monster
->trow
== NO_ROOM
)) {
523 if ((monster
->row
< rogue
.row
) && (row
< monster
->row
)) return(0);
524 if ((monster
->row
> rogue
.row
) && (row
> monster
->row
)) return(0);
525 if ((monster
->col
< rogue
.col
) && (col
< monster
->col
)) return(0);
526 if ((monster
->col
> rogue
.col
) && (col
> monster
->col
)) return(0);
528 if (dungeon
[row
][col
] & OBJECT
) {
529 obj
= object_at(&level_objects
, row
, col
);
530 if ((obj
->what_is
== SCROL
) && (obj
->which_kind
== SCARE_MONSTER
)) {
540 if (!(monster
->m_flags
& NAPPING
)) {
541 monster
->m_flags
&= (~(ASLEEP
| IMITATES
| WAKENS
));
545 wake_room(rn
, entering
, row
, col
)
554 wake_percent
= (rn
== party_room
) ? PARTY_WAKE_PERCENT
: WAKE_PERCENT
;
556 wake_percent
/= (STEALTH_FACTOR
+ stealthy
);
559 monster
= level_monsters
.next_monster
;
562 in_room
= (rn
== get_room_number(monster
->row
, monster
->col
));
565 monster
->trow
= NO_ROOM
;
571 if ((monster
->m_flags
& WAKENS
) &&
572 (rn
== get_room_number(monster
->row
, monster
->col
))) {
573 if (rand_percent(wake_percent
)) {
577 monster
= monster
->next_monster
;
587 if (blind
|| ((monster
->m_flags
& INVISIBLE
) &&
588 !(detect_monster
|| see_invisible
|| r_see_invisible
))) {
592 ch
= get_rand('A', 'Z') - 'A';
595 ch
= monster
->m_char
- 'A';
599 rogue_is_around(row
, col
)
602 short rdif
, cdif
, retval
;
604 rdif
= row
- rogue
.row
;
605 cdif
= col
- rogue
.col
;
607 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
617 for (i
= 0; ((i
< 15) && (!found
)); i
++) {
618 monster
= gr_monster((object
*) 0, 0);
619 if (!(monster
->m_flags
& (WAKENS
| WANDERS
))) {
620 free_object(monster
);
628 for (i
= 0; ((i
< 25) && (!found
)); i
++) {
629 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
| STAIRS
| OBJECT
));
630 if (!rogue_can_see(row
, col
)) {
631 put_m_at(row
, col
, monster
);
636 free_object(monster
);
650 monster
= level_monsters
.next_monster
;
653 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
654 if (monster
->m_flags
& IMITATES
) {
655 monster
->m_flags
&= (~IMITATES
);
656 monster
->m_flags
|= WAKENS
;
658 monster
= monster
->next_monster
;
672 for (i
= 0; i
< 9; i
++) {
673 rand_around(i
, &row
, &col
);
674 if (((row
== rogue
.row
) && (col
= rogue
.col
)) ||
675 (row
< MIN_ROW
) || (row
> (DROWS
-2)) ||
676 (col
< 0) || (col
> (DCOLS
-1))) {
679 if ((!(dungeon
[row
][col
] & MONSTER
)) &&
680 (dungeon
[row
][col
] & (FLOOR
|TUNNEL
|STAIRS
|DOOR
))) {
686 monster
= gr_monster((object
*) 0, 0);
687 put_m_at(row
, col
, monster
);
688 mvaddch(row
, col
, gmc(monster
));
689 if (monster
->m_flags
& (WANDERS
| WAKENS
)) {
693 message("you hear a faint cry of anguish in the distance", 0);
697 put_m_at(row
, col
, monster
)
703 dungeon
[row
][col
] |= MONSTER
;
704 monster
->trail_char
= mvinch(row
, col
);
705 (void) add_to_pack(monster
, &level_monsters
, 0);
706 aim_monster(monster
);
714 rn
= get_room_number(monster
->row
, monster
->col
);
717 for (i
= 0; i
< 4; i
++) {
719 if (rooms
[rn
].doors
[d
].oth_room
!= NO_ROOM
) {
720 monster
->trow
= rooms
[rn
].doors
[d
].door_row
;
721 monster
->tcol
= rooms
[rn
].doors
[d
].door_col
;
727 rogue_can_see(row
, col
)
733 (((get_room_number(row
, col
) == cur_room
) &&
734 !(rooms
[cur_room
].is_room
& R_MAZE
)) ||
735 rogue_is_around(row
, col
));
740 move_confused(monster
)
745 if (!(monster
->m_flags
& ASLEEP
)) {
746 if (--monster
->moves_confused
<= 0) {
747 monster
->m_flags
&= (~CONFUSED
);
749 if (monster
->m_flags
& STATIONARY
) {
750 return(coin_toss() ? 1 : 0);
751 } else if (rand_percent(15)) {
757 for (i
= 0; i
< 9; i
++) {
758 rand_around(i
, &row
, &col
);
759 if ((row
== rogue
.row
) && (col
== rogue
.col
)) {
762 if (mtry(monster
, row
, col
)) {
775 if (!rand_percent(FLIT_PERCENT
+ ((monster
->m_flags
& FLIES
) ? 20 : 0))) {
778 if (rand_percent(10)) {
784 for (i
= 0; i
< 9; i
++) {
785 rand_around(i
, &row
, &col
);
786 if ((row
== rogue
.row
) && (col
== rogue
.col
)) {
789 if (mtry(monster
, row
, col
)) {
799 char *rs
= "%!?]=/):*";
806 no_room_for_monster(rn
)
811 for (i
= rooms
[rn
].top_row
+1; i
< rooms
[rn
].bottom_row
; i
++) {
812 for (j
= rooms
[rn
].left_col
+1; j
< rooms
[rn
].right_col
; j
++) {
813 if (!(dungeon
[i
][j
] & MONSTER
)) {
825 message("you hear a high pitched humming noise", 0);
827 monster
= level_monsters
.next_monster
;
831 monster
->m_flags
&= (~IMITATES
);
832 if (rogue_can_see(monster
->row
, monster
->col
)) {
833 mvaddch(monster
->row
, monster
->col
, monster
->m_char
);
835 monster
= monster
->next_monster
;
840 mon_sees(monster
, row
, col
)
843 short rn
, rdif
, cdif
, retval
;
845 rn
= get_room_number(row
, col
);
847 if ( (rn
!= NO_ROOM
) &&
848 (rn
== get_room_number(monster
->row
, monster
->col
)) &&
849 !(rooms
[rn
].is_room
& R_MAZE
)) {
852 rdif
= row
- monster
->row
;
853 cdif
= col
- monster
->col
;
855 retval
= (rdif
>= -1) && (rdif
<= 1) && (cdif
>= -1) && (cdif
<= 1);
863 monster
= level_monsters
.next_monster
;
866 if ((monster
->m_char
== 'A') &&
867 mon_can_go(monster
, rogue
.row
, rogue
.col
)) {
868 mv_1_monster(monster
, rogue
.row
, rogue
.col
);
869 monster
->m_flags
|= ALREADY_MOVED
;
871 monster
= monster
->next_monster
;