MCPcopy Create free account
hub / github.com/NetHack/NetHack / flood_fill_rm

Function flood_fill_rm

src/mkmap.c:152–242  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

150 * exactly matching levl[sx][sy].typ and walls are included as well.
151 */
152void
153flood_fill_rm(
154 coordxy sx,
155 coordxy sy,
156 int rmno,
157 boolean lit,
158 boolean anyroom)
159{
160 coordxy i, nx;
161 schar fg_typ = levl[sx][sy].typ;
162
163 /* back up to find leftmost uninitialized location */
164 while (sx > 0 && (anyroom ? IS_ROOM(levl[sx][sy].typ)
165 : levl[sx][sy].typ == fg_typ)
166 && (int) levl[sx][sy].roomno != rmno)
167 sx--;
168 sx++; /* compensate for extra decrement */
169
170 /* assume sx,sy is valid */
171 if (sx < gm.min_rx)
172 gm.min_rx = sx;
173 if (sy < gm.min_ry)
174 gm.min_ry = sy;
175
176 for (i = sx; i <= WIDTH && levl[i][sy].typ == fg_typ; i++) {
177 levl[i][sy].roomno = rmno;
178 levl[i][sy].lit = lit;
179 if (anyroom) {
180 /* add walls to room as well */
181 coordxy ii, jj;
182 for (ii = (i == sx ? i - 1 : i); ii <= i + 1; ii++)
183 for (jj = sy - 1; jj <= sy + 1; jj++)
184 if (isok(ii, jj) && (IS_WALL(levl[ii][jj].typ)
185 || IS_DOOR(levl[ii][jj].typ)
186 || levl[ii][jj].typ == SDOOR)) {
187 levl[ii][jj].edge = 1;
188 if (lit)
189 levl[ii][jj].lit = lit;
190
191 if (levl[ii][jj].roomno == NO_ROOM)
192 levl[ii][jj].roomno = rmno;
193 else if ((int) levl[ii][jj].roomno != rmno)
194 levl[ii][jj].roomno = SHARED;
195 }
196 }
197 gn.n_loc_filled++;
198 }
199 nx = i;
200
201 if (isok(sx, sy - 1)) {
202 for (i = sx; i < nx; i++)
203 if (levl[i][sy - 1].typ == fg_typ) {
204 if ((int) levl[i][sy - 1].roomno != rmno)
205 flood_fill_rm(i, sy - 1, rmno, lit, anyroom);
206 } else {
207 if ((i > sx || isok(i - 1, sy - 1))
208 && levl[i - 1][sy - 1].typ == fg_typ) {
209 if ((int) levl[i - 1][sy - 1].roomno != rmno)

Callers 2

join_mapFunction · 0.85
lspo_regionFunction · 0.85

Calls 1

isokFunction · 0.85

Tested by

no test coverage detected