Annotation of researchv10no/games/rogue/misc.c, revision 1.1

1.1     ! root        1: #include <curses.h>
        !             2: #include "rogue.h"
        !             3: #include <ctype.h>
        !             4: 
        !             5: /*
        !             6:  * all sorts of miscellaneous routines
        !             7:  *
        !             8:  * @(#)misc.c  3.13 (Berkeley) 6/15/81
        !             9:  */
        !            10: 
        !            11: /*
        !            12:  * tr_name:
        !            13:  *     print the name of a trap
        !            14:  */
        !            15: 
        !            16: char *
        !            17: tr_name(ch)
        !            18: char ch;
        !            19: {
        !            20:     register char *s;
        !            21: 
        !            22:     switch (ch)
        !            23:     {
        !            24:        when TRAPDOOR:
        !            25:            s = terse ? "A trapdoor." : "You found a trapdoor.";
        !            26:        when BEARTRAP:
        !            27:            s = terse ? "A beartrap." : "You found a beartrap.";
        !            28:        when SLEEPTRAP:
        !            29:            s = terse ? "A sleeping gas trap.":"You found a sleeping gas trap.";
        !            30:        when ARROWTRAP:
        !            31:            s = terse ? "An arrow trap." : "You found an arrow trap.";
        !            32:        when TELTRAP:
        !            33:            s = terse ? "A teleport trap." : "You found a teleport trap.";
        !            34:        when DARTTRAP:
        !            35:            s = terse ? "A dart trap." : "You found a poison dart trap.";
        !            36:     }
        !            37:     return s;
        !            38: }
        !            39: 
        !            40: /*
        !            41:  * Look:
        !            42:  *     A quick glance all around the player
        !            43:  */
        !            44: 
        !            45: look(wakeup)
        !            46: bool wakeup;
        !            47: {
        !            48:     register int x, y;
        !            49:     register char ch;
        !            50:     register int oldx, oldy;
        !            51:     register bool inpass;
        !            52:     register int passcount = 0;
        !            53:     register struct room *rp;
        !            54:     register int ey, ex;
        !            55: 
        !            56:     getyx(cw, oldy, oldx);
        !            57:     if (oldrp != NULL && (oldrp->r_flags & ISDARK) && off(player, ISBLIND))
        !            58:     {
        !            59:        for (x = oldpos.x - 1; x <= oldpos.x + 1; x++)
        !            60:            for (y = oldpos.y - 1; y <= oldpos.y + 1; y++)
        !            61:                if ((y != hero.y || x != hero.x) && show(y, x) == FLOOR)
        !            62:                    mvwaddch(cw, y, x, ' ');
        !            63:     }
        !            64:     inpass = ((rp = roomin(&hero)) == NULL);
        !            65:     ey = hero.y + 1;
        !            66:     ex = hero.x + 1;
        !            67:     for (x = hero.x - 1; x <= ex; x++)
        !            68:        if (x >= 0 && x < COLS) for (y = hero.y - 1; y <= ey; y++)
        !            69:        {
        !            70:            if (y <= 0 || y >= LINES - 1)
        !            71:                continue;
        !            72:            if (isupper(mvwinch(mw, y, x)))
        !            73:            {
        !            74:                register struct linked_list *it;
        !            75:                register struct thing *tp;
        !            76: 
        !            77:                if (wakeup)
        !            78:                    it = wake_monster(y, x);
        !            79:                else
        !            80:                    it = find_mons(y, x);
        !            81:                tp = (struct thing *) ldata(it);
        !            82:                if ((tp->t_oldch = mvinch(y, x)) == TRAP)
        !            83:                    tp->t_oldch =
        !            84:                        (trap_at(y,x)->tr_flags&ISFOUND) ? TRAP : FLOOR;
        !            85:                if (tp->t_oldch == FLOOR && (rp->r_flags & ISDARK)
        !            86:                    && off(player, ISBLIND))
        !            87:                        tp->t_oldch = ' ';
        !            88:            }
        !            89:            /*
        !            90:             * Secret doors show as walls
        !            91:             */
        !            92:            if ((ch = show(y, x)) == SECRETDOOR)
        !            93:                ch = secretdoor(y, x);
        !            94:            /*
        !            95:             * Don't show room walls if he is in a passage
        !            96:             */
        !            97:            if (off(player, ISBLIND))
        !            98:            {
        !            99:                if (y == hero.y && x == hero.x
        !           100:                 || (inpass && (ch == '-' || ch == '|')))
        !           101:                        continue;
        !           102:            }
        !           103:            else if (y != hero.y || x != hero.x)
        !           104:                continue;
        !           105:            wmove(cw, y, x);
        !           106:            waddch(cw, ch);
        !           107:            if (door_stop && !firstmove && running)
        !           108:            {
        !           109:                switch (runch)
        !           110:                {
        !           111:                    when 'h':
        !           112:                        if (x == ex)
        !           113:                            continue;
        !           114:                    when 'j':
        !           115:                        if (y == hero.y - 1)
        !           116:                            continue;
        !           117:                    when 'k':
        !           118:                        if (y == ey)
        !           119:                            continue;
        !           120:                    when 'l':
        !           121:                        if (x == hero.x - 1)
        !           122:                            continue;
        !           123:                    when 'y':
        !           124:                        if ((x + y) - (hero.x + hero.y) >= 1)
        !           125:                            continue;
        !           126:                    when 'u':
        !           127:                        if ((y - x) - (hero.y - hero.x) >= 1)
        !           128:                            continue;
        !           129:                    when 'n':
        !           130:                        if ((x + y) - (hero.x + hero.y) <= -1)
        !           131:                            continue;
        !           132:                    when 'b':
        !           133:                        if ((y - x) - (hero.y - hero.x) <= -1)
        !           134:                            continue;
        !           135:                }
        !           136:                switch (ch)
        !           137:                {
        !           138:                    case DOOR:
        !           139:                        if (x == hero.x || y == hero.y)
        !           140:                            running = FALSE;
        !           141:                        break;
        !           142:                    case PASSAGE:
        !           143:                        if (x == hero.x || y == hero.y)
        !           144:                            passcount++;
        !           145:                        break;
        !           146:                    case FLOOR:
        !           147:                    case '|':
        !           148:                    case '-':
        !           149:                    case ' ':
        !           150:                        break;
        !           151:                    default:
        !           152:                        running = FALSE;
        !           153:                        break;
        !           154:                }
        !           155:            }
        !           156:        }
        !           157:     if (door_stop && !firstmove && passcount > 1)
        !           158:        running = FALSE;
        !           159:     mvwaddch(cw, hero.y, hero.x, PLAYER);
        !           160:     wmove(cw, oldy, oldx);
        !           161:     oldpos = hero;
        !           162:     oldrp = rp;
        !           163: }
        !           164: 
        !           165: /*
        !           166:  * secret_door:
        !           167:  *     Figure out what a secret door looks like.
        !           168:  */
        !           169: 
        !           170: secretdoor(y, x)
        !           171: register int y, x;
        !           172: {
        !           173:     register int i;
        !           174:     register struct room *rp;
        !           175:     register coord *cpp;
        !           176:     static coord cp;
        !           177: 
        !           178:     cp.y = y;
        !           179:     cp.x = x;
        !           180:     cpp = &cp;
        !           181:     for (rp = rooms, i = 0; i < MAXROOMS; rp++, i++)
        !           182:        if (inroom(rp, cpp))
        !           183:            if (y == rp->r_pos.y || y == rp->r_pos.y + rp->r_max.y - 1)
        !           184:                return('-');
        !           185:            else
        !           186:                return('|');
        !           187: 
        !           188:     return('p');
        !           189: }
        !           190: 
        !           191: /*
        !           192:  * find_obj:
        !           193:  *     find the unclaimed object at y, x
        !           194:  */
        !           195: 
        !           196: struct linked_list *
        !           197: find_obj(y, x)
        !           198: register int y;
        !           199: int x;
        !           200: {
        !           201:     register struct linked_list *obj;
        !           202:     register struct object *op;
        !           203: 
        !           204:     for (obj = lvl_obj; obj != NULL; obj = next(obj))
        !           205:     {
        !           206:        op = (struct object *) ldata(obj);
        !           207:        if (op->o_pos.y == y && op->o_pos.x == x)
        !           208:                return obj;
        !           209:     }
        !           210:     debug(sprintf(prbuf, "Non-object %d,%d", y, x));
        !           211:     return NULL;
        !           212: }
        !           213: 
        !           214: /*
        !           215:  * eat:
        !           216:  *     She wants to eat something, so let her try
        !           217:  */
        !           218: 
        !           219: eat()
        !           220: {
        !           221:     register struct linked_list *item;
        !           222:     register struct object *obj;
        !           223: 
        !           224:     if ((item = get_item("eat", FOOD)) == NULL)
        !           225:        return;
        !           226:     obj = (struct object *) ldata(item);
        !           227:     if (obj->o_type != FOOD)
        !           228:     {
        !           229:        if (!terse)
        !           230:            msg("Ugh, you would get ill if you ate that.");
        !           231:        else
        !           232:            msg("That's Inedible!");
        !           233:        return;
        !           234:     }
        !           235:     inpack--;
        !           236:     if (--obj->o_count < 1)
        !           237:     {
        !           238:        detach(pack, item);
        !           239:        discard(item);
        !           240:     }
        !           241:     if (obj->o_which == 1)
        !           242:        msg("My, that was a yummy %s", fruit);
        !           243:     else
        !           244:        if (rnd(100) > 70)
        !           245:        {
        !           246:            msg("Yuk, this food tastes awful");
        !           247:            pstats.s_exp++;
        !           248:            check_level();
        !           249:        }
        !           250:        else
        !           251:            msg("Yum, that tasted good");
        !           252:     if ((food_left += HUNGERTIME + rnd(400) - 200) > STOMACHSIZE)
        !           253:        food_left = STOMACHSIZE;
        !           254:     hungry_state = 0;
        !           255:     if (obj == cur_weapon)
        !           256:        cur_weapon = NULL;
        !           257: }
        !           258: 
        !           259: /*
        !           260:  * Used to modify the playes strength
        !           261:  * it keeps track of the highest it has been, just in case
        !           262:  */
        !           263: 
        !           264: chg_str(amt)
        !           265: register int amt;
        !           266: {
        !           267:     if (amt == 0)
        !           268:        return;
        !           269:     if (amt > 0)
        !           270:     {
        !           271:        while (amt--)
        !           272:        {
        !           273:            if (pstats.s_str.st_str < 18)
        !           274:                pstats.s_str.st_str++;
        !           275:            else if (pstats.s_str.st_add == 0)
        !           276:                pstats.s_str.st_add = rnd(50) + 1;
        !           277:            else if (pstats.s_str.st_add <= 50)
        !           278:                pstats.s_str.st_add = 51 + rnd(24);
        !           279:            else if (pstats.s_str.st_add <= 75)
        !           280:                pstats.s_str.st_add = 76 + rnd(14);
        !           281:            else if (pstats.s_str.st_add <= 90)
        !           282:                pstats.s_str.st_add = 91;
        !           283:            else if (pstats.s_str.st_add < 100)
        !           284:                pstats.s_str.st_add++;
        !           285:        }
        !           286:        if (pstats.s_str.st_str > max_stats.s_str.st_str ||
        !           287:            (pstats.s_str.st_str == 18 &&
        !           288:             pstats.s_str.st_add > max_stats.s_str.st_add))
        !           289:                max_stats.s_str = pstats.s_str;
        !           290:     }
        !           291:     else
        !           292:     {
        !           293:        while (amt++)
        !           294:        {
        !           295:            if (pstats.s_str.st_str < 18 || pstats.s_str.st_add == 0)
        !           296:                pstats.s_str.st_str--;
        !           297:            else if (pstats.s_str.st_add < 51)
        !           298:                pstats.s_str.st_add = 0;
        !           299:            else if (pstats.s_str.st_add < 76)
        !           300:                pstats.s_str.st_add = 1 + rnd(50);
        !           301:            else if (pstats.s_str.st_add < 91)
        !           302:                pstats.s_str.st_add = 51 + rnd(25);
        !           303:            else if (pstats.s_str.st_add < 100)
        !           304:                pstats.s_str.st_add = 76 + rnd(14);
        !           305:            else
        !           306:                pstats.s_str.st_add = 91 + rnd(8);
        !           307:        }
        !           308:        if (pstats.s_str.st_str < 3)
        !           309:            pstats.s_str.st_str = 3;
        !           310:     }
        !           311: }
        !           312: 
        !           313: /*
        !           314:  * add_haste:
        !           315:  *     add a haste to the player
        !           316:  */
        !           317: 
        !           318: add_haste(potion)
        !           319: bool potion;
        !           320: {
        !           321:     if (on(player, ISHASTE))
        !           322:     {
        !           323:        msg("You faint from exhaustion.");
        !           324:        no_command += rnd(8);
        !           325:        extinguish(nohaste);
        !           326:     }
        !           327:     else
        !           328:     {
        !           329:        player.t_flags |= ISHASTE;
        !           330:        if (potion)
        !           331:            fuse(nohaste, 0, rnd(4)+4, AFTER);
        !           332:     }
        !           333: }
        !           334: 
        !           335: /*
        !           336:  * aggravate:
        !           337:  *     aggravate all the monsters on this level
        !           338:  */
        !           339: 
        !           340: aggravate()
        !           341: {
        !           342:     register struct linked_list *mi;
        !           343: 
        !           344:     for (mi = mlist; mi != NULL; mi = next(mi))
        !           345:        runto(&((struct thing *) ldata(mi))->t_pos, &hero);
        !           346: }
        !           347: 
        !           348: /*
        !           349:  * for printfs: if string starts with a vowel, return "n" for an "an"
        !           350:  */
        !           351: char *
        !           352: vowelstr(str)
        !           353: register char *str;
        !           354: {
        !           355:     switch (*str)
        !           356:     {
        !           357:        case 'a':
        !           358:        case 'e':
        !           359:        case 'i':
        !           360:        case 'o':
        !           361:        case 'u':
        !           362:            return "n";
        !           363:        default:
        !           364:            return "";
        !           365:     }
        !           366: }
        !           367: 
        !           368: /* 
        !           369:  * see if the object is one of the currently used items
        !           370:  */
        !           371: is_current(obj)
        !           372: register struct object *obj;
        !           373: {
        !           374:     if (obj == NULL)
        !           375:        return FALSE;
        !           376:     if (obj == cur_armor || obj == cur_weapon || obj == cur_ring[LEFT]
        !           377:        || obj == cur_ring[RIGHT])
        !           378:     {
        !           379:        msg(terse ? "In use." : "That's already in use.");
        !           380:        return TRUE;
        !           381:     }
        !           382:     return FALSE;
        !           383: }
        !           384: 
        !           385: /*
        !           386:  * set up the direction co_ordinate for use in varios "prefix" commands
        !           387:  */
        !           388: get_dir()
        !           389: {
        !           390:     register char *prompt;
        !           391:     register bool gotit;
        !           392: 
        !           393:     if (!terse)
        !           394:        msg(prompt = "Which direction? ");
        !           395:     else
        !           396:        prompt = "Direction: ";
        !           397:     do
        !           398:     {
        !           399:        gotit = TRUE;
        !           400:        switch (readchar())
        !           401:        {
        !           402:            when 'h': case'H': delta.y =  0; delta.x = -1;
        !           403:            when 'j': case'J': delta.y =  1; delta.x =  0;
        !           404:            when 'k': case'K': delta.y = -1; delta.x =  0;
        !           405:            when 'l': case'L': delta.y =  0; delta.x =  1;
        !           406:            when 'y': case'Y': delta.y = -1; delta.x = -1;
        !           407:            when 'u': case'U': delta.y = -1; delta.x =  1;
        !           408:            when 'b': case'B': delta.y =  1; delta.x = -1;
        !           409:            when 'n': case'N': delta.y =  1; delta.x =  1;
        !           410:            when ESCAPE: return FALSE;
        !           411:            otherwise:
        !           412:                mpos = 0;
        !           413:                msg(prompt);
        !           414:                gotit = FALSE;
        !           415:        }
        !           416:     } until (gotit);
        !           417:     if (on(player, ISHUH) && rnd(100) > 80)
        !           418:        do
        !           419:        {
        !           420:            delta.y = rnd(3) - 1;
        !           421:            delta.x = rnd(3) - 1;
        !           422:        } while (delta.y == 0 && delta.x == 0);
        !           423:     mpos = 0;
        !           424:     return TRUE;
        !           425: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.