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

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

1.1     ! rubenllo    1: /*
        !             2:  * Do anything associated with a new dungeon level
        !             3:  *
        !             4:  * @(#)new_level.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 "rogue.h"
        !            18: #include "rogue.ext"
        !            19:
        !            20: void put_things(void);
        !            21:
        !            22: /*
        !            23:  * new_level:
        !            24:  *     Dig and draw a new level
        !            25:  */
        !            26: void
        !            27: new_level(int ltype)
        !            28: {
        !            29:        register int i;
        !            30:        register char ch;
        !            31:        struct coord traploc;
        !            32:        struct room *rp;
        !            33:
        !            34:        if (level > max_level)
        !            35:                max_level = level;
        !            36:
        !            37:        wclear(cw);
        !            38:        wclear(mw);
        !            39:        clear();
        !            40:
        !            41:        isfight = FALSE;
        !            42:        levtype = ltype;
        !            43:
        !            44:        free_list(mlist);                       /* free monster list */
        !            45:
        !            46:        if (levtype == POSTLEV)
        !            47:                do_post();
        !            48:        else {
        !            49:                lev_mon();                      /* fill in monster list */
        !            50:
        !            51:                if (levtype == MAZELEV)
        !            52:                        do_maze();
        !            53:                else {                          /* normal levels */
        !            54:                        do_rooms();             /* Draw rooms */
        !            55:                        do_passages();          /* Draw passages */
        !            56:                }
        !            57:                no_food++;
        !            58:                put_things();                   /* Place objects (if any) */
        !            59:        }
        !            60:        /*
        !            61:         * Place the staircase down.
        !            62:         */
        !            63:        stairs = *rnd_pos(&rooms[rnd_room()]);
        !            64:        mvaddch(stairs.y, stairs.x, STAIRS);
        !            65:        ntraps = 0;
        !            66:
        !            67:        if (levtype == NORMLEV)
        !            68:        {
        !            69:                struct trap *trp, *maxtrp;
        !            70:
        !            71:                /* Place the traps for normal levels only */
        !            72:
        !            73:                if (rnd(10) < level)
        !            74:                {
        !            75:                        ntraps = rnd(level / 4) + 1;
        !            76:
        !            77:                        if (ntraps > MAXTRAPS)
        !            78:                                ntraps = MAXTRAPS;
        !            79:
        !            80:                        maxtrp = &traps[ntraps];
        !            81:                        for (trp = &traps[0]; trp < maxtrp; trp++)
        !            82:                        {
        !            83: again:
        !            84:                                switch(rnd(TYPETRAPS + 1))
        !            85:                                {
        !            86:                                        case 0:
        !            87:                                                if (rnd(100) > 25)
        !            88:                                                        goto again;
        !            89:                                                else
        !            90:                                                        ch = POST;
        !            91:
        !            92:                                        when 1: ch = TRAPDOOR;
        !            93:                                        when 2: ch = BEARTRAP;
        !            94:                                        when 3: ch = SLEEPTRAP;
        !            95:                                        when 4: ch = ARROWTRAP;
        !            96:                                        when 5: ch = TELTRAP;
        !            97:                                        when 6: ch = DARTTRAP;
        !            98:                                        when 7: ch = MAZETRAP;
        !            99:                                        when 8:
        !           100:                                        case 9:
        !           101:                                                if (rnd(100) > 80)
        !           102:                                                        goto again;
        !           103:                                                else
        !           104:                                                        ch = POOL;
        !           105:                                }
        !           106:                                trp->tr_flags = 0;
        !           107:                                traploc = *rnd_pos(&rooms[rnd_room()]);
        !           108:                                mvaddch(traploc.y,traploc.x,ch);
        !           109:                                trp->tr_type = ch;
        !           110:                                trp->tr_pos = traploc;
        !           111:
        !           112:                                if (ch == POOL || ch == POST)
        !           113:                                        trp->tr_flags |= ISFOUND;
        !           114:
        !           115:                                if (ch==TELTRAP && rnd(100)<20 && trp<maxtrp-1)
        !           116:                                {
        !           117:                                        struct coord newloc;
        !           118:
        !           119:                                        newloc = *rnd_pos(&rooms[rnd_room()]);
        !           120:                                        trp->tr_goto = newloc;
        !           121:                                        trp++;
        !           122:                                        trp->tr_goto = traploc;
        !           123:                                        trp->tr_type = TELTRAP;
        !           124:                                        trp->tr_pos = newloc;
        !           125:                                        mvaddch(newloc.y, newloc.x, TELTRAP);
        !           126:                                }
        !           127:                                else
        !           128:                                        trp->tr_goto = rndspot;
        !           129:                        }
        !           130:                }
        !           131:        }
        !           132:        do
        !           133:        {
        !           134:                rp = &rooms[rnd_room()];
        !           135:                hero = *rnd_pos(rp);
        !           136:        } while(levtype==MAZELEV&&DISTANCE(hero.y,hero.x,stairs.y,stairs.x)<10);
        !           137:
        !           138:        player.t_room = rp;
        !           139:        player.t_oldch = mvinch(hero.y, hero.x);
        !           140:        light(&hero);
        !           141:        mvwaddch(cw,hero.y,hero.x,PLAYER);
        !           142:        nochange = FALSE;
        !           143: }
        !           144:
        !           145:
        !           146: /*
        !           147:  * rnd_room:
        !           148:  *     Pick a room that is really there
        !           149:  */
        !           150: int
        !           151: rnd_room(void)
        !           152: {
        !           153:        register int rm;
        !           154:
        !           155:        if (levtype != NORMLEV)
        !           156:                rm = 0;
        !           157:        else
        !           158:        {
        !           159:                do {
        !           160:                        rm = rnd(MAXROOMS);
        !           161:                } while (rf_on(&rooms[rm],ISGONE));
        !           162:        }
        !           163:        return rm;
        !           164: }
        !           165:
        !           166:
        !           167: /*
        !           168:  * put_things:
        !           169:  *     put potions and scrolls on this level
        !           170:  */
        !           171:
        !           172: void
        !           173: put_things(void)
        !           174: {
        !           175:        register int i, cnt, rm;
        !           176:        struct linked_list *item;
        !           177:        struct object *cur;
        !           178:        struct coord tp;
        !           179:
        !           180:        /* Throw away stuff left on the previous level (if anything) */
        !           181:
        !           182:        free_list(lvl_obj);
        !           183:
        !           184:        /* The only way to get new stuff is to go down into the dungeon. */
        !           185:
        !           186:        if (goingup())
        !           187:                return;
        !           188:
        !           189:        /* Do MAXOBJ attempts to put things on a level */
        !           190:
        !           191:        for (i = 0; i < MAXOBJ; i++)
        !           192:        {
        !           193:                if (rnd(100) < 40)
        !           194:                {
        !           195:                        item = new_thing(FALSE, ANYTHING);
        !           196:                        attach(lvl_obj, item);
        !           197:                        cur = OBJPTR(item);
        !           198:                        cnt = 0;
        !           199:                        do {
        !           200:                                /* skip treasure rooms */
        !           201:                                rm = rnd_room();
        !           202:                                if (++cnt > 500)
        !           203:                                        break;
        !           204:                        } while(rf_on(&rooms[rm],ISTREAS) && levtype!=MAZELEV);
        !           205:
        !           206:                        tp = *rnd_pos(&rooms[rm]);
        !           207:                        mvaddch(tp.y, tp.x, cur->o_type);
        !           208:                        cur->o_pos = tp;
        !           209:                }
        !           210:        }
        !           211:        /*
        !           212:         * If he is really deep in the dungeon and he hasn't found the
        !           213:         * amulet yet, put it somewhere on the ground
        !           214:         */
        !           215:        if (level >= AMLEVEL && !amulet && rnd(100) < 70)
        !           216:        {
        !           217:                item = new_thing(FALSE, AMULET, 0);
        !           218:                attach(lvl_obj, item);
        !           219:                cur = OBJPTR(item);
        !           220:                rm = rnd_room();
        !           221:                tp = *rnd_pos(&rooms[rm]);
        !           222:                mvaddch(tp.y, tp.x, cur->o_type);
        !           223:                cur->o_pos = tp;
        !           224:        }
        !           225:
        !           226:        for (i = 0; i < MAXROOMS; i++)          /* loop through all */
        !           227:        {
        !           228:                if (rf_on(&rooms[i],ISTREAS))   /* treasure rooms */
        !           229:                {
        !           230:                        int numthgs, isfood;
        !           231:
        !           232:                        numthgs = rnd(level / 3) + 6;
        !           233:                        while (numthgs-- >= 0)
        !           234:                        {
        !           235:                                isfood = TRUE;
        !           236:                                do {
        !           237:                                        item = new_thing(TRUE, ANYTHING);
        !           238:                                        cur = OBJPTR(item);
        !           239:
        !           240:                                        /* dont create food for */
        !           241:                                        if (cur->o_type == FOOD)
        !           242:                                                discard(item);
        !           243:
        !           244:                                        /* treasure rooms */
        !           245:                                        else
        !           246:                                                isfood = FALSE;
        !           247:
        !           248:                                } while (isfood);
        !           249:
        !           250:                                attach(lvl_obj, item);
        !           251:                                tp = *rnd_pos(&rooms[i]);
        !           252:                                mvaddch(tp.y, tp.x, cur->o_type);
        !           253:                                cur->o_pos = tp;
        !           254:                        }
        !           255:                }
        !           256:        }
        !           257: }

CVSweb