Annotation of early-roguelike/rogue4/scrolls.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: * Read a scroll and let it happen
! 3: *
! 4: * @(#)scrolls.c 4.21 (Berkeley) 4/6/82
! 5: *
! 6: * Rogue: Exploring the Dungeons of Doom
! 7: * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
! 8: * All rights reserved.
! 9: *
! 10: * See the file LICENSE.TXT for full copyright and licensing information.
! 11: */
! 12:
! 13: #include <curses.h>
! 14: #include <ctype.h>
! 15: #include "rogue.h"
! 16:
! 17: /*
! 18: * read_scroll:
! 19: * Read a scroll from the pack and do the appropriate thing
! 20: */
! 21: void
! 22: read_scroll(void)
! 23: {
! 24: register THING *obj;
! 25: register int y, x;
! 26: register char ch;
! 27: register THING *op;
! 28: register int index;
! 29: register bool discardit = FALSE;
! 30:
! 31: obj = get_item("read", SCROLL);
! 32: if (obj == NULL)
! 33: return;
! 34: if (obj->o_type != SCROLL)
! 35: {
! 36: if (!terse)
! 37: msg("there is nothing on it to read");
! 38: else
! 39: msg("nothing to read");
! 40: return;
! 41: }
! 42: msg("as you read the scroll, it vanishes");
! 43: /*
! 44: * Calculate the effect it has on the poor guy.
! 45: */
! 46: if (obj == cur_weapon)
! 47: cur_weapon = NULL;
! 48: switch (obj->o_which)
! 49: {
! 50: case S_CONFUSE:
! 51: /*
! 52: * Scroll of monster confusion. Give him that power.
! 53: */
! 54: player.t_flags |= CANHUH;
! 55: msg("your hands begin to glow red");
! 56: when S_ARMOR:
! 57: if (cur_armor != NULL)
! 58: {
! 59: cur_armor->o_ac--;
! 60: cur_armor->o_flags &= ~ISCURSED;
! 61: msg("your armor glows faintly for a moment");
! 62: }
! 63: when S_HOLD:
! 64: /*
! 65: * Hold monster scroll. Stop all monsters within two spaces
! 66: * from chasing after the hero.
! 67: */
! 68:
! 69: for (x = hero.x - 2; x <= hero.x + 2; x++)
! 70: if (x >= 0 && x < COLS)
! 71: for (y = hero.y - 2; y <= hero.y + 2; y++)
! 72: if (y >= 0 && y <= LINES - 1)
! 73: if ((op = moat(y, x)) != NULL)
! 74: {
! 75: op->t_flags &= ~ISRUN;
! 76: op->t_flags |= ISHELD;
! 77: }
! 78: when S_SLEEP:
! 79: /*
! 80: * Scroll which makes you fall asleep
! 81: */
! 82: s_know[S_SLEEP] = TRUE;
! 83: no_command += rnd(SLEEPTIME) + 4;
! 84: player.t_flags &= ~ISRUN;
! 85: msg("you fall asleep");
! 86: when S_CREATE:
! 87: /*
! 88: * Create a monster
! 89: * First look in a circle around him, next try his room
! 90: * otherwise give up
! 91: */
! 92: {
! 93: register bool appear = 0;
! 94: coord mp;
! 95:
! 96: /*
! 97: * Search for an open place
! 98: */
! 99: for (y = hero.y - 1; y <= hero.y + 1; y++)
! 100: for (x = hero.x - 1; x <= hero.x + 1; x++)
! 101: {
! 102: /*
! 103: * Don't put a monster in top of the player.
! 104: */
! 105: if (y == hero.y && x == hero.x)
! 106: continue;
! 107: /*
! 108: * Or anything else nasty
! 109: * Also avoid a mimic which is disguised as scroll
! 110: */
! 111: if (moat(y, x) == NULL && step_ok(ch = winat(y, x)))
! 112: {
! 113: if (ch == SCROLL
! 114: && find_obj(y, x)->o_which == S_SCARE)
! 115: continue;
! 116: if (rnd(++appear) == 0)
! 117: {
! 118: mp.y = y;
! 119: mp.x = x;
! 120: }
! 121: }
! 122: }
! 123: if (appear)
! 124: {
! 125: op = new_item();
! 126: new_monster(op, randmonster(FALSE), &mp);
! 127: }
! 128: else
! 129: msg("you hear a faint cry of anguish in the distance");
! 130: }
! 131: when S_IDENT:
! 132: /*
! 133: * Identify, let the rogue figure something out
! 134: */
! 135: s_know[S_IDENT] = TRUE;
! 136: msg("this scroll is an identify scroll");
! 137: whatis(TRUE);
! 138: when S_MAP:
! 139: /*
! 140: * Scroll of magic mapping.
! 141: */
! 142: s_know[S_MAP] = TRUE;
! 143: msg("oh, now this scroll has a map on it");
! 144: /*
! 145: * Take all the things we want to keep hidden out of the window
! 146: */
! 147: for (y = 1; y < LINES - 1; y++)
! 148: for (x = 0; x < COLS; x++)
! 149: {
! 150: index = INDEX(y, x);
! 151: switch (ch = _level[index])
! 152: {
! 153: case '-':
! 154: case '|':
! 155: if (!(_flags[index] & F_REAL))
! 156: {
! 157: ch = _level[index] = DOOR;
! 158: _flags[index] &= ~F_REAL;
! 159: }
! 160: case PASSAGE:
! 161: _flags[index] |= F_SEEN;
! 162: case DOOR:
! 163: case STAIRS:
! 164: if ((op = moat(y, x)) != NULL)
! 165: if (op->t_oldch == ' ')
! 166: op->t_oldch = ch;
! 167: break;
! 168: default:
! 169: ch = ' ';
! 170: }
! 171: if (ch != ' ')
! 172: mvaddch(y, x, ch);
! 173: }
! 174: when S_GFIND:
! 175: /*
! 176: * Potion of gold detection
! 177: */
! 178: ch = FALSE;
! 179: wclear(hw);
! 180: for (op = lvl_obj; op != NULL; op = next(op))
! 181: if (op->o_type == GOLD)
! 182: {
! 183: ch = TRUE;
! 184: mvwaddch(hw, op->o_pos.y, op->o_pos.x, GOLD);
! 185: }
! 186: if (ch)
! 187: {
! 188: s_know[S_GFIND] = TRUE;
! 189: show_win(hw,
! 190: "You begin to feel greedy and you sense gold.--More--");
! 191: }
! 192: else
! 193: msg("you feel a pull downward");
! 194: when S_TELEP:
! 195: /*
! 196: * Scroll of teleportation:
! 197: * Make him dissapear and reappear
! 198: */
! 199: {
! 200: register struct room *cur_room;
! 201:
! 202: cur_room = proom;
! 203: teleport();
! 204: if (cur_room != proom)
! 205: s_know[S_TELEP] = TRUE;
! 206: }
! 207: when S_ENCH:
! 208: if (cur_weapon == NULL || cur_weapon->o_type != WEAPON)
! 209: msg("you feel a strange sense of loss");
! 210: else
! 211: {
! 212: cur_weapon->o_flags &= ~ISCURSED;
! 213: if (rnd(2) == 0)
! 214: cur_weapon->o_hplus++;
! 215: else
! 216: cur_weapon->o_dplus++;
! 217: msg("your %s glows blue for a moment", w_names[cur_weapon->o_which]);
! 218: }
! 219: when S_SCARE:
! 220: /*
! 221: * Reading it is a mistake and produces laughter at the
! 222: * poor rogue's boo boo.
! 223: */
! 224: msg("you hear maniacal laughter in the distance");
! 225: when S_REMOVE:
! 226: if (cur_armor != NULL)
! 227: cur_armor->o_flags &= ~ISCURSED;
! 228: if (cur_weapon != NULL)
! 229: cur_weapon->o_flags &= ~ISCURSED;
! 230: if (cur_ring[LEFT] != NULL)
! 231: cur_ring[LEFT]->o_flags &= ~ISCURSED;
! 232: if (cur_ring[RIGHT] != NULL)
! 233: cur_ring[RIGHT]->o_flags &= ~ISCURSED;
! 234: msg("you feel as if somebody is watching over you");
! 235: when S_AGGR:
! 236: /*
! 237: * This scroll aggravates all the monsters on the current
! 238: * level and sets them running towards the hero
! 239: */
! 240: aggravate();
! 241: msg("you hear a high pitched humming noise");
! 242: when S_NOP:
! 243: msg("this scroll seems to be blank");
! 244: when S_GENOCIDE:
! 245: s_know[S_GENOCIDE] = TRUE;
! 246: msg("you have been granted the boon of genocide");
! 247: genocide();
! 248: otherwise:
! 249: msg("what a puzzling scroll!");
! 250: return;
! 251: }
! 252: look(TRUE); /* put the result of the scroll on the screen */
! 253: status();
! 254: /*
! 255: * Get rid of the thing
! 256: */
! 257: inpack--;
! 258: if (obj->o_count > 1)
! 259: obj->o_count--;
! 260: else
! 261: {
! 262: detach(pack, obj);
! 263: discardit = TRUE;
! 264: }
! 265:
! 266: call_it(s_know[obj->o_which], &s_guess[obj->o_which]);
! 267:
! 268: if (discardit)
! 269: discard(obj);
! 270: }
CVSweb