Difference between revisions of "Source:NetHack 3.6.1/src/mkmap.c"

From NetHackWiki
Jump to navigation Jump to search
(beep boop)
 
m (beep boop)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
 
Below is the full text to '''mkmap.c''' from the [[NetHack 3.6.1 source code|source code]] of [[NetHack 3.6.1]]. To link to a particular line, write [[Source:NetHack 3.6.1/src/mkmap.c#line123|<nowiki>[[Source:NetHack 3.6.1/src/mkmap.c#line123]]</nowiki>]], for example.
 
Below is the full text to '''mkmap.c''' from the [[NetHack 3.6.1 source code|source code]] of [[NetHack 3.6.1]]. To link to a particular line, write [[Source:NetHack 3.6.1/src/mkmap.c#line123|<nowiki>[[Source:NetHack 3.6.1/src/mkmap.c#line123]]</nowiki>]], for example.
  
{{NGPL}}
+
== Top of file ==
 +
 
 
  <span id="line1">1. /* NetHack 3.6 mkmap.c $NHDT-Date: 1432512767 2015/05/25 00:12:47 $  $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */</span>
 
  <span id="line1">1. /* NetHack 3.6 mkmap.c $NHDT-Date: 1432512767 2015/05/25 00:12:47 $  $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */</span>
 
  <span id="line2">2. /* Copyright (c) J. C. Collet, M. Stephenson and D. Cohrs, 1992  */</span>
 
  <span id="line2">2. /* Copyright (c) J. C. Collet, M. Stephenson and D. Cohrs, 1992  */</span>
 
  <span id="line3">3. /* NetHack may be freely redistributed.  See license for details. */</span>
 
  <span id="line3">3. /* NetHack may be freely redistributed.  See license for details. */</span>
 +
 +
{{NGPL}}
 +
 
  <span id="line4">4. </span>
 
  <span id="line4">4. </span>
 
  <span id="line5">5. #include "hack.h"</span>
 
  <span id="line5">5. #include "hack.h"</span>
Line 30: Line 34:
 
  <span id="line26">26. static int n_loc_filled;</span>
 
  <span id="line26">26. static int n_loc_filled;</span>
 
  <span id="line27">27. </span>
 
  <span id="line27">27. </span>
 +
 +
== init_map ==
 +
 
  <span id="line28">28. STATIC_OVL void</span>
 
  <span id="line28">28. STATIC_OVL void</span>
 
  <span id="line29">29. init_map(bg_typ)</span>
 
  <span id="line29">29. init_map(bg_typ)</span>
Line 41: Line 48:
 
  <span id="line37">37. }</span>
 
  <span id="line37">37. }</span>
 
  <span id="line38">38. </span>
 
  <span id="line38">38. </span>
 +
 +
== init_fill ==
 +
 
  <span id="line39">39. STATIC_OVL void</span>
 
  <span id="line39">39. STATIC_OVL void</span>
 
  <span id="line40">40. init_fill(bg_typ, fg_typ)</span>
 
  <span id="line40">40. init_fill(bg_typ, fg_typ)</span>
Line 60: Line 70:
 
  <span id="line56">56. }</span>
 
  <span id="line56">56. }</span>
 
  <span id="line57">57. </span>
 
  <span id="line57">57. </span>
 +
 +
== get_map ==
 +
 
  <span id="line58">58. STATIC_OVL schar</span>
 
  <span id="line58">58. STATIC_OVL schar</span>
 
  <span id="line59">59. get_map(col, row, bg_typ)</span>
 
  <span id="line59">59. get_map(col, row, bg_typ)</span>
Line 73: Line 86:
 
  <span id="line69">69.                         0,  1 /**/,  1,  -1 /**/, 1,  0 /**/, 1, 1 };</span>
 
  <span id="line69">69.                         0,  1 /**/,  1,  -1 /**/, 1,  0 /**/, 1, 1 };</span>
 
  <span id="line70">70. </span>
 
  <span id="line70">70. </span>
 +
 +
== pass_one ==
 +
 
  <span id="line71">71. STATIC_OVL void</span>
 
  <span id="line71">71. STATIC_OVL void</span>
 
  <span id="line72">72. pass_one(bg_typ, fg_typ)</span>
 
  <span id="line72">72. pass_one(bg_typ, fg_typ)</span>
Line 107: Line 123:
 
  <span id="line103">103. #define new_loc(i, j) *(new_locations + ((j) * (WIDTH + 1)) + (i))</span>
 
  <span id="line103">103. #define new_loc(i, j) *(new_locations + ((j) * (WIDTH + 1)) + (i))</span>
 
  <span id="line104">104. </span>
 
  <span id="line104">104. </span>
 +
 +
== pass_two ==
 +
 
  <span id="line105">105. STATIC_OVL void</span>
 
  <span id="line105">105. STATIC_OVL void</span>
 
  <span id="line106">106. pass_two(bg_typ, fg_typ)</span>
 
  <span id="line106">106. pass_two(bg_typ, fg_typ)</span>
Line 131: Line 150:
 
  <span id="line127">127. }</span>
 
  <span id="line127">127. }</span>
 
  <span id="line128">128. </span>
 
  <span id="line128">128. </span>
 +
 +
== pass_three ==
 +
 
  <span id="line129">129. STATIC_OVL void</span>
 
  <span id="line129">129. STATIC_OVL void</span>
 
  <span id="line130">130. pass_three(bg_typ, fg_typ)</span>
 
  <span id="line130">130. pass_three(bg_typ, fg_typ)</span>
Line 155: Line 177:
 
  <span id="line151">151. }</span>
 
  <span id="line151">151. }</span>
 
  <span id="line152">152. </span>
 
  <span id="line152">152. </span>
 +
 +
== flood_fill_rm ==
 +
 
  <span id="line153">153. /*</span>
 
  <span id="line153">153. /*</span>
 
  <span id="line154">154.  * use a flooding algorithm to find all locations that should</span>
 
  <span id="line154">154.  * use a flooding algorithm to find all locations that should</span>
Line 251: Line 276:
 
  <span id="line247">247. }</span>
 
  <span id="line247">247. }</span>
 
  <span id="line248">248. </span>
 
  <span id="line248">248. </span>
 +
 +
== wallify_map ==
 +
 
  <span id="line249">249. /*</span>
 
  <span id="line249">249. /*</span>
 
  <span id="line250">250.  * If we have drawn a map without walls, this allows us to</span>
 
  <span id="line250">250.  * If we have drawn a map without walls, this allows us to</span>
Line 274: Line 302:
 
  <span id="line270">270. }</span>
 
  <span id="line270">270. }</span>
 
  <span id="line271">271. </span>
 
  <span id="line271">271. </span>
 +
 +
== join_map ==
 +
 
  <span id="line272">272. STATIC_OVL void</span>
 
  <span id="line272">272. STATIC_OVL void</span>
 
  <span id="line273">273. join_map(bg_typ, fg_typ)</span>
 
  <span id="line273">273. join_map(bg_typ, fg_typ)</span>
Line 347: Line 378:
 
  <span id="line343">343. }</span>
 
  <span id="line343">343. }</span>
 
  <span id="line344">344. </span>
 
  <span id="line344">344. </span>
 +
 +
== finish_map ==
 +
 
  <span id="line345">345. STATIC_OVL void</span>
 
  <span id="line345">345. STATIC_OVL void</span>
 
  <span id="line346">346. finish_map(fg_typ, bg_typ, lit, walled, icedpools)</span>
 
  <span id="line346">346. finish_map(fg_typ, bg_typ, lit, walled, icedpools)</span>
Line 379: Line 413:
 
  <span id="line375">375. }</span>
 
  <span id="line375">375. }</span>
 
  <span id="line376">376. </span>
 
  <span id="line376">376. </span>
 +
 +
== remove_rooms ==
 +
 
  <span id="line377">377. /*</span>
 
  <span id="line377">377. /*</span>
 
  <span id="line378">378.  * When level processed by join_map is overlaid by a MAP, some rooms may no</span>
 
  <span id="line378">378.  * When level processed by join_map is overlaid by a MAP, some rooms may no</span>
Line 414: Line 451:
 
  <span id="line410">410. }</span>
 
  <span id="line410">410. }</span>
 
  <span id="line411">411. </span>
 
  <span id="line411">411. </span>
 +
 +
== remove_room ==
 +
 
  <span id="line412">412. /*</span>
 
  <span id="line412">412. /*</span>
 
  <span id="line413">413.  * Remove roomno from the rooms array, decrementing nroom.  Also updates</span>
 
  <span id="line413">413.  * Remove roomno from the rooms array, decrementing nroom.  Also updates</span>
Line 453: Line 493:
 
  <span id="line449">449. #define N_P3_ITER 2 /* tune map smoothing via this value */</span>
 
  <span id="line449">449. #define N_P3_ITER 2 /* tune map smoothing via this value */</span>
 
  <span id="line450">450. </span>
 
  <span id="line450">450. </span>
 +
 +
== mkmap ==
 +
 
  <span id="line451">451. void</span>
 
  <span id="line451">451. void</span>
 
  <span id="line452">452. mkmap(init_lev)</span>
 
  <span id="line452">452. mkmap(init_lev)</span>

Latest revision as of 00:25, 18 May 2018

Below is the full text to mkmap.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/mkmap.c#line123]], for example.

Top of file

 /* NetHack 3.6	mkmap.c	$NHDT-Date: 1432512767 2015/05/25 00:12:47 $  $NHDT-Branch: master $:$NHDT-Revision: 1.16 $ */
 /* Copyright (c) J. C. Collet, M. Stephenson and D. Cohrs, 1992   */
 /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

 
 #include "hack.h"
 #include "sp_lev.h"
 
 #define HEIGHT (ROWNO - 1)
 #define WIDTH (COLNO - 2)
 
 STATIC_DCL void FDECL(init_map, (SCHAR_P));
 STATIC_DCL void FDECL(init_fill, (SCHAR_P, SCHAR_P));
 STATIC_DCL schar FDECL(get_map, (int, int, SCHAR_P));
 STATIC_DCL void FDECL(pass_one, (SCHAR_P, SCHAR_P));
 STATIC_DCL void FDECL(pass_two, (SCHAR_P, SCHAR_P));
 STATIC_DCL void FDECL(pass_three, (SCHAR_P, SCHAR_P));
 STATIC_DCL void NDECL(wallify_map);
 STATIC_DCL void FDECL(join_map, (SCHAR_P, SCHAR_P));
 STATIC_DCL void FDECL(finish_map,
                       (SCHAR_P, SCHAR_P, BOOLEAN_P, BOOLEAN_P, BOOLEAN_P));
 STATIC_DCL void FDECL(remove_room, (unsigned));
 void FDECL(mkmap, (lev_init *));
 
 static char *new_locations;
 int min_rx, max_rx, min_ry, max_ry; /* rectangle bounds for regions */
 static int n_loc_filled;
 

init_map

 STATIC_OVL void
 init_map(bg_typ)
 schar bg_typ;
 {
     register int i, j;
 
     for (i = 1; i < COLNO; i++)
         for (j = 0; j < ROWNO; j++)
             levl[i][j].typ = bg_typ;
 }
 

init_fill

 STATIC_OVL void
 init_fill(bg_typ, fg_typ)
 schar bg_typ, fg_typ;
 {
     register int i, j;
     long limit, count;
 
     limit = (WIDTH * HEIGHT * 2) / 5;
     count = 0;
     while (count < limit) {
         i = rn1(WIDTH - 1, 2);
         j = rnd(HEIGHT - 1);
         if (levl[i][j].typ == bg_typ) {
             levl[i][j].typ = fg_typ;
             count++;
         }
     }
 }
 

get_map

 STATIC_OVL schar
 get_map(col, row, bg_typ)
 int col, row;
 schar bg_typ;
 {
     if (col <= 0 || row < 0 || col > WIDTH || row >= HEIGHT)
         return bg_typ;
     return levl[col][row].typ;
 }
 
 static int dirs[16] = { -1, -1 /**/, -1, 0 /**/,  -1, 1 /**/, 0, -1 /**/,
                         0,  1 /**/,  1,  -1 /**/, 1,  0 /**/, 1, 1 };
 

pass_one

 STATIC_OVL void
 pass_one(bg_typ, fg_typ)
 schar bg_typ, fg_typ;
 {
     register int i, j;
     short count, dr;
 
     for (i = 2; i <= WIDTH; i++)
         for (j = 1; j < HEIGHT; j++) {
             for (count = 0, dr = 0; dr < 8; dr++)
                 if (get_map(i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ)
                     == fg_typ)
                     count++;
 
             switch (count) {
             case 0: /* death */
             case 1:
             case 2:
                 levl[i][j].typ = bg_typ;
                 break;
             case 5:
             case 6:
             case 7:
             case 8:
                 levl[i][j].typ = fg_typ;
                 break;
             default:
                 break;
             }
         }
 }
 
 #define new_loc(i, j) *(new_locations + ((j) * (WIDTH + 1)) + (i))
 

pass_two

 STATIC_OVL void
 pass_two(bg_typ, fg_typ)
 schar bg_typ, fg_typ;
 {
     register int i, j;
     short count, dr;
 
     for (i = 2; i <= WIDTH; i++)
         for (j = 1; j < HEIGHT; j++) {
             for (count = 0, dr = 0; dr < 8; dr++)
                 if (get_map(i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ)
                     == fg_typ)
                     count++;
             if (count == 5)
                 new_loc(i, j) = bg_typ;
             else
                 new_loc(i, j) = get_map(i, j, bg_typ);
         }
 
     for (i = 2; i <= WIDTH; i++)
         for (j = 1; j < HEIGHT; j++)
             levl[i][j].typ = new_loc(i, j);
 }
 

pass_three

 STATIC_OVL void
 pass_three(bg_typ, fg_typ)
 schar bg_typ, fg_typ;
 {
     register int i, j;
     short count, dr;
 
     for (i = 2; i <= WIDTH; i++)
         for (j = 1; j < HEIGHT; j++) {
             for (count = 0, dr = 0; dr < 8; dr++)
                 if (get_map(i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ)
                     == fg_typ)
                     count++;
             if (count < 3)
                 new_loc(i, j) = bg_typ;
             else
                 new_loc(i, j) = get_map(i, j, bg_typ);
         }
 
     for (i = 2; i <= WIDTH; i++)
         for (j = 1; j < HEIGHT; j++)
             levl[i][j].typ = new_loc(i, j);
 }
 

flood_fill_rm

 /*
  * use a flooding algorithm to find all locations that should
  * have the same rm number as the current location.
  * if anyroom is TRUE, use IS_ROOM to check room membership instead of
  * exactly matching levl[sx][sy].typ and walls are included as well.
  */
 void
 flood_fill_rm(sx, sy, rmno, lit, anyroom)
 int sx;
 register int sy;
 register int rmno;
 boolean lit;
 boolean anyroom;
 {
     register int i;
     int nx;
     schar fg_typ = levl[sx][sy].typ;
 
     /* back up to find leftmost uninitialized location */
     while (sx > 0 && (anyroom ? IS_ROOM(levl[sx][sy].typ)
                               : levl[sx][sy].typ == fg_typ)
            && (int) levl[sx][sy].roomno != rmno)
         sx--;
     sx++; /* compensate for extra decrement */
 
     /* assume sx,sy is valid */
     if (sx < min_rx)
         min_rx = sx;
     if (sy < min_ry)
         min_ry = sy;
 
     for (i = sx; i <= WIDTH && levl[i][sy].typ == fg_typ; i++) {
         levl[i][sy].roomno = rmno;
         levl[i][sy].lit = lit;
         if (anyroom) {
             /* add walls to room as well */
             register int ii, jj;
             for (ii = (i == sx ? i - 1 : i); ii <= i + 1; ii++)
                 for (jj = sy - 1; jj <= sy + 1; jj++)
                     if (isok(ii, jj) && (IS_WALL(levl[ii][jj].typ)
                                          || IS_DOOR(levl[ii][jj].typ)
                                          || levl[ii][jj].typ == SDOOR)) {
                         levl[ii][jj].edge = 1;
                         if (lit)
                             levl[ii][jj].lit = lit;
                         if ((int) levl[ii][jj].roomno != rmno)
                             levl[ii][jj].roomno = SHARED;
                     }
         }
         n_loc_filled++;
     }
     nx = i;
 
     if (isok(sx, sy - 1)) {
         for (i = sx; i < nx; i++)
             if (levl[i][sy - 1].typ == fg_typ) {
                 if ((int) levl[i][sy - 1].roomno != rmno)
                     flood_fill_rm(i, sy - 1, rmno, lit, anyroom);
             } else {
                 if ((i > sx || isok(i - 1, sy - 1))
                     && levl[i - 1][sy - 1].typ == fg_typ) {
                     if ((int) levl[i - 1][sy - 1].roomno != rmno)
                         flood_fill_rm(i - 1, sy - 1, rmno, lit, anyroom);
                 }
                 if ((i < nx - 1 || isok(i + 1, sy - 1))
                     && levl[i + 1][sy - 1].typ == fg_typ) {
                     if ((int) levl[i + 1][sy - 1].roomno != rmno)
                         flood_fill_rm(i + 1, sy - 1, rmno, lit, anyroom);
                 }
             }
     }
     if (isok(sx, sy + 1)) {
         for (i = sx; i < nx; i++)
             if (levl[i][sy + 1].typ == fg_typ) {
                 if ((int) levl[i][sy + 1].roomno != rmno)
                     flood_fill_rm(i, sy + 1, rmno, lit, anyroom);
             } else {
                 if ((i > sx || isok(i - 1, sy + 1))
                     && levl[i - 1][sy + 1].typ == fg_typ) {
                     if ((int) levl[i - 1][sy + 1].roomno != rmno)
                         flood_fill_rm(i - 1, sy + 1, rmno, lit, anyroom);
                 }
                 if ((i < nx - 1 || isok(i + 1, sy + 1))
                     && levl[i + 1][sy + 1].typ == fg_typ) {
                     if ((int) levl[i + 1][sy + 1].roomno != rmno)
                         flood_fill_rm(i + 1, sy + 1, rmno, lit, anyroom);
                 }
             }
     }
 
     if (nx > max_rx)
         max_rx = nx - 1; /* nx is just past valid region */
     if (sy > max_ry)
         max_ry = sy;
 }
 

wallify_map

 /*
  * If we have drawn a map without walls, this allows us to
  * auto-magically wallify it.  Taken from lev_main.c.
  */
 STATIC_OVL void
 wallify_map()
 {
     int x, y, xx, yy;
 
     for (x = 1; x < COLNO; x++)
         for (y = 0; y < ROWNO; y++)
             if (levl[x][y].typ == STONE) {
                 for (yy = y - 1; yy <= y + 1; yy++)
                     for (xx = x - 1; xx <= x + 1; xx++)
                         if (isok(xx, yy) && levl[xx][yy].typ == ROOM) {
                             if (yy != y)
                                 levl[x][y].typ = HWALL;
                             else
                                 levl[x][y].typ = VWALL;
                         }
             }
 }
 

join_map

 STATIC_OVL void
 join_map(bg_typ, fg_typ)
 schar bg_typ, fg_typ;
 {
     register struct mkroom *croom, *croom2;
 
     register int i, j;
     int sx, sy;
     coord sm, em;
 
     /* first, use flood filling to find all of the regions that need joining
      */
     for (i = 2; i <= WIDTH; i++)
         for (j = 1; j < HEIGHT; j++) {
             if (levl[i][j].typ == fg_typ && levl[i][j].roomno == NO_ROOM) {
                 min_rx = max_rx = i;
                 min_ry = max_ry = j;
                 n_loc_filled = 0;
                 flood_fill_rm(i, j, nroom + ROOMOFFSET, FALSE, FALSE);
                 if (n_loc_filled > 3) {
                     add_room(min_rx, min_ry, max_rx, max_ry, FALSE, OROOM,
                              TRUE);
                     rooms[nroom - 1].irregular = TRUE;
                     if (nroom >= (MAXNROFROOMS * 2))
                         goto joinm;
                 } else {
                     /*
                      * it's a tiny hole; erase it from the map to avoid
                      * having the player end up here with no way out.
                      */
                     for (sx = min_rx; sx <= max_rx; sx++)
                         for (sy = min_ry; sy <= max_ry; sy++)
                             if ((int) levl[sx][sy].roomno
                                 == nroom + ROOMOFFSET) {
                                 levl[sx][sy].typ = bg_typ;
                                 levl[sx][sy].roomno = NO_ROOM;
                             }
                 }
             }
         }
 
 joinm:
     /*
      * Ok, now we can actually join the regions with fg_typ's.
      * The rooms are already sorted due to the previous loop,
      * so don't call sort_rooms(), which can screw up the roomno's
      * validity in the levl structure.
      */
     for (croom = &rooms[0], croom2 = croom + 1; croom2 < &rooms[nroom];) {
         /* pick random starting and end locations for "corridor" */
         if (!somexy(croom, &sm) || !somexy(croom2, &em)) {
             /* ack! -- the level is going to be busted */
             /* arbitrarily pick centers of both rooms and hope for the best */
             impossible("No start/end room loc in join_map.");
             sm.x = croom->lx + ((croom->hx - croom->lx) / 2);
             sm.y = croom->ly + ((croom->hy - croom->ly) / 2);
             em.x = croom2->lx + ((croom2->hx - croom2->lx) / 2);
             em.y = croom2->ly + ((croom2->hy - croom2->ly) / 2);
         }
 
         (void) dig_corridor(&sm, &em, FALSE, fg_typ, bg_typ);
 
         /* choose next region to join */
         /* only increment croom if croom and croom2 are non-overlapping */
         if (croom2->lx > croom->hx
             || ((croom2->ly > croom->hy || croom2->hy < croom->ly)
                 && rn2(3))) {
             croom = croom2;
         }
         croom2++; /* always increment the next room */
     }
 }
 

finish_map

 STATIC_OVL void
 finish_map(fg_typ, bg_typ, lit, walled, icedpools)
 schar fg_typ, bg_typ;
 boolean lit, walled, icedpools;
 {
     int i, j;
 
     if (walled)
         wallify_map();
 
     if (lit) {
         for (i = 1; i < COLNO; i++)
             for (j = 0; j < ROWNO; j++)
                 if ((!IS_ROCK(fg_typ) && levl[i][j].typ == fg_typ)
                     || (!IS_ROCK(bg_typ) && levl[i][j].typ == bg_typ)
                     || (bg_typ == TREE && levl[i][j].typ == bg_typ)
                     || (walled && IS_WALL(levl[i][j].typ)))
                     levl[i][j].lit = TRUE;
         for (i = 0; i < nroom; i++)
             rooms[i].rlit = 1;
     }
     /* light lava even if everything's otherwise unlit;
        ice might be frozen pool rather than frozen moat */
     for (i = 1; i < COLNO; i++)
         for (j = 0; j < ROWNO; j++) {
             if (levl[i][j].typ == LAVAPOOL)
                 levl[i][j].lit = TRUE;
             else if (levl[i][j].typ == ICE)
                 levl[i][j].icedpool = icedpools ? ICED_POOL : ICED_MOAT;
         }
 }
 

remove_rooms

 /*
  * When level processed by join_map is overlaid by a MAP, some rooms may no
  * longer be valid.  All rooms in the region lx <= x < hx, ly <= y < hy are
  * removed.  Rooms partially in the region are truncated.  This function
  * must be called before the REGIONs or ROOMs of the map are processed, or
  * those rooms will be removed as well.  Assumes roomno fields in the
  * region are already cleared, and roomno and irregular fields outside the
  * region are all set.
  */
 void
 remove_rooms(lx, ly, hx, hy)
 int lx, ly, hx, hy;
 {
     int i;
     struct mkroom *croom;
 
     for (i = nroom - 1; i >= 0; --i) {
         croom = &rooms[i];
         if (croom->hx < lx || croom->lx >= hx || croom->hy < ly
             || croom->ly >= hy)
             continue; /* no overlap */
 
         if (croom->lx < lx || croom->hx >= hx || croom->ly < ly
             || croom->hy >= hy) { /* partial overlap */
             /* TODO: ensure remaining parts of room are still joined */
 
             if (!croom->irregular)
                 impossible("regular room in joined map");
         } else {
             /* total overlap, remove the room */
             remove_room((unsigned) i);
         }
     }
 }
 

remove_room

 /*
  * Remove roomno from the rooms array, decrementing nroom.  Also updates
  * all level roomno values of affected higher numbered rooms.  Assumes
  * level structure contents corresponding to roomno have already been reset.
  * Currently handles only the removal of rooms that have no subrooms.
  */
 STATIC_OVL void
 remove_room(roomno)
 unsigned roomno;
 {
     struct mkroom *croom = &rooms[roomno];
     struct mkroom *maxroom = &rooms[--nroom];
     int i, j;
     unsigned oroomno;
 
     if (croom != maxroom) {
         /* since the order in the array only matters for making corridors,
          * copy the last room over the one being removed on the assumption
          * that corridors have already been dug. */
         (void) memcpy((genericptr_t) croom, (genericptr_t) maxroom,
                       sizeof(struct mkroom));
 
         /* since maxroom moved, update affected level roomno values */
         oroomno = nroom + ROOMOFFSET;
         roomno += ROOMOFFSET;
         for (i = croom->lx; i <= croom->hx; ++i)
             for (j = croom->ly; j <= croom->hy; ++j) {
                 if (levl[i][j].roomno == oroomno)
                     levl[i][j].roomno = roomno;
             }
     }
 
     maxroom->hx = -1; /* just like add_room */
 }
 
 #define N_P1_ITER 1 /* tune map generation via this value */
 #define N_P2_ITER 1 /* tune map generation via this value */
 #define N_P3_ITER 2 /* tune map smoothing via this value */
 

mkmap

 void
 mkmap(init_lev)
 lev_init *init_lev;
 {
     schar bg_typ = init_lev->bg, fg_typ = init_lev->fg;
     boolean smooth = init_lev->smoothed, join = init_lev->joined;
     xchar lit = init_lev->lit, walled = init_lev->walled;
     int i;
 
     if (lit < 0)
         lit = (rnd(1 + abs(depth(&u.uz))) < 11 && rn2(77)) ? 1 : 0;
 
     new_locations = (char *) alloc((WIDTH + 1) * HEIGHT);
 
     init_map(bg_typ);
     init_fill(bg_typ, fg_typ);
 
     for (i = 0; i < N_P1_ITER; i++)
         pass_one(bg_typ, fg_typ);
 
     for (i = 0; i < N_P2_ITER; i++)
         pass_two(bg_typ, fg_typ);
 
     if (smooth)
         for (i = 0; i < N_P3_ITER; i++)
             pass_three(bg_typ, fg_typ);
 
     if (join)
         join_map(bg_typ, fg_typ);
 
     finish_map(fg_typ, bg_typ, (boolean) lit, (boolean) walled,
                init_lev->icedpools);
     /* a walled, joined level is cavernous, not mazelike -dlc */
     if (walled && join) {
         level.flags.is_maze_lev = FALSE;
         level.flags.is_cavernous_lev = TRUE;
     }
     free(new_locations);
 }
 
 /*mkmap.c*/