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

Annotation of early-roguelike/rogue4/new_level.c, Revision 1.1

1.1     ! rubenllo    1: /*
        !             2:  * new_level:
        !             3:  *     Dig and draw a new level
        !             4:  *
        !             5:  * @(#)new_level.c     4.19 (Berkeley) 1/12/82
        !             6:  *
        !             7:  * Rogue: Exploring the Dungeons of Doom
        !             8:  * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
        !             9:  * All rights reserved.
        !            10:  *
        !            11:  * See the file LICENSE.TXT for full copyright and licensing information.
        !            12:  */
        !            13:
        !            14: #include <stdlib.h>
        !            15: #include <time.h>
        !            16: #include <curses.h>
        !            17: #include <string.h>
        !            18: #include "rogue.h"
        !            19:
        !            20: #define TREAS_ROOM 20  /* one chance in TREAS_ROOM for a treasure room */
        !            21: #define MAXTREAS 10    /* maximum number of treasures in a treasure room */
        !            22: #define MINTREAS 2     /* minimum number of treasures in a treasure room */
        !            23:
        !            24: void put_things(void);
        !            25: void treas_room(void);
        !            26:
        !            27: void
        !            28: new_level(void)
        !            29: {
        !            30:     register int rm, i;
        !            31:     register THING *tp;
        !            32:     register char *sp;
        !            33:     register THING **mp;
        !            34:     register int index;
        !            35:     coord stairs;
        !            36:
        !            37:     player.t_flags &= ~ISHELD; /* unhold when you go down just in case */
        !            38:     if (level > max_level)
        !            39:        max_level = level;
        !            40:     /*
        !            41:      * Clean things off from last level
        !            42:      */
        !            43:     clear();
        !            44:     for (sp = _level; sp < &_level[MAXCOLS*MAXLINES]; )
        !            45:        *sp++ = ' ';
        !            46:     for (sp = _flags; sp < &_flags[MAXCOLS*MAXLINES]; )
        !            47:        *sp++ = F_REAL;
        !            48:     for (mp = _monst; mp < &_monst[MAXCOLS*MAXLINES]; )
        !            49:        *mp++ = NULL;
        !            50:     clear();
        !            51:     /*
        !            52:      * Free up the monsters on the last level
        !            53:      */
        !            54:     for (tp = mlist; tp != NULL; tp = next(tp))
        !            55:        free_list(tp->t_pack);
        !            56:     free_list(mlist);
        !            57:     /*
        !            58:      * Throw away stuff left on the previous level (if anything)
        !            59:      */
        !            60:     free_list(lvl_obj);
        !            61:     do_rooms();                                /* Draw rooms */
        !            62:     do_passages();                     /* Draw passages */
        !            63:     no_food++;
        !            64:     put_things();                      /* Place objects (if any) */
        !            65:     /*
        !            66:      * Place the staircase down.
        !            67:      */
        !            68:     i = 0;
        !            69:     do {
        !            70:         rm = rnd_room();
        !            71:        rnd_pos(&rooms[rm], &stairs);
        !            72:        index = INDEX(stairs.y, stairs.x);
        !            73:        if (i++ > 100)
        !            74:        {
        !            75:            i = 0;
        !            76:            srand(md_random_seed());
        !            77:        }
        !            78:     } until (_level[index] == FLOOR);
        !            79:     _level[index] = STAIRS;
        !            80:     /*
        !            81:      * Place the traps
        !            82:      */
        !            83:     if (rnd(10) < level)
        !            84:     {
        !            85:        ntraps = rnd(level / 4) + 1;
        !            86:        if (ntraps > MAXTRAPS)
        !            87:            ntraps = MAXTRAPS;
        !            88:        i = ntraps;
        !            89:        while (i--)
        !            90:        {
        !            91:            do
        !            92:            {
        !            93:                rm = rnd_room();
        !            94:                rnd_pos(&rooms[rm], &stairs);
        !            95:                index = INDEX(stairs.y, stairs.x);
        !            96:            } until (_level[index] == FLOOR && (_flags[index] & F_REAL));
        !            97:            sp = &_flags[index];
        !            98:            *sp &= ~(F_REAL | F_TMASK);
        !            99:            *sp |= rnd(NTRAPS);
        !           100:        }
        !           101:     }
        !           102:     do
        !           103:     {
        !           104:        rm = rnd_room();
        !           105:        rnd_pos(&rooms[rm], &hero);
        !           106:        index = INDEX(hero.y, hero.x);
        !           107:     } until (_level[index] == FLOOR && (_flags[index] & F_REAL)
        !           108:        && _monst[index] == NULL);
        !           109:     enter_room(&hero);
        !           110:     move(hero.y, hero.x);
        !           111:     addch(PLAYER);
        !           112:     if (on(player, SEEMONST))
        !           113:        turn_see(FALSE);
        !           114: }
        !           115:
        !           116: /*
        !           117:  * rnd_room:
        !           118:  *     Pick a room that is really there
        !           119:  */
        !           120: int
        !           121: rnd_room(void)
        !           122: {
        !           123:     register int rm;
        !           124:
        !           125:     do
        !           126:     {
        !           127:        rm = rnd(MAXROOMS);
        !           128:     } while (rooms[rm].r_flags & ISGONE);
        !           129:     return rm;
        !           130: }
        !           131:
        !           132: /*
        !           133:  * put_things:
        !           134:  *     Put potions and scrolls on this level
        !           135:  */
        !           136: void
        !           137: put_things(void)
        !           138: {
        !           139:     register int i;
        !           140:     register THING *cur;
        !           141:     register int rm;
        !           142:     coord tp;
        !           143:
        !           144:     /*
        !           145:      * Once you have found the amulet, the only way to get new stuff is
        !           146:      * go down into the dungeon.
        !           147:      */
        !           148:     if (amulet && level < max_level)
        !           149:        return;
        !           150:     /*
        !           151:      * check for treasure rooms, and if so, put it in.
        !           152:      */
        !           153:     if (rnd(TREAS_ROOM) == 0)
        !           154:        treas_room();
        !           155:     /*
        !           156:      * Do MAXOBJ attempts to put things on a level
        !           157:      */
        !           158:     for (i = 0; i < MAXOBJ; i++)
        !           159:        if (rnd(100) < 35)
        !           160:        {
        !           161:            /*
        !           162:             * Pick a new object and link it in the list
        !           163:             */
        !           164:            cur = new_thing();
        !           165:            attach(lvl_obj, cur);
        !           166:            /*
        !           167:             * Put it somewhere
        !           168:             */
        !           169:            do {
        !           170:                rm = rnd_room();
        !           171:                rnd_pos(&rooms[rm], &tp);
        !           172:            } until (chat(tp.y, tp.x) == FLOOR);
        !           173:            chat(tp.y, tp.x) = cur->o_type;
        !           174:            cur->o_pos = tp;
        !           175:        }
        !           176:     /*
        !           177:      * If he is really deep in the dungeon and he hasn't found the
        !           178:      * amulet yet, put it somewhere on the ground
        !           179:      */
        !           180:     if (level >= AMULETLEVEL && !amulet)
        !           181:     {
        !           182:        cur = new_item();
        !           183:        attach(lvl_obj, cur);
        !           184:        cur->o_hplus = cur->o_dplus = 0;
        !           185:        strcpy(cur->o_damage,"0d0");
        !           186:        strcpy(cur->o_hurldmg,"0d0");
        !           187:        cur->o_ac = 11;
        !           188:        cur->o_type = AMULET;
        !           189:        /*
        !           190:         * Put it somewhere
        !           191:         */
        !           192:        do {
        !           193:            rm = rnd_room();
        !           194:            rnd_pos(&rooms[rm], &tp);
        !           195:        } until (winat(tp.y, tp.x) == FLOOR);
        !           196:        chat(tp.y, tp.x) = AMULET;
        !           197:        cur->o_pos = tp;
        !           198:     }
        !           199: }
        !           200:
        !           201: /*
        !           202:  * treas_room:
        !           203:  *     Add a treasure room
        !           204:  */
        !           205: #define MAXTRIES 10    /* max number of tries to put down a monster */
        !           206:
        !           207: void
        !           208: treas_room(void)
        !           209: {
        !           210:     register int nm, index;
        !           211:     register THING *tp;
        !           212:     register struct room *rp;
        !           213:     register int spots, num_monst;
        !           214:     coord mp;
        !           215:
        !           216:     rp = &rooms[rnd_room()];
        !           217:     spots = (rp->r_max.y - 2) * (rp->r_max.x - 2) - MINTREAS;
        !           218:     if (spots > (MAXTREAS - MINTREAS))
        !           219:        spots = (MAXTREAS - MINTREAS);
        !           220:     num_monst = nm = rnd(spots) + MINTREAS;
        !           221:     while (nm--)
        !           222:     {
        !           223:        do
        !           224:        {
        !           225:            rnd_pos(rp, &mp);
        !           226:            index = INDEX(mp.y, mp.x);
        !           227:        } until (_level[index] == FLOOR);
        !           228:        tp = new_thing();
        !           229:        tp->o_pos = mp;
        !           230:        attach(lvl_obj, tp);
        !           231:        _level[index] = tp->o_type;
        !           232:     }
        !           233:
        !           234:     /*
        !           235:      * fill up room with monsters from the next level down
        !           236:      */
        !           237:
        !           238:     if ((nm = rnd(spots) + MINTREAS) < num_monst + 2)
        !           239:        nm = num_monst + 2;
        !           240:     spots = (rp->r_max.y - 2) * (rp->r_max.x - 2);
        !           241:     if (nm > spots)
        !           242:        nm = spots;
        !           243:     level++;
        !           244:     while (nm--)
        !           245:     {
        !           246:        spots = 0;
        !           247:        do
        !           248:        {
        !           249:            rnd_pos(rp, &mp);
        !           250:            index = INDEX(mp.y, mp.x);
        !           251:            spots++;
        !           252:        } until (_monst[index] == NULL || spots > MAXTRIES);
        !           253:        if (_monst[index] == NULL)
        !           254:        {
        !           255:            tp = new_item();
        !           256:            new_monster(tp, randmonster(FALSE), &mp);
        !           257:            tp->t_flags |= ISMEAN;      /* no sloughers in THIS room */
        !           258:            give_pack(tp);
        !           259:        }
        !           260:     }
        !           261:     level--;
        !           262: }

CVSweb