Rogue 3.6 reconstruction from http://rogue.rogueforge.net/rogue36/.
[rogue-pphs.git] / weapons.c
1 /*
2 * Functions for dealing with problems brought about by weapons
3 *
4 * @(#)weapons.c 3.17 (Berkeley) 6/15/81
5 *
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include "curses.h"
14 #include <ctype.h>
15 #include <string.h>
16 #include "rogue.h"
17
18 #define NONE 100
19
20 char *w_names[MAXWEAPONS] = {
21 "mace",
22 "long sword",
23 "short bow",
24 "arrow",
25 "dagger",
26 "rock",
27 "two handed sword",
28 "sling",
29 "dart",
30 "crossbow",
31 "crossbow bolt",
32 "spear",
33 };
34
35 static struct init_weps {
36 char *iw_dam;
37 char *iw_hrl;
38 char iw_launch;
39 int iw_flags;
40 } init_dam[MAXWEAPONS] = {
41 "2d4", "1d3", NONE, 0, /* Mace */
42 "1d10", "1d2", NONE,0, /* Long sword */
43 "1d1", "1d1", NONE, 0, /* Bow */
44 "1d1", "1d6", BOW, ISMANY|ISMISL, /* Arrow */
45 "1d6", "1d4", NONE, ISMISL, /* Dagger */
46 "1d2", "1d4", SLING,ISMANY|ISMISL, /* Rock */
47 "3d6", "1d2", NONE, 0, /* 2h sword */
48 "0d0", "0d0", NONE, 0, /* Sling */
49 "1d1", "1d3", NONE, ISMANY|ISMISL, /* Dart */
50 "1d1", "1d1", NONE, 0, /* Crossbow */
51 "1d2", "1d10", CROSSBOW, ISMANY|ISMISL,/* Crossbow bolt */
52 "1d8", "1d6", NONE, ISMISL, /* Spear */
53 };
54
55 /*
56 * missile:
57 * Fire a missile in a given direction
58 */
59
60 missile(ydelta, xdelta)
61 int ydelta, xdelta;
62 {
63 register struct object *obj;
64 register struct linked_list *item, *nitem;
65
66 /*
67 * Get which thing we are hurling
68 */
69 if ((item = get_item("throw", WEAPON)) == NULL)
70 return;
71 obj = (struct object *) ldata(item);
72 if (!dropcheck(obj) || is_current(obj))
73 return;
74 /*
75 * Get rid of the thing. If it is a non-multiple item object, or
76 * if it is the last thing, just drop it. Otherwise, create a new
77 * item with a count of one.
78 */
79 if (obj->o_count < 2)
80 {
81 detach(pack, item);
82 inpack--;
83 }
84 else
85 {
86 obj->o_count--;
87 if (obj->o_group == 0)
88 inpack--;
89 nitem = (struct linked_list *) new_item(sizeof *obj);
90 obj = (struct object *) ldata(nitem);
91 *obj = *((struct object *) ldata(item));
92 obj->o_count = 1;
93 item = nitem;
94 }
95 do_motion(obj, ydelta, xdelta);
96 /*
97 * AHA! Here it has hit something. If it is a wall or a door,
98 * or if it misses (combat) the mosnter, put it on the floor
99 */
100 if (!isupper(mvwinch(mw, obj->o_pos.y, obj->o_pos.x))
101 || !hit_monster(unc(obj->o_pos), obj))
102 fall(item, TRUE);
103 mvwaddch(cw, hero.y, hero.x, PLAYER);
104 }
105
106 /*
107 * do the actual motion on the screen done by an object traveling
108 * across the room
109 */
110 do_motion(obj, ydelta, xdelta)
111 register struct object *obj;
112 register int ydelta, xdelta;
113 {
114 /*
115 * Come fly with us ...
116 */
117 obj->o_pos = hero;
118 for (;;)
119 {
120 register int ch;
121
122 /*
123 * Erase the old one
124 */
125 if (!ce(obj->o_pos, hero) && cansee(unc(obj->o_pos)) &&
126 mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ')
127 mvwaddch(cw, obj->o_pos.y, obj->o_pos.x,
128 show(obj->o_pos.y, obj->o_pos.x));
129 /*
130 * Get the new position
131 */
132 obj->o_pos.y += ydelta;
133 obj->o_pos.x += xdelta;
134 if (step_ok(ch = winat(obj->o_pos.y, obj->o_pos.x)) && ch != DOOR)
135 {
136 /*
137 * It hasn't hit anything yet, so display it
138 * If it alright.
139 */
140 if (cansee(unc(obj->o_pos)) &&
141 mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ')
142 {
143 mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, obj->o_type);
144 draw(cw);
145 }
146 continue;
147 }
148 break;
149 }
150 }
151
152 /*
153 * fall:
154 * Drop an item someplace around here.
155 */
156
157 fall(item, pr)
158 register struct linked_list *item;
159 bool pr;
160 {
161 register struct object *obj;
162 register struct room *rp;
163 static coord fpos;
164
165 obj = (struct object *) ldata(item);
166 if (fallpos(&obj->o_pos, &fpos, TRUE))
167 {
168 mvaddch(fpos.y, fpos.x, obj->o_type);
169 obj->o_pos = fpos;
170 if ((rp = roomin(&hero)) != NULL && !(rp->r_flags & ISDARK))
171 {
172 light(&hero);
173 mvwaddch(cw, hero.y, hero.x, PLAYER);
174 }
175 attach(lvl_obj, item);
176 return;
177 }
178 if (pr)
179 if (obj->o_type == WEAPON) /* BUGFUX: Identification trick */
180 msg("Your %s vanishes as it hits the ground.", w_names[obj->o_which]);
181 else
182 msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE));
183 discard(item);
184 }
185
186 /*
187 * init_weapon:
188 * Set up the initial goodies for a weapon
189 */
190
191 init_weapon(weap, type)
192 register struct object *weap;
193 char type;
194 {
195 register struct init_weps *iwp;
196
197 iwp = &init_dam[type];
198 strcpy(weap->o_damage,iwp->iw_dam);
199 strcpy(weap->o_hurldmg,iwp->iw_hrl);
200 weap->o_launch = iwp->iw_launch;
201 weap->o_flags = iwp->iw_flags;
202 if (weap->o_flags & ISMANY)
203 {
204 weap->o_count = rnd(8) + 8;
205 weap->o_group = newgrp();
206 }
207 else
208 weap->o_count = 1;
209 }
210
211 /*
212 * Does the missile hit the monster
213 */
214
215 hit_monster(y, x, obj)
216 register int y, x;
217 struct object *obj;
218 {
219 static coord mp;
220
221 mp.y = y;
222 mp.x = x;
223 return fight(&mp, winat(y, x), obj, TRUE);
224 }
225
226 /*
227 * num:
228 * Figure out the plus number for armor/weapons
229 */
230
231 char *
232 num(n1, n2)
233 register int n1, n2;
234 {
235 static char numbuf[80];
236
237 if (n1 == 0 && n2 == 0)
238 return "+0";
239 if (n2 == 0)
240 sprintf(numbuf, "%s%d", n1 < 0 ? "" : "+", n1);
241 else
242 sprintf(numbuf, "%s%d,%s%d",
243 n1 < 0 ? "" : "+", n1, n2 < 0 ? "" : "+", n2);
244 return numbuf;
245 }
246
247 /*
248 * wield:
249 * Pull out a certain weapon
250 */
251
252 wield()
253 {
254 register struct linked_list *item;
255 register struct object *obj, *oweapon;
256
257 oweapon = cur_weapon;
258 if (!dropcheck(cur_weapon))
259 {
260 cur_weapon = oweapon;
261 return;
262 }
263 cur_weapon = oweapon;
264 if ((item = get_item("wield", WEAPON)) == NULL)
265 {
266 bad:
267 after = FALSE;
268 return;
269 }
270
271 obj = (struct object *) ldata(item);
272 if (obj->o_type == ARMOR)
273 {
274 msg("You can't wield armor");
275 goto bad;
276 }
277 if (is_current(obj))
278 goto bad;
279
280 if (terse)
281 addmsg("W");
282 else
283 addmsg("You are now w");
284 msg("ielding %s", inv_name(obj, TRUE));
285 cur_weapon = obj;
286 }
287
288 /*
289 * pick a random position around the give (y, x) coordinates
290 */
291 fallpos(pos, newpos, passages)
292 register coord *pos, *newpos;
293 register bool passages;
294 {
295 register int y, x, cnt, ch;
296
297 cnt = 0;
298 for (y = pos->y - 1; y <= pos->y + 1; y++)
299 for (x = pos->x - 1; x <= pos->x + 1; x++)
300 {
301 /*
302 * check to make certain the spot is empty, if it is,
303 * put the object there, set it in the level list
304 * and re-draw the room if he can see it
305 */
306 if (y == hero.y && x == hero.x)
307 continue;
308 if (((ch = winat(y, x)) == FLOOR || (passages && ch == PASSAGE))
309 && rnd(++cnt) == 0)
310 {
311 newpos->y = y;
312 newpos->x = x;
313 }
314 }
315 return (cnt != 0);
316 }