Allow defining random-teleport exclusion zones in lua

Adds a new lua command

  des.exclusion({ type = "teleport", region = { x1,y1, x2,y2 } });

which allows defining "exclusion zones" in the level, areas where
random teleports (or falling into the level) will never place the hero.
Does not prevent targeted teleportation into the area.

Breaks saves and bones.
This commit is contained in:
Pasi Kallinen
2023-08-24 17:42:06 +03:00
parent 0794a64b9d
commit e407af4477
15 changed files with 143 additions and 3 deletions

View File

@@ -297,6 +297,22 @@ maze0xy(coord *cc)
return;
}
static boolean
is_exclusion_zone(xint16 type, coordxy x, coordxy y)
{
struct exclusion_zone *ez = ge.exclusion_zones;
while (ez) {
if (((type == LR_DOWNTELE && (ez->zonetype == LR_DOWNTELE || ez->zonetype == LR_TELE))
|| (type == LR_UPTELE && (ez->zonetype == LR_UPTELE || ez->zonetype == LR_TELE))
|| type == ez->zonetype)
&& within_bounded_area(x, y, ez->lx, ez->ly, ez->hx, ez->hy))
return TRUE;
ez = ez->next;
}
return FALSE;
}
/*
* Bad if:
* pos is occupied OR
@@ -375,7 +391,7 @@ put_lregion_here(
{
struct monst *mtmp;
if (bad_location(x, y, nlx, nly, nhx, nhy)) {
if (bad_location(x, y, nlx, nly, nhx, nhy) || is_exclusion_zone(rtype, x, y)) {
if (!oneshot) {
return FALSE; /* caller should try again */
} else {
@@ -389,7 +405,7 @@ put_lregion_here(
mtmp->mtrapped = 0;
deltrap(t);
}
if (bad_location(x, y, nlx, nly, nhx, nhy))
if (bad_location(x, y, nlx, nly, nhx, nhy) || is_exclusion_zone(rtype, x, y))
return FALSE;
}
}