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

Annotation of early-roguelike/arogue5/command.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:  * Read and execute the user commands
                      3:  *
                      4:  * Advanced Rogue
                      5:  * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
                      6:  * All rights reserved.
                      7:  *
                      8:  * Based on "Rogue: Exploring the Dungeons of Doom"
                      9:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
                     10:  * All rights reserved.
                     11:  *
                     12:  * See the file LICENSE.TXT for full copyright and licensing information.
                     13:  */
                     14:
                     15: #include "curses.h"
                     16: #include <stdlib.h>
                     17: #include <string.h>
                     18: #include <limits.h>
                     19: #include <ctype.h>
                     20: #include <signal.h>
                     21: #include "rogue.h"
                     22: #include "mach_dep.h"
                     23:
                     24: void help(void);
                     25: void identify(void);
                     26: void d_level(void);
                     27: void u_level(void);
                     28: void shell(void);
                     29: void call(bool mark);
                     30:
                     31: /*
                     32:  * command:
                     33:  *     Process the user commands
                     34:  */
                     35:
                     36: void
                     37: command(void)
                     38: {
                     39:     register char ch;
                     40:     register int ntimes = 1;                   /* Number of player moves */
                     41:     static char countch, direction, newcount = FALSE;
                     42:     struct linked_list *item;
                     43:     bool an_after = FALSE;
                     44:
                     45:     if (on(player, ISHASTE)) {
                     46:        ntimes++;
                     47:        turns--;        /* correct for later */
                     48:     }
                     49:     if (on(player, ISSLOW) || on(player, ISDANCE)) {
                     50:        if (player.t_turn != TRUE) {
                     51:            ntimes--;
                     52:            turns++;
                     53:            an_after = TRUE;
                     54:        }
                     55:        player.t_turn ^= TRUE;
                     56:     }
                     57:
                     58:     /*
                     59:      * Let the daemons start up
                     60:      */
                     61:     do_daemons(BEFORE);
                     62:     do_fuses(BEFORE);
                     63:     while (ntimes-- > 0)
                     64:     {
                     65:        /* One more tick of the clock. */
                     66:        if ((++turns % DAYLENGTH) == 0) {
                     67:            daytime ^= TRUE;
                     68:            if (levtype == OUTSIDE) {
                     69:                if (daytime) msg("The sun rises above the horizon");
                     70:                else msg("The sun sinks below the horizon");
                     71:            }
                     72:            light(&hero);
                     73:        }
                     74:
                     75:        look(after, FALSE);
                     76:        if (!running) door_stop = FALSE;
                     77:        lastscore = purse;
                     78:        wmove(cw, hero.y, hero.x);
                     79:        if (!((running || count) && jump)) {
                     80:            status(FALSE);
                     81:            wmove(cw, hero.y, hero.x);
                     82:            draw(cw);                   /* Draw screen */
                     83:        }
                     84:        take = 0;
                     85:        after = TRUE;
                     86:        /*
                     87:         * Read command or continue run
                     88:         */
                     89:        if (!no_command)
                     90:        {
                     91:            if (running) {
                     92:                /* If in a corridor or maze, if we are at a turn with only one
                     93:                 * way to go, turn that way.
                     94:                 */
                     95:                if ((winat(hero.y, hero.x) == PASSAGE || levtype == MAZELEV) &&
                     96:                    off(player, ISHUH) && (off(player, ISBLIND))) {
                     97:                    int y, x;
                     98:                    if (getdelta(runch, &y, &x) == TRUE) {
                     99:                        corr_move(y, x);
                    100:                    }
                    101:                }
                    102:                ch = runch;
                    103:            }
                    104:            else if (count) ch = countch;
                    105:            else
                    106:            {
                    107:                ch = readchar();
                    108:                if (mpos != 0 && !running)      /* Erase message if its there */
                    109:                    msg("");
                    110:            }
                    111:        }
                    112:        else ch = '.';
                    113:        if (no_command)
                    114:        {
                    115:            if (--no_command == 0)
                    116:                msg("You can move again.");
                    117:        }
                    118:        else
                    119:        {
                    120:            /*
                    121:             * check for prefixes
                    122:             */
                    123:            if (isdigit(ch))
                    124:            {
                    125:                count = 0;
                    126:                newcount = TRUE;
                    127:                while (isdigit(ch))
                    128:                {
                    129:                    count = count * 10 + (ch - '0');
                    130:                    if (count > 255)
                    131:                        count = 255;
                    132:                    ch = readchar();
                    133:                }
                    134:                countch = ch;
                    135:                /*
                    136:                 * turn off count for commands which don't make sense
                    137:                 * to repeat
                    138:                 */
                    139:                switch (ch) {
                    140:                    case 'h': case 'j': case 'k': case 'l':
                    141:                    case 'y': case 'u': case 'b': case 'n':
                    142:                    case 'H': case 'J': case 'K': case 'L':
                    143:                    case 'Y': case 'U': case 'B': case 'N':
                    144:                    case 'q': case 'r': case 's': case 'f':
                    145:                    case 't': case 'C': case 'I': case '.':
                    146:                    case 'z': case 'p':
                    147:                        break;
                    148:                    default:
                    149:                        count = 0;
                    150:                }
                    151:            }
                    152:
                    153:            /* Save current direction */
                    154:            if (!running) /* If running, it is already saved */
                    155:            switch (ch) {
                    156:                case 'h': case 'j': case 'k': case 'l':
                    157:                case 'y': case 'u': case 'b': case 'n':
                    158:                case 'H': case 'J': case 'K': case 'L':
                    159:                case 'Y': case 'U': case 'B': case 'N':
                    160:                    runch = tolower(ch);
                    161:            }
                    162:
                    163:            /* Perform the action */
                    164:            switch (ch) {
                    165:                case 'f':
                    166:                    if (!on(player, ISBLIND))
                    167:                    {
                    168:                        door_stop = TRUE;
                    169:                        firstmove = TRUE;
                    170:                    }
                    171:                    if (count && !newcount)
                    172:                        ch = direction;
                    173:                    else
                    174:                        ch = readchar();
                    175:                    switch (ch)
                    176:                    {
                    177:                        case 'h': case 'j': case 'k': case 'l':
                    178:                        case 'y': case 'u': case 'b': case 'n':
                    179:                            ch = toupper(ch);
                    180:                    }
                    181:                    direction = ch;
                    182:            }
                    183:            newcount = FALSE;
                    184:            /*
                    185:             * execute a command
                    186:             */
                    187:            if (count && !running)
                    188:                count--;
                    189:            switch (ch)
                    190:            {
                    191:                case '!' : shell();
                    192:                when 'h' : do_move(0, -1);
                    193:                when 'j' : do_move(1, 0);
                    194:                when 'k' : do_move(-1, 0);
                    195:                when 'l' : do_move(0, 1);
                    196:                when 'y' : do_move(-1, -1);
                    197:                when 'u' : do_move(-1, 1);
                    198:                when 'b' : do_move(1, -1);
                    199:                when 'n' : do_move(1, 1);
                    200:                when 'H' : do_run('h');
                    201:                when 'J' : do_run('j');
                    202:                when 'K' : do_run('k');
                    203:                when 'L' : do_run('l');
                    204:                when 'Y' : do_run('y');
                    205:                when 'U' : do_run('u');
                    206:                when 'B' : do_run('b');
                    207:                when 'N' : do_run('n');
                    208:                when 't':
                    209:                    if((item=get_item(pack,"throw", ALL)) != NULL && get_dir())
                    210:                        missile(delta.y, delta.x, item, &player);
                    211:                    else
                    212:                        after = FALSE;
                    213:                when 'Q' : after = FALSE; quit(-1);
                    214:                when 'i' : after = FALSE; inventory(pack, ALL);
                    215:                when 'I' : after = FALSE; picky_inven();
                    216:                when 'd' : drop(NULL);
                    217:                when 'P' : grab(hero.y, hero.x);
                    218:                when 'q' : quaff(-1, 0, TRUE);
                    219:                when 'r' : read_scroll(-1, 0, TRUE);
                    220:                when 'e' : eat();
                    221:                when 'w' : wield();
                    222:                when 'W' : wear();
                    223:                when 'T' : take_off();
                    224:                when 'o' : option();
                    225:                when 'c' : call(FALSE);
                    226:                when 'm' : call(TRUE);
                    227:                when '>' : after = FALSE; d_level();
                    228:                when '<' : after = FALSE; u_level();
                    229:                when '?' : after = FALSE; help();
                    230:                when '/' : after = FALSE; identify();
                    231:                when CTRL('U') : use_mm(-1);
                    232:                when CTRL('T') :
                    233:                    if (get_dir()) steal();
                    234:                    else after = FALSE;
                    235:                when 'D' : dip_it();
                    236:                when 'G' : gsense();
                    237:                when '^' : set_trap(&player, hero.y, hero.x);
                    238:                when 's' : search(FALSE, FALSE);
                    239:                when 'z' : if (!do_zap(TRUE, 0, FALSE))
                    240:                                after=FALSE;
                    241:                when 'p' : pray();
                    242:                when 'C' : cast();
                    243:                when 'a' :
                    244:                    if (get_dir())
                    245:                        affect();
                    246:                    else after = FALSE;
                    247:                when 'v' : after = FALSE;
                    248:                           msg("Advanced Rogue Version %s.",
                    249:                                release);
                    250:                when CTRL('L') : after = FALSE; clearok(curscr, TRUE);
                    251:                                touchwin(cw); /* MMMMMMMMMM */
                    252:                when CTRL('R') : after = FALSE; msg(huh);
                    253:                when 'S' :
                    254:                    after = FALSE;
                    255:                    if (save_game())
                    256:                    {
                    257:                        wclear(cw);
                    258:                        draw(cw);
                    259:                        endwin();
                    260:                        printf("\n");
                    261:                        exit(0);
                    262:                    }
                    263:                when '.' : ;                    /* Rest command */
                    264:                when ' ' : after = FALSE;       /* Do Nothing */
                    265: #ifdef WIZARD
                    266:                when CTRL('P') :
                    267:                    after = FALSE;
                    268:                    if (wizard)
                    269:                    {
                    270:                        wizard = FALSE;
                    271:                        trader = 0;
                    272:                        msg("Not wizard any more");
                    273:                    }
                    274:                    else
                    275:                    {
                    276:                        if (waswizard || passwd())
                    277:                        {
                    278:                            msg("Welcome, oh mighty wizard.");
                    279:                            wizard = waswizard = TRUE;
                    280:                        }
                    281:                        else
                    282:                            msg("Sorry");
                    283:                    }
                    284: #endif
                    285:                when ESCAPE :   /* Escape */
                    286:                    door_stop = FALSE;
                    287:                    count = 0;
                    288:                    after = FALSE;
                    289:                when '#':
                    290:                    if (levtype == POSTLEV)             /* buy something */
                    291:                        buy_it();
                    292:                    after = FALSE;
                    293:                when '$':
                    294:                    if (levtype == POSTLEV)             /* price something */
                    295:                        price_it();
                    296:                    after = FALSE;
                    297:                when '%':
                    298:                    if (levtype == POSTLEV)             /* sell something */
                    299:                        sell_it();
                    300:                    after = FALSE;
                    301:                otherwise :
                    302:                    after = FALSE;
                    303: #ifdef WIZARD
                    304:                    if (wizard) switch (ch)
                    305:                    {
                    306:                        case 'M' : create_obj(TRUE, 0, 0);
                    307:                        when CTRL('W') : wanderer();
                    308:                        when CTRL('I') : inventory(lvl_obj, ALL);
                    309:                        when CTRL('Z') : whatis(NULL);
                    310:                        when CTRL('D') : level++; new_level(NORMLEV);
                    311:                        when CTRL('F') : overlay(stdscr,cw);
                    312:                        when CTRL('X') : overlay(mw,cw);
                    313:                        when CTRL('J') : teleport();
                    314:                        when CTRL('E') : sprintf(outstring,"food left: %d\tfood level: %d",
                    315:                                                food_left, foodlev);
                    316:                                       msg(outstring);
                    317:                        when CTRL('A') : activity();
                    318:                        when CTRL('C') :
                    319:                        {
                    320:                            int tlev;
                    321:                            prbuf[0] = '\0';
                    322:                            msg("Which level? ");
                    323:                            if(get_str(prbuf, msgw) == NORM) {
                    324:                                tlev = atoi(prbuf);
                    325:                                if(tlev < 1) {
                    326:                                    mpos = 0;
                    327:                                    msg("Illegal level.");
                    328:                                }
                    329:                                else if (tlev > 199) {
                    330:                                        levtype = MAZELEV;
                    331:                                        level = tlev - 200 + 1;
                    332:                                }
                    333:                                else if (tlev > 99) {
                    334:                                        levtype = POSTLEV;
                    335:                                        level = tlev - 100 + 1;
                    336:                                }
                    337:                                else {
                    338:                                        levtype = NORMLEV;
                    339:                                        level = tlev;
                    340:                                }
                    341:                                new_level(levtype);
                    342:                            }
                    343:                        }
                    344:                        when CTRL('N') :
                    345:                        {
                    346:                            if ((item=get_item(pack, "charge", STICK)) != NULL){
                    347:                                (OBJPTR(item))->o_charges=10000;
                    348:                            }
                    349:                        }
                    350:                        when CTRL('H') :
                    351:                        {
                    352:                            register int i;
                    353:                            register struct object *obj;
                    354:
                    355:                            for (i = 0; i < 9; i++)
                    356:                                raise_level(TRUE);
                    357:                            /*
                    358:                             * Give the rogue a sword
                    359:                             */
                    360:                            if(cur_weapon==NULL || cur_weapon->o_type!=RELIC) {
                    361:                                item = spec_item(WEAPON, TWOSWORD, 5, 5);
                    362:                                add_pack(item, TRUE, NULL);
                    363:                                cur_weapon = OBJPTR(item);
                    364:                                cur_weapon->o_flags |= (ISKNOW | ISPROT);
                    365:                            }
                    366:                            /*
                    367:                             * And his suit of armor
                    368:                             */
                    369:                            if (player.t_ctype == C_THIEF)
                    370:                                item = spec_item(ARMOR, STUDDED_LEATHER, 10, 0);
                    371:                            else
                    372:                                item = spec_item(ARMOR, PLATE_ARMOR, 7, 0);
                    373:                            obj = OBJPTR(item);
                    374:                            obj->o_flags |= (ISKNOW | ISPROT);
                    375:                            obj->o_weight = armors[PLATE_ARMOR].a_wght;
                    376:                            cur_armor = obj;
                    377:                            add_pack(item, TRUE, NULL);
                    378:                            purse += 20000;
                    379:                        }
                    380:                        otherwise :
                    381:                            msg("Illegal command '%s'.", unctrl(ch));
                    382:                            count = 0;
                    383:                    }
                    384:                    else
                    385: #endif
                    386:                    {
                    387:                        msg("Illegal command '%s'.", unctrl(ch));
                    388:                        count = 0;
                    389:                        after = FALSE;
                    390:                    }
                    391:            }
                    392:            /*
                    393:             * turn off flags if no longer needed
                    394:             */
                    395:            if (!running)
                    396:                door_stop = FALSE;
                    397:        }
                    398:        /*
                    399:         * If he ran into something to take, let him pick it up.
                    400:         * unless its a trading post
                    401:         */
                    402:        if (auto_pickup && take != 0 && levtype != POSTLEV)
                    403:            pick_up(take);
                    404:        if (!running)
                    405:            door_stop = FALSE;
                    406:
                    407:        /* If after is true, mark an_after as true so that if
                    408:         * we are hasted, the first "after" will be noted.
                    409:         * if after is FALSE then stay in this loop
                    410:         */
                    411:        if (after) an_after = TRUE;
                    412:        else ntimes++;
                    413:     }
                    414:
                    415:     /*
                    416:      * Kick off the rest if the daemons and fuses
                    417:      */
                    418:     if (an_after)
                    419:     {
                    420:        /*
                    421:         * If player is infested, take off a hit point
                    422:         */
                    423:        if (on(player, HASINFEST)) {
                    424:            if ((pstats.s_hpt -= infest_dam) <= 0) death(D_INFESTATION);
                    425:        }
                    426:        /*
                    427:         * if player has body rot then take off five hits
                    428:         */
                    429:        if (on(player, DOROT)) {
                    430:             if ((pstats.s_hpt -= 5) <= 0) death(D_ROT);
                    431:        }
                    432:        do_daemons(AFTER);
                    433:        do_fuses(AFTER);
                    434:        if (!((running || count) && jump)) look(FALSE, FALSE);
                    435:
                    436:
                    437:     }
                    438:     t_free_list(monst_dead);
                    439: }
                    440:
                    441: /*
                    442:  * quit:
                    443:  *     Have player make certain, then exit.
                    444:  */
                    445:
                    446: void
                    447: quit(int sig)
                    448: {
                    449:     NOOP(sig);
                    450:
                    451:     /*
                    452:      * Reset the signal in case we got here via an interrupt
                    453:      */
                    454:     if (signal(SIGINT, &quit) != &quit)
                    455:        mpos = 0;
                    456:     msg("Really quit? ");
                    457:     draw(cw);
                    458:     if (readchar() == 'y')
                    459:     {
                    460:        clear();
                    461:        move(LINES-1, 0);
                    462:        draw(stdscr);
                    463:        writelog(pstats.s_exp + (long) purse, CHICKEN, 0);
                    464:        score(pstats.s_exp + (long) purse, CHICKEN, 0);
                    465:        exit(0);
                    466:     }
                    467:     else
                    468:     {
                    469:        signal(SIGINT, quit);
                    470:        wmove(cw, 0, 0);
                    471:        wclrtoeol(cw);
                    472:        status(FALSE);
                    473:        draw(cw);
                    474:        mpos = 0;
                    475:        count = 0;
                    476:        running = FALSE;
                    477:     }
                    478: }
                    479:
                    480: /*
                    481:  * bugkill:
                    482:  *     killed by a program bug instead of voluntarily.
                    483:  */
                    484:
                    485: void
                    486: bugkill(int sig)
                    487: {
                    488:     signal(sig, quit); /* If we get it again, give up */
                    489:     death(D_SIGNAL);   /* Killed by a bug */
                    490: }
                    491:
                    492:
                    493: /*
                    494:  * search:
                    495:  *     Player gropes about him to find hidden things.
                    496:  */
                    497:
                    498: void
                    499: search(bool is_thief, bool door_chime)
                    500: {
                    501:     register int x, y;
                    502:     register char ch,  /* The trap or door character */
                    503:                 sch,   /* Trap or door character (as seen on screen) */
                    504:                 mch;   /* Monster, if a monster is on the trap or door */
                    505:     register struct linked_list *item;
                    506:     register struct thing *mp; /* Status on surrounding monster */
                    507:
                    508:     /*
                    509:      * Look all around the hero, if there is something hidden there,
                    510:      * give him a chance to find it.  If its found, display it.
                    511:      */
                    512:     if (on(player, ISBLIND))
                    513:        return;
                    514:     for (x = hero.x - 1; x <= hero.x + 1; x++)
                    515:        for (y = hero.y - 1; y <= hero.y + 1; y++)
                    516:        {
                    517:            if (y==hero.y && x==hero.x)
                    518:                continue;
                    519:
                    520:            /* Mch and ch will be the same unless there is a monster here */
                    521:            mch = CCHAR( winat(y, x) );
                    522:            ch = CCHAR( mvwinch(stdscr, y, x) );
                    523:            sch = CCHAR( mvwinch(cw, y, x) );   /* What's on the screen */
                    524:
                    525:            if (door_chime == FALSE && isatrap(ch)) {
                    526:                    register struct trap *tp;
                    527:
                    528:                    /* Is there a monster on the trap? */
                    529:                    if (mch != ch && (item = find_mons(y, x)) != NULL) {
                    530:                        mp = THINGPTR(item);
                    531:                        if (sch == mch) sch = mp->t_oldch;
                    532:                    }
                    533:                    else mp = NULL;
                    534:
                    535:                    /*
                    536:                     * is this one found already?
                    537:                     */
                    538:                    if (isatrap(sch))
                    539:                        continue;       /* give him chance for other traps */
                    540:                    tp = trap_at(y, x);
                    541:                    /*
                    542:                     * if the thief set it then don't display it.
                    543:                     * if its not a thief he has 50/50 shot
                    544:                     */
                    545:                    if((tp->tr_flags&ISTHIEFSET) || (!is_thief && rnd(100)>50))
                    546:                        continue;       /* give him chance for other traps */
                    547:                    tp->tr_flags |= ISFOUND;
                    548:
                    549:                    /* Let's update the screen */
                    550:                    if (mp != NULL && CCHAR(mvwinch(cw, y, x)) == mch)
                    551:                        mp->t_oldch = ch; /* Will change when monst moves */
                    552:                    else mvwaddch(cw, y, x, ch);
                    553:
                    554:                    count = 0;
                    555:                    running = FALSE;
                    556:                    msg(tr_name(tp->tr_type));
                    557:            }
                    558:            else if (ch == SECRETDOOR) {
                    559:                if (door_chime == TRUE || (!is_thief && rnd(100) < 20)) {
                    560:                    /* Is there a monster on the door? */
                    561:                    if (mch != ch && (item = find_mons(y, x)) != NULL) {
                    562:                        mp = THINGPTR(item);
                    563:
                    564:                        /* Screen will change when monster moves */
                    565:                        if (sch == mch) mp->t_oldch = ch;
                    566:                    }
                    567:                    mvaddch(y, x, DOOR);
                    568:                    count = 0;
                    569:                }
                    570:            }
                    571:        }
                    572: }
                    573:
                    574:
                    575: /*
                    576:  * help:
                    577:  *     Give single character help, or the whole mess if he wants it
                    578:  */
                    579:
                    580: void
                    581: help(void)
                    582: {
                    583:     register struct h_list *strp = helpstr;
                    584: #ifdef WIZARD
                    585:     struct h_list *wizp = wiz_help;
                    586: #endif
                    587:     register char helpch;
                    588:     register int cnt;
                    589:
                    590:     msg("Character you want help for (* for all): ");
                    591:     helpch = readchar();
                    592:     mpos = 0;
                    593:     /*
                    594:      * If its not a *, print the right help string
                    595:      * or an error if he typed a funny character.
                    596:      */
                    597:     if (helpch != '*') {
                    598:        wmove(cw, 0, 0);
                    599:        while (strp->h_ch) {
                    600:            if (strp->h_ch == helpch) {
                    601:                sprintf(outstring,"%s%s", unctrl(strp->h_ch), strp->h_desc);
                    602:                msg(outstring);
                    603:                return;
                    604:            }
                    605:            strp++;
                    606:        }
                    607: #ifdef WIZARD
                    608:        if (wizard) {
                    609:            while (wizp->h_ch) {
                    610:                if (wizp->h_ch == helpch) {
                    611:                    sprintf(outstring,"%s%s", unctrl(wizp->h_ch), wizp->h_desc);
                    612:                    msg(outstring);
                    613:                    return;
                    614:                }
                    615:                wizp++;
                    616:            }
                    617:        }
                    618: #endif
                    619:
                    620:        msg("Unknown character '%s'", unctrl(helpch));
                    621:        return;
                    622:     }
                    623:     /*
                    624:      * Here we print help for everything.
                    625:      * Then wait before we return to command mode
                    626:      */
                    627:     wclear(hw);
                    628:     cnt = 0;
                    629:     while (strp->h_ch) {
                    630:        mvwaddstr(hw, cnt % 23, cnt > 22 ? 40 : 0, unctrl(strp->h_ch));
                    631:        waddstr(hw, strp->h_desc);
                    632:        strp++;
                    633:        if (++cnt >= 46 && strp->h_ch) {
                    634:            wmove(hw, LINES-1, 0);
                    635:            wprintw(hw, morestr);
                    636:            draw(hw);
                    637:            wait_for(hw,' ');
                    638:            wclear(hw);
                    639:            cnt = 0;
                    640:        }
                    641:     }
                    642: #ifdef WIZARD
                    643:     if (wizard) {
                    644:        while (wizp->h_ch) {
                    645:            mvwaddstr(hw, cnt % 23, cnt > 22 ? 40 : 0, unctrl(wizp->h_ch));
                    646:            waddstr(hw, wizp->h_desc);
                    647:            wizp++;
                    648:            if (++cnt >= 46 && wizp->h_ch) {
                    649:                wmove(hw, LINES-1, 0);
                    650:                wprintw(hw, morestr);
                    651:                draw(hw);
                    652:                wait_for(hw,' ');
                    653:                wclear(hw);
                    654:                cnt = 0;
                    655:            }
                    656:        }
                    657:     }
                    658: #endif
                    659:     wmove(hw, LINES-1, 0);
                    660:     wprintw(hw, spacemsg);
                    661:     draw(hw);
                    662:     wait_for(hw,' ');
                    663:     wclear(hw);
                    664:     draw(hw);
                    665:     wmove(cw, 0, 0);
                    666:     wclrtoeol(cw);
                    667:     status(FALSE);
                    668:     touchwin(cw);
                    669: }
                    670: /*
                    671:  * identify:
                    672:  *     Tell the player what a certain thing is.
                    673:  */
                    674:
                    675: void
                    676: identify(void)
                    677: {
                    678:     register char ch;
                    679:     const char *str;
                    680:
                    681:     msg("What do you want identified? ");
                    682:     ch = readchar();
                    683:     mpos = 0;
                    684:     if (ch == ESCAPE)
                    685:     {
                    686:        msg("");
                    687:        return;
                    688:     }
                    689:     if (isalpha(ch))
                    690:        str = monsters[id_monst(ch)].m_name;
                    691:     else switch(ch)
                    692:     {
                    693:        case '|':
                    694:        case '-':
                    695:            str = (levtype == OUTSIDE) ? "boundary of sector"
                    696:                                       : "wall of a room";
                    697:        when GOLD:      str = "gold";
                    698:        when STAIRS :   str = (levtype == OUTSIDE) ? "entrance to a dungeon"
                    699:                                                   : "passage leading down";
                    700:        when DOOR:      str = "door";
                    701:        when FLOOR:     str = (levtype == OUTSIDE) ? "meadow" : "room floor";
                    702:        when VPLAYER:   str = "the hero of the game ---> you";
                    703:        when IPLAYER:   str = "you (but invisible)";
                    704:        when PASSAGE:   str = "passage";
                    705:        when POST:      str = "trading post";
                    706:        when POOL:      str = (levtype == OUTSIDE) ? "lake"
                    707:                                                   : "a shimmering pool";
                    708:        when TRAPDOOR:  str = "trapdoor";
                    709:        when ARROWTRAP: str = "arrow trap";
                    710:        when SLEEPTRAP: str = "sleeping gas trap";
                    711:        when BEARTRAP:  str = "bear trap";
                    712:        when TELTRAP:   str = "teleport trap";
                    713:        when DARTTRAP:  str = "dart trap";
                    714:        when MAZETRAP:  str = "entrance to a maze";
                    715:        when FOREST:    str = "forest";
                    716:        when POTION:    str = "potion";
                    717:        when SCROLL:    str = "scroll";
                    718:        when FOOD:      str = "food";
                    719:        when WEAPON:    str = "weapon";
                    720:        when ' ' :      str = "solid rock";
                    721:        when ARMOR:     str = "armor";
                    722:        when MM:        str = "miscellaneous magic";
                    723:        when RING:      str = "ring";
                    724:        when STICK:     str = "wand or staff";
                    725:        when SECRETDOOR:str = "secret door";
                    726:        when RELIC:     str = "artifact";
                    727:        otherwise:      str = "unknown character";
                    728:     }
                    729:     sprintf(outstring,"'%s' : %s", unctrl(ch), str);
                    730:     msg(outstring);
                    731: }
                    732:
                    733: /*
                    734:  * d_level:
                    735:  *     He wants to go down a level
                    736:  */
                    737:
                    738: void
                    739: d_level(void)
                    740: {
                    741:     bool no_phase=FALSE;
                    742:
                    743:
                    744:     /* If we are at a top-level trading post, we probably can't go down */
                    745:     if (levtype == POSTLEV && level == 0 && rnd(100) < 80) {
                    746:        msg("I see no way down.");
                    747:        return;
                    748:     }
                    749:
                    750:     if (winat(hero.y, hero.x) != STAIRS) {
                    751:        if (off(player, CANINWALL) ||   /* Must use stairs if can't phase */
                    752:            (levtype == OUTSIDE && rnd(100) < 90)) {
                    753:            msg("I see no way down.");
                    754:            return;
                    755:        }
                    756:
                    757:        /* Is there any dungeon left below? */
                    758:        if (level >= nfloors) {
                    759:            msg("There is only solid rock below.");
                    760:            return;
                    761:        }
                    762:
                    763:        extinguish(unphase);    /* Using phase to go down gets rid of it */
                    764:        no_phase = TRUE;
                    765:     }
                    766:
                    767:     /* Is this the bottom? */
                    768:     if (level >= nfloors) {
                    769:        msg("The stairway only goes up.");
                    770:        return;
                    771:     }
                    772:
                    773:     level++;
                    774:     new_level(NORMLEV);
                    775:     if (no_phase) unphase();
                    776: }
                    777:
                    778: /*
                    779:  * u_level:
                    780:  *     He wants to go up a level
                    781:  */
                    782:
                    783: void
                    784: u_level(void)
                    785: {
                    786:     bool no_phase = FALSE;
                    787:     register struct linked_list *item;
                    788:     struct thing *tp;
                    789:     struct object *obj;
                    790:
                    791:     if (winat(hero.y, hero.x) != STAIRS) {
                    792:        if (off(player, CANINWALL)) {   /* Must use stairs if can't phase */
                    793:            msg("I see no way up.");
                    794:            return;
                    795:        }
                    796:
                    797:        extinguish(unphase);
                    798:        no_phase = TRUE;
                    799:     }
                    800:
                    801:     if (level == 0) {
                    802:        msg("The stairway only goes down.");
                    803:        return;
                    804:     }
                    805:
                    806:     /*
                    807:      * does he have the item he was quested to get?
                    808:      */
                    809:     if (level == 1) {
                    810:        for (item = pack; item != NULL; item = next(item)) {
                    811:            obj = OBJPTR(item);
                    812:            if (obj->o_type == RELIC && obj->o_which == quest_item)
                    813:                total_winner();
                    814:        }
                    815:     }
                    816:     /*
                    817:      * check to see if he trapped a UNIQUE, If he did then put it back
                    818:      * in the monster table for next time
                    819:      */
                    820:     for (item = tlist; item != NULL; item = next(item)) {
                    821:        tp = THINGPTR(item);
                    822:        if (on(*tp, ISUNIQUE))
                    823:            monsters[tp->t_index].m_normal = TRUE;
                    824:     }
                    825:     t_free_list(tlist);        /* Monsters that fell below are long gone! */
                    826:
                    827:     if (levtype != POSTLEV) level--;
                    828:     if (level > 0) new_level(NORMLEV);
                    829:     else {
                    830:        level = -1;     /* Indicate that we are new to the outside */
                    831:        new_level(OUTSIDE);     /* Leaving the dungeon */
                    832:        msg("You emerge into the %s", daytime ? "light" : "night");
                    833:     }
                    834:
                    835:     if (no_phase) unphase();
                    836: }
                    837:
                    838: /*
                    839:  * Let him escape for a while
                    840:  */
                    841:
                    842: void
                    843: shell(void)
                    844: {
                    845:     /*
                    846:      * Set the terminal back to original mode
                    847:      */
                    848:     wclear(hw);
                    849:     wmove(hw, LINES-1, 0);
                    850:     draw(hw);
                    851:     endwin();
                    852:     in_shell = TRUE;
                    853:     fflush(stdout);
                    854:
                    855:     md_shellescape();
                    856:
                    857:     printf(retstr);
                    858:     fflush(stdout);
                    859:     nonl();
                    860:     noecho();
                    861:     raw();
                    862:     keypad(cw,1);
                    863:     in_shell = FALSE;
                    864:     wait_for(hw,'\n');
                    865:     clearok(cw, TRUE);
                    866:     touchwin(cw);
                    867:     wmove(cw,0,0);
                    868:     draw(cw);
                    869: }
                    870:
                    871: /*
                    872:  * allow a user to call a potion, scroll, or ring something
                    873:  */
                    874: void
                    875: call(bool mark)
                    876: {
                    877:     register struct object *obj;
                    878:     register struct linked_list *item;
                    879:     register char **guess = NULL, *elsewise = NULL;
                    880:     register bool *know;
                    881:
                    882:     if (mark) item = get_item(pack, "mark", ALL);
                    883:     else item = get_item(pack, "call", CALLABLE);
                    884:     /*
                    885:      * Make certain that it is somethings that we want to wear
                    886:      */
                    887:     if (item == NULL)
                    888:        return;
                    889:     obj = OBJPTR(item);
                    890:     switch (obj->o_type)
                    891:     {
                    892:        case RING:
                    893:            guess = r_guess;
                    894:            know = r_know;
                    895:            elsewise = (r_guess[obj->o_which] != NULL ?
                    896:                        r_guess[obj->o_which] : r_stones[obj->o_which]);
                    897:        when POTION:
                    898:            guess = p_guess;
                    899:            know = p_know;
                    900:            elsewise = (p_guess[obj->o_which] != NULL ?
                    901:                        p_guess[obj->o_which] : p_colors[obj->o_which]);
                    902:        when SCROLL:
                    903:            guess = s_guess;
                    904:            know = s_know;
                    905:            elsewise = (s_guess[obj->o_which] != NULL ?
                    906:                        s_guess[obj->o_which] : s_names[obj->o_which]);
                    907:        when STICK:
                    908:            guess = ws_guess;
                    909:            know = ws_know;
                    910:            elsewise = (ws_guess[obj->o_which] != NULL ?
                    911:                        ws_guess[obj->o_which] : ws_made[obj->o_which]);
                    912:        when MM:
                    913:            guess = m_guess;
                    914:            know = m_know;
                    915:            elsewise = (m_guess[obj->o_which] != NULL ?
                    916:                        m_guess[obj->o_which] : "nothing");
                    917:        otherwise:
                    918:            if (!mark) {
                    919:                msg("You can't call that anything.");
                    920:                return;
                    921:            }
                    922:            else know = (bool *) 0;
                    923:     }
                    924:     if ((obj->o_flags & ISPOST)        || (know && know[obj->o_which]) && !mark) {
                    925:        msg("That has already been identified.");
                    926:        return;
                    927:     }
                    928:     if (mark) {
                    929:        if (obj->o_mark[0]) {
                    930:            addmsg(terse ? "M" : "Was m");
                    931:            msg("arked \"%s\"", obj->o_mark);
                    932:        }
                    933:        msg(terse ? "Mark it: " : "What do you want to mark it? ");
                    934:        prbuf[0] = '\0';
                    935:     }
                    936:     else {
                    937:        addmsg(terse ? "C" : "Was c");
                    938:        msg("alled \"%s\"", elsewise);
                    939:        msg(terse ? "Call it: " : "What do you want to call it? ");
                    940:        if (guess[obj->o_which] != NULL)
                    941:            free(guess[obj->o_which]);
                    942:        strcpy(prbuf, elsewise);
                    943:     }
                    944:     if (get_str(prbuf, msgw) == NORM) {
                    945:        if (mark) {
                    946:            strncpy(obj->o_mark, prbuf, MARKLEN-1);
                    947:            obj->o_mark[MARKLEN-1] = '\0';
                    948:        }
                    949:        else {
                    950:            guess[obj->o_which] = new((unsigned int) strlen(prbuf) + 1);
                    951:            strcpy(guess[obj->o_which], prbuf);
                    952:        }
                    953:     }
                    954: }

CVSweb