Mercurial > hg > early-roguelike
annotate srogue/weapons.c @ 259:096d3cfd9afd
UltraRogue: add the -n option.
author | John "Elwin" Edwards |
---|---|
date | Thu, 09 Feb 2017 16:29:45 -0500 |
parents | 94a0d9dd5ce1 |
children | e52a8a7ad4c5 |
rev | line source |
---|---|
36
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
1 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
2 * Functions for dealing with weapons |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
3 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
4 * @(#)weapons.c 9.0 (rdk) 7/17/84 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
5 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
6 * Super-Rogue |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
7 * Copyright (C) 1984 Robert D. Kindelberger |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
8 * All rights reserved. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
9 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
10 * Based on "Rogue: Exploring the Dungeons of Doom" |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
12 * All rights reserved. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
13 * |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
14 * See the file LICENSE.TXT for full copyright and licensing information. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
15 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
16 |
217
94a0d9dd5ce1
Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents:
36
diff
changeset
|
17 #include <string.h> |
36
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
18 #include <ctype.h> |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
19 #include "rogue.h" |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
20 #include "rogue.ext" |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
21 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
22 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
23 * missile: |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
24 * Fire a missile in a given direction |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
25 */ |
217
94a0d9dd5ce1
Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents:
36
diff
changeset
|
26 void |
94a0d9dd5ce1
Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents:
36
diff
changeset
|
27 missile(int ydelta, int xdelta) |
36
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
28 { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
29 reg struct object *obj, *nowwield; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
30 reg struct linked_list *item, *nitem; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
31 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
32 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
33 * Get which thing we are hurling |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
34 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
35 nowwield = cur_weapon; /* must save current weap */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
36 if ((item = get_item("throw", WEAPON)) == NULL) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
37 return; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
38 obj = OBJPTR(item); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
39 if (!dropcheck(obj) || is_current(obj)) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
40 return; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
41 if (obj == nowwield || obj->o_type != WEAPON) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
42 reg int c; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
43 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
44 msg("Do you want to throw that %s? (y or n)",obj->o_typname); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
45 do { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
46 c = readchar(); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
47 if (isupper(c)) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
48 c = tolower(c); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
49 if (c == ESCAPE || c == 'n') { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
50 msg(""); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
51 cur_weapon = nowwield; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
52 after = FALSE; /* ooops, a mistake */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
53 return; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
54 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
55 } while (c != 'y'); /* keep looking for good ans */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
56 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
57 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
58 * Get rid of the thing. If it is a non-multiple item object, or |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
59 * if it is the last thing, just drop it. Otherwise, create a new |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
60 * item with a count of one. |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
61 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
62 if (obj->o_count < 2) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
63 detach(pack, item); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
64 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
65 else { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
66 obj->o_count--; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
67 obj->o_vol = itemvol(obj); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
68 nitem = new_item(sizeof *obj); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
69 obj = OBJPTR(nitem); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
70 *obj = *(OBJPTR(item)); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
71 obj->o_count = 1; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
72 obj->o_vol = itemvol(obj); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
73 item = nitem; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
74 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
75 updpack(); /* new pack weight */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
76 do_motion(obj, ydelta, xdelta); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
77 if (!isalpha(mvwinch(mw, obj->o_pos.y, obj->o_pos.x)) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
78 || !hit_monster(&obj->o_pos, obj)) |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
79 fall(item, TRUE); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
80 mvwaddch(cw, hero.y, hero.x, PLAYER); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
81 } |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
82 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
83 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
84 * do the actual motion on the screen done by an object traveling |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
85 * across the room |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
86 */ |
217
94a0d9dd5ce1
Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents:
36
diff
changeset
|
87 void |
94a0d9dd5ce1
Super-Rogue: convert to ANSI-style function declarations.
John "Elwin" Edwards
parents:
36
diff
changeset
|
88 do_motion(struct object *obj, int ydelta, int xdelta) |
36
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
89 { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
90 reg int ch, y, x; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
91 |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
92 obj->o_pos = hero; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
93 while (1) { |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
94 y = obj->o_pos.y; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
95 x = obj->o_pos.x; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
96 if (!ce(obj->o_pos, hero) && cansee(unc(obj->o_pos)) && |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
97 mvwinch(cw, y, x) != ' ') |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
98 mvwaddch(cw, y, x, show(y, x)); |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
99 /* |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
100 * Get the new position |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
101 */ |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
102 obj->o_pos.y += ydelta; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|
103 obj->o_pos.x += xdelta; |
2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff
changeset
|