|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * This code is derived from software contributed to Berkeley by ! 6: * Timothy C. Stoehr. ! 7: * ! 8: * Redistribution and use in source and binary forms are permitted ! 9: * provided that: (1) source distributions retain this entire copyright ! 10: * notice and comment, and (2) distributions including binaries display ! 11: * the following acknowledgement: ``This product includes software ! 12: * developed by the University of California, Berkeley and its contributors'' ! 13: * in the documentation or other materials provided with the distribution ! 14: * and in all advertising materials mentioning features or use of this ! 15: * software. Neither the name of the University nor the names of its ! 16: * contributors may be used to endorse or promote products derived ! 17: * from this software without specific prior written permission. ! 18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 19: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 20: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 21: */ ! 22: ! 23: #ifndef lint ! 24: static char sccsid[] = "@(#)throw.c 5.3 (Berkeley) 6/1/90"; ! 25: #endif /* not lint */ ! 26: ! 27: /* ! 28: * throw.c ! 29: * ! 30: * This source herein may be modified and/or distributed by anybody who ! 31: * so desires, with the following restrictions: ! 32: * 1.) No portion of this notice shall be removed. ! 33: * 2.) Credit shall not be taken for the creation of this source. ! 34: * 3.) This code is not to be traded, sold, or used for personal ! 35: * gain or profit. ! 36: * ! 37: */ ! 38: ! 39: #include "rogue.h" ! 40: ! 41: extern short cur_room; ! 42: extern char *curse_message; ! 43: extern char hit_message[]; ! 44: ! 45: throw() ! 46: { ! 47: short wch, d; ! 48: boolean first_miss = 1; ! 49: object *weapon; ! 50: short dir, row, col; ! 51: object *monster; ! 52: ! 53: while (!is_direction(dir = rgetchar(), &d)) { ! 54: sound_bell(); ! 55: if (first_miss) { ! 56: message("direction? ", 0); ! 57: first_miss = 0; ! 58: } ! 59: } ! 60: check_message(); ! 61: if (dir == CANCEL) { ! 62: return; ! 63: } ! 64: if ((wch = pack_letter("throw what?", WEAPON)) == CANCEL) { ! 65: return; ! 66: } ! 67: check_message(); ! 68: ! 69: if (!(weapon = get_letter_object(wch))) { ! 70: message("no such item.", 0); ! 71: return; ! 72: } ! 73: if ((weapon->in_use_flags & BEING_USED) && weapon->is_cursed) { ! 74: message(curse_message, 0); ! 75: return; ! 76: } ! 77: row = rogue.row; col = rogue.col; ! 78: ! 79: if ((weapon->in_use_flags & BEING_WIELDED) && (weapon->quantity <= 1)) { ! 80: unwield(rogue.weapon); ! 81: } else if (weapon->in_use_flags & BEING_WORN) { ! 82: mv_aquatars(); ! 83: unwear(rogue.armor); ! 84: print_stats(STAT_ARMOR); ! 85: } else if (weapon->in_use_flags & ON_EITHER_HAND) { ! 86: un_put_on(weapon); ! 87: } ! 88: monster = get_thrown_at_monster(weapon, d, &row, &col); ! 89: mvaddch(rogue.row, rogue.col, rogue.fchar); ! 90: refresh(); ! 91: ! 92: if (rogue_can_see(row, col) && ((row != rogue.row) || (col != rogue.col))){ ! 93: mvaddch(row, col, get_dungeon_char(row, col)); ! 94: } ! 95: if (monster) { ! 96: wake_up(monster); ! 97: check_gold_seeker(monster); ! 98: ! 99: if (!throw_at_monster(monster, weapon)) { ! 100: flop_weapon(weapon, row, col); ! 101: } ! 102: } else { ! 103: flop_weapon(weapon, row, col); ! 104: } ! 105: vanish(weapon, 1, &rogue.pack); ! 106: } ! 107: ! 108: throw_at_monster(monster, weapon) ! 109: object *monster, *weapon; ! 110: { ! 111: short damage, hit_chance; ! 112: short t; ! 113: ! 114: hit_chance = get_hit_chance(weapon); ! 115: damage = get_weapon_damage(weapon); ! 116: if ((weapon->which_kind == ARROW) && ! 117: (rogue.weapon && (rogue.weapon->which_kind == BOW))) { ! 118: damage += get_weapon_damage(rogue.weapon); ! 119: damage = ((damage * 2) / 3); ! 120: hit_chance += (hit_chance / 3); ! 121: } else if ((weapon->in_use_flags & BEING_WIELDED) && ! 122: ((weapon->which_kind == DAGGER) || ! 123: (weapon->which_kind == SHURIKEN) || ! 124: (weapon->which_kind == DART))) { ! 125: damage = ((damage * 3) / 2); ! 126: hit_chance += (hit_chance / 3); ! 127: } ! 128: t = weapon->quantity; ! 129: weapon->quantity = 1; ! 130: sprintf(hit_message, "the %s", name_of(weapon)); ! 131: weapon->quantity = t; ! 132: ! 133: if (!rand_percent(hit_chance)) { ! 134: (void) strcat(hit_message, "misses "); ! 135: return(0); ! 136: } ! 137: s_con_mon(monster); ! 138: (void) strcat(hit_message, "hit "); ! 139: (void) mon_damage(monster, damage); ! 140: return(1); ! 141: } ! 142: ! 143: object * ! 144: get_thrown_at_monster(obj, dir, row, col) ! 145: object *obj; ! 146: short dir; ! 147: short *row, *col; ! 148: { ! 149: short orow, ocol; ! 150: short i, ch; ! 151: ! 152: orow = *row; ocol = *col; ! 153: ! 154: ch = get_mask_char(obj->what_is); ! 155: ! 156: for (i = 0; i < 24; i++) { ! 157: get_dir_rc(dir, row, col, 0); ! 158: if ( (((*col <= 0) || (*col >= DCOLS-1)) || ! 159: (dungeon[*row][*col] == NOTHING)) || ! 160: ((dungeon[*row][*col] & (HORWALL | VERTWALL | HIDDEN)) && ! 161: (!(dungeon[*row][*col] & TRAP)))) { ! 162: *row = orow; ! 163: *col = ocol; ! 164: return(0); ! 165: } ! 166: if ((i != 0) && rogue_can_see(orow, ocol)) { ! 167: mvaddch(orow, ocol, get_dungeon_char(orow, ocol)); ! 168: } ! 169: if (rogue_can_see(*row, *col)) { ! 170: if (!(dungeon[*row][*col] & MONSTER)) { ! 171: mvaddch(*row, *col, ch); ! 172: } ! 173: refresh(); ! 174: } ! 175: orow = *row; ocol = *col; ! 176: if (dungeon[*row][*col] & MONSTER) { ! 177: if (!imitating(*row, *col)) { ! 178: return(object_at(&level_monsters, *row, *col)); ! 179: } ! 180: } ! 181: if (dungeon[*row][*col] & TUNNEL) { ! 182: i += 2; ! 183: } ! 184: } ! 185: return(0); ! 186: } ! 187: ! 188: flop_weapon(weapon, row, col) ! 189: object *weapon; ! 190: short row, col; ! 191: { ! 192: object *new_weapon, *monster; ! 193: short i = 0; ! 194: char msg[80]; ! 195: boolean found = 0; ! 196: short mch, dch; ! 197: unsigned short mon; ! 198: ! 199: while ((i < 9) && dungeon[row][col] & ~(FLOOR | TUNNEL | DOOR | MONSTER)) { ! 200: rand_around(i++, &row, &col); ! 201: if ((row > (DROWS-2)) || (row < MIN_ROW) || ! 202: (col > (DCOLS-1)) || (col < 0) || (!dungeon[row][col]) || ! 203: (dungeon[row][col] & ~(FLOOR | TUNNEL | DOOR | MONSTER))) { ! 204: continue; ! 205: } ! 206: found = 1; ! 207: break; ! 208: } ! 209: ! 210: if (found || (i == 0)) { ! 211: new_weapon = alloc_object(); ! 212: *new_weapon = *weapon; ! 213: new_weapon->in_use_flags = NOT_USED; ! 214: new_weapon->quantity = 1; ! 215: new_weapon->ichar = 'L'; ! 216: place_at(new_weapon, row, col); ! 217: if (rogue_can_see(row, col) && ! 218: ((row != rogue.row) || (col != rogue.col))) { ! 219: mon = dungeon[row][col] & MONSTER; ! 220: dungeon[row][col] &= (~MONSTER); ! 221: dch = get_dungeon_char(row, col); ! 222: if (mon) { ! 223: mch = mvinch(row, col); ! 224: if (monster = object_at(&level_monsters, row, col)) { ! 225: monster->trail_char = dch; ! 226: } ! 227: if ((mch < 'A') || (mch > 'Z')) { ! 228: mvaddch(row, col, dch); ! 229: } ! 230: } else { ! 231: mvaddch(row, col, dch); ! 232: } ! 233: dungeon[row][col] |= mon; ! 234: } ! 235: } else { ! 236: short t; ! 237: ! 238: t = weapon->quantity; ! 239: weapon->quantity = 1; ! 240: sprintf(msg, "the %svanishes as it hits the ground", ! 241: name_of(weapon)); ! 242: weapon->quantity = t; ! 243: message(msg, 0); ! 244: } ! 245: } ! 246: ! 247: rand_around(i, r, c) ! 248: short i, *r, *c; ! 249: { ! 250: static char* pos = "\010\007\001\003\004\005\002\006\0"; ! 251: static short row, col; ! 252: short j; ! 253: ! 254: if (i == 0) { ! 255: short x, y, o, t; ! 256: ! 257: row = *r; ! 258: col = *c; ! 259: ! 260: o = get_rand(1, 8); ! 261: ! 262: for (j = 0; j < 5; j++) { ! 263: x = get_rand(0, 8); ! 264: y = (x + o) % 9; ! 265: t = pos[x]; ! 266: pos[x] = pos[y]; ! 267: pos[y] = t; ! 268: } ! 269: } ! 270: switch((short)pos[i]) { ! 271: case 0: ! 272: *r = row + 1; ! 273: *c = col + 1; ! 274: break; ! 275: case 1: ! 276: *r = row + 1; ! 277: *c = col - 1; ! 278: break; ! 279: case 2: ! 280: *r = row - 1; ! 281: *c = col + 1; ! 282: break; ! 283: case 3: ! 284: *r = row - 1; ! 285: *c = col - 1; ! 286: break; ! 287: case 4: ! 288: *r = row; ! 289: *c = col + 1; ! 290: break; ! 291: case 5: ! 292: *r = row + 1; ! 293: *c = col; ! 294: break; ! 295: case 6: ! 296: *r = row; ! 297: *c = col; ! 298: break; ! 299: case 7: ! 300: *r = row - 1; ! 301: *c = col; ! 302: break; ! 303: case 8: ! 304: *r = row; ! 305: *c = col - 1; ! 306: break; ! 307: } ! 308: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.