2 * Functions for dealing with problems brought about by weapons
4 * @(#)weapons.c 3.17 (Berkeley) 6/15/81
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * See the file LICENSE.TXT for full copyright and licensing information.
20 char *w_names
[MAXWEAPONS
] = {
35 static struct init_weps
{
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 */
57 * Fire a missile in a given direction
60 missile(ydelta
, xdelta
)
63 register struct object
*obj
;
64 register struct linked_list
*item
, *nitem
;
67 * Get which thing we are hurling
69 if ((item
= get_item("throw", WEAPON
)) == NULL
)
71 obj
= (struct object
*) ldata(item
);
72 if (!dropcheck(obj
) || is_current(obj
))
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.
87 if (obj
->o_group
== 0)
89 nitem
= (struct linked_list
*) new_item(sizeof *obj
);
90 obj
= (struct object
*) ldata(nitem
);
91 *obj
= *((struct object
*) ldata(item
));
95 do_motion(obj
, ydelta
, xdelta
);
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
100 if (!isupper(mvwinch(mw
, obj
->o_pos
.y
, obj
->o_pos
.x
))
101 || !hit_monster(unc(obj
->o_pos
), obj
))
103 mvwaddch(cw
, hero
.y
, hero
.x
, PLAYER
);
107 * do the actual motion on the screen done by an object traveling
110 do_motion(obj
, ydelta
, xdelta
)
111 register struct object
*obj
;
112 register int ydelta
, xdelta
;
115 * Come fly with us ...
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
));
130 * Get the new position
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
)
137 * It hasn't hit anything yet, so display it
140 if (cansee(unc(obj
->o_pos
)) &&
141 mvwinch(cw
, obj
->o_pos
.y
, obj
->o_pos
.x
) != ' ')
143 mvwaddch(cw
, obj
->o_pos
.y
, obj
->o_pos
.x
, obj
->o_type
);
154 * Drop an item someplace around here.
158 register struct linked_list
*item
;
161 register struct object
*obj
;
162 register struct room
*rp
;
165 obj
= (struct object
*) ldata(item
);
166 if (fallpos(&obj
->o_pos
, &fpos
, TRUE
))
168 mvaddch(fpos
.y
, fpos
.x
, obj
->o_type
);
170 if ((rp
= roomin(&hero
)) != NULL
&& !(rp
->r_flags
& ISDARK
))
173 mvwaddch(cw
, hero
.y
, hero
.x
, PLAYER
);
175 attach(lvl_obj
, item
);
179 if (obj
->o_type
== WEAPON
) /* BUGFUX: Identification trick */
180 msg("Your %s vanishes as it hits the ground.", w_names
[obj
->o_which
]);
182 msg("%s vanishes as it hits the ground.", inv_name(obj
,TRUE
));
188 * Set up the initial goodies for a weapon
191 init_weapon(weap
, type
)
192 register struct object
*weap
;
195 register struct init_weps
*iwp
;
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
)
204 weap
->o_count
= rnd(8) + 8;
205 weap
->o_group
= newgrp();
212 * Does the missile hit the monster
215 hit_monster(y
, x
, obj
)
223 return fight(&mp
, winat(y
, x
), obj
, TRUE
);
228 * Figure out the plus number for armor/weapons
235 static char numbuf
[80];
237 if (n1
== 0 && n2
== 0)
240 sprintf(numbuf
, "%s%d", n1
< 0 ? "" : "+", n1
);
242 sprintf(numbuf
, "%s%d,%s%d",
243 n1
< 0 ? "" : "+", n1
, n2
< 0 ? "" : "+", n2
);
249 * Pull out a certain weapon
254 register struct linked_list
*item
;
255 register struct object
*obj
, *oweapon
;
257 oweapon
= cur_weapon
;
258 if (!dropcheck(cur_weapon
))
260 cur_weapon
= oweapon
;
263 cur_weapon
= oweapon
;
264 if ((item
= get_item("wield", WEAPON
)) == NULL
)
271 obj
= (struct object
*) ldata(item
);
272 if (obj
->o_type
== ARMOR
)
274 msg("You can't wield armor");
283 addmsg("You are now w");
284 msg("ielding %s", inv_name(obj
, TRUE
));
289 * pick a random position around the give (y, x) coordinates
291 fallpos(pos
, newpos
, passages
)
292 register coord
*pos
, *newpos
;
293 register bool passages
;
295 register int y
, x
, cnt
, ch
;
298 for (y
= pos
->y
- 1; y
<= pos
->y
+ 1; y
++)
299 for (x
= pos
->x
- 1; x
<= pos
->x
+ 1; x
++)
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
306 if (y
== hero
.y
&& x
== hero
.x
)
308 if (((ch
= winat(y
, x
)) == FLOOR
|| (passages
&& ch
== PASSAGE
))