-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathweapons.c
456 lines (406 loc) · 10.1 KB
/
weapons.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
weapons.c - Functions for dealing with problems brought about by weapons
Last Modified: Dec 30, 1990
UltraRogue
Copyright (C) 1984, 1985, 1986, 1987, 1990 Herb Chong
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1983, 1984 Michael Morgan, Ken Dalka and AT&T
All rights reserved.
Based on "Super-Rogue"
Copyright (C) 1982, 1983 Robert D. Kindelberger
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <ctype.h>
#include "rogue.h"
/*
* missile: Fire a missile in a given direction
*/
missile(ydelta, xdelta, item, tp)
int ydelta, xdelta;
struct linked_list *item;
struct thing *tp;
{
struct object *obj;
struct linked_list *nitem;
if (item == NULL) /* Get which thing we are hurling */
return;
obj = OBJPTR(item);
if (!dropcheck(obj) || is_current(obj))
return;
/*
* Get rid of the thing. If it is a non-multiple item object, or if
* it is the last thing, just drop it. Otherwise, create a new item
* with a count of one.
*/
if (obj->o_count < 2) {
if (tp->t_pack == pack)
rem_pack(obj);
else
detach(tp->t_pack, item);
}
else {
obj->o_count--;
nitem = (struct linked_list *) new_item(sizeof *obj);
obj = OBJPTR(nitem);
*obj = *(OBJPTR(item));
obj->o_count = 1;
item = nitem;
}
switch (obj->o_type) {
when ARTIFACT:
has_artifact &= ~(1 << obj->o_which);
when SCROLL:
if (obj->o_which == S_SCARE && obj->o_flags & ISBLESSED)
obj->o_flags &= ~ISBLESSED;
else
obj->o_flags |= ISCURSED;
}
updpack();
do_motion(obj, ydelta, xdelta, tp);
/*
* AHA! Here it has hit something. If it is a wall or a door, or if
* it misses (combat) the monster, put it on the floor
*/
if (!hit_monster(obj->o_pos.y, obj->o_pos.x, obj, tp)) {
if (obj->o_type == WEAPON && obj->o_which == GRENADE) {
static coord fpos;
hearmsg("BOOOM!");
aggravate();
if (ntraps + 1 < 2 * MAXTRAPS &&
fallpos(&obj->o_pos, &fpos, TRUE)) {
mvaddch(fpos.y, fpos.x, TRAPDOOR);
traps[ntraps].tr_type = TRAPDOOR;
traps[ntraps].tr_flags = ISFOUND;
traps[ntraps].tr_show = TRAPDOOR;
traps[ntraps].tr_pos.y = fpos.y;
traps[ntraps++].tr_pos.x = fpos.x;
light(&hero);
}
discard(item);
}
else if (obj->o_flags & ISLOST) {
if (obj->o_type == WEAPON)
addmsg("The %s", weaps[obj->o_which].w_name);
else
addmsg(inv_name(obj, LOWERCASE));
msg(" vanishes in a puff of greasy smoke.");
discard(item);
}
else {
fall(&player, item, TRUE);
if (obj->o_flags & CANRETURN)
msg("You have %s.", inv_name(obj, LOWERCASE));
}
}
else if (obj->o_flags & ISOWNED) {
add_pack(item, NOMESSAGE);
msg("You have %s.", inv_name(obj, LOWERCASE));
}
mvwaddch(cw, hero.y, hero.x, PLAYER);
}
/*
* do the actual motion on the screen done by an object traveling across the
* room
*/
do_motion(obj, ydelta, xdelta, tp)
struct object *obj;
int ydelta, xdelta;
struct thing *tp;
{
/*
* Come fly with us ...
*/
obj->o_pos = tp->t_pos;
for (;;) {
int ch;
/*
* Erase the old one
*/
if (!ce(obj->o_pos, tp->t_pos) &&
cansee(obj->o_pos.y, obj->o_pos.x) &&
mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') {
mvwaddch(cw, obj->o_pos.y, obj->o_pos.x,
show(obj->o_pos.y, obj->o_pos.x));
}
/*
* Get the new position
*/
obj->o_pos.y += ydelta;
obj->o_pos.x += xdelta;
if (shoot_ok(ch = winat(obj->o_pos.y, obj->o_pos.x)) &&
ch != DOOR && !ce(obj->o_pos, hero)) {
/*
* It hasn't hit anything yet, so display it If it
* alright.
*/
if (cansee(obj->o_pos.y, obj->o_pos.x) &&
mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') {
mvwaddch(cw, obj->o_pos.y, obj->o_pos.x,
obj->o_type);
wrefresh(cw);
}
continue;
}
break;
}
}
/*
* fall: Drop an item someplace around here.
*/
fall(tp, item, pr)
struct linked_list *item;
struct thing *tp;
bool pr;
{
struct object *obj;
struct room *rp;
static coord fpos;
obj = OBJPTR(item);
rp = roomin(&(tp->t_pos));
if (obj->o_flags & CANRETURN) {
add_pack(item, NOMESSAGE);
msg("You have %s.", inv_name(obj, LOWERCASE));
return;
}
else if (fallpos(&obj->o_pos, &fpos, TRUE)) {
if (obj->o_flags & CANBURN && obj->o_type == WEAPON
&& obj->o_which == MOLOTOV
&& ntraps + 1 < 2 * MAXTRAPS) {
mvaddch(fpos.y, fpos.x, FIRETRAP);
traps[ntraps].tr_type = FIRETRAP;
traps[ntraps].tr_flags = ISFOUND;
traps[ntraps].tr_show = FIRETRAP;
traps[ntraps].tr_pos.y = fpos.y;
traps[ntraps++].tr_pos.x = fpos.x;
if (rp != NULL)
rp->r_flags &= ~ISDARK;
}
else {
obj->o_pos = fpos;
add_obj(item, fpos.y, fpos.x);
}
if (rp != NULL &&
(!(rp->r_flags & ISDARK) ||
(rp->r_flags & HASFIRE))) {
light(&hero);
mvwaddch(cw, hero.y, hero.x, PLAYER);
}
return;
}
if (pr) {
if (cansee(obj->o_pos.y, obj->o_pos.x)) {
if (obj->o_type == WEAPON)
addmsg("The %s", weaps[obj->o_which].w_name);
else
addmsg(inv_name(obj, LOWERCASE));
msg(" vanishes as it hits the ground.");
}
}
discard(item);
}
/*
* init_weapon: Set up the initial goodies for a weapon
*/
init_weapon(weap, type)
struct object *weap;
char type;
{
struct init_weps *iwp = &weaps[type];
weap->o_damage = iwp->w_dam;
weap->o_hurldmg = iwp->w_hrl;
weap->o_launch = iwp->w_launch;
weap->o_flags = iwp->w_flags;
weap->o_weight = iwp->w_wght;
if (weap->o_flags & ISMANY) {
weap->o_count = rnd(8) + 8;
weap->o_group = ++group;
}
else
weap->o_count = 1;
}
/*
* hit_monster - does the missile hit the target
*/
hit_monster(y, x, weapon, thrower)
int y, x;
struct object *weapon;
struct thing *thrower;
{
struct linked_list *mon;
static coord target;
target.y = y;
target.x = x;
if (thrower == &player)
return (fight(&target, weapon, THROWN));
if (ce(target, hero)) {
if (good_monster(*thrower)) {
if (on(*thrower, ISFAMILIAR))
msg("Please get out of the way, Master! I nearly hit you.");
else
msg("Get out of the way %s!", whoami);
return (FALSE);
}
return (attack(thrower, weapon, THROWN));
}
if ((mon = find_mons(y, x)) != NULL)
return (mon_mon_attack(thrower, mon, weapon, THROWN));
else
return (FALSE);
}
/*
* num: Figure out the plus number for armor/weapons
*/
char *num(n1, n2)
int n1, n2;
{
static char numbuf[2 * LINELEN];
if (n1 == 0 && n2 == 0)
return "+0";
if (n2 == 0)
sprintf(numbuf, "%s%d", n1 < 0 ? "" : "+", n1);
else
sprintf(numbuf, "%s%d, %s%d", n1 < 0 ? "" : "+",
n1, n2 < 0 ? "" : "+", n2);
return (numbuf);
}
/*
* wield: Pull out a certain weapon
*/
wield()
{
struct linked_list *item;
struct object *obj, *oweapon;
oweapon = cur_weapon;
if (!dropcheck(cur_weapon)) {
cur_weapon = oweapon;
return;
}
cur_weapon = oweapon;
if ((item = get_item("wield", WEAPON)) == NULL) {
after = FALSE;
return;
}
obj = OBJPTR(item);
if (is_current(obj)) {
after = FALSE;
return;
}
wield_ok(&player, obj, TRUE);
msg("%sielding %s.", (terse ? "W" : "You are now w"),
inv_name(obj, LOWERCASE));
cur_weapon = obj;
}
/*
* pick a random position around the give (y, x) coordinates
*/
fallpos(pos, newpos, passages)
coord *pos, *newpos;
bool passages;
{
int y, x, cnt, ch;
cnt = 0;
for (y = pos->y - 1; y <= pos->y + 1; y++)
for (x = pos->x - 1; x <= pos->x + 1; x++)
/*
* check to make certain the spot is empty, if it is,
* put the object there, set it in the level list and
* re-draw the room if he can see it
*/
if (y == hero.y && x == hero.x)
continue;
else
switch (ch = winat(y, x)) {
case GOLD:
case POTION:
case SCROLL:
case FOOD:
case WEAPON:
case ARMOR:
case RING:
case STICK:
case FLOOR:
case PASSAGE:
case ARTIFACT:
newpos->y = y;
newpos->x = x;
cnt++;
}
return (cnt);
}
/*
* wield_ok: enforce player class weapons restrictions
*/
bool
wield_ok(wieldee, obj, print_message)
struct thing *wieldee;
struct object *obj;
bool print_message;
{
int which = obj->o_which;
bool ret_val = TRUE;
int class_type = wieldee->t_ctype;
if (obj->o_type != WEAPON) {
ret_val = FALSE;
return (ret_val);
}
else
switch (class_type) {
when C_MAGICIAN: /* need one hand free */
case C_ILLUSION:
if (obj->o_flags & ISTWOH)
ret_val = FALSE;
when C_THIEF: /* need portable weapon */
case C_ASSASIN:
case C_NINJA:
if (obj->o_flags & ISTWOH)
ret_val = FALSE;
when C_CLERIC: /* No sharp weapons */
if (obj->o_flags & ISSHARP)
ret_val = FALSE;
when C_DRUID: /* No non-silver metal
* weapons */
if (obj->o_flags & ISMETAL &&
!(obj->o_flags & ISSILVER))
ret_val = FALSE;
when C_PALADIN: /* must wield sharp stuff */
if ((obj->o_flags & ISSHARP) == FALSE)
ret_val = FALSE;
when C_FIGHTER: /* wield anything */
case C_RANGER:
case C_MONSTER:
;
otherwise: /* Unknown class */
debug("Unknown class %d.", class_type);
break;
}
if (itemweight(obj) > 18 * pstats.s_str) {
if (wieldee == &player && print_message == TRUE)
msg("That is too heavy for you to swing effectively!");
ret_val = FALSE;
return (ret_val);
}
if (ret_val == FALSE && print_message == MESSAGE)
switch (class_type) {
when C_MAGICIAN:
case C_ILLUSION:
msg("You'll find it hard to cast spells while wielding that!");
when C_THIEF:
case C_ASSASIN:
case C_NINJA:
msg("Don't expect to backstab anyone while wielding that!");
when C_CLERIC:
case C_DRUID:
case C_PALADIN:
msg("Your god strongly disapproves of your wielding that!");
case C_FIGHTER:
case C_RANGER:
case C_MONSTER:
break;
}
return (ret_val);
}