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