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