Annotation of early-roguelike/srogue/weapons.c, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: * Functions for dealing with weapons
3: *
4: * @(#)weapons.c 9.0 (rdk) 7/17/84
5: *
6: * Super-Rogue
7: * Copyright (C) 1984 Robert D. Kindelberger
8: * All rights reserved.
9: *
10: * Based on "Rogue: Exploring the Dungeons of Doom"
11: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12: * All rights reserved.
13: *
14: * See the file LICENSE.TXT for full copyright and licensing information.
15: */
16:
17: #include <string.h>
18: #include <ctype.h>
19: #include "rogue.h"
20: #include "rogue.ext"
21:
22: /*
23: * missile:
24: * Fire a missile in a given direction
25: */
26: void
27: missile(int ydelta, int xdelta)
28: {
29: reg struct object *obj, *nowwield;
30: reg struct linked_list *item, *nitem;
31:
32: /*
33: * Get which thing we are hurling
34: */
35: nowwield = cur_weapon; /* must save current weap */
36: if ((item = get_item("throw", WEAPON)) == NULL)
37: return;
38: obj = OBJPTR(item);
39: if (!dropcheck(obj) || is_current(obj))
40: return;
41: if (obj == nowwield || obj->o_type != WEAPON) {
42: reg int c;
43:
44: msg("Do you want to throw that %s? (y or n)",obj->o_typname);
45: do {
46: c = readchar();
47: if (isupper(c))
48: c = tolower(c);
49: if (c == ESCAPE || c == 'n') {
50: msg("");
51: cur_weapon = nowwield;
52: after = FALSE; /* ooops, a mistake */
53: return;
54: }
55: } while (c != 'y'); /* keep looking for good ans */
56: }
57: /*
58: * Get rid of the thing. If it is a non-multiple item object, or
59: * if it is the last thing, just drop it. Otherwise, create a new
60: * item with a count of one.
61: */
62: if (obj->o_count < 2) {
63: detach(pack, item);
64: }
65: else {
66: obj->o_count--;
67: obj->o_vol = itemvol(obj);
68: nitem = new_item(sizeof *obj);
69: obj = OBJPTR(nitem);
70: *obj = *(OBJPTR(item));
71: obj->o_count = 1;
72: obj->o_vol = itemvol(obj);
73: item = nitem;
74: }
75: updpack(); /* new pack weight */
76: do_motion(obj, ydelta, xdelta);
77: if (!isalpha(mvwinch(mw, obj->o_pos.y, obj->o_pos.x))
78: || !hit_monster(&obj->o_pos, obj))
79: fall(item, TRUE);
80: mvwaddch(cw, hero.y, hero.x, PLAYER);
81: }
82:
83: /*
84: * do the actual motion on the screen done by an object traveling
85: * across the room
86: */
87: void
88: do_motion(struct object *obj, int ydelta, int xdelta)
89: {
90: reg int ch, y, x;
91:
92: obj->o_pos = hero;
93: while (1) {
94: y = obj->o_pos.y;
95: x = obj->o_pos.x;
96: if (!ce(obj->o_pos, hero) && cansee(unc(obj->o_pos)) &&
97: mvwinch(cw, y, x) != ' ')
98: mvwaddch(cw, y, x, show(y, x));
99: /*
100: * Get the new position
101: */
102: obj->o_pos.y += ydelta;
103: obj->o_pos.x += xdelta;
104: y = obj->o_pos.y;
105: x = obj->o_pos.x;
106: ch = winat(y, x);
107: if (step_ok(ch) && ch != DOOR) {
108: if (cansee(unc(obj->o_pos)) && mvwinch(cw, y, x) != ' ') {
109: mvwaddch(cw, y, x, obj->o_type);
110: draw(cw);
111: }
112: continue;
113: }
114: break;
115: }
116: }
117:
118: /*
119: * fall:
120: * Drop an item someplace around here.
121: */
122:
123: void
124: fall(struct linked_list *item, bool pr)
125: {
126: reg struct object *obj;
127: reg struct room *rp;
128: static struct coord fpos;
129:
130: obj = OBJPTR(item);
131: if (fallpos(&obj->o_pos, &fpos, TRUE)) {
132: mvaddch(fpos.y, fpos.x, obj->o_type);
133: obj->o_pos = fpos;
134: rp = player.t_room;
135: if (rp != NULL && !rf_on(rp,ISDARK)) {
136: light(&hero);
137: mvwaddch(cw, hero.y, hero.x, PLAYER);
138: }
139: attach(lvl_obj, item);
140: return;
141: }
142:
143: if (pr)
144: if (obj->o_type == WEAPON) /* BUGFIX: Identification trick */
145: msg("Your %s vanishes as it hits the ground.", w_magic[obj->o_which].mi_name);
146: else
147: msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE));
148:
149: discard(item);
150: }
151:
152: /*
153: * init_weapon:
154: * Set up the initial goodies for a weapon
155: */
156:
157: void
158: init_weapon(struct object *weap, int type)
159: {
160: reg struct init_weps *iwp;
161:
162: weap->o_type = WEAPON;
163: weap->o_which = type;
164: iwp = &weaps[type];
165: strcpy(weap->o_damage,iwp->w_dam);
166: strcpy(weap->o_hurldmg,iwp->w_hrl);
167: weap->o_launch = iwp->w_launch;
168: weap->o_flags = iwp->w_flags;
169: weap->o_weight = iwp->w_wght;
170: weap->o_typname = things[TYP_WEAPON].mi_name;
171: if (o_on(weap,ISMANY))
172: weap->o_count = rnd(8) + 8;
173: else
174: weap->o_count = 1;
175: weap->o_group = newgrp();
176: weap->o_vol = itemvol(weap);
177: }
178:
179: /*
180: * hit_monster:
181: * Does the missile hit the monster
182: */
183: bool
184: hit_monster(struct coord *mp, struct object *obj)
185: {
186: return fight(mp, obj, TRUE);
187: }
188:
189: /*
190: * num:
191: * Figure out the plus number for armor/weapons
192: */
193: char *
194: num(int n1, int n2)
195: {
196: static char numbuf[LINLEN];
197:
198: if (n1 == 0 && n2 == 0)
199: return "+0";
200: if (n2 == 0)
201: sprintf(numbuf, "%s%d", n1 < 0 ? "" : "+", n1);
202: else
203: sprintf(numbuf,"%s%d,%s%d",n1<0 ? "":"+",n1,n2<0 ? "":"+",n2);
204: return numbuf;
205: }
206:
207: /*
208: * wield:
209: * Pull out a certain weapon
210: */
211: void
212: wield(void)
213: {
214: reg struct linked_list *item;
215: reg struct object *obj, *oweapon;
216:
217: oweapon = cur_weapon;
218: if (!dropcheck(cur_weapon)) {
219: cur_weapon = oweapon;
220: return;
221: }
222: cur_weapon = oweapon;
223: if ((item = get_item("wield", WEAPON)) == NULL)
224: return;
225: obj = OBJPTR(item);
226: if (is_current(obj)) {
227: after = FALSE;
228: return;
229: }
230: msg("Wielding %s", inv_name(obj, TRUE));
231: cur_weapon = obj;
232: }
233:
234: /*
235: * fallpos:
236: * Pick a random position around the give (y, x) coordinates
237: */
238: bool
239: fallpos(struct coord *pos, struct coord *newpos, bool passages)
240: {
241: reg int y, x, ch;
242:
243: for (y = pos->y - 1; y <= pos->y + 1; y++) {
244: for (x = pos->x - 1; x <= pos->x + 1; x++) {
245: /*
246: * check to make certain the spot is empty, if it is,
247: * put the object there, set it in the level list
248: * and re-draw the room if he can see it
249: */
250: if (y == hero.y && x == hero.x)
251: continue;
252: ch = winat(y, x);
253: if (ch == FLOOR || (passages && ch == PASSAGE)) {
254: newpos->y = y;
255: newpos->x = x;
256: return TRUE;
257: }
258: }
259: }
260: return FALSE;
261: }
CVSweb