Annotation of early-roguelike/srogue/scrolls.c, Revision 1.1
1.1 ! rubenllo 1: /*
! 2: * Read a scroll and let it happen
! 3: *
! 4: * @(#)scrolls.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 <stdlib.h>
! 18: #include <string.h>
! 19: #include <ctype.h>
! 20: #include "rogue.h"
! 21: #include "rogue.ext"
! 22:
! 23: /*
! 24: * read_scroll:
! 25: * Let the hero read a scroll
! 26: */
! 27: void
! 28: read_scroll(void)
! 29: {
! 30: reg struct object *obj;
! 31: reg struct linked_list *item;
! 32: reg int i, j, wh;
! 33: reg char ch, nch;
! 34: struct room *rp;
! 35: struct linked_list *titem;
! 36: char buf[LINLEN];
! 37: bool bless, curse;
! 38:
! 39: if ((item = get_item("read", SCROLL)) == NULL)
! 40: return;
! 41: obj = OBJPTR(item);
! 42: if (obj->o_type != SCROLL) {
! 43: msg("Nothing to read.");
! 44: after = FALSE;
! 45: return;
! 46: }
! 47: msg("As you read the scroll, it vanishes.");
! 48: wh = obj->o_which;
! 49: bless = o_on(obj, ISBLESS);
! 50: curse = o_on(obj, ISCURSED);
! 51: del_pack(item); /* Get rid of the thing */
! 52:
! 53: /*
! 54: * Calculate the effect it has on the hero
! 55: */
! 56: switch(wh) {
! 57: case S_KNOWALL:
! 58: if (!curse) {
! 59: idenpack(); /* identify all the pack */
! 60: msg("You feel more knowledgable.");
! 61: chg_abil(WIS,1,TRUE);
! 62: s_know[S_KNOWALL] = TRUE;
! 63: }
! 64: when S_CONFUSE:
! 65: if (!curse) {
! 66: /*
! 67: * Scroll of monster confusion. Give him that power.
! 68: */
! 69: msg("Your hands begin to glow red.");
! 70: player.t_flags |= CANHUH;
! 71: s_know[S_CONFUSE] = TRUE;
! 72: }
! 73: when S_LIGHT:
! 74: rp = player.t_room;
! 75: if (!curse) {
! 76: if (rp == NULL) {
! 77: s_know[S_LIGHT] = TRUE;
! 78: msg("The corridor glows and then fades.");
! 79: }
! 80: else {
! 81: if (rf_on(rp,ISDARK)) {
! 82: s_know[S_LIGHT] = TRUE;
! 83: msg("The room is lit.");
! 84: rp->r_flags &= ~ISDARK;
! 85: }
! 86: light(&hero);
! 87: mvwaddch(cw, hero.y, hero.x, PLAYER);
! 88: }
! 89: }
! 90: when S_ARMOR:
! 91: if (!curse) {
! 92: if (cur_armor != NULL && o_off(cur_armor,ISPROT)) {
! 93: s_know[S_ARMOR] = TRUE;
! 94: msg("Your armor glows faintly for a moment.");
! 95: if (o_on(cur_armor,ISCURSED))
! 96: cur_armor->o_ac = armors[cur_armor->o_which].a_class;
! 97: else
! 98: cur_armor->o_ac--;
! 99: resoflg(cur_armor,ISCURSED);
! 100: }
! 101: }
! 102: when S_HOLD:
! 103: if (!curse) {
! 104: /*
! 105: * Hold monster scroll. Stop all monsters within 3 spaces
! 106: * from chasing after the hero.
! 107: */
! 108: reg int x,y;
! 109: reg struct linked_list *mon;
! 110:
! 111: for (x = hero.x - 3; x <= hero.x + 3; x++) {
! 112: for (y = hero.y - 3; y <= hero.y + 3; y++) {
! 113: if (y > 0 && x > 0 && isalpha(mvwinch(mw, y, x))) {
! 114: if ((mon = find_mons(y, x)) != NULL) {
! 115: reg struct thing *th;
! 116:
! 117: th = THINGPTR(mon);
! 118: th->t_flags &= ~ISRUN;
! 119: th->t_flags |= ISHELD;
! 120: th->t_flags |= ISSTUCK;
! 121: }
! 122: }
! 123: }
! 124: }
! 125: }
! 126: when S_SLEEP:
! 127: /*
! 128: * Scroll which makes you fall asleep
! 129: */
! 130: if (!bless) {
! 131: s_know[S_SLEEP] = TRUE;
! 132: msg("You fall asleep.");
! 133: player.t_nocmd += 4 + rnd(SLEEPTIME);
! 134: }
! 135: when S_CREATE:
! 136: if (!bless) {
! 137: if (makemons(mtlev[rnd(levcount)]->m_show))
! 138: s_know[S_CREATE] = TRUE;
! 139: else
! 140: msg("You hear a faint cry of anguish in the distance.");
! 141: }
! 142: when S_IDENT:
! 143: if (!curse) {
! 144: msg("This scroll is an identify scroll");
! 145: s_know[S_IDENT] = TRUE;
! 146: whatis(NULL);
! 147: }
! 148: when S_MAP:
! 149: if (curse)
! 150: break;
! 151: s_know[S_MAP] = TRUE;
! 152: addmsg("Oh, now this scroll has a ");
! 153: if (rnd(100) < 10 || bless) {
! 154: addmsg("very detailed map on it.");
! 155: endmsg();
! 156: displevl();
! 157: }
! 158: else {
! 159: addmsg("map on it.");
! 160: endmsg();
! 161: overwrite(stdscr, hw);
! 162: for (i = 1; i < LINES - 2; i++) {
! 163: for (j = 0; j < COLS; j++) {
! 164: switch (nch = ch = mvwinch(hw, i, j)) {
! 165: case SECRETDOOR:
! 166: nch = DOOR;
! 167: mvaddch(i, j, nch);
! 168: case '-':
! 169: case '|':
! 170: case DOOR:
! 171: case PASSAGE:
! 172: case ' ':
! 173: case STAIRS:
! 174: if (mvwinch(mw, i, j) != ' ') {
! 175: struct thing *it;
! 176: struct linked_list *blah;
! 177:
! 178: blah = find_mons(i, j);
! 179: if (blah != NULL) {
! 180: it = THINGPTR(blah);
! 181: if (it->t_oldch == ' ')
! 182: it->t_oldch = nch;
! 183: }
! 184: }
! 185: break;
! 186: default:
! 187: nch = ' ';
! 188: }
! 189: if (nch != ch)
! 190: waddch(hw, nch);
! 191: }
! 192: }
! 193: overlay(cw, hw);
! 194: overwrite(hw, cw);
! 195: }
! 196: when S_GFIND:
! 197: if (!curse) {
! 198: int gtotal = 0;
! 199: struct room *rp;
! 200:
! 201: wclear(hw);
! 202: for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
! 203: gtotal += rp->r_goldval;
! 204: if (rp->r_goldval != 0 &&
! 205: mvinch(rp->r_gold.y,rp->r_gold.x) == GOLD)
! 206: mvwaddch(hw,rp->r_gold.y,rp->r_gold.x,GOLD);
! 207: }
! 208: if (gtotal) {
! 209: s_know[S_GFIND] = TRUE;
! 210: msg("You begin to feel greedy and sense gold.");
! 211: overlay(hw,cw);
! 212: }
! 213: else
! 214: msg("You begin to feel a pull downward.");
! 215: }
! 216: when S_TELEP:
! 217: if (!curse) {
! 218: int rm;
! 219: struct room *cur_room;
! 220:
! 221: cur_room = player.t_room;
! 222: rm = teleport(rndspot, &player);
! 223: if (cur_room != &rooms[rm])
! 224: s_know[S_TELEP] = TRUE;
! 225: }
! 226: when S_ENCH:
! 227: if (!curse) {
! 228: if (cur_weapon == NULL || (cur_weapon != NULL &&
! 229: (o_on(cur_weapon,ISPROT) || cur_weapon->o_type != WEAPON)))
! 230: msg("You feel a strange sense of loss.");
! 231: else {
! 232: s_know[S_ENCH] = TRUE;
! 233: if (o_on(cur_weapon,ISCURSED)) {
! 234: resoflg(cur_weapon,ISCURSED);
! 235: cur_weapon->o_hplus = rnd(2);
! 236: cur_weapon->o_dplus = rnd(2);
! 237: }
! 238: else { /* weapon was not cursed here */
! 239: if (rnd(100) < 50)
! 240: cur_weapon->o_hplus += 1;
! 241: else
! 242: cur_weapon->o_dplus += 1;
! 243: }
! 244: setoflg(cur_weapon, ISKNOW);
! 245: msg("Your %s glows blue for a moment.",
! 246: w_magic[cur_weapon->o_which].mi_name);
! 247: }
! 248: }
! 249: when S_SCARE:
! 250: /*
! 251: * A monster will refuse to step on a scare monster scroll
! 252: * if it is dropped. Thus reading it is a mistake and produces
! 253: * laughter at the poor rogue's boo boo.
! 254: */
! 255: msg("You hear maniacal laughter in the distance.");
! 256: when S_REMOVE:
! 257: if (!curse) {
! 258: if (cur_armor != NULL && o_off(cur_armor,ISPROT))
! 259: resoflg(cur_armor,ISCURSED);
! 260: if (cur_weapon != NULL && o_off(cur_weapon,ISPROT))
! 261: resoflg(cur_weapon,ISCURSED);
! 262: if (cur_ring[LEFT]!=NULL && o_off(cur_ring[LEFT],ISPROT))
! 263: resoflg(cur_ring[LEFT],ISCURSED);
! 264: if (cur_ring[RIGHT]!=NULL && o_off(cur_ring[RIGHT],ISPROT))
! 265: resoflg(cur_ring[RIGHT],ISCURSED);
! 266: msg("You feel as if somebody is watching over you.");
! 267: s_know[S_REMOVE] = TRUE;
! 268: }
! 269: when S_AGGR:
! 270: if (!bless) {
! 271: if (mlist != NULL) {
! 272: aggravate();
! 273: msg("You hear a high pitched humming noise.");
! 274: s_know[S_AGGR] = TRUE;
! 275: }
! 276: }
! 277: when S_NOP:
! 278: msg("This scroll seems to be blank.");
! 279: when S_GENOCIDE:
! 280: if (!curse) {
! 281: msg("You have been granted the boon of genocide.");
! 282: genocide();
! 283: s_know[S_GENOCIDE] = TRUE;
! 284: }
! 285: when S_DCURSE:
! 286: if (!bless) {
! 287: struct linked_list *ll;
! 288: struct object *lb;
! 289:
! 290: msg("Your pack shudders.");
! 291: for (ll = pack ; ll != NULL ; ll = next(ll)) {
! 292: lb = OBJPTR(ll);
! 293: if (o_off(lb,ISPROT)) {
! 294: resoflg(lb, ISBLESS);
! 295: setoflg(lb, ISCURSED);
! 296: }
! 297: }
! 298: }
! 299: when S_DLEVEL:
! 300: if (!bless) {
! 301: int much = rnd(9) - 4;
! 302:
! 303: if (much != 0) {
! 304: level += much;
! 305: if (level < 1)
! 306: level = 1;
! 307: mpos = 0;
! 308: new_level(NORMLEV); /* change levels */
! 309: msg("You are whisked away to another region.");
! 310: s_know[S_DLEVEL] = TRUE;
! 311: }
! 312: }
! 313: when S_PROTECT:
! 314: if (!curse) {
! 315: struct linked_list *ll;
! 316: struct object *lb;
! 317:
! 318: msg("You are granted the power of protection.");
! 319: if ((ll = get_item("protect",0)) != NULL) {
! 320: lb = OBJPTR(ll);
! 321: setoflg(lb,ISPROT);
! 322: mpos = 0;
! 323: msg("Protected %s.",inv_name(lb,TRUE));
! 324: }
! 325: s_know[S_PROTECT] = TRUE;
! 326: }
! 327: when S_ALLENCH:
! 328: if (!curse) {
! 329: struct linked_list *ll;
! 330: struct object *lb;
! 331: int howmuch, ac, good;
! 332:
! 333: msg("You are granted the power of enchantment.");
! 334: good = TRUE;
! 335: if ((ll = get_item("enchant",0)) != NULL) {
! 336: lb = OBJPTR(ll);
! 337: resoflg(lb,ISCURSED);
! 338: resoflg(lb,ISPROT);
! 339: howmuch = rnd(3) + 1;
! 340: switch(lb->o_type) {
! 341: case RING:
! 342: if (lb->o_ac < 0)
! 343: lb->o_ac = 0;
! 344: lb->o_ac += howmuch;
! 345: when ARMOR:
! 346: ac = armors[lb->o_which].a_class;
! 347: if (lb->o_ac > ac)
! 348: lb->o_ac = ac;
! 349: lb->o_ac -= howmuch;
! 350: when STICK:
! 351: lb->o_charges += howmuch + 10;
! 352: when WEAPON:
! 353: if (lb->o_dplus < 0)
! 354: lb->o_dplus = 0;
! 355: if (lb->o_hplus < 0)
! 356: lb->o_hplus = 0;
! 357: lb->o_hplus += howmuch;
! 358: lb->o_dplus += howmuch;
! 359: otherwise:
! 360: msg("You are injured as the scroll flashes & bursts into flames !!!");
! 361: chg_hpt(-roll(6,6),FALSE,K_SCROLL);
! 362: good = FALSE;
! 363: }
! 364: if (good) {
! 365: mpos = 0;
! 366: msg("Enchanted %s.",inv_name(lb,TRUE));
! 367: }
! 368: }
! 369: s_know[S_ALLENCH] = TRUE;
! 370: }
! 371: when S_BLESS:
! 372: if (!curse) {
! 373: struct linked_list *ll;
! 374: struct object *lb;
! 375:
! 376: msg("Your pack glistens brightly.");
! 377: for (ll = pack ; ll != NULL ; ll = next(ll)) {
! 378: whatis(ll);
! 379: lb = OBJPTR(ll);
! 380: resoflg(lb,ISCURSED);
! 381: setoflg(lb,ISBLESS);
! 382: }
! 383: }
! 384: when S_MAKEIT:
! 385: if (!curse) {
! 386: msg("You have been endowed with the power of creation.");
! 387: s_know[S_MAKEIT] = TRUE;
! 388: create_obj(TRUE);
! 389: }
! 390: when S_BAN: {
! 391: int howdeep;
! 392: char *ptr = "";
! 393:
! 394: if (bless) {
! 395: if (level > 6) {
! 396: howdeep = 1 + rnd(5);
! 397: ptr = "elevated to the upper";
! 398: }
! 399: else {
! 400: howdeep = -1;
! 401: bless = FALSE;
! 402: }
! 403: }
! 404: else {
! 405: howdeep = level + 10 + rnd(20) + (curse * 20);
! 406: ptr = "banished to the lower";
! 407: }
! 408: if ((!bless && level < howdeep) || bless) {
! 409: level = howdeep;
! 410: new_level(NORMLEV);
! 411: mpos = 0;
! 412: msg("You are %s regions.", ptr);
! 413: s_know[S_BAN] = TRUE;
! 414: }
! 415: }
! 416: when S_CWAND:
! 417: if (!curse) {
! 418: struct linked_list *ll;
! 419: struct object *lb;
! 420: bool wands = FALSE;
! 421:
! 422: for (ll = pack ; ll != NULL ; ll = next(ll)) {
! 423: lb = OBJPTR(ll);
! 424: if (lb->o_type == STICK) {
! 425: whatis(ll);
! 426: setoflg(lb, ISKNOW);
! 427: resoflg(lb, ISCURSED);
! 428: lb->o_charges += rnd(11) + 5;
! 429: wands = TRUE;
! 430: }
! 431: }
! 432: if (wands) {
! 433: msg("Your sticks gleam.");
! 434: s_know[wh] = TRUE;
! 435: }
! 436: }
! 437: when S_LOCTRAP: {
! 438: struct trap *trp;
! 439:
! 440: if (ntraps > 0) {
! 441: for (trp = &traps[0]; trp < &traps[ntraps]; trp++)
! 442: trp->tr_flags |= ISFOUND;
! 443: look(FALSE);
! 444: msg("You now recognize pitfalls.");
! 445: s_know[S_LOCTRAP] = TRUE;
! 446: }
! 447: }
! 448: otherwise:
! 449: msg("What a puzzling scroll!");
! 450: return;
! 451: }
! 452: look(TRUE);
! 453: nochange = FALSE;
! 454: if (s_know[wh] && s_guess[wh]) {
! 455: free(s_guess[wh]);
! 456: s_guess[wh] = NULL;
! 457: }
! 458: else if (!s_know[wh] && s_guess[wh] == NULL) {
! 459: strcpy(buf, s_names[wh]);
! 460: msg(callit);
! 461: if (get_str(buf, cw) == NORM) {
! 462: s_guess[wh] = new(strlen(buf) + 1);
! 463: strcpy(s_guess[wh], buf);
! 464: }
! 465: }
! 466: }
CVSweb