Annotation of researchv10no/games/rogue/new_level.c, revision 1.1

1.1     ! root        1: #include <curses.h>
        !             2: #include "rogue.h"
        !             3: 
        !             4: /*
        !             5:  * new_level:
        !             6:  *     Dig and draw a new level
        !             7:  *
        !             8:  * @(#)new_level.c     3.7 (Berkeley) 6/2/81
        !             9:  */
        !            10: 
        !            11: new_level()
        !            12: {
        !            13:     register int rm, i;
        !            14:     register char ch;
        !            15:     coord stairs;
        !            16: 
        !            17:     if (level > max_level)
        !            18:        max_level = level;
        !            19:     wclear(cw);
        !            20:     wclear(mw);
        !            21:     clear();
        !            22:     status();
        !            23:     /*
        !            24:      * Free up the monsters on the last level
        !            25:      */
        !            26:     free_list(mlist);
        !            27:     do_rooms();                                /* Draw rooms */
        !            28:     do_passages();                     /* Draw passages */
        !            29:     no_food++;
        !            30:     put_things();                      /* Place objects (if any) */
        !            31:     /*
        !            32:      * Place the staircase down.
        !            33:      */
        !            34:     do {
        !            35:         rm = rnd_room();
        !            36:        rnd_pos(&rooms[rm], &stairs);
        !            37:     } until (winat(stairs.y, stairs.x) == FLOOR);
        !            38:     addch(STAIRS);
        !            39:     /*
        !            40:      * Place the traps
        !            41:      */
        !            42:     if (rnd(10) < level)
        !            43:     {
        !            44:        ntraps = rnd(level/4)+1;
        !            45:        if (ntraps > MAXTRAPS)
        !            46:            ntraps = MAXTRAPS;
        !            47:        i = ntraps;
        !            48:        while (i--)
        !            49:        {
        !            50:            do
        !            51:            {
        !            52:                rm = rnd_room();
        !            53:                rnd_pos(&rooms[rm], &stairs);
        !            54:            } until (winat(stairs.y, stairs.x) == FLOOR);
        !            55:            switch(rnd(6))
        !            56:            {
        !            57:                when 0: ch = TRAPDOOR;
        !            58:                when 1: ch = BEARTRAP;
        !            59:                when 2: ch = SLEEPTRAP;
        !            60:                when 3: ch = ARROWTRAP;
        !            61:                when 4: ch = TELTRAP;
        !            62:                when 5: ch = DARTTRAP;
        !            63:            }
        !            64:            addch(TRAP);
        !            65:            traps[i].tr_type = ch;
        !            66:            traps[i].tr_flags = 0;
        !            67:            traps[i].tr_pos = stairs;
        !            68:        }
        !            69:     }
        !            70:     do
        !            71:     {
        !            72:        rm = rnd_room();
        !            73:        rnd_pos(&rooms[rm], &hero);
        !            74:     }
        !            75:     until(winat(hero.y, hero.x) == FLOOR);
        !            76:     light(&hero);
        !            77:     wmove(cw, hero.y, hero.x);
        !            78:     waddch(cw, PLAYER);
        !            79: }
        !            80: 
        !            81: /*
        !            82:  * Pick a room that is really there
        !            83:  */
        !            84: 
        !            85: rnd_room()
        !            86: {
        !            87:     register int rm;
        !            88: 
        !            89:     do
        !            90:     {
        !            91:        rm = rnd(MAXROOMS);
        !            92:     } while (rooms[rm].r_flags & ISGONE);
        !            93:     return rm;
        !            94: }
        !            95: 
        !            96: /*
        !            97:  * put_things:
        !            98:  *     put potions and scrolls on this level
        !            99:  */
        !           100: 
        !           101: put_things()
        !           102: {
        !           103:     register int i;
        !           104:     register struct linked_list *item;
        !           105:     register struct object *cur;
        !           106:     register int rm;
        !           107:     coord tp;
        !           108: 
        !           109:     /*
        !           110:      * Throw away stuff left on the previous level (if anything)
        !           111:      */
        !           112:     free_list(lvl_obj);
        !           113:     /*
        !           114:      * Once you have found the amulet, the only way to get new stuff is
        !           115:      * go down into the dungeon.
        !           116:      */
        !           117:     if (amulet && level < max_level)
        !           118:        return;
        !           119:     /*
        !           120:      * Do MAXOBJ attempts to put things on a level
        !           121:      */
        !           122:     for (i = 0; i < MAXOBJ; i++)
        !           123:        if (rnd(100) < 35)
        !           124:        {
        !           125:            /*
        !           126:             * Pick a new object and link it in the list
        !           127:             */
        !           128:            item = new_thing();
        !           129:            attach(lvl_obj, item);
        !           130:            cur = (struct object *) ldata(item);
        !           131:            /*
        !           132:             * Put it somewhere
        !           133:             */
        !           134:            do {
        !           135:                rm = rnd_room();
        !           136:                rnd_pos(&rooms[rm], &tp);
        !           137:            } until (winat(tp.y, tp.x) == FLOOR);
        !           138:            mvaddch(tp.y, tp.x, cur->o_type);
        !           139:            cur->o_pos = tp;
        !           140:        }
        !           141:     /*
        !           142:      * If he is really deep in the dungeon and he hasn't found the
        !           143:      * amulet yet, put it somewhere on the ground
        !           144:      */
        !           145:     if (level > 25 && !amulet)
        !           146:     {
        !           147:        item = new_item(sizeof *cur);
        !           148:        attach(lvl_obj, item);
        !           149:        cur = (struct object *) ldata(item);
        !           150:        cur->o_hplus = cur->o_dplus = 0;
        !           151:        cur->o_damage = cur->o_hurldmg = "0d0";
        !           152:        cur->o_ac = 11;
        !           153:        cur->o_type = AMULET;
        !           154:        /*
        !           155:         * Put it somewhere
        !           156:         */
        !           157:        do {
        !           158:            rm = rnd_room();
        !           159:            rnd_pos(&rooms[rm], &tp);
        !           160:        } until (winat(tp.y, tp.x) == FLOOR);
        !           161:        mvaddch(tp.y, tp.x, cur->o_type);
        !           162:        cur->o_pos = tp;
        !           163:     }
        !           164: }

unix.superglobalmegacorp.com

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