]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/trap.c
1 /* $NetBSD: trap.c,v 1.4 1997/10/12 11:46:09 lukem 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
[] = "@(#)trap.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: trap.c,v 1.4 1997/10/12 11:46:09 lukem 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 trap traps
[MAX_TRAPS
];
63 boolean trap_door
= 0;
66 char *trap_strings
[TRAPS
* 2] = {
68 "you fell down a trap",
70 "you are caught in a bear trap",
74 "a small dart just hit you in the shoulder",
76 "a strange white mist envelops you and you fall asleep",
78 "a gush of water hits you on the head"
87 for (i
= 0; ((i
< MAX_TRAPS
) && (traps
[i
].trap_type
!= NO_TRAP
)); i
++) {
88 if ((traps
[i
].trap_row
== row
) && (traps
[i
].trap_col
== col
)) {
89 return(traps
[i
].trap_type
);
101 if ((t
= trap_at(row
, col
)) == NO_TRAP
) {
104 dungeon
[row
][col
] &= (~HIDDEN
);
105 if (rand_percent(rogue
.exp
+ ring_exp
)) {
106 message("the trap failed", 1);
112 new_level_message
= trap_strings
[(t
*2)+1];
115 message(trap_strings
[(t
*2)+1], 1);
116 bear_trap
= get_rand(4, 7);
119 mvaddch(rogue
.row
, rogue
.col
, '^');
123 message(trap_strings
[(t
*2)+1], 1);
124 rogue
.hp_current
-= get_damage("1d6", 1);
125 if (rogue
.hp_current
<= 0) {
126 rogue
.hp_current
= 0;
128 if ((!sustain_strength
) && rand_percent(40) &&
129 (rogue
.str_current
>= 3)) {
132 print_stats(STAT_HP
| STAT_STRENGTH
);
133 if (rogue
.hp_current
<= 0) {
134 killed_by((object
*) 0, POISON_DART
);
137 case SLEEPING_GAS_TRAP
:
138 message(trap_strings
[(t
*2)+1], 1);
142 message(trap_strings
[(t
*2)+1], 1);
151 short i
, n
, tries
= 0;
154 if (cur_level
<= 2) {
156 } else if (cur_level
<= 7) {
158 } else if (cur_level
<= 11) {
160 } else if (cur_level
<= 16) {
162 } else if (cur_level
<= 21) {
164 } else if (cur_level
<= (AMULET_LEVEL
+ 2)) {
167 n
= get_rand(5, MAX_TRAPS
);
169 for (i
= 0; i
< n
; i
++) {
170 traps
[i
].trap_type
= get_rand(0, (TRAPS
- 1));
172 if ((i
== 0) && (party_room
!= NO_ROOM
)) {
174 row
= get_rand((rooms
[party_room
].top_row
+1),
175 (rooms
[party_room
].bottom_row
-1));
176 col
= get_rand((rooms
[party_room
].left_col
+1),
177 (rooms
[party_room
].right_col
-1));
179 } while (((dungeon
[row
][col
] & (OBJECT
|STAIRS
|TRAP
|TUNNEL
)) ||
180 (dungeon
[row
][col
] == NOTHING
)) && (tries
< 15));
182 gr_row_col(&row
, &col
, (FLOOR
| MONSTER
));
185 gr_row_col(&row
, &col
, (FLOOR
| MONSTER
));
187 traps
[i
].trap_row
= row
;
188 traps
[i
].trap_col
= col
;
189 dungeon
[row
][col
] |= (TRAP
| HIDDEN
);
196 short dir
, row
, col
, d
, t
;
198 message("direction? ", 0);
200 while (!is_direction(dir
= rgetchar(), &d
)) {
211 get_dir_rc(d
, &row
, &col
, 0);
213 if ((dungeon
[row
][col
] & TRAP
) && (!(dungeon
[row
][col
] & HIDDEN
))) {
214 t
= trap_at(row
, col
);
215 message(trap_strings
[t
*2], 0);
217 message("no trap there", 0);
226 for (i
= 0; i
< DROWS
; i
++) {
227 for (j
= 0; j
< DCOLS
; j
++) {
228 if (dungeon
[i
][j
] & TRAP
) {
240 short s
, i
, j
, row
, col
, t
;
241 short shown
= 0, found
= 0;
242 static boolean reg_search
;
244 for (i
= -1; i
<= 1; i
++) {
245 for (j
= -1; j
<= 1; j
++) {
248 if ((row
< MIN_ROW
) || (row
>= (DROWS
-1)) ||
249 (col
< 0) || (col
>= DCOLS
)) {
252 if (dungeon
[row
][col
] & HIDDEN
) {
257 for (s
= 0; s
< n
; s
++) {
258 for (i
= -1; i
<= 1; i
++) {
259 for (j
= -1; j
<= 1; j
++) {
261 col
= rogue
.col
+ j
;
262 if ((row
< MIN_ROW
) || (row
>= (DROWS
-1)) ||
263 (col
< 0) || (col
>= DCOLS
)) {
266 if (dungeon
[row
][col
] & HIDDEN
) {
267 if (rand_percent(17 + (rogue
.exp
+ ring_exp
))) {
268 dungeon
[row
][col
] &= (~HIDDEN
);
269 if ((!blind
) && ((row
!= rogue
.row
) ||
270 (col
!= rogue
.col
))) {
271 mvaddch(row
, col
, get_dungeon_char(row
, col
));
274 if (dungeon
[row
][col
] & TRAP
) {
275 t
= trap_at(row
, col
);
276 message(trap_strings
[t
*2], 1);
280 if (((shown
== found
) && (found
> 0)) || interrupted
) {
285 if ((!is_auto
) && (reg_search
= !reg_search
)) {