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

Function get_location

src/sp_lev.c:1201–1269  ·  view source on GitHub ↗

* Translate a given coordinate from a special level definition into an actual * location on the map. * * If x or y is negative, we generate a random coordinate within the area. If * not negative, they are interpreted as relative to the last defined map or * room, and are output as absolute svl.level.locations coordinates. * * The "humidity" flag is used to ensure that engravings aren't crea

Source from the content-addressed store, hash-verified

1199 * underwater, or eels on dry land.
1200 */
1201staticfn void
1202get_location(
1203 coordxy *x, coordxy *y,
1204 getloc_flags_t humidity,
1205 struct mkroom *croom)
1206{
1207 int cpt = 0;
1208 int mx, my, sx, sy;
1209
1210 if (croom) {
1211 mx = croom->lx;
1212 my = croom->ly;
1213 sx = croom->hx - mx + 1;
1214 sy = croom->hy - my + 1;
1215 } else {
1216 mx = gx.xstart;
1217 my = gy.ystart;
1218 sx = gx.xsize;
1219 sy = gy.ysize;
1220 }
1221
1222 if (*x >= 0) { /* normal locations */
1223 *x += mx;
1224 *y += my;
1225 } else { /* random location */
1226 do {
1227 if (croom) { /* handle irregular areas */
1228 coord tmpc;
1229 (void) somexy(croom, &tmpc);
1230 *x = tmpc.x;
1231 *y = tmpc.y;
1232 } else {
1233 *x = mx + rn2((int) sx);
1234 *y = my + rn2((int) sy);
1235 }
1236 if (is_ok_location(*x, *y, humidity))
1237 break;
1238 } while (++cpt < 100);
1239 if (cpt >= 100) {
1240 int xx, yy;
1241
1242 /* last try */
1243 for (xx = 0; xx < sx; xx++)
1244 for (yy = 0; yy < sy; yy++) {
1245 *x = mx + xx;
1246 *y = my + yy;
1247 if (is_ok_location(*x, *y, humidity))
1248 goto found_it;
1249 }
1250 if (!(humidity & NO_LOC_WARN)) {
1251 impossible("get_location: can't find a place!");
1252 } else {
1253 *x = *y = -1;
1254 }
1255 }
1256 }
1257 found_it:
1258 ;

Callers 6

get_location_coordFunction · 0.85
create_monsterFunction · 0.85
lspo_replace_terrainFunction · 0.85
levregion_addFunction · 0.85
lspo_regionFunction · 0.85
lspo_wall_propertyFunction · 0.85

Calls 5

somexyFunction · 0.85
rn2Function · 0.85
is_ok_locationFunction · 0.85
isokFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected