This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weapons.c
288 lines (261 loc) · 5.67 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
/*
* Functions for dealing with problems brought about by weapons
*
* @(#)weapons.c 4.34 (Berkeley) 02/05/99
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
#include <ctype.h>
#include "rogue.h"
#define NO_WEAPON -1
int group = 2;
static struct init_weaps {
char *iw_dam; /* Damage when wielded */
char *iw_hrl; /* Damage when thrown */
char iw_launch; /* Launching weapon */
int iw_flags; /* Miscellaneous flags */
} init_dam[MAXWEAPONS] = {
{ "2x4", "1x3", NO_WEAPON, 0, }, /* Mace */
{ "3x4", "1x2", NO_WEAPON, 0, }, /* Long sword */
{ "1x1", "1x1", NO_WEAPON, 0, }, /* Bow */
{ "1x1", "2x3", BOW, ISMANY|ISMISL, }, /* Arrow */
{ "1x6", "1x4", NO_WEAPON, ISMISL|ISMISL, }, /* Dagger */
{ "4x4", "1x2", NO_WEAPON, 0, }, /* 2h sword */
{ "1x1", "1x3", NO_WEAPON, ISMANY|ISMISL, }, /* Dart */
{ "1x2", "2x4", NO_WEAPON, ISMANY|ISMISL, }, /* Shuriken */
{ "2x3", "1x6", NO_WEAPON, ISMISL, }, /* Spear */
};
/*
* missile:
* Fire a missile in a given direction
*/
void
missile(int ydelta, int xdelta)
{
THING *obj;
/*
* Get which thing we are hurling
*/
if ((obj = get_item("throw", WEAPON)) == NULL)
return;
if (!dropcheck(obj) || is_current(obj))
return;
obj = leave_pack(obj, TRUE, FALSE);
do_motion(obj, ydelta, xdelta);
/*
* 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 (moat(obj->o_pos.y, obj->o_pos.x) == NULL ||
!hit_monster(unc(obj->o_pos), obj))
fall(obj, TRUE);
}
/*
* do_motion:
* Do the actual motion on the screen done by an object traveling
* across the room
*/
void
do_motion(THING *obj, int ydelta, int xdelta)
{
int ch;
/*
* Come fly with us ...
*/
obj->o_pos = hero;
for (;;)
{
/*
* Erase the old one
*/
if (!ce(obj->o_pos, hero) && cansee(unc(obj->o_pos)) && !terse)
{
ch = chat(obj->o_pos.y, obj->o_pos.x);
if (ch == FLOOR && !show_floor())
ch = ' ';
mvaddch(obj->o_pos.y, obj->o_pos.x, ch);
}
/*
* Get the new position
*/
obj->o_pos.y += ydelta;
obj->o_pos.x += xdelta;
if (step_ok(ch = winat(obj->o_pos.y, obj->o_pos.x)) && ch != DOOR)
{
/*
* It hasn't hit anything yet, so display it
* If it alright.
*/
if (cansee(unc(obj->o_pos)) && !terse)
{
mvaddch(obj->o_pos.y, obj->o_pos.x, obj->o_type);
refresh();
}
continue;
}
break;
}
}
/*
* fall:
* Drop an item someplace around here.
*/
void
fall(THING *obj, bool pr)
{
PLACE *pp;
static coord fpos;
if (fallpos(&obj->o_pos, &fpos))
{
pp = INDEX(fpos.y, fpos.x);
pp->p_ch = (char) obj->o_type;
obj->o_pos = fpos;
if (cansee(fpos.y, fpos.x))
{
if (pp->p_monst != NULL)
pp->p_monst->t_oldch = (char) obj->o_type;
else
mvaddch(fpos.y, fpos.x, obj->o_type);
}
attach(lvl_obj, obj);
return;
}
if (pr)
{
if (has_hit)
{
endmsg();
has_hit = FALSE;
}
msg("the %s vanishes as it hits the ground",
weap_info[obj->o_which].oi_name);
}
discard(obj);
}
/*
* init_weapon:
* Set up the initial goodies for a weapon
*/
void
init_weapon(THING *weap, int which)
{
struct init_weaps *iwp;
weap->o_type = WEAPON;
weap->o_which = which;
iwp = &init_dam[which];
strncpy(weap->o_damage, iwp->iw_dam, sizeof(weap->o_damage));
strncpy(weap->o_hurldmg,iwp->iw_hrl, sizeof(weap->o_hurldmg));
weap->o_launch = iwp->iw_launch;
weap->o_flags = iwp->iw_flags;
weap->o_hplus = 0;
weap->o_dplus = 0;
if (which == DAGGER)
{
weap->o_count = rnd(4) + 2;
weap->o_group = group++;
}
else if (weap->o_flags & ISMANY)
{
weap->o_count = rnd(8) + 8;
weap->o_group = group++;
}
else
{
weap->o_count = 1;
weap->o_group = 0;
}
}
/*
* hit_monster:
* Does the missile hit the monster?
*/
int
hit_monster(int y, int x, THING *obj)
{
static coord mp;
mp.y = y;
mp.x = x;
return fight(&mp, obj, TRUE);
}
/*
* num:
* Figure out the plus number for armor/weapons
*/
char *
num(int n1, int n2, char type)
{
static char numbuf[10];
sprintf(numbuf, n1 < 0 ? "%d" : "+%d", n1);
if (type == WEAPON)
sprintf(&numbuf[strlen(numbuf)], n2 < 0 ? ",%d" : ",+%d", n2);
return numbuf;
}
/*
* wield:
* Pull out a certain weapon
*/
void
wield()
{
THING *obj, *oweapon;
char *sp;
oweapon = cur_weapon;
if (!dropcheck(cur_weapon))
{
cur_weapon = oweapon;
return;
}
cur_weapon = oweapon;
if ((obj = get_item("wield", WEAPON)) == NULL)
{
bad:
after = FALSE;
return;
}
if (obj->o_type == ARMOR)
{
msg("you can't wield armor");
goto bad;
}
if (is_current(obj))
goto bad;
sp = inv_name(obj, TRUE);
cur_weapon = obj;
if (!terse)
addmsg("you are now ");
msg("wielding %s (%c)", sp, obj->o_packch);
}
/*
* fallpos:
* Pick a random position around the give (y, x) coordinates
*/
bool
fallpos(coord *pos, coord *newpos)
{
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;
if (((ch = chat(y, x)) == FLOOR || ch == PASSAGE)
&& rnd(++cnt) == 0)
{
newpos->y = y;
newpos->x = x;
}
}
return (bool)(cnt != 0);
}