]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/trap.c
1 /* $NetBSD: trap.c,v 1.6 2003/08/07 09:37:40 agc 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
[] = "@(#)trap.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: trap.c,v 1.6 2003/08/07 09:37:40 agc 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 trap traps
[MAX_TRAPS
];
59 boolean trap_door
= 0;
62 const char *const trap_strings
[TRAPS
* 2] = {
64 "you fell down a trap",
66 "you are caught in a bear trap",
70 "a small dart just hit you in the shoulder",
72 "a strange white mist envelops you and you fall asleep",
74 "a gush of water hits you on the head"
83 for (i
= 0; ((i
< MAX_TRAPS
) && (traps
[i
].trap_type
!= NO_TRAP
)); i
++) {
84 if ((traps
[i
].trap_row
== row
) && (traps
[i
].trap_col
== col
)) {
85 return(traps
[i
].trap_type
);
97 if ((t
= trap_at(row
, col
)) == NO_TRAP
) {
100 dungeon
[row
][col
] &= (~HIDDEN
);
101 if (rand_percent(rogue
.exp
+ ring_exp
)) {
102 message("the trap failed", 1);
108 new_level_message
= trap_strings
[(t
*2)+1];
111 message(trap_strings
[(t
*2)+1], 1);
112 bear_trap
= get_rand(4, 7);
115 mvaddch(rogue
.row
, rogue
.col
, '^');
119 message(trap_strings
[(t
*2)+1], 1);
120 rogue
.hp_current
-= get_damage("1d6", 1);
121 if (rogue
.hp_current
<= 0) {
122 rogue
.hp_current
= 0;
124 if ((!sustain_strength
) && rand_percent(40) &&
125 (rogue
.str_current
>= 3)) {
128 print_stats(STAT_HP
| STAT_STRENGTH
);
129 if (rogue
.hp_current
<= 0) {
130 killed_by((object
*) 0, POISON_DART
);
133 case SLEEPING_GAS_TRAP
:
134 message(trap_strings
[(t
*2)+1], 1);
138 message(trap_strings
[(t
*2)+1], 1);
147 short i
, n
, tries
= 0;
150 if (cur_level
<= 2) {
152 } else if (cur_level
<= 7) {
154 } else if (cur_level
<= 11) {
156 } else if (cur_level
<= 16) {
158 } else if (cur_level
<= 21) {
160 } else if (cur_level
<= (AMULET_LEVEL
+ 2)) {
163 n
= get_rand(5, MAX_TRAPS
);
165 for (i
= 0; i
< n
; i
++) {
166 traps
[i
].trap_type
= get_rand(0, (TRAPS
- 1));
168 if ((i
== 0) && (party_room
!= NO_ROOM
)) {
170 row
= get_rand((rooms
[party_room
].top_row
+1),
171 (rooms
[party_room
].bottom_row
-1));
172 col
= get_rand((rooms
[party_room
].left_col
+1),
173 (rooms
[party_room
].right_col
-1));
175 } while (((dungeon
[row
][col
] & (OBJECT
|STAIRS
|TRAP
|TUNNEL
)) ||
176 (dungeon
[row
][col
] == NOTHING
)) && (tries
< 15));
178 gr_row_col(&row
, &col
, (FLOOR
| MONSTER
));
181 gr_row_col(&row
, &col
, (FLOOR
| MONSTER
));
183 traps
[i
].trap_row
= row
;
184 traps
[i
].trap_col
= col
;
185 dungeon
[row
][col
] |= (TRAP
| HIDDEN
);
192 short dir
, row
, col
, d
, t
;
194 message("direction? ", 0);
196 while (!is_direction(dir
= rgetchar(), &d
)) {
207 get_dir_rc(d
, &row
, &col
, 0);
209 if ((dungeon
[row
][col
] & TRAP
) && (!(dungeon
[row
][col
] & HIDDEN
))) {
210 t
= trap_at(row
, col
);
211 message(trap_strings
[t
*2], 0);
213 message("no trap there", 0);
222 for (i
= 0; i
< DROWS
; i
++) {
223 for (j
= 0; j
< DCOLS
; j
++) {
224 if (dungeon
[i
][j
] & TRAP
) {
236 short s
, i
, j
, row
, col
, t
;
237 short shown
= 0, found
= 0;
238 static boolean reg_search
;
240 for (i
= -1; i
<= 1; i
++) {
241 for (j
= -1; j
<= 1; j
++) {
244 if ((row
< MIN_ROW
) || (row
>= (DROWS
-1)) ||
245 (col
< 0) || (col
>= DCOLS
)) {
248 if (dungeon
[row
][col
] & HIDDEN
) {
253 for (s
= 0; s
< n
; s
++) {
254 for (i
= -1; i
<= 1; i
++) {
255 for (j
= -1; j
<= 1; j
++) {
257 col
= rogue
.col
+ j
;
258 if ((row
< MIN_ROW
) || (row
>= (DROWS
-1)) ||
259 (col
< 0) || (col
>= DCOLS
)) {
262 if (dungeon
[row
][col
] & HIDDEN
) {
263 if (rand_percent(17 + (rogue
.exp
+ ring_exp
))) {
264 dungeon
[row
][col
] &= (~HIDDEN
);
265 if ((!blind
) && ((row
!= rogue
.row
) ||
266 (col
!= rogue
.col
))) {
267 mvaddch(row
, col
, get_dungeon_char(row
, col
));
270 if (dungeon
[row
][col
] & TRAP
) {
271 t
= trap_at(row
, col
);
272 message(trap_strings
[t
*2], 1);
276 if (((shown
== found
) && (found
> 0)) || interrupted
) {
281 if ((!is_auto
) && (reg_search
= !reg_search
)) {