[BACK]Return to scrolls.c CVS log [TXT][DIR] Up to [contributed] / early-roguelike / rogue3

Annotation of early-roguelike/rogue3/scrolls.c, Revision 1.1

1.1     ! rubenllo    1:
        !             2: /*
        !             3:  * Read a scroll and let it happen
        !             4:  *
        !             5:  * @(#)scrolls.c       3.5 (Berkeley) 6/15/81
        !             6:  *
        !             7:  * Rogue: Exploring the Dungeons of Doom
        !             8:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
        !             9:  * All rights reserved.
        !            10:  *
        !            11:  * See the file LICENSE.TXT for full copyright and licensing information.
        !            12:  */
        !            13:
        !            14: #include "curses.h"
        !            15: #include <stdlib.h>
        !            16: #include <ctype.h>
        !            17: #include <string.h>
        !            18: #include "rogue.h"
        !            19:
        !            20: void
        !            21: read_scroll()
        !            22: {
        !            23:     struct object *obj;
        !            24:     struct linked_list *item;
        !            25:     struct room *rp;
        !            26:     int i,j;
        !            27:     int ch, nch;
        !            28:     struct linked_list *titem;
        !            29:     char buf[80];
        !            30:
        !            31:     item = get_item("read", SCROLL);
        !            32:     if (item == NULL)
        !            33:        return;
        !            34:     obj = (struct object *) ldata(item);
        !            35:     if (obj->o_type != SCROLL)
        !            36:     {
        !            37:        if (!terse)
        !            38:            msg("There is nothing on it to read");
        !            39:        else
        !            40:            msg("Nothing to read");
        !            41:        return;
        !            42:     }
        !            43:     msg("As you read the scroll, it vanishes.");
        !            44:     /*
        !            45:      * Calculate the effect it has on the poor guy.
        !            46:      */
        !            47:     if (obj == cur_weapon)
        !            48:        cur_weapon = NULL;
        !            49:     switch(obj->o_which)
        !            50:     {
        !            51:        case S_CONFUSE:
        !            52:            /*
        !            53:             * Scroll of monster confusion.  Give him that power.
        !            54:             */
        !            55:            msg("Your hands begin to glow red");
        !            56:            player.t_flags |= CANHUH;
        !            57:        when S_LIGHT:
        !            58:            s_know[S_LIGHT] = TRUE;
        !            59:            if ((rp = roomin(&hero)) == NULL)
        !            60:                msg("The corridor glows and then fades");
        !            61:            else
        !            62:            {
        !            63:                addmsg("The room is lit");
        !            64:                if (!terse)
        !            65:                    addmsg(" by a shimmering blue light.");
        !            66:                endmsg();
        !            67:                rp->r_flags &= ~ISDARK;
        !            68:                /*
        !            69:                 * Light the room and put the player back up
        !            70:                 */
        !            71:                light(&hero);
        !            72:                mvwaddch(cw, hero.y, hero.x, PLAYER);
        !            73:            }
        !            74:        when S_ARMOR:
        !            75:            if (cur_armor != NULL)
        !            76:            {
        !            77:                msg("Your armor glows faintly for a moment");
        !            78:                cur_armor->o_ac--;
        !            79:                cur_armor->o_flags &= ~ISCURSED;
        !            80:            }
        !            81:        when S_HOLD:
        !            82:            /*
        !            83:             * Hold monster scroll.  Stop all monsters within two spaces
        !            84:             * from chasing after the hero.
        !            85:             */
        !            86:            {
        !            87:                int x,y;
        !            88:                struct linked_list *mon;
        !            89:
        !            90:                for (x = hero.x-2; x <= hero.x+2; x++)
        !            91:                    for (y = hero.y-2; y <= hero.y+2; y++)
        !            92:                        if (y > 0 && x > 0 && isupper(mvwinch(mw, y, x)))
        !            93:                            if ((mon = find_mons(y, x)) != NULL)
        !            94:                            {
        !            95:                                struct thing *th;
        !            96:
        !            97:                                th = (struct thing *) ldata(mon);
        !            98:                                th->t_flags &= ~ISRUN;
        !            99:                                th->t_flags |= ISHELD;
        !           100:                            }
        !           101:            }
        !           102:        when S_SLEEP:
        !           103:            /*
        !           104:             * Scroll which makes you fall asleep
        !           105:             */
        !           106:            s_know[S_SLEEP] = TRUE;
        !           107:            msg("You fall asleep.");
        !           108:            no_command += 4 + rnd(SLEEPTIME);
        !           109:        when S_CREATE:
        !           110:            /*
        !           111:             * Create a monster
        !           112:             * First look in a circle around him, next try his room
        !           113:             * otherwise give up
        !           114:             */
        !           115:            {
        !           116:                int x, y;
        !           117:                int appear = 0;
        !           118:                coord mp;
        !           119:
        !           120:                /*
        !           121:                 * Search for an open place
        !           122:                 */
        !           123:                for (y = hero.y-1; y <= hero.y+1; y++)
        !           124:                    for (x = hero.x-1; x <= hero.x+1; x++)
        !           125:                    {
        !           126:                        /*
        !           127:                         * Don't put a monster in top of the player.
        !           128:                         */
        !           129:                        if (y == hero.y && x == hero.x)
        !           130:                            continue;
        !           131:                        /*
        !           132:                         * Or anything else nasty
        !           133:                         */
        !           134:                        if (step_ok(winat(y, x)))
        !           135:                        {
        !           136:                            if (rnd(++appear) == 0)
        !           137:                            {
        !           138:                                mp.y = y;
        !           139:                                mp.x = x;
        !           140:                            }
        !           141:                        }
        !           142:                    }
        !           143:                if (appear)
        !           144:                {
        !           145:                    titem = new_item(sizeof (struct thing));
        !           146:                    new_monster(titem, randmonster(FALSE), &mp);
        !           147:                }
        !           148:                else
        !           149:                    msg("You hear a faint cry of anguish in the distance.");
        !           150:            }
        !           151:        when S_IDENT:
        !           152:            /*
        !           153:             * Identify, let the rogue figure something out
        !           154:             */
        !           155:            msg("This scroll is an identify scroll");
        !           156:            s_know[S_IDENT] = TRUE;
        !           157:            whatis();
        !           158:        when S_MAP:
        !           159:            /*
        !           160:             * Scroll of magic mapping.
        !           161:             */
        !           162:            s_know[S_MAP] = TRUE;
        !           163:            msg("Oh, now this scroll has a map on it.");
        !           164:            overwrite(stdscr, hw);
        !           165:            /*
        !           166:             * Take all the things we want to keep hidden out of the window
        !           167:             */
        !           168:            for (i = 0; i < LINES; i++)
        !           169:                for (j = 0; j < COLS; j++)
        !           170:                {
        !           171:                    switch (nch = ch = mvwinch(hw, i, j))
        !           172:                    {
        !           173:                        case SECRETDOOR:
        !           174:                             nch = DOOR;
        !           175:                            mvaddch(i, j, nch);
        !           176:                        case '-':
        !           177:                        case '|':
        !           178:                        case DOOR:
        !           179:                        case PASSAGE:
        !           180:                        case ' ':
        !           181:                        case STAIRS:
        !           182:                            if (mvwinch(mw, i, j) != ' ')
        !           183:                            {
        !           184:                                struct thing *it;
        !           185:
        !           186:                                it = (struct thing *) ldata(find_mons(i, j));
        !           187:                                if ((it != NULL) && (it->t_oldch == ' '))
        !           188:                                    it->t_oldch = nch;
        !           189:                            }
        !           190:                            break;
        !           191:                        default:
        !           192:                            nch = ' ';
        !           193:                    }
        !           194:                    if (nch != ch)
        !           195:                        waddch(hw, nch);
        !           196:                }
        !           197:            /*
        !           198:             * Copy in what he has discovered
        !           199:             */
        !           200:            overlay(cw, hw);
        !           201:            /*
        !           202:             * And set up for display
        !           203:             */
        !           204:            overwrite(hw, cw);
        !           205:        when S_GFIND:
        !           206:            /*
        !           207:             * Potion of gold detection
        !           208:             */
        !           209:            {
        !           210:                int gtotal = 0;
        !           211:
        !           212:                wclear(hw);
        !           213:                for (i = 0; i < MAXROOMS; i++)
        !           214:                {
        !           215:                    gtotal += rooms[i].r_goldval;
        !           216:                    if (rooms[i].r_goldval != 0 &&
        !           217:                        mvwinch(stdscr, rooms[i].r_gold.y, rooms[i].r_gold.x)
        !           218:                        == GOLD)
        !           219:                        mvwaddch(hw,rooms[i].r_gold.y,rooms[i].r_gold.x,GOLD);
        !           220:                }
        !           221:                if (gtotal)
        !           222:                {
        !           223:                    s_know[S_GFIND] = TRUE;
        !           224:                    show_win(hw,
        !           225:                        "You begin to feel greedy and you sense gold.--More--");
        !           226:                }
        !           227:                else msg("You begin to feel a pull downward");
        !           228:            }
        !           229:        when S_TELEP:
        !           230:            /*
        !           231:             * Scroll of teleportation:
        !           232:             * Make him dissapear and reappear
        !           233:             */
        !           234:            {
        !           235:                int rm;
        !           236:                struct room *cur_room;
        !           237:
        !           238:                cur_room = roomin(&hero);
        !           239:                rm = teleport();
        !           240:                if (cur_room != &rooms[rm])
        !           241:                    s_know[S_TELEP] = TRUE;
        !           242:            }
        !           243:        when S_ENCH:
        !           244:            if (cur_weapon == NULL)
        !           245:                msg("You feel a strange sense of loss.");
        !           246:            else
        !           247:            {
        !           248:                cur_weapon->o_flags &= ~ISCURSED;
        !           249:                if (rnd(100) > 50)
        !           250:                    cur_weapon->o_hplus++;
        !           251:                else
        !           252:                    cur_weapon->o_dplus++;
        !           253:                msg("Your %s glows blue for a moment.", w_names[cur_weapon->o_which]);
        !           254:            }
        !           255:        when S_SCARE:
        !           256:            /*
        !           257:             * A monster will refuse to step on a scare monster scroll
        !           258:             * if it is dropped.  Thus reading it is a mistake and produces
        !           259:             * laughter at the poor rogue's boo boo.
        !           260:             */
        !           261:            msg("You hear maniacal laughter in the distance.");
        !           262:        when S_REMOVE:
        !           263:            if (cur_armor != NULL)
        !           264:                cur_armor->o_flags &= ~ISCURSED;
        !           265:            if (cur_weapon != NULL)
        !           266:                cur_weapon->o_flags &= ~ISCURSED;
        !           267:            if (cur_ring[LEFT] != NULL)
        !           268:                cur_ring[LEFT]->o_flags &= ~ISCURSED;
        !           269:            if (cur_ring[RIGHT] != NULL)
        !           270:                cur_ring[RIGHT]->o_flags &= ~ISCURSED;
        !           271:            msg("You feel as if somebody is watching over you.");
        !           272:        when S_AGGR:
        !           273:            /*
        !           274:             * This scroll aggravates all the monsters on the current
        !           275:             * level and sets them running towards the hero
        !           276:             */
        !           277:            aggravate();
        !           278:            msg("You hear a high pitched humming noise.");
        !           279:        when S_NOP:
        !           280:            msg("This scroll seems to be blank.");
        !           281:        when S_GENOCIDE:
        !           282:            msg("You have been granted the boon of genocide");
        !           283:            genocide();
        !           284:            s_know[S_GENOCIDE] = TRUE;
        !           285:        otherwise:
        !           286:            msg("What a puzzling scroll!");
        !           287:            return;
        !           288:     }
        !           289:     look(TRUE);        /* put the result of the scroll on the screen */
        !           290:     status();
        !           291:     if (s_know[obj->o_which] && s_guess[obj->o_which])
        !           292:     {
        !           293:        free(s_guess[obj->o_which]);
        !           294:        s_guess[obj->o_which] = NULL;
        !           295:     }
        !           296:     else if (!s_know[obj->o_which] && askme && s_guess[obj->o_which] == NULL)
        !           297:     {
        !           298:        msg(terse ? "Call it: " : "What do you want to call it? ");
        !           299:        if (get_str(buf, cw) == NORM)
        !           300:        {
        !           301:            s_guess[obj->o_which] = malloc((unsigned int) strlen(buf) + 1);
        !           302:            if (s_guess[obj->o_which] != NULL)
        !           303:                strcpy(s_guess[obj->o_which], buf);
        !           304:        }
        !           305:     }
        !           306:     /*
        !           307:      * Get rid of the thing
        !           308:      */
        !           309:     inpack--;
        !           310:     if (obj->o_count > 1)
        !           311:        obj->o_count--;
        !           312:     else
        !           313:     {
        !           314:        detach(pack, item);
        !           315:         discard(item);
        !           316:     }
        !           317: }

CVSweb