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

Annotation of early-roguelike/srogue/wizard.c, Revision 1.1

1.1     ! rubenllo    1: /*
        !             2:  * Mostly wizard commands. Sometimes used by players.
        !             3:  *
        !             4:  * @(#)wizard.c        9.0     (rdk)    7/17/84
        !             5:  *
        !             6:  * Super-Rogue
        !             7:  * Copyright (C) 1984 Robert D. Kindelberger
        !             8:  * All rights reserved.
        !             9:  *
        !            10:  * Based on "Rogue: Exploring the Dungeons of Doom"
        !            11:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
        !            12:  * All rights reserved.
        !            13:  *
        !            14:  * See the file LICENSE.TXT for full copyright and licensing information.
        !            15:  */
        !            16:
        !            17: #include <stdlib.h>
        !            18: #include <ctype.h>
        !            19: #include <string.h>
        !            20: #include "rogue.h"
        !            21: #include "rogue.ext"
        !            22:
        !            23: /*
        !            24:  * whatis:
        !            25:  *     What a certain object is
        !            26:  */
        !            27: void
        !            28: whatis(struct linked_list *what)
        !            29: {
        !            30:        reg struct object *obj;
        !            31:        reg struct linked_list *item;
        !            32:        reg int wh;
        !            33:
        !            34:        if (what == NULL) {                             /* we need to ask */
        !            35:                if ((item = get_item("identify", 0)) == NULL)
        !            36:                        return;
        !            37:        }
        !            38:        else                                                    /* no need to ask */
        !            39:                item = what;
        !            40:        obj = OBJPTR(item);
        !            41:        setoflg(obj, ISKNOW);
        !            42:        wh = obj->o_which;
        !            43:        switch (obj->o_type) {
        !            44:                case SCROLL:
        !            45:                        s_know[wh] = TRUE;
        !            46:                        if (s_guess[wh]) {
        !            47:                                free(s_guess[wh]);
        !            48:                                s_guess[wh] = NULL;
        !            49:                        }
        !            50:            when POTION:
        !            51:                        p_know[wh] = TRUE;
        !            52:                        if (p_guess[wh]) {
        !            53:                                free(p_guess[wh]);
        !            54:                                p_guess[wh] = NULL;
        !            55:                        }
        !            56:                when STICK:
        !            57:                        ws_know[wh] = TRUE;
        !            58:                        if (ws_guess[wh]) {
        !            59:                                free(ws_guess[wh]);
        !            60:                        ws_guess[wh] = NULL;
        !            61:                        }
        !            62:            when RING:
        !            63:                        r_know[wh] = TRUE;
        !            64:                        if (r_guess[wh]) {
        !            65:                                free(r_guess[wh]);
        !            66:                                r_guess[wh] = NULL;
        !            67:                        }
        !            68:        }
        !            69:        if (what == NULL)
        !            70:                msg(inv_name(obj, FALSE));
        !            71: }
        !            72:
        !            73:
        !            74: /*
        !            75:  * create_obj:
        !            76:  *     Create any object for wizard or scroll (almost)
        !            77:  */
        !            78: void
        !            79: create_obj(bool fscr)
        !            80: {
        !            81:        reg struct linked_list *item;
        !            82:        reg struct object *obj;
        !            83:        reg int wh, ch, otype;
        !            84:        char newitem, newtype, msz, *oname;
        !            85:        struct magic_info *mf;
        !            86:        bool nogood = TRUE, inhw = FALSE;
        !            87:
        !            88:        if (fscr)
        !            89:                msg(" ");
        !            90:        else if (wizard) {
        !            91:                msg("Create what?%s: ", starlist);
        !            92:                ch = readchar();
        !            93:                mpos = 0;
        !            94:                if (ch == ESCAPE)
        !            95:                        return;
        !            96:                else if (ch != '*')
        !            97:                        nogood = FALSE;
        !            98:        }
        !            99:        if (nogood) {
        !           100:                inhw = TRUE;
        !           101:                wclear(hw);
        !           102:                wprintw(hw,"Item\tKey\n\n");
        !           103:                for (otype = 0; otype < NUMTHINGS; otype++) {
        !           104:                        if (otype != TYP_AMULET || wizard) {
        !           105:                                mf = &thnginfo[otype];
        !           106:                                wprintw(hw,"%s\t %c\n",things[otype].mi_name,mf->mf_show);
        !           107:                        }
        !           108:                }
        !           109:                if (wizard)
        !           110:                        waddstr(hw,"monster\t (A-z)");
        !           111:                wprintw(hw,"\n\nWhat do you want to create? ");
        !           112:                draw(hw);
        !           113:                do {
        !           114:                        ch = readchar();
        !           115:                        if (ch == ESCAPE) {
        !           116:                                after = FALSE;
        !           117:                                restscr(cw);
        !           118:                                return;
        !           119:                        }
        !           120:                        switch (ch) {
        !           121:                                case RING:              case STICK:     case POTION:
        !           122:                                case SCROLL:    case ARMOR:     case WEAPON:
        !           123:                                case FOOD:              case AMULET:
        !           124:                                        nogood = FALSE;
        !           125:                                        break;
        !           126:                                default:
        !           127:                                        if (isalpha(ch))
        !           128:                                                nogood = FALSE;
        !           129:                        }
        !           130:                } while (nogood);
        !           131:        }
        !           132:        if (isalpha(ch)) {
        !           133:                if (inhw)
        !           134:                        restscr(cw);
        !           135:                makemons(ch);           /* make monster & be done with it */
        !           136:                return;
        !           137:        }
        !           138:        otype = getindex(ch);
        !           139:        if (otype == -1 || (otype == AMULET && !wizard)) {
        !           140:                if (inhw)
        !           141:                        restscr(cw);
        !           142:                mpos = 0;
        !           143:                msg("You can't create that !!");
        !           144:                return;
        !           145:        }
        !           146:        newitem = ch;
        !           147:        mf = &thnginfo[otype];
        !           148:        oname = things[otype].mi_name;
        !           149:        msz = mf->mf_max;
        !           150:        nogood = TRUE;
        !           151:        if (msz == 1) {         /* if only one type of item */
        !           152:                ch = 'a';
        !           153:                nogood = FALSE;
        !           154:        }
        !           155:        else if (!fscr && wizard) {
        !           156:                if (!inhw) {
        !           157:                        msg("Which %s?%s: ", oname, starlist);
        !           158:                        ch = readchar();
        !           159:                        if (ch == ESCAPE)
        !           160:                                return;
        !           161:                        if (ch != '*')
        !           162:                                nogood = FALSE;
        !           163:                }
        !           164:        }
        !           165:        if (nogood) {
        !           166:                struct magic_item *wmi;
        !           167:                int ii;
        !           168:
        !           169:                mpos = 0;
        !           170:                inhw = TRUE;
        !           171:                switch(newitem) {
        !           172:                        case POTION:    wmi = &p_magic[0];
        !           173:                        when SCROLL:    wmi = &s_magic[0];
        !           174:                        when RING:              wmi = &r_magic[0];
        !           175:                        when STICK:             wmi = &ws_magic[0];
        !           176:                        when WEAPON:    wmi = &w_magic[0];
        !           177:                        otherwise:              wmi = &a_magic[0];
        !           178:                }
        !           179:                wclear(hw);
        !           180:                for (ii = 0 ; ii < msz ; ii++) {
        !           181:                        mvwaddch(hw,ii % 13,ii > 12 ? COLS/2 : 0, ii + 'a');
        !           182:                        waddstr(hw,") ");
        !           183:                        waddstr(hw,wmi->mi_name);
        !           184:                        wmi++;
        !           185:                }
        !           186:                sprintf(prbuf,"Which %s? ", oname);
        !           187:                mvwaddstr(hw,LINES - 1, 0, prbuf);
        !           188:                draw(hw);
        !           189:                do {
        !           190:                        ch = readchar();
        !           191:                        if (ch == ESCAPE) {
        !           192:                                restscr(cw);
        !           193:                                msg("");
        !           194:                                return;
        !           195:                        }
        !           196:                } while (!isalpha(ch));
        !           197:        }
        !           198:        if (inhw)                       /* restore screen if need be */
        !           199:                restscr(cw);
        !           200:
        !           201:        newtype = tolower(ch) - 'a';
        !           202:        if (newtype < 0 || newtype >= msz) {    /* if an illegal value */
        !           203:                mpos = 0;
        !           204:                after = FALSE;
        !           205:                if (inhw)
        !           206:                        restscr(cw);
        !           207:                msg("There is no such %s", oname);
        !           208:                return;
        !           209:        }
        !           210:        mpos = 0;
        !           211:        item = new_thing(FALSE, newitem, newtype);
        !           212:        obj = OBJPTR(item);
        !           213:        wh = obj->o_type;
        !           214:        if (wh == WEAPON || wh == ARMOR || wh == RING) {
        !           215:                if (fscr)                                       /* users get +3 to -3 */
        !           216:                        ch = rnd(7) - 3;
        !           217:                else {                                          /* wizard gets to choose */
        !           218:                        if (wh == RING)
        !           219:                                init_ring(obj, TRUE);
        !           220:                        else
        !           221:                                ch = getbless();
        !           222:                }
        !           223:                if (wh == WEAPON)
        !           224:                        obj->o_hplus = obj->o_dplus = ch;
        !           225:                else if (wh == ARMOR)
        !           226:                        obj->o_ac = armors[obj->o_which].a_class - ch;
        !           227:                if (ch < 0)
        !           228:                        setoflg(obj, ISCURSED);
        !           229:                else
        !           230:                        resoflg(obj, ISCURSED);
        !           231:        }
        !           232:        /* Don't let scrolls of aquirement give multiple scrolls of
        !           233:         * aquirement, or you will be able to scum for ANYTHING. */
        !           234:        if (!wizard && wh == SCROLL && obj->o_which == S_MAKEIT)
        !           235:                obj->o_count = 1;
        !           236:        mpos = 0;
        !           237:        if (fscr)
        !           238:                whatis(item);                   /* identify for aquirement scroll */
        !           239:        wh = add_pack(item, FALSE);
        !           240:        if (wh == FALSE)                        /* won't fit in pack */
        !           241:                discard(item);
        !           242: }
        !           243:
        !           244:
        !           245: /*
        !           246:  * getbless:
        !           247:  *     Get a blessing for a wizards object
        !           248:  */
        !           249: int
        !           250: getbless(void)
        !           251: {
        !           252:        int bless;
        !           253:
        !           254:        msg("Blessing: ");
        !           255:        prbuf[0] = '\0';
        !           256:        bless = get_str(prbuf, cw);
        !           257:        if (bless == NORM)
        !           258:                bless = atoi(prbuf);
        !           259:        else
        !           260:                bless = 0;
        !           261:        return bless;
        !           262: }
        !           263:
        !           264: /*
        !           265:  * makemons:
        !           266:  *     Make a monster
        !           267:  */
        !           268: bool
        !           269: makemons(int what)
        !           270: {
        !           271:        reg int x, y, oktomake = FALSE, appear = 1;
        !           272:        struct coord mp;
        !           273:
        !           274:        oktomake = FALSE;
        !           275:        for (x = hero.x - 1 ; x <= hero.x + 1 ; x++) {
        !           276:                for (y = hero.y - 1 ; y <= hero.y + 1 ; y++) {
        !           277:                        if (x != hero.x || y != hero.y) {
        !           278:                                if (step_ok(winat(y, x)) && rnd(++appear) == 0) {
        !           279:                                        mp.x = x;
        !           280:                                        mp.y = y;
        !           281:                                        oktomake = TRUE;
        !           282:                                        break;
        !           283:                                }
        !           284:                        }
        !           285:                }
        !           286:        }
        !           287:        if (oktomake) {
        !           288:                new_monster(midx(what), &mp, FALSE);
        !           289:                look(FALSE);
        !           290:        }
        !           291:        return oktomake;
        !           292: }
        !           293:
        !           294: /*
        !           295:  * telport:
        !           296:  *     Bamf the thing someplace else
        !           297:  */
        !           298: int
        !           299: teleport(struct coord spot, struct thing *th)
        !           300: {
        !           301:        reg int rm, y, x;
        !           302:        struct coord oldspot;
        !           303:        struct room *rp;
        !           304:        bool ishero;
        !           305:
        !           306:        ishero = (th == &player);
        !           307:        oldspot = th->t_pos;
        !           308:        y = th->t_pos.y;
        !           309:        x = th->t_pos.x;
        !           310:        mvwaddch(cw, y, x, th->t_oldch);
        !           311:        if (!ishero)
        !           312:                mvwaddch(mw, y, x, ' ');
        !           313:        rp = roomin(&spot);
        !           314:        if (spot.y < 0 || !step_ok(winat(spot.y, spot.x))) {
        !           315:                rp = &rooms[rnd_room()];
        !           316:                th->t_pos = *rnd_pos(rp);
        !           317:        }
        !           318:        else
        !           319:                th->t_pos = spot;
        !           320:        rm = rp - &rooms[0];
        !           321:        th->t_room = rp;
        !           322:        th->t_oldch = mvwinch(cw, th->t_pos.y, th->t_pos.x);
        !           323:        if (ishero)
        !           324:                light(&oldspot);
        !           325:        th->t_nomove = 0;
        !           326:        if (ishero) {
        !           327:                light(&hero);
        !           328:                mvwaddch(cw, hero.y, hero.x, PLAYER);
        !           329:                /*
        !           330:                 * turn off ISHELD in case teleportation was done
        !           331:                 * while fighting a Fungi or Bone Devil.
        !           332:                 */
        !           333:                if (pl_on(ISHELD))
        !           334:                        unhold('F');
        !           335:                count = 0;
        !           336:                running = FALSE;
        !           337:                flushinp();                     /* flush typeahead */
        !           338:                nochange = FALSE;
        !           339:        }
        !           340:        else
        !           341:                mvwaddch(mw, th->t_pos.y, th->t_pos.x, th->t_type);
        !           342:        return rm;
        !           343: }
        !           344:
        !           345: /*
        !           346:  * passwd:
        !           347:  *     See if user knows password
        !           348:  */
        !           349: bool
        !           350: passwd(void)
        !           351: {
        !           352:        reg char *sp, c;
        !           353:        bool passok;
        !           354:        char buf[LINLEN], *xcrypt();
        !           355:
        !           356:        msg(wizstr);
        !           357:        mpos = 0;
        !           358:        sp = buf;
        !           359:        while ((c = getchar()) != '\n' && c != '\r' && c != ESCAPE)
        !           360:        if (c == md_killchar())
        !           361:                sp = buf;
        !           362:        else if (c == md_erasechar() && sp > buf)
        !           363:                sp--;
        !           364:        else
        !           365:                *sp++ = c;
        !           366:        if (sp == buf)
        !           367:                passok = FALSE;
        !           368:        else {
        !           369:                *sp = '\0';
        !           370:                passok = (strcmp(PASSWD, xcrypt(buf, "mT")) == 0);
        !           371:        }
        !           372:        return passok;
        !           373: }

CVSweb