Annotation of 43BSDReno/games/rogue/use.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Timothy C. Stoehr.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted
        !             9:  * provided that: (1) source distributions retain this entire copyright
        !            10:  * notice and comment, and (2) distributions including binaries display
        !            11:  * the following acknowledgement:  ``This product includes software
        !            12:  * developed by the University of California, Berkeley and its contributors''
        !            13:  * in the documentation or other materials provided with the distribution
        !            14:  * and in all advertising materials mentioning features or use of this
        !            15:  * software. Neither the name of the University nor the names of its
        !            16:  * contributors may be used to endorse or promote products derived
        !            17:  * from this software without specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)use.c      5.3 (Berkeley) 6/1/90";
        !            25: #endif /* not lint */
        !            26: 
        !            27: /*
        !            28:  * use.c
        !            29:  *
        !            30:  * This source herein may be modified and/or distributed by anybody who
        !            31:  * so desires, with the following restrictions:
        !            32:  *    1.)  No portion of this notice shall be removed.
        !            33:  *    2.)  Credit shall not be taken for the creation of this source.
        !            34:  *    3.)  This code is not to be traded, sold, or used for personal
        !            35:  *         gain or profit.
        !            36:  *
        !            37:  */
        !            38: 
        !            39: #include "rogue.h"
        !            40: 
        !            41: short halluc = 0;
        !            42: short blind = 0;
        !            43: short confused = 0;
        !            44: short levitate = 0;
        !            45: short haste_self = 0;
        !            46: boolean see_invisible = 0;
        !            47: short extra_hp = 0;
        !            48: boolean detect_monster = 0;
        !            49: boolean con_mon = 0;
        !            50: char *strange_feeling = "you have a strange feeling for a moment, then it passes";
        !            51: 
        !            52: extern short bear_trap;
        !            53: extern char hunger_str[];
        !            54: extern short cur_room;
        !            55: extern long level_points[];
        !            56: extern boolean being_held;
        !            57: extern char *fruit, *you_can_move_again;
        !            58: extern boolean sustain_strength;
        !            59: 
        !            60: quaff()
        !            61: {
        !            62:        short ch;
        !            63:        char buf[80];
        !            64:        object *obj;
        !            65: 
        !            66:        ch = pack_letter("quaff what?", POTION);
        !            67: 
        !            68:        if (ch == CANCEL) {
        !            69:                return;
        !            70:        }
        !            71:        if (!(obj = get_letter_object(ch))) {
        !            72:                message("no such item.", 0);
        !            73:                return;
        !            74:        }
        !            75:        if (obj->what_is != POTION) {
        !            76:                message("you can't drink that", 0);
        !            77:                return;
        !            78:        }
        !            79:        switch(obj->which_kind) {
        !            80:                case INCREASE_STRENGTH:
        !            81:                        message("you feel stronger now, what bulging muscles!",
        !            82:                        0);
        !            83:                        rogue.str_current++;
        !            84:                        if (rogue.str_current > rogue.str_max) {
        !            85:                                rogue.str_max = rogue.str_current;
        !            86:                        }
        !            87:                        break;
        !            88:                case RESTORE_STRENGTH:
        !            89:                        rogue.str_current = rogue.str_max;
        !            90:                        message("this tastes great, you feel warm all over", 0);
        !            91:                        break;
        !            92:                case HEALING:
        !            93:                        message("you begin to feel better", 0);
        !            94:                        potion_heal(0);
        !            95:                        break;
        !            96:                case EXTRA_HEALING:
        !            97:                        message("you begin to feel much better", 0);
        !            98:                        potion_heal(1);
        !            99:                        break;
        !           100:                case POISON:
        !           101:                        if (!sustain_strength) {
        !           102:                                rogue.str_current -= get_rand(1, 3);
        !           103:                                if (rogue.str_current < 1) {
        !           104:                                        rogue.str_current = 1;
        !           105:                                }
        !           106:                        }
        !           107:                        message("you feel very sick now", 0);
        !           108:                        if (halluc) {
        !           109:                                unhallucinate();
        !           110:                        }
        !           111:                        break;
        !           112:                case RAISE_LEVEL:
        !           113:                        rogue.exp_points = level_points[rogue.exp - 1];
        !           114:                        message("you suddenly feel much more skillful", 0);
        !           115:                        add_exp(1, 1);
        !           116:                        break;
        !           117:                case BLINDNESS:
        !           118:                        go_blind();
        !           119:                        break;
        !           120:                case HALLUCINATION:
        !           121:                        message("oh wow, everything seems so cosmic", 0);
        !           122:                        halluc += get_rand(500, 800);
        !           123:                        break;
        !           124:                case DETECT_MONSTER:
        !           125:                        show_monsters();
        !           126:                        if (!(level_monsters.next_monster)) {
        !           127:                                message(strange_feeling, 0);
        !           128:                        }
        !           129:                        break;
        !           130:                case DETECT_OBJECTS:
        !           131:                        if (level_objects.next_object) {
        !           132:                                if (!blind) {
        !           133:                                        show_objects();
        !           134:                                }
        !           135:                        } else {
        !           136:                                message(strange_feeling, 0);
        !           137:                        }
        !           138:                        break;
        !           139:                case CONFUSION:
        !           140:                        message((halluc ? "what a trippy feeling" :
        !           141:                        "you feel confused"), 0);
        !           142:                        cnfs();
        !           143:                        break;
        !           144:                case LEVITATION:
        !           145:                        message("you start to float in the air", 0);
        !           146:                        levitate += get_rand(15, 30);
        !           147:                        being_held = bear_trap = 0;
        !           148:                        break;
        !           149:                case HASTE_SELF:
        !           150:                        message("you feel yourself moving much faster", 0);
        !           151:                        haste_self += get_rand(11, 21);
        !           152:                        if (!(haste_self % 2)) {
        !           153:                                haste_self++;
        !           154:                        }
        !           155:                        break;
        !           156:                case SEE_INVISIBLE:
        !           157:                        sprintf(buf, "hmm, this potion tastes like %sjuice", fruit);
        !           158:                        message(buf, 0);
        !           159:                        if (blind) {
        !           160:                                unblind();
        !           161:                        }
        !           162:                        see_invisible = 1;
        !           163:                        relight();
        !           164:                        break;
        !           165:        }
        !           166:        print_stats((STAT_STRENGTH | STAT_HP));
        !           167:        if (id_potions[obj->which_kind].id_status != CALLED) {
        !           168:                id_potions[obj->which_kind].id_status = IDENTIFIED;
        !           169:        }
        !           170:        vanish(obj, 1, &rogue.pack);
        !           171: }
        !           172: 
        !           173: read_scroll()
        !           174: {
        !           175:        short ch;
        !           176:        object *obj;
        !           177:        char msg[DCOLS];
        !           178: 
        !           179:        ch = pack_letter("read what?", SCROL);
        !           180: 
        !           181:        if (ch == CANCEL) {
        !           182:                return;
        !           183:        }
        !           184:        if (!(obj = get_letter_object(ch))) {
        !           185:                message("no such item.", 0);
        !           186:                return;
        !           187:        }
        !           188:        if (obj->what_is != SCROL) {
        !           189:                message("you can't read that", 0);
        !           190:                return;
        !           191:        }
        !           192:        switch(obj->which_kind) {
        !           193:                case SCARE_MONSTER:
        !           194:                        message("you hear a maniacal laughter in the distance",
        !           195:                        0);
        !           196:                        break;
        !           197:                case HOLD_MONSTER:
        !           198:                        hold_monster();
        !           199:                        break;
        !           200:                case ENCH_WEAPON:
        !           201:                        if (rogue.weapon) {
        !           202:                                if (rogue.weapon->what_is == WEAPON) {
        !           203:                                        sprintf(msg, "your %sglow%s %sfor a moment",
        !           204:                                        name_of(rogue.weapon),
        !           205:                                        ((rogue.weapon->quantity <= 1) ? "s" : ""),
        !           206:                                        get_ench_color());
        !           207:                                        message(msg, 0);
        !           208:                                        if (coin_toss()) {
        !           209:                                                rogue.weapon->hit_enchant++;
        !           210:                                        } else {
        !           211:                                                rogue.weapon->d_enchant++;
        !           212:                                        }
        !           213:                                }
        !           214:                                rogue.weapon->is_cursed = 0;
        !           215:                        } else {
        !           216:                                message("your hands tingle", 0);
        !           217:                        }
        !           218:                        break;
        !           219:                case ENCH_ARMOR:
        !           220:                        if (rogue.armor) {
        !           221:                                sprintf(msg, "your armor glows %sfor a moment",
        !           222:                                get_ench_color());
        !           223:                                message(msg, 0);
        !           224:                                rogue.armor->d_enchant++;
        !           225:                                rogue.armor->is_cursed = 0;
        !           226:                                print_stats(STAT_ARMOR);
        !           227:                        } else {
        !           228:                                message("your skin crawls", 0);
        !           229:                        }
        !           230:                        break;
        !           231:                case IDENTIFY:
        !           232:                        message("this is a scroll of identify", 0);
        !           233:                        obj->identified = 1;
        !           234:                        id_scrolls[obj->which_kind].id_status = IDENTIFIED;
        !           235:                        idntfy();
        !           236:                        break;
        !           237:                case TELEPORT:
        !           238:                        tele();
        !           239:                        break;
        !           240:                case SLEEP:
        !           241:                        message("you fall asleep", 0);
        !           242:                        take_a_nap();
        !           243:                        break;
        !           244:                case PROTECT_ARMOR:
        !           245:                        if (rogue.armor) {
        !           246:                                message( "your armor is covered by a shimmering gold shield",0);
        !           247:                                rogue.armor->is_protected = 1;
        !           248:                                rogue.armor->is_cursed = 0;
        !           249:                        } else {
        !           250:                                message("your acne seems to have disappeared", 0);
        !           251:                        }
        !           252:                        break;
        !           253:                case REMOVE_CURSE:
        !           254:                                message((!halluc) ?
        !           255:                                        "you feel as though someone is watching over you" :
        !           256:                                        "you feel in touch with the universal oneness", 0);
        !           257:                        uncurse_all();
        !           258:                        break;
        !           259:                case CREATE_MONSTER:
        !           260:                        create_monster();
        !           261:                        break;
        !           262:                case AGGRAVATE_MONSTER:
        !           263:                        aggravate();
        !           264:                        break;
        !           265:                case MAGIC_MAPPING:
        !           266:                        message("this scroll seems to have a map on it", 0);
        !           267:                        draw_magic_map();
        !           268:                        break;
        !           269:                case CON_MON:
        !           270:                        con_mon = 1;
        !           271:                        sprintf(msg, "your hands glow %sfor a moment", get_ench_color());
        !           272:                        message(msg, 0);
        !           273:                        break;
        !           274:        }
        !           275:        if (id_scrolls[obj->which_kind].id_status != CALLED) {
        !           276:                id_scrolls[obj->which_kind].id_status = IDENTIFIED;
        !           277:        }
        !           278:        vanish(obj, (obj->which_kind != SLEEP), &rogue.pack);
        !           279: }
        !           280: 
        !           281: /* vanish() does NOT handle a quiver of weapons with more than one
        !           282:  *  arrow (or whatever) in the quiver.  It will only decrement the count.
        !           283:  */
        !           284: 
        !           285: vanish(obj, rm, pack)
        !           286: object *obj;
        !           287: short rm;
        !           288: object *pack;
        !           289: {
        !           290:        if (obj->quantity > 1) {
        !           291:                obj->quantity--;
        !           292:        } else {
        !           293:                if (obj->in_use_flags & BEING_WIELDED) {
        !           294:                        unwield(obj);
        !           295:                } else if (obj->in_use_flags & BEING_WORN) {
        !           296:                        unwear(obj);
        !           297:                } else if (obj->in_use_flags & ON_EITHER_HAND) {
        !           298:                        un_put_on(obj);
        !           299:                }
        !           300:                take_from_pack(obj, pack);
        !           301:                free_object(obj);
        !           302:        }
        !           303:        if (rm) {
        !           304:                (void) reg_move();
        !           305:        }
        !           306: }
        !           307: 
        !           308: potion_heal(extra)
        !           309: {
        !           310:        float ratio;
        !           311:        short add;
        !           312: 
        !           313:        rogue.hp_current += rogue.exp;
        !           314: 
        !           315:        ratio = ((float)rogue.hp_current) / rogue.hp_max;
        !           316: 
        !           317:        if (ratio >= 1.00) {
        !           318:                rogue.hp_max += (extra ? 2 : 1);
        !           319:                extra_hp += (extra ? 2 : 1);
        !           320:                rogue.hp_current = rogue.hp_max;
        !           321:        } else if (ratio >= 0.90) {
        !           322:                rogue.hp_max += (extra ? 1 : 0);
        !           323:                extra_hp += (extra ? 1 : 0);
        !           324:                rogue.hp_current = rogue.hp_max;
        !           325:        } else {
        !           326:                if (ratio < 0.33) {
        !           327:                        ratio = 0.33;
        !           328:                }
        !           329:                if (extra) {
        !           330:                        ratio += ratio;
        !           331:                }
        !           332:                add = (short)(ratio * ((float)rogue.hp_max - rogue.hp_current));
        !           333:                rogue.hp_current += add;
        !           334:                if (rogue.hp_current > rogue.hp_max) {
        !           335:                        rogue.hp_current = rogue.hp_max;
        !           336:                }
        !           337:        }
        !           338:        if (blind) {
        !           339:                unblind();
        !           340:        }
        !           341:        if (confused && extra) {
        !           342:                        unconfuse();
        !           343:        } else if (confused) {
        !           344:                confused = (confused / 2) + 1;
        !           345:        }
        !           346:        if (halluc && extra) {
        !           347:                unhallucinate();
        !           348:        } else if (halluc) {
        !           349:                halluc = (halluc / 2) + 1;
        !           350:        }
        !           351: }
        !           352: 
        !           353: idntfy()
        !           354: {
        !           355:        short ch;
        !           356:        object *obj;
        !           357:        struct id *id_table;
        !           358:        char desc[DCOLS];
        !           359: AGAIN:
        !           360:        ch = pack_letter("what would you like to identify?", ALL_OBJECTS);
        !           361: 
        !           362:        if (ch == CANCEL) {
        !           363:                return;
        !           364:        }
        !           365:        if (!(obj = get_letter_object(ch))) {
        !           366:                message("no such item, try again", 0);
        !           367:                message("", 0);
        !           368:                check_message();
        !           369:                goto AGAIN;
        !           370:        }
        !           371:        obj->identified = 1;
        !           372:        if (obj->what_is & (SCROL | POTION | WEAPON | ARMOR | WAND | RING)) {
        !           373:                id_table = get_id_table(obj);
        !           374:                id_table[obj->which_kind].id_status = IDENTIFIED;
        !           375:        }
        !           376:        get_desc(obj, desc);
        !           377:        message(desc, 0);
        !           378: }
        !           379: 
        !           380: eat()
        !           381: {
        !           382:        short ch;
        !           383:        short moves;
        !           384:        object *obj;
        !           385:        char buf[70];
        !           386: 
        !           387:        ch = pack_letter("eat what?", FOOD);
        !           388: 
        !           389:        if (ch == CANCEL) {
        !           390:                return;
        !           391:        }
        !           392:        if (!(obj = get_letter_object(ch))) {
        !           393:                message("no such item.", 0);
        !           394:                return;
        !           395:        }
        !           396:        if (obj->what_is != FOOD) {
        !           397:                message("you can't eat that", 0);
        !           398:                return;
        !           399:        }
        !           400:        if ((obj->which_kind == FRUIT) || rand_percent(60)) {
        !           401:                moves = get_rand(950, 1150);
        !           402:                if (obj->which_kind == RATION) {
        !           403:                        message("yum, that tasted good", 0);
        !           404:                } else {
        !           405:                        sprintf(buf, "my, that was a yummy %s", fruit);
        !           406:                        message(buf, 0);
        !           407:                }
        !           408:        } else {
        !           409:                moves = get_rand(750, 950);
        !           410:                message("yuk, that food tasted awful", 0);
        !           411:                add_exp(2, 1);
        !           412:        }
        !           413:        rogue.moves_left /= 3;
        !           414:        rogue.moves_left += moves;
        !           415:        hunger_str[0] = 0;
        !           416:        print_stats(STAT_HUNGER);
        !           417: 
        !           418:        vanish(obj, 1, &rogue.pack);
        !           419: }
        !           420: 
        !           421: hold_monster()
        !           422: {
        !           423:        short i, j;
        !           424:        short mcount = 0;
        !           425:        object *monster;
        !           426:        short row, col;
        !           427: 
        !           428:        for (i = -2; i <= 2; i++) {
        !           429:                for (j = -2; j <= 2; j++) {
        !           430:                        row = rogue.row + i;
        !           431:                        col = rogue.col + j;
        !           432:                        if ((row < MIN_ROW) || (row > (DROWS-2)) || (col < 0) ||
        !           433:                                 (col > (DCOLS-1))) {
        !           434:                                continue;
        !           435:                        }
        !           436:                        if (dungeon[row][col] & MONSTER) {
        !           437:                                monster = object_at(&level_monsters, row, col);
        !           438:                                monster->m_flags |= ASLEEP;
        !           439:                                monster->m_flags &= (~WAKENS);
        !           440:                                mcount++;
        !           441:                        }
        !           442:                }
        !           443:        }
        !           444:        if (mcount == 0) {
        !           445:                message("you feel a strange sense of loss", 0);
        !           446:        } else if (mcount == 1) {
        !           447:                message("the monster freezes", 0);
        !           448:        } else {
        !           449:                message("the monsters around you freeze", 0);
        !           450:        }
        !           451: }
        !           452: 
        !           453: tele()
        !           454: {
        !           455:        mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
        !           456: 
        !           457:        if (cur_room >= 0) {
        !           458:                darken_room(cur_room);
        !           459:        }
        !           460:        put_player(get_room_number(rogue.row, rogue.col));
        !           461:        being_held = 0;
        !           462:        bear_trap = 0;
        !           463: }
        !           464: 
        !           465: hallucinate()
        !           466: {
        !           467:        object *obj, *monster;
        !           468:        short ch;
        !           469: 
        !           470:        if (blind) return;
        !           471: 
        !           472:        obj = level_objects.next_object;
        !           473: 
        !           474:        while (obj) {
        !           475:                ch = mvinch(obj->row, obj->col);
        !           476:                if (((ch < 'A') || (ch > 'Z')) &&
        !           477:                        ((obj->row != rogue.row) || (obj->col != rogue.col)))
        !           478:                if ((ch != ' ') && (ch != '.') && (ch != '#') && (ch != '+')) {
        !           479:                        addch(gr_obj_char());
        !           480:                }
        !           481:                obj = obj->next_object;
        !           482:        }
        !           483:        monster = level_monsters.next_monster;
        !           484: 
        !           485:        while (monster) {
        !           486:                ch = mvinch(monster->row, monster->col);
        !           487:                if ((ch >= 'A') && (ch <= 'Z')) {
        !           488:                        addch(get_rand('A', 'Z'));
        !           489:                }
        !           490:                monster = monster->next_monster;
        !           491:        }
        !           492: }
        !           493: 
        !           494: unhallucinate()
        !           495: {
        !           496:        halluc = 0;
        !           497:        relight();
        !           498:        message("everything looks SO boring now", 1);
        !           499: }
        !           500: 
        !           501: unblind()
        !           502: {
        !           503:        blind = 0;
        !           504:        message("the veil of darkness lifts", 1);
        !           505:        relight();
        !           506:        if (halluc) {
        !           507:                hallucinate();
        !           508:        }
        !           509:        if (detect_monster) {
        !           510:                show_monsters();
        !           511:        }
        !           512: }
        !           513: 
        !           514: relight()
        !           515: {
        !           516:        if (cur_room == PASSAGE) {
        !           517:                light_passage(rogue.row, rogue.col);
        !           518:        } else {
        !           519:                light_up_room(cur_room);
        !           520:        }
        !           521:        mvaddch(rogue.row, rogue.col, rogue.fchar);
        !           522: }
        !           523: 
        !           524: take_a_nap()
        !           525: {
        !           526:        short i;
        !           527: 
        !           528:        i = get_rand(2, 5);
        !           529:        md_sleep(1);
        !           530: 
        !           531:        while (i--) {
        !           532:                mv_mons();
        !           533:        }
        !           534:        md_sleep(1);
        !           535:        message(you_can_move_again, 0);
        !           536: }
        !           537: 
        !           538: go_blind()
        !           539: {
        !           540:        short i, j;
        !           541: 
        !           542:        if (!blind) {
        !           543:                message("a cloak of darkness falls around you", 0);
        !           544:        }
        !           545:        blind += get_rand(500, 800);
        !           546: 
        !           547:        if (detect_monster) {
        !           548:                object *monster;
        !           549: 
        !           550:                monster = level_monsters.next_monster;
        !           551: 
        !           552:                while (monster) {
        !           553:                        mvaddch(monster->row, monster->col, monster->trail_char);
        !           554:                        monster = monster->next_monster;
        !           555:                }
        !           556:        }
        !           557:        if (cur_room >= 0) {
        !           558:                for (i = rooms[cur_room].top_row + 1;
        !           559:                         i < rooms[cur_room].bottom_row; i++) {
        !           560:                        for (j = rooms[cur_room].left_col + 1;
        !           561:                                 j < rooms[cur_room].right_col; j++) {
        !           562:                                mvaddch(i, j, ' ');
        !           563:                        }
        !           564:                }
        !           565:        }
        !           566:        mvaddch(rogue.row, rogue.col, rogue.fchar);
        !           567: }
        !           568: 
        !           569: char *
        !           570: get_ench_color()
        !           571: {
        !           572:        if (halluc) {
        !           573:                return(id_potions[get_rand(0, POTIONS-1)].title);
        !           574:        } else if (con_mon) {
        !           575:                return("red ");
        !           576:        } 
        !           577:        return("blue ");
        !           578: }
        !           579: 
        !           580: cnfs()
        !           581: {
        !           582:        confused += get_rand(12, 22);
        !           583: }
        !           584: 
        !           585: unconfuse()
        !           586: {
        !           587:        char msg[80];
        !           588: 
        !           589:        confused = 0;
        !           590:        sprintf(msg, "you feel less %s now", (halluc ? "trippy" : "confused"));
        !           591:        message(msg, 1);
        !           592: }
        !           593: 
        !           594: uncurse_all()
        !           595: {
        !           596:        object *obj;
        !           597: 
        !           598:        obj = rogue.pack.next_object;
        !           599: 
        !           600:        while (obj) {
        !           601:                obj->is_cursed = 0;
        !           602:                obj = obj->next_object;
        !           603:        }
        !           604: }

unix.superglobalmegacorp.com

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