2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)throw.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/throw.c,v 1.3 1999/11/30 03:49:28 billf Exp $
39 * This source herein may be modified and/or distributed by anybody who
40 * so desires, with the following restrictions:
41 * 1.) No portion of this notice shall be removed.
42 * 2.) Credit shall not be taken for the creation of this source.
43 * 3.) This code is not to be traded, sold, or used for personal
50 static void flop_weapon(object *, short, short);
51 static object *get_thrown_at_monster(object *, short, short *, short *);
52 static boolean throw_at_monster(object *, object *);
58 boolean first_miss = 1;
63 while (!is_direction(dir = rgetchar(), &d)) {
66 message("direction? ", 0);
74 if ((wch = pack_letter("throw what?", WEAPON)) == CANCEL) {
79 if (!(weapon = get_letter_object(wch))) {
80 message("no such item.", 0);
83 if ((weapon->in_use_flags & BEING_USED) && weapon->is_cursed) {
84 message(curse_message, 0);
87 row = rogue.row; col = rogue.col;
89 if ((weapon->in_use_flags & BEING_WIELDED) && (weapon->quantity <= 1)) {
90 unwield(rogue.weapon);
91 } else if (weapon->in_use_flags & BEING_WORN) {
94 print_stats(STAT_ARMOR);
95 } else if (weapon->in_use_flags & ON_EITHER_HAND) {
98 monster = get_thrown_at_monster(weapon, d, &row, &col);
99 mvaddch(rogue.row, rogue.col, rogue.fchar);
102 if (rogue_can_see(row, col) && ((row != rogue.row) || (col != rogue.col))) {
103 mvaddch(row, col, get_dungeon_char(row, col));
107 check_gold_seeker(monster);
109 if (!throw_at_monster(monster, weapon)) {
110 flop_weapon(weapon, row, col);
113 flop_weapon(weapon, row, col);
115 vanish(weapon, 1, &rogue.pack);
119 throw_at_monster(object *monster, object *weapon)
121 short damage, hit_chance;
124 hit_chance = get_hit_chance(weapon);
125 damage = get_weapon_damage(weapon);
126 if ((weapon->which_kind == ARROW) &&
127 (rogue.weapon && (rogue.weapon->which_kind == BOW))) {
128 damage += get_weapon_damage(rogue.weapon);
129 damage = ((damage * 2) / 3);
130 hit_chance += (hit_chance / 3);
131 } else if ((weapon->in_use_flags & BEING_WIELDED) &&
132 ((weapon->which_kind == DAGGER) ||
133 (weapon->which_kind == SHURIKEN) ||
134 (weapon->which_kind == DART))) {
135 damage = ((damage * 3) / 2);
136 hit_chance += (hit_chance / 3);
138 t = weapon->quantity;
139 weapon->quantity = 1;
140 sprintf(hit_message, "the %s", name_of(weapon));
141 weapon->quantity = t;
143 if (!rand_percent(hit_chance)) {
144 strcat(hit_message, "misses ");
148 strcat(hit_message, "hit ");
149 mon_damage(monster, damage);
154 get_thrown_at_monster(object *obj, short dir, short *row, short *col)
159 orow = *row; ocol = *col;
161 ch = get_mask_char(obj->what_is);
163 for (i = 0; i < 24; i++) {
164 get_dir_rc(dir, row, col, 0);
165 if ( (((*col <= 0) || (*col >= DCOLS-1)) ||
166 (dungeon[*row][*col] == NOTHING)) ||
167 ((dungeon[*row][*col] & (HORWALL | VERTWALL | HIDDEN)) &&
168 (!(dungeon[*row][*col] & TRAP)))) {
173 if ((i != 0) && rogue_can_see(orow, ocol)) {
174 mvaddch(orow, ocol, get_dungeon_char(orow, ocol));
176 if (rogue_can_see(*row, *col)) {
177 if (!(dungeon[*row][*col] & MONSTER)) {
178 mvaddch(*row, *col, ch);
182 orow = *row; ocol = *col;
183 if (dungeon[*row][*col] & MONSTER) {
184 if (!imitating(*row, *col)) {
185 return(object_at(&level_monsters, *row, *col));
188 if (dungeon[*row][*col] & TUNNEL) {
196 flop_weapon(object *weapon, short row, short col)
198 object *new_weapon, *monster;
205 while ((i < 9) && dungeon[row][col] & ~(FLOOR | TUNNEL | DOOR | MONSTER)) {
206 rand_around(i++, &row, &col);
207 if ((row > (DROWS-2)) || (row < MIN_ROW) ||
208 (col > (DCOLS-1)) || (col < 0) || (!dungeon[row][col]) ||
209 (dungeon[row][col] & ~(FLOOR | TUNNEL | DOOR | MONSTER))) {
216 if (found || (i == 0)) {
217 new_weapon = alloc_object();
218 *new_weapon = *weapon;
219 new_weapon->in_use_flags = NOT_USED;
220 new_weapon->quantity = 1;
221 new_weapon->ichar = 'L';
222 place_at(new_weapon, row, col);
223 if (rogue_can_see(row, col) &&
224 ((row != rogue.row) || (col != rogue.col))) {
225 mon = dungeon[row][col] & MONSTER;
226 dungeon[row][col] &= (~MONSTER);
227 dch = get_dungeon_char(row, col);
229 mch = mvinch(row, col);
230 if ((monster = object_at(&level_monsters,
231 row, col)) != NULL) {
232 monster->trail_char = dch;
234 if ((mch < 'A') || (mch > 'Z')) {
235 mvaddch(row, col, dch);
238 mvaddch(row, col, dch);
240 dungeon[row][col] |= mon;
245 t = weapon->quantity;
246 weapon->quantity = 1;
247 sprintf(msg, "the %svanishes as it hits the ground",
249 weapon->quantity = t;
255 rand_around(short i, short *r, short *c)
257 static char pos[] = "\010\007\001\003\004\005\002\006\0";
258 static short row, col;
269 for (j = 0; j < 5; j++) {
277 switch((short)pos[i]) {