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

Function add_region

src/region.c:283–338  ·  view source on GitHub ↗

* Add a region to the list. * This actually activates the region. */

Source from the content-addressed store, hash-verified

281 * This actually activates the region.
282 */
283void
284add_region(NhRegion *reg)
285{
286 NhRegion **tmp_reg;
287 int i, j;
288
289 if (gm.max_regions <= svn.n_regions) {
290 tmp_reg = gr.regions;
291 gr.regions =
292 (NhRegion **) alloc((gm.max_regions + 10) * sizeof (NhRegion *));
293 if (gm.max_regions > 0) {
294 (void) memcpy((genericptr_t) gr.regions, (genericptr_t) tmp_reg,
295 gm.max_regions * sizeof (NhRegion *));
296 free((genericptr_t) tmp_reg);
297 }
298 gm.max_regions += 10;
299 }
300 gr.regions[svn.n_regions] = reg;
301 svn.n_regions++;
302 /* Check for monsters inside the region */
303 for (i = reg->bounding_box.lx; i <= reg->bounding_box.hx; i++)
304 for (j = reg->bounding_box.ly; j <= reg->bounding_box.hy; j++) {
305 struct monst *mtmp;
306 boolean is_inside = FALSE;
307
308 /* Some regions can cross the level boundaries */
309 if (!isok(i, j))
310 continue;
311 if (inside_region(reg, i, j)) {
312 is_inside = TRUE;
313 /* if there's a monster here, add it to the region */
314 if ((mtmp = m_at(i, j)) != 0
315#if 0
316 /* leave this bit (to exclude long worm tails) out;
317 assume that worms use "cutaneous respiration" (they
318 breath through their skin rather than nose/gills/&c)
319 so their tails are susceptible to poison gas */
320 && mtmp->mx == i && mtmp->my == j
321#endif
322 ) {
323 add_mon_to_reg(reg, mtmp);
324 }
325 }
326 if (reg->visible) {
327 if (is_inside)
328 block_point(i, j);
329 if (cansee(i, j))
330 newsym(i, j);
331 }
332 }
333 /* Check for player now... */
334 if (inside_region(reg, u.ux, u.uy))
335 set_hero_inside(reg);
336 else
337 clear_hero_inside(reg);
338}
339
340/*

Callers 2

create_force_fieldFunction · 0.85
make_gas_cloudFunction · 0.85

Calls 6

isokFunction · 0.85
inside_regionFunction · 0.85
add_mon_to_regFunction · 0.85
block_pointFunction · 0.85
newsymFunction · 0.85
allocFunction · 0.70

Tested by

no test coverage detected