Annotation of early-roguelike/arogue5/weapons.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: * Functions for dealing with problems brought about by weapons
! 3: *
! 4: * Advanced Rogue
! 5: * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
! 6: * All rights reserved.
! 7: *
! 8: * Based on "Rogue: Exploring the Dungeons of Doom"
! 9: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
! 10: * All rights reserved.
! 11: *
! 12: * See the file LICENSE.TXT for full copyright and licensing information.
! 13: */
! 14:
! 15: #include "curses.h"
! 16: #include <ctype.h>
! 17: #include <string.h>
! 18: #include "rogue.h"
! 19:
! 20:
! 21:
! 22: /*
! 23: * do the actual motion on the screen done by an object traveling
! 24: * across the room
! 25: */
! 26: void
! 27: do_motion(struct object *obj, int ydelta, int xdelta, struct thing *tp)
! 28: {
! 29:
! 30: /*
! 31: * Come fly with us ...
! 32: */
! 33: obj->o_pos = tp->t_pos;
! 34: for (; ;) {
! 35: register int ch;
! 36: /*
! 37: * Erase the old one
! 38: */
! 39: if (!ce(obj->o_pos, tp->t_pos) &&
! 40: cansee(unc(obj->o_pos)) &&
! 41: mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') {
! 42: mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, show(obj->o_pos.y, obj->o_pos.x));
! 43: }
! 44: /*
! 45: * Get the new position
! 46: */
! 47: obj->o_pos.y += ydelta;
! 48: obj->o_pos.x += xdelta;
! 49: if (shoot_ok(ch = winat(obj->o_pos.y, obj->o_pos.x)) && ch != DOOR && !ce(obj->o_pos, hero)) {
! 50: /*
! 51: * It hasn't hit anything yet, so display it
! 52: * If it alright.
! 53: */
! 54: if (cansee(unc(obj->o_pos)) &&
! 55: mvwinch(cw, obj->o_pos.y, obj->o_pos.x) != ' ') {
! 56: mvwaddch(cw, obj->o_pos.y, obj->o_pos.x, obj->o_type);
! 57: draw(cw);
! 58: }
! 59: continue;
! 60: }
! 61: break;
! 62: }
! 63: }
! 64:
! 65:
! 66: /*
! 67: * fall:
! 68: * Drop an item someplace around here.
! 69: */
! 70:
! 71: void
! 72: fall(struct linked_list *item, bool pr)
! 73: {
! 74: register struct object *obj;
! 75: register struct room *rp;
! 76: register int i;
! 77: coord *fpos = NULL;
! 78:
! 79: obj = OBJPTR(item);
! 80: /*
! 81: * try to drop the item, look up to 3 squares away for now
! 82: */
! 83: for (i=1; i<4; i++) {
! 84: if ((fpos = fallpos(&obj->o_pos, FALSE, i)) != NULL)
! 85: break;
! 86: }
! 87:
! 88: if (fpos != NULL) {
! 89: mvaddch(fpos->y, fpos->x, obj->o_type);
! 90: obj->o_pos = *fpos;
! 91: if ((rp = roomin(&hero)) != NULL &&
! 92: lit_room(rp)) {
! 93: light(&hero);
! 94: mvwaddch(cw, hero.y, hero.x, PLAYER);
! 95: }
! 96: attach(lvl_obj, item);
! 97: return;
! 98: }
! 99:
! 100:
! 101: if (pr) {
! 102: if (obj->o_type == WEAPON) /* BUGFIX: Identification trick */
! 103: msg("The %s vanishes as it hits the ground.",
! 104: weaps[obj->o_which].w_name);
! 105: else
! 106: msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE));
! 107: }
! 108: o_discard(item);
! 109: }
! 110:
! 111:
! 112: /*
! 113: * Does the missile hit the monster
! 114: */
! 115:
! 116: bool
! 117: hit_monster(int y, int x, struct object *obj, struct thing *tp)
! 118: {
! 119: static coord mp;
! 120:
! 121: mp.y = y;
! 122: mp.x = x;
! 123: if (tp == &player) {
! 124: /* Make sure there is a monster where it landed */
! 125: if (!isalpha(mvwinch(mw, y, x))) {
! 126: return(FALSE);
! 127: }
! 128: return(fight(&mp, obj, TRUE));
! 129: } else {
! 130: if (!ce(mp, hero)) {
! 131: return(FALSE);
! 132: }
! 133: return(attack(tp, obj, TRUE));
! 134: }
! 135: }
! 136:
! 137: /*
! 138: * init_weapon:
! 139: * Set up the initial goodies for a weapon
! 140: */
! 141:
! 142: void
! 143: init_weapon(struct object *weap, char type)
! 144: {
! 145: register struct init_weps *iwp;
! 146:
! 147: iwp = &weaps[type];
! 148: strcpy(weap->o_damage,iwp->w_dam);
! 149: strcpy(weap->o_hurldmg,iwp->w_hrl);
! 150: weap->o_launch = iwp->w_launch;
! 151: weap->o_flags = iwp->w_flags;
! 152: weap->o_weight = iwp->w_wght;
! 153: if (weap->o_flags & ISMANY) {
! 154: weap->o_count = rnd(8) + 8;
! 155: weap->o_group = newgrp();
! 156: } else {
! 157: weap->o_count = 1;
! 158: }
! 159: }
! 160:
! 161: /*
! 162: * missile:
! 163: * Fire a missile in a given direction
! 164: */
! 165:
! 166: void
! 167: missile(int ydelta, int xdelta, struct linked_list *item, struct thing *tp)
! 168: {
! 169: register struct object *obj;
! 170: register struct linked_list *nitem;
! 171: char ch;
! 172:
! 173: /*
! 174: * Get which thing we are hurling
! 175: */
! 176: if (item == NULL) {
! 177: return;
! 178: }
! 179: obj = OBJPTR(item);
! 180:
! 181: #if 0 /* Do we really want to make this check */
! 182: if (is_current(obj)) { /* Are we holding it? */
! 183: msg(terse ? "Holding it." : "You are already holding it.");
! 184: return;
! 185: }
! 186: #endif
! 187:
! 188: if (!dropcheck(obj)) return; /* Can we get rid of it? */
! 189:
! 190: if(!(obj->o_flags & ISMISL)) {
! 191: for(;;) {
! 192: msg(terse ? "Really throw? (y or n): "
! 193: : "Do you really want to throw %s? (y or n): ",
! 194: inv_name(obj, TRUE));
! 195: mpos = 0;
! 196: ch = readchar();
! 197: if (ch == 'n' || ch == ESCAPE) {
! 198: after = FALSE;
! 199: return;
! 200: }
! 201: if (ch == 'y')
! 202: break;
! 203: }
! 204: }
! 205: /*
! 206: * Get rid of the thing. If it is a non-multiple item object, or
! 207: * if it is the last thing, just drop it. Otherwise, create a new
! 208: * item with a count of one.
! 209: */
! 210: if (obj->o_count < 2) {
! 211: detach(tp->t_pack, item);
! 212: if (tp->t_pack == pack) {
! 213: inpack--;
! 214: }
! 215: }
! 216: else {
! 217: obj->o_count--;
! 218: nitem = (struct linked_list *) new_item(sizeof *obj);
! 219: obj = OBJPTR(nitem);
! 220: *obj = *(OBJPTR(item));
! 221: obj->o_count = 1;
! 222: item = nitem;
! 223: }
! 224: updpack (FALSE);
! 225: do_motion(obj, ydelta, xdelta, tp);
! 226: /*
! 227: * AHA! Here it has hit something. If it is a wall or a door,
! 228: * or if it misses (combat) the monster, put it on the floor
! 229: */
! 230: if (!hit_monster(unc(obj->o_pos), obj, tp)) {
! 231: fall(item, TRUE);
! 232: }
! 233: mvwaddch(cw, hero.y, hero.x, PLAYER);
! 234: }
! 235:
! 236: /*
! 237: * num:
! 238: * Figure out the plus number for armor/weapons
! 239: */
! 240:
! 241: char *
! 242: num(int n1, int n2)
! 243: {
! 244: static char numbuf[LINELEN];
! 245:
! 246: if (n1 == 0 && n2 == 0) {
! 247: return "+0";
! 248: }
! 249: if (n2 == 0) {
! 250: sprintf(numbuf, "%s%d", n1 < 0 ? "" : "+", n1);
! 251: } else {
! 252: sprintf(numbuf, "%s%d, %s%d", n1 < 0 ? "" : "+", n1, n2 < 0 ? "" : "+", n2);
! 253: }
! 254: return(numbuf);
! 255: }
! 256:
! 257: /*
! 258: * wield:
! 259: * Pull out a certain weapon
! 260: */
! 261:
! 262: void
! 263: wield(void)
! 264: {
! 265: register struct linked_list *item;
! 266: register struct object *obj, *oweapon;
! 267:
! 268: if ((oweapon = cur_weapon) != NULL) {
! 269: if (!dropcheck(cur_weapon)) {
! 270: cur_weapon = oweapon;
! 271: return;
! 272: }
! 273: if (terse)
! 274: addmsg("Was ");
! 275: else
! 276: addmsg("You were ");
! 277: msg("wielding %s", inv_name(oweapon, TRUE));
! 278: }
! 279: if ((item = get_item(pack, "wield", WIELDABLE)) == NULL) {
! 280: after = FALSE;
! 281: return;
! 282: }
! 283: obj = OBJPTR(item);
! 284: if (is_current(obj)) {
! 285: msg("Item in use.");
! 286: after = FALSE;
! 287: return;
! 288: }
! 289: if (player.t_ctype != C_FIGHTER &&
! 290: obj->o_type == WEAPON &&
! 291: (obj->o_which == TWOSWORD || obj->o_which == BASWORD)) {
! 292: msg("Only fighters can wield a %s", weaps[obj->o_which].w_name);
! 293: return;
! 294: }
! 295: if (terse) {
! 296: addmsg("W");
! 297: } else {
! 298: addmsg("You are now w");
! 299: }
! 300: msg("ielding %s", inv_name(obj, TRUE));
! 301: cur_weapon = obj;
! 302: }
! 303:
CVSweb