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

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

1.1     ! rubenllo    1: /*
        !             2:  * Read a scroll and let it happen
        !             3:  *
        !             4:  * @(#)scrolls.c       4.44 (Berkeley) 02/05/99
        !             5:  *
        !             6:  * Rogue: Exploring the Dungeons of Doom
        !             7:  * Copyright (C) 1980-1983, 1985, 1999 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:
        !            22: void
        !            23: read_scroll(void)
        !            24: {
        !            25:     THING *obj;
        !            26:     PLACE *pp;
        !            27:     int y, x;
        !            28:     int ch;
        !            29:     int i;
        !            30:     int discardit = FALSE;
        !            31:     struct room *cur_room;
        !            32:     THING *orig_obj;
        !            33:     coord mp;
        !            34:
        !            35:     obj = get_item("read", SCROLL);
        !            36:     if (obj == NULL)
        !            37:        return;
        !            38:     if (obj->o_type != SCROLL)
        !            39:     {
        !            40:        if (!terse)
        !            41:            msg("there is nothing on it to read");
        !            42:        else
        !            43:            msg("nothing to read");
        !            44:        return;
        !            45:     }
        !            46:     /*
        !            47:      * Calculate the effect it has on the poor guy.
        !            48:      */
        !            49:     if (obj == cur_weapon)
        !            50:        cur_weapon = NULL;
        !            51:     /*
        !            52:      * Get rid of the thing
        !            53:      */
        !            54:     discardit = (obj->o_count == 1);
        !            55:     leave_pack(obj, FALSE, FALSE);
        !            56:     orig_obj = obj;
        !            57:
        !            58:     switch (obj->o_which)
        !            59:     {
        !            60:        case S_CONFUSE:
        !            61:            /*
        !            62:             * Scroll of monster confusion.  Give him that power.
        !            63:             */
        !            64:            player.t_flags |= CANHUH;
        !            65:            msg("your hands begin to glow %s", pick_color("red"));
        !            66:        when S_ARMOR:
        !            67:            if (cur_armor != NULL)
        !            68:            {
        !            69:                cur_armor->o_arm--;
        !            70:                cur_armor->o_flags &= ~ISCURSED;
        !            71:                msg("your armor glows %s for a moment", pick_color("silver"));
        !            72:            }
        !            73:        when S_HOLD:
        !            74:            /*
        !            75:             * Hold monster scroll.  Stop all monsters within two spaces
        !            76:             * from chasing after the hero.
        !            77:             */
        !            78:
        !            79:            ch = 0;
        !            80:            for (x = hero.x - 2; x <= hero.x + 2; x++)
        !            81:                if (x >= 0 && x < NUMCOLS)
        !            82:                    for (y = hero.y - 2; y <= hero.y + 2; y++)
        !            83:                        if (y >= 0 && y <= NUMLINES - 1)
        !            84:                            if ((obj = moat(y, x)) != NULL && on(*obj, ISRUN))
        !            85:                            {
        !            86:                                obj->t_flags &= ~ISRUN;
        !            87:                                obj->t_flags |= ISHELD;
        !            88:                                ch++;
        !            89:                            }
        !            90:            if (ch)
        !            91:            {
        !            92:                addmsg("the monster");
        !            93:                if (ch > 1)
        !            94:                    addmsg("s around you");
        !            95:                addmsg(" freeze");
        !            96:                if (ch == 1)
        !            97:                    addmsg("s");
        !            98:                endmsg();
        !            99:                scr_info[S_HOLD].oi_know = TRUE;
        !           100:            }
        !           101:            else
        !           102:                msg("you feel a strange sense of loss");
        !           103:        when S_SLEEP:
        !           104:            /*
        !           105:             * Scroll which makes you fall asleep
        !           106:             */
        !           107:            scr_info[S_SLEEP].oi_know = TRUE;
        !           108:            no_command += rnd(SLEEPTIME) + 4;
        !           109:            player.t_flags &= ~ISRUN;
        !           110:            msg("you fall asleep");
        !           111:        when S_CREATE:
        !           112:            /*
        !           113:             * Create a monster:
        !           114:             * First look in a circle around him, next try his room
        !           115:             * otherwise give up
        !           116:             */
        !           117:            i = 0;
        !           118:            for (y = hero.y - 1; y <= hero.y + 1; y++)
        !           119:                for (x = hero.x - 1; x <= hero.x + 1; x++)
        !           120:                    /*
        !           121:                     * Don't put a monster in top of the player.
        !           122:                     */
        !           123:                    if (y == hero.y && x == hero.x)
        !           124:                        continue;
        !           125:                    /*
        !           126:                     * Or anything else nasty
        !           127:                     * Also avoid a xeroc which is disguised as scroll
        !           128:                     */
        !           129:                    else if (moat(y, x) == NULL && step_ok(ch = winat(y, x)))
        !           130:                    {
        !           131:                        if (ch == SCROLL
        !           132:                            && find_obj(y, x)->o_which == S_SCARE)
        !           133:                                continue;
        !           134:                        else if (rnd(++i) == 0)
        !           135:                        {
        !           136:                            mp.y = y;
        !           137:                            mp.x = x;
        !           138:                        }
        !           139:                    }
        !           140:            if (i == 0)
        !           141:                msg("you hear a faint cry of anguish in the distance");
        !           142:            else
        !           143:            {
        !           144:                obj = new_item();
        !           145:                new_monster(obj, randmonster(FALSE), &mp);
        !           146:            }
        !           147:        when S_ID_POTION:
        !           148:        case S_ID_SCROLL:
        !           149:        case S_ID_WEAPON:
        !           150:        case S_ID_ARMOR:
        !           151:        case S_ID_R_OR_S:
        !           152:        {
        !           153:            int id_type[S_ID_R_OR_S + 1] =
        !           154:                { 0, 0, 0, 0, 0, POTION, SCROLL, WEAPON, ARMOR, R_OR_S };
        !           155:            /*
        !           156:             * Identify, let him figure something out
        !           157:             */
        !           158:            scr_info[obj->o_which].oi_know = TRUE;
        !           159:            msg("this scroll is an %s scroll", scr_info[obj->o_which].oi_name);
        !           160:            whatis(TRUE, id_type[obj->o_which]);
        !           161:        }
        !           162:        when S_MAP:
        !           163:            /*
        !           164:             * Scroll of magic mapping.
        !           165:             */
        !           166:            scr_info[S_MAP].oi_know = TRUE;
        !           167:            msg("oh, now this scroll has a map on it");
        !           168:            /*
        !           169:             * take all the things we want to keep hidden out of the window
        !           170:             */
        !           171:            for (y = 1; y < NUMLINES - 1; y++)
        !           172:                for (x = 0; x < NUMCOLS; x++)
        !           173:                {
        !           174:                    pp = INDEX(y, x);
        !           175:                    switch (ch = pp->p_ch)
        !           176:                    {
        !           177:                        case DOOR:
        !           178:                        case STAIRS:
        !           179:                            break;
        !           180:
        !           181:                        case '-':
        !           182:                        case '|':
        !           183:                            if (!(pp->p_flags & F_REAL))
        !           184:                            {
        !           185:                                ch = pp->p_ch = DOOR;
        !           186:                                pp->p_flags |= F_REAL;
        !           187:                            }
        !           188:                            break;
        !           189:
        !           190:                        case ' ':
        !           191:                            if (pp->p_flags & F_REAL)
        !           192:                                goto def;
        !           193:                            pp->p_flags |= F_REAL;
        !           194:                            ch = pp->p_ch = PASSAGE;
        !           195:                            /* FALLTHROUGH */
        !           196:
        !           197:                        case PASSAGE:
        !           198: pass:
        !           199:                            if (!(pp->p_flags & F_REAL))
        !           200:                                pp->p_ch = PASSAGE;
        !           201:                            pp->p_flags |= (F_SEEN|F_REAL);
        !           202:                            ch = PASSAGE;
        !           203:                            break;
        !           204:
        !           205:                        case FLOOR:
        !           206:                            if (pp->p_flags & F_REAL)
        !           207:                                ch = ' ';
        !           208:                            else
        !           209:                            {
        !           210:                                ch = TRAP;
        !           211:                                pp->p_ch = TRAP;
        !           212:                                pp->p_flags |= (F_SEEN|F_REAL);
        !           213:                            }
        !           214:                            break;
        !           215:
        !           216:                        default:
        !           217: def:
        !           218:                            if (pp->p_flags & F_PASS)
        !           219:                                goto pass;
        !           220:                            ch = ' ';
        !           221:                            break;
        !           222:                    }
        !           223:                    if (ch != ' ')
        !           224:                    {
        !           225:                        if ((obj = pp->p_monst) != NULL)
        !           226:                            obj->t_oldch = ch;
        !           227:                        if (obj == NULL || !on(player, SEEMONST))
        !           228:                            mvaddch(y, x, ch);
        !           229:                    }
        !           230:                }
        !           231:        when S_FDET:
        !           232:            /*
        !           233:             * Potion of gold detection
        !           234:             */
        !           235:            ch = FALSE;
        !           236:            wclear(hw);
        !           237:            for (obj = lvl_obj; obj != NULL; obj = next(obj))
        !           238:                if (obj->o_type == FOOD)
        !           239:                {
        !           240:                    ch = TRUE;
        !           241:                    wmove(hw, obj->o_pos.y, obj->o_pos.x);
        !           242:                    waddch(hw, FOOD);
        !           243:                }
        !           244:            if (ch)
        !           245:            {
        !           246:                scr_info[S_FDET].oi_know = TRUE;
        !           247:                show_win("Your nose tingles and you smell food.--More--");
        !           248:            }
        !           249:            else
        !           250:                msg("your nose tingles");
        !           251:        when S_TELEP:
        !           252:            /*
        !           253:             * Scroll of teleportation:
        !           254:             * Make him dissapear and reappear
        !           255:             */
        !           256:            {
        !           257:                cur_room = proom;
        !           258:                teleport();
        !           259:                if (cur_room != proom)
        !           260:                    scr_info[S_TELEP].oi_know = TRUE;
        !           261:            }
        !           262:        when S_ENCH:
        !           263:            if (cur_weapon == NULL || cur_weapon->o_type != WEAPON)
        !           264:                msg("you feel a strange sense of loss");
        !           265:            else
        !           266:            {
        !           267:                cur_weapon->o_flags &= ~ISCURSED;
        !           268:                if (rnd(2) == 0)
        !           269:                    cur_weapon->o_hplus++;
        !           270:                else
        !           271:                    cur_weapon->o_dplus++;
        !           272:                msg("your %s glows %s for a moment",
        !           273:                    weap_info[cur_weapon->o_which].oi_name, pick_color("blue"));
        !           274:            }
        !           275:        when S_SCARE:
        !           276:            /*
        !           277:             * Reading it is a mistake and produces laughter at her
        !           278:             * poor boo boo.
        !           279:             */
        !           280:            msg("you hear maniacal laughter in the distance");
        !           281:        when S_REMOVE:
        !           282:            uncurse(cur_armor);
        !           283:            uncurse(cur_weapon);
        !           284:            uncurse(cur_ring[LEFT]);
        !           285:            uncurse(cur_ring[RIGHT]);
        !           286:            msg(choose_str("you feel in touch with the Universal Onenes",
        !           287:                           "you feel as if somebody is watching over you"));
        !           288:        when S_AGGR:
        !           289:            /*
        !           290:             * This scroll aggravates all the monsters on the current
        !           291:             * level and sets them running towards the hero
        !           292:             */
        !           293:            aggravate();
        !           294:            msg("you hear a high pitched humming noise");
        !           295:        when S_PROTECT:
        !           296:            if (cur_armor != NULL)
        !           297:            {
        !           298:                cur_armor->o_flags |= ISPROT;
        !           299:                msg("your armor is covered by a shimmering %s shield",
        !           300:                    pick_color("gold"));
        !           301:            }
        !           302:            else
        !           303:                msg("you feel a strange sense of loss");
        !           304: #ifdef MASTER
        !           305:        otherwise:
        !           306:            msg("what a puzzling scroll!");
        !           307:            return;
        !           308: #endif
        !           309:     }
        !           310:     obj = orig_obj;
        !           311:     look(TRUE);        /* put the result of the scroll on the screen */
        !           312:     status();
        !           313:
        !           314:     call_it(&scr_info[obj->o_which]);
        !           315:
        !           316:     if (discardit)
        !           317:        discard(obj);
        !           318: }
        !           319:
        !           320: /*
        !           321:  * uncurse:
        !           322:  *     Uncurse an item
        !           323:  */
        !           324:
        !           325: void
        !           326: uncurse(THING *obj)
        !           327: {
        !           328:     if (obj != NULL)
        !           329:        obj->o_flags &= ~ISCURSED;
        !           330: }

CVSweb