-
Notifications
You must be signed in to change notification settings - Fork 1
/
weapons.c
261 lines (239 loc) · 5.41 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
/*
* Functions for dealing with weapons
*
* @(#)weapons.c 9.0 (rdk) 7/17/84
*
* Super-Rogue
* Copyright (C) 1984 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 <curses.h>
#include <stdbool.h>
#include <stdio.h>
#include "rogue.h"
#include "rogue.ext"
/*
* missile:
* Fire a missile in a given direction
*/
int missile(int ydelta,int xdelta)
{
struct object *obj, *nowwield;
struct linked_list *item, *nitem;
/*
* Get which thing we are hurling
*/
nowwield = cur_weapon; /* must save current weap */
if ((item = get_item("throw", WEAPON)) == NULL)
return 0;
obj = OBJPTR(item);
if (!dropcheck(obj) || is_current(obj))
return 0;
if (obj == nowwield || obj->o_type != WEAPON) {
int c;
msg("Do you want to throw that %s? (y or n)",obj->o_typname);
do {
c = readchar();
if (isupper(c))
c = tolower(c);
if (c == ESCAPE || c == 'n') {
msg("");
cur_weapon = nowwield;
after = FALSE; /* ooops, a mistake */
return 0;
}
} while (c != 'y'); /* keep looking for good ans */
}
/*
* 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) {
detach(pack, item);
}
else {
obj->o_count--;
obj->o_vol = itemvol(obj);
nitem = new_item(sizeof *obj);
obj = OBJPTR(nitem);
*obj = *(OBJPTR(item));
obj->o_count = 1;
obj->o_vol = itemvol(obj);
item = nitem;
}
updpack(); /* new pack weight */
do_motion(obj, ydelta, xdelta);
if (!isalpha(mvwinch(mw, obj->o_pos.y, obj->o_pos.x))
|| !hit_monster(&obj->o_pos, obj))
fall(item, TRUE);
mvwaddch(cw, hero.y, hero.x, PLAYER);
return 0;
}
/*
* do the actual motion on the screen done by an object traveling
* across the room
*/
void do_motion(struct object *obj,int ydelta,int xdelta)
{
int ch, y, x;
obj->o_pos = hero;
while (1) {
y = obj->o_pos.y;
x = obj->o_pos.x;
if (!ce(obj->o_pos, hero) && cansee(unc(obj->o_pos)) &&
mvwinch(cw, y, x) != ' ')
mvwaddch(cw, y, x, show(y, x));
/*
* Get the new position
*/
obj->o_pos.y += ydelta;
obj->o_pos.x += xdelta;
y = obj->o_pos.y;
x = obj->o_pos.x;
ch = winat(y, x);
if (step_ok(ch) && ch != DOOR) {
if (cansee(unc(obj->o_pos)) && mvwinch(cw, y, x) != ' ') {
mvwaddch(cw, y, x, obj->o_type);
draw(cw);
}
continue;
}
break;
}
}
/*
* fall:
* Drop an item someplace around here.
*/
int fall(struct linked_list *item,bool pr)
{
struct object *obj;
struct room *rp;
static struct coord fpos;
obj = OBJPTR(item);
if (fallpos(&obj->o_pos, &fpos, TRUE)) {
mvaddch(fpos.y, fpos.x, obj->o_type);
obj->o_pos = fpos;
rp = player.t_room;
if (rp != NULL && !rf_on(rp,ISDARK)) {
light(&hero);
mvwaddch(cw, hero.y, hero.x, PLAYER);
}
attach(lvl_obj, item);
return 0;
}
if (pr) {
if (obj->o_type == WEAPON) { /* BUGFIX: Identification trick */
msg("Your %s vanishes as it hits the ground.", w_magic[obj->o_which].mi_name);
} else {
msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE));
}
}
discard(item);
return 0;
}
/*
* init_weapon:
* Set up the initial goodies for a weapon
*/
void init_weapon(struct object *weap,int type)
{
struct init_weps *iwp;
weap->o_type = WEAPON;
weap->o_which = type;
iwp = &weaps[type];
strcpy(weap->o_damage,iwp->w_dam);
strcpy(weap->o_hurldmg,iwp->w_hrl);
weap->o_launch = iwp->w_launch;
weap->o_flags = iwp->w_flags;
weap->o_weight = iwp->w_wght;
weap->o_typname = things[TYP_WEAPON].mi_name;
if (o_on(weap,ISMANY))
weap->o_count = rnd(8) + 8;
else
weap->o_count = 1;
weap->o_group = newgrp();
weap->o_vol = itemvol(weap);
}
/*
* hit_monster:
* Does the missile hit the monster
*/
bool hit_monster(struct coord *mp,struct object *obj)
{
return fight(mp, obj, TRUE);
}
/*
* num:
* Figure out the plus number for armor/weapons
*/
char *num(int n1,int n2)
{
static char numbuf[LINLEN];
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
*/
int wield()
{
struct linked_list *item;
struct object *obj, *oweapon;
oweapon = cur_weapon;
if (!dropcheck(cur_weapon)) {
cur_weapon = oweapon;
return 0;
}
cur_weapon = oweapon;
if ((item = get_item("wield", WEAPON)) == NULL)
return 0;
obj = OBJPTR(item);
if (is_current(obj)) {
after = FALSE;
return 0;
}
msg("Wielding %s", inv_name(obj, TRUE));
cur_weapon = obj;
return 0;
}
/*
* fallpos:
* Pick a random position around the give (y, x) coordinates
*/
bool fallpos(struct coord *pos,struct coord *newpos,bool passages)
{
int y, x, ch;
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;
ch = winat(y, x);
if (ch == FLOOR || (passages && ch == PASSAGE)) {
newpos->y = y;
newpos->x = x;
return TRUE;
}
}
}
return FALSE;
}