throw.c revision 1.3 1 1.3 cgd /* $NetBSD: throw.c,v 1.3 1995/04/22 10:28:32 cgd Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.3 cgd * Copyright (c) 1988, 1993
5 1.3 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Timothy C. Stoehr.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.1 cgd * This product includes software developed by the University of
21 1.1 cgd * California, Berkeley and its contributors.
22 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
23 1.1 cgd * may be used to endorse or promote products derived from this software
24 1.1 cgd * without specific prior written permission.
25 1.1 cgd *
26 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 cgd * SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.1 cgd #ifndef lint
40 1.3 cgd #if 0
41 1.3 cgd static char sccsid[] = "@(#)throw.c 8.1 (Berkeley) 5/31/93";
42 1.3 cgd #else
43 1.3 cgd static char rcsid[] = "$NetBSD: throw.c,v 1.3 1995/04/22 10:28:32 cgd Exp $";
44 1.3 cgd #endif
45 1.1 cgd #endif /* not lint */
46 1.1 cgd
47 1.1 cgd /*
48 1.1 cgd * throw.c
49 1.1 cgd *
50 1.1 cgd * This source herein may be modified and/or distributed by anybody who
51 1.1 cgd * so desires, with the following restrictions:
52 1.1 cgd * 1.) No portion of this notice shall be removed.
53 1.1 cgd * 2.) Credit shall not be taken for the creation of this source.
54 1.1 cgd * 3.) This code is not to be traded, sold, or used for personal
55 1.1 cgd * gain or profit.
56 1.1 cgd *
57 1.1 cgd */
58 1.1 cgd
59 1.1 cgd #include "rogue.h"
60 1.1 cgd
61 1.1 cgd extern short cur_room;
62 1.1 cgd extern char *curse_message;
63 1.1 cgd extern char hit_message[];
64 1.1 cgd
65 1.1 cgd throw()
66 1.1 cgd {
67 1.1 cgd short wch, d;
68 1.1 cgd boolean first_miss = 1;
69 1.1 cgd object *weapon;
70 1.1 cgd short dir, row, col;
71 1.1 cgd object *monster;
72 1.1 cgd
73 1.1 cgd while (!is_direction(dir = rgetchar(), &d)) {
74 1.1 cgd sound_bell();
75 1.1 cgd if (first_miss) {
76 1.1 cgd message("direction? ", 0);
77 1.1 cgd first_miss = 0;
78 1.1 cgd }
79 1.1 cgd }
80 1.1 cgd check_message();
81 1.1 cgd if (dir == CANCEL) {
82 1.1 cgd return;
83 1.1 cgd }
84 1.1 cgd if ((wch = pack_letter("throw what?", WEAPON)) == CANCEL) {
85 1.1 cgd return;
86 1.1 cgd }
87 1.1 cgd check_message();
88 1.1 cgd
89 1.1 cgd if (!(weapon = get_letter_object(wch))) {
90 1.1 cgd message("no such item.", 0);
91 1.1 cgd return;
92 1.1 cgd }
93 1.1 cgd if ((weapon->in_use_flags & BEING_USED) && weapon->is_cursed) {
94 1.1 cgd message(curse_message, 0);
95 1.1 cgd return;
96 1.1 cgd }
97 1.1 cgd row = rogue.row; col = rogue.col;
98 1.1 cgd
99 1.1 cgd if ((weapon->in_use_flags & BEING_WIELDED) && (weapon->quantity <= 1)) {
100 1.1 cgd unwield(rogue.weapon);
101 1.1 cgd } else if (weapon->in_use_flags & BEING_WORN) {
102 1.1 cgd mv_aquatars();
103 1.1 cgd unwear(rogue.armor);
104 1.1 cgd print_stats(STAT_ARMOR);
105 1.1 cgd } else if (weapon->in_use_flags & ON_EITHER_HAND) {
106 1.1 cgd un_put_on(weapon);
107 1.1 cgd }
108 1.1 cgd monster = get_thrown_at_monster(weapon, d, &row, &col);
109 1.1 cgd mvaddch(rogue.row, rogue.col, rogue.fchar);
110 1.1 cgd refresh();
111 1.1 cgd
112 1.1 cgd if (rogue_can_see(row, col) && ((row != rogue.row) || (col != rogue.col))){
113 1.1 cgd mvaddch(row, col, get_dungeon_char(row, col));
114 1.1 cgd }
115 1.1 cgd if (monster) {
116 1.1 cgd wake_up(monster);
117 1.1 cgd check_gold_seeker(monster);
118 1.1 cgd
119 1.1 cgd if (!throw_at_monster(monster, weapon)) {
120 1.1 cgd flop_weapon(weapon, row, col);
121 1.1 cgd }
122 1.1 cgd } else {
123 1.1 cgd flop_weapon(weapon, row, col);
124 1.1 cgd }
125 1.1 cgd vanish(weapon, 1, &rogue.pack);
126 1.1 cgd }
127 1.1 cgd
128 1.1 cgd throw_at_monster(monster, weapon)
129 1.1 cgd object *monster, *weapon;
130 1.1 cgd {
131 1.1 cgd short damage, hit_chance;
132 1.1 cgd short t;
133 1.1 cgd
134 1.1 cgd hit_chance = get_hit_chance(weapon);
135 1.1 cgd damage = get_weapon_damage(weapon);
136 1.1 cgd if ((weapon->which_kind == ARROW) &&
137 1.1 cgd (rogue.weapon && (rogue.weapon->which_kind == BOW))) {
138 1.1 cgd damage += get_weapon_damage(rogue.weapon);
139 1.1 cgd damage = ((damage * 2) / 3);
140 1.1 cgd hit_chance += (hit_chance / 3);
141 1.1 cgd } else if ((weapon->in_use_flags & BEING_WIELDED) &&
142 1.1 cgd ((weapon->which_kind == DAGGER) ||
143 1.1 cgd (weapon->which_kind == SHURIKEN) ||
144 1.1 cgd (weapon->which_kind == DART))) {
145 1.1 cgd damage = ((damage * 3) / 2);
146 1.1 cgd hit_chance += (hit_chance / 3);
147 1.1 cgd }
148 1.1 cgd t = weapon->quantity;
149 1.1 cgd weapon->quantity = 1;
150 1.1 cgd sprintf(hit_message, "the %s", name_of(weapon));
151 1.1 cgd weapon->quantity = t;
152 1.1 cgd
153 1.1 cgd if (!rand_percent(hit_chance)) {
154 1.1 cgd (void) strcat(hit_message, "misses ");
155 1.1 cgd return(0);
156 1.1 cgd }
157 1.1 cgd s_con_mon(monster);
158 1.1 cgd (void) strcat(hit_message, "hit ");
159 1.1 cgd (void) mon_damage(monster, damage);
160 1.1 cgd return(1);
161 1.1 cgd }
162 1.1 cgd
163 1.1 cgd object *
164 1.1 cgd get_thrown_at_monster(obj, dir, row, col)
165 1.1 cgd object *obj;
166 1.1 cgd short dir;
167 1.1 cgd short *row, *col;
168 1.1 cgd {
169 1.1 cgd short orow, ocol;
170 1.1 cgd short i, ch;
171 1.1 cgd
172 1.1 cgd orow = *row; ocol = *col;
173 1.1 cgd
174 1.1 cgd ch = get_mask_char(obj->what_is);
175 1.1 cgd
176 1.1 cgd for (i = 0; i < 24; i++) {
177 1.1 cgd get_dir_rc(dir, row, col, 0);
178 1.1 cgd if ( (((*col <= 0) || (*col >= DCOLS-1)) ||
179 1.1 cgd (dungeon[*row][*col] == NOTHING)) ||
180 1.1 cgd ((dungeon[*row][*col] & (HORWALL | VERTWALL | HIDDEN)) &&
181 1.1 cgd (!(dungeon[*row][*col] & TRAP)))) {
182 1.1 cgd *row = orow;
183 1.1 cgd *col = ocol;
184 1.1 cgd return(0);
185 1.1 cgd }
186 1.1 cgd if ((i != 0) && rogue_can_see(orow, ocol)) {
187 1.1 cgd mvaddch(orow, ocol, get_dungeon_char(orow, ocol));
188 1.1 cgd }
189 1.1 cgd if (rogue_can_see(*row, *col)) {
190 1.1 cgd if (!(dungeon[*row][*col] & MONSTER)) {
191 1.1 cgd mvaddch(*row, *col, ch);
192 1.1 cgd }
193 1.1 cgd refresh();
194 1.1 cgd }
195 1.1 cgd orow = *row; ocol = *col;
196 1.1 cgd if (dungeon[*row][*col] & MONSTER) {
197 1.1 cgd if (!imitating(*row, *col)) {
198 1.1 cgd return(object_at(&level_monsters, *row, *col));
199 1.1 cgd }
200 1.1 cgd }
201 1.1 cgd if (dungeon[*row][*col] & TUNNEL) {
202 1.1 cgd i += 2;
203 1.1 cgd }
204 1.1 cgd }
205 1.1 cgd return(0);
206 1.1 cgd }
207 1.1 cgd
208 1.1 cgd flop_weapon(weapon, row, col)
209 1.1 cgd object *weapon;
210 1.1 cgd short row, col;
211 1.1 cgd {
212 1.1 cgd object *new_weapon, *monster;
213 1.1 cgd short i = 0;
214 1.1 cgd char msg[80];
215 1.1 cgd boolean found = 0;
216 1.1 cgd short mch, dch;
217 1.1 cgd unsigned short mon;
218 1.1 cgd
219 1.1 cgd while ((i < 9) && dungeon[row][col] & ~(FLOOR | TUNNEL | DOOR | MONSTER)) {
220 1.1 cgd rand_around(i++, &row, &col);
221 1.1 cgd if ((row > (DROWS-2)) || (row < MIN_ROW) ||
222 1.1 cgd (col > (DCOLS-1)) || (col < 0) || (!dungeon[row][col]) ||
223 1.1 cgd (dungeon[row][col] & ~(FLOOR | TUNNEL | DOOR | MONSTER))) {
224 1.1 cgd continue;
225 1.1 cgd }
226 1.1 cgd found = 1;
227 1.1 cgd break;
228 1.1 cgd }
229 1.1 cgd
230 1.1 cgd if (found || (i == 0)) {
231 1.1 cgd new_weapon = alloc_object();
232 1.1 cgd *new_weapon = *weapon;
233 1.1 cgd new_weapon->in_use_flags = NOT_USED;
234 1.1 cgd new_weapon->quantity = 1;
235 1.1 cgd new_weapon->ichar = 'L';
236 1.1 cgd place_at(new_weapon, row, col);
237 1.1 cgd if (rogue_can_see(row, col) &&
238 1.1 cgd ((row != rogue.row) || (col != rogue.col))) {
239 1.1 cgd mon = dungeon[row][col] & MONSTER;
240 1.1 cgd dungeon[row][col] &= (~MONSTER);
241 1.1 cgd dch = get_dungeon_char(row, col);
242 1.1 cgd if (mon) {
243 1.1 cgd mch = mvinch(row, col);
244 1.1 cgd if (monster = object_at(&level_monsters, row, col)) {
245 1.1 cgd monster->trail_char = dch;
246 1.1 cgd }
247 1.1 cgd if ((mch < 'A') || (mch > 'Z')) {
248 1.1 cgd mvaddch(row, col, dch);
249 1.1 cgd }
250 1.1 cgd } else {
251 1.1 cgd mvaddch(row, col, dch);
252 1.1 cgd }
253 1.1 cgd dungeon[row][col] |= mon;
254 1.1 cgd }
255 1.1 cgd } else {
256 1.1 cgd short t;
257 1.1 cgd
258 1.1 cgd t = weapon->quantity;
259 1.1 cgd weapon->quantity = 1;
260 1.1 cgd sprintf(msg, "the %svanishes as it hits the ground",
261 1.1 cgd name_of(weapon));
262 1.1 cgd weapon->quantity = t;
263 1.1 cgd message(msg, 0);
264 1.1 cgd }
265 1.1 cgd }
266 1.1 cgd
267 1.1 cgd rand_around(i, r, c)
268 1.1 cgd short i, *r, *c;
269 1.1 cgd {
270 1.1 cgd static char* pos = "\010\007\001\003\004\005\002\006\0";
271 1.1 cgd static short row, col;
272 1.1 cgd short j;
273 1.1 cgd
274 1.1 cgd if (i == 0) {
275 1.1 cgd short x, y, o, t;
276 1.1 cgd
277 1.1 cgd row = *r;
278 1.1 cgd col = *c;
279 1.1 cgd
280 1.1 cgd o = get_rand(1, 8);
281 1.1 cgd
282 1.1 cgd for (j = 0; j < 5; j++) {
283 1.1 cgd x = get_rand(0, 8);
284 1.1 cgd y = (x + o) % 9;
285 1.1 cgd t = pos[x];
286 1.1 cgd pos[x] = pos[y];
287 1.1 cgd pos[y] = t;
288 1.1 cgd }
289 1.1 cgd }
290 1.1 cgd switch((short)pos[i]) {
291 1.1 cgd case 0:
292 1.1 cgd *r = row + 1;
293 1.1 cgd *c = col + 1;
294 1.1 cgd break;
295 1.1 cgd case 1:
296 1.1 cgd *r = row + 1;
297 1.1 cgd *c = col - 1;
298 1.1 cgd break;
299 1.1 cgd case 2:
300 1.1 cgd *r = row - 1;
301 1.1 cgd *c = col + 1;
302 1.1 cgd break;
303 1.1 cgd case 3:
304 1.1 cgd *r = row - 1;
305 1.1 cgd *c = col - 1;
306 1.1 cgd break;
307 1.1 cgd case 4:
308 1.1 cgd *r = row;
309 1.1 cgd *c = col + 1;
310 1.1 cgd break;
311 1.1 cgd case 5:
312 1.1 cgd *r = row + 1;
313 1.1 cgd *c = col;
314 1.1 cgd break;
315 1.1 cgd case 6:
316 1.1 cgd *r = row;
317 1.1 cgd *c = col;
318 1.1 cgd break;
319 1.1 cgd case 7:
320 1.1 cgd *r = row - 1;
321 1.1 cgd *c = col;
322 1.1 cgd break;
323 1.1 cgd case 8:
324 1.1 cgd *r = row;
325 1.1 cgd *c = col - 1;
326 1.1 cgd break;
327 1.1 cgd }
328 1.1 cgd }
329