]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/throw.c
1 /* $NetBSD: throw.c,v 1.7 2006/03/30 05:04:22 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
[] = "@(#)throw.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: throw.c,v 1.7 2006/03/30 05:04:22 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
62 boolean first_miss
= 1;
67 while (!is_direction(dir
= rgetchar(), &d
)) {
70 message("direction? ", 0);
78 if ((wch
= pack_letter("throw what?", WEAPON
)) == CANCEL
) {
83 if (!(weapon
= get_letter_object(wch
))) {
84 message("no such item.", 0);
87 if ((weapon
->in_use_flags
& BEING_USED
) && weapon
->is_cursed
) {
88 message(curse_message
, 0);
91 row
= rogue
.row
; col
= rogue
.col
;
93 if ((weapon
->in_use_flags
& BEING_WIELDED
) && (weapon
->quantity
<= 1)) {
94 unwield(rogue
.weapon
);
95 } else if (weapon
->in_use_flags
& BEING_WORN
) {
98 print_stats(STAT_ARMOR
);
99 } else if (weapon
->in_use_flags
& ON_EITHER_HAND
) {
102 monster
= get_thrown_at_monster(weapon
, d
, &row
, &col
);
103 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
106 if (rogue_can_see(row
, col
) && ((row
!= rogue
.row
) || (col
!= rogue
.col
))){
107 mvaddch(row
, col
, get_dungeon_char(row
, col
));
111 check_gold_seeker(monster
);
113 if (!throw_at_monster(monster
, weapon
)) {
114 flop_weapon(weapon
, row
, col
);
117 flop_weapon(weapon
, row
, col
);
119 vanish(weapon
, 1, &rogue
.pack
);
123 throw_at_monster(monster
, weapon
)
124 object
*monster
, *weapon
;
126 short damage
, hit_chance
;
129 hit_chance
= get_hit_chance(weapon
);
130 damage
= get_weapon_damage(weapon
);
131 if ((weapon
->which_kind
== ARROW
) &&
132 (rogue
.weapon
&& (rogue
.weapon
->which_kind
== BOW
))) {
133 damage
+= get_weapon_damage(rogue
.weapon
);
134 damage
= ((damage
* 2) / 3);
135 hit_chance
+= (hit_chance
/ 3);
136 } else if ((weapon
->in_use_flags
& BEING_WIELDED
) &&
137 ((weapon
->which_kind
== DAGGER
) ||
138 (weapon
->which_kind
== SHURIKEN
) ||
139 (weapon
->which_kind
== DART
))) {
140 damage
= ((damage
* 3) / 2);
141 hit_chance
+= (hit_chance
/ 3);
143 t
= weapon
->quantity
;
144 weapon
->quantity
= 1;
145 sprintf(hit_message
, "the %s", name_of(weapon
));
146 weapon
->quantity
= t
;
148 if (!rand_percent(hit_chance
)) {
149 (void) strcat(hit_message
, "misses ");
153 (void) strcat(hit_message
, "hit ");
154 (void) mon_damage(monster
, damage
);
159 get_thrown_at_monster(obj
, dir
, row
, col
)
167 orow
= *row
; ocol
= *col
;
169 ch
= get_mask_char(obj
->what_is
);
171 for (i
= 0; i
< 24; i
++) {
172 get_dir_rc(dir
, row
, col
, 0);
173 if ( (((*col
<= 0) || (*col
>= DCOLS
-1)) ||
174 (dungeon
[*row
][*col
] == NOTHING
)) ||
175 ((dungeon
[*row
][*col
] & (HORWALL
| VERTWALL
| HIDDEN
)) &&
176 (!(dungeon
[*row
][*col
] & TRAP
)))) {
181 if ((i
!= 0) && rogue_can_see(orow
, ocol
)) {
182 mvaddch(orow
, ocol
, get_dungeon_char(orow
, ocol
));
184 if (rogue_can_see(*row
, *col
)) {
185 if (!(dungeon
[*row
][*col
] & MONSTER
)) {
186 mvaddch(*row
, *col
, ch
);
190 orow
= *row
; ocol
= *col
;
191 if (dungeon
[*row
][*col
] & MONSTER
) {
192 if (!imitating(*row
, *col
)) {
193 return(object_at(&level_monsters
, *row
, *col
));
196 if (dungeon
[*row
][*col
] & TUNNEL
) {
204 flop_weapon(weapon
, row
, col
)
208 object
*new_weapon
, *monster
;
215 if ((row
< 0) || (row
>= DROWS
) || (col
< 0) || (col
>= DCOLS
))
216 clean_up("flop_weapon: weapon landed outside of dungeon");
218 while ((i
< 9) && dungeon
[row
][col
] & ~(FLOOR
| TUNNEL
| DOOR
| MONSTER
)) {
219 rand_around(i
++, &row
, &col
);
220 if ((row
> (DROWS
-2)) || (row
< MIN_ROW
) ||
221 (col
> (DCOLS
-1)) || (col
< 0) || (!dungeon
[row
][col
]) ||
222 (dungeon
[row
][col
] & ~(FLOOR
| TUNNEL
| DOOR
| MONSTER
))) {
229 if (found
|| (i
== 0)) {
230 new_weapon
= alloc_object();
231 *new_weapon
= *weapon
;
232 new_weapon
->in_use_flags
= NOT_USED
;
233 new_weapon
->quantity
= 1;
234 new_weapon
->ichar
= 'L';
235 place_at(new_weapon
, row
, col
);
236 if (rogue_can_see(row
, col
) &&
237 ((row
!= rogue
.row
) || (col
!= rogue
.col
))) {
238 mon
= dungeon
[row
][col
] & MONSTER
;
239 dungeon
[row
][col
] &= (~MONSTER
);
240 dch
= get_dungeon_char(row
, col
);
242 mch
= mvinch(row
, col
);
243 if ((monster
= object_at(&level_monsters
,
244 row
, col
)) != NULL
) {
245 monster
->trail_char
= dch
;
247 if ((mch
< 'A') || (mch
> 'Z')) {
248 mvaddch(row
, col
, dch
);
251 mvaddch(row
, col
, dch
);
253 dungeon
[row
][col
] |= mon
;
258 t
= weapon
->quantity
;
259 weapon
->quantity
= 1;
260 sprintf(msg
, "the %svanishes as it hits the ground",
262 weapon
->quantity
= t
;
271 static char pos
[] = "\010\007\001\003\004\005\002\006\0";
272 static short row
, col
;
283 for (j
= 0; j
< 5; j
++) {
291 switch((short)pos
[i
]) {