Checking for Void Space when spawning

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Checking for Void Space when spawning

Post by Virathas »

I have been trying to create an airstrike beacon that supposed to work simply: In a radius area missiles spawn from the ceiling falling down and exploding when hiting the floor. Also the missiles can only spawn from Sky.

Sky restriction was pretty easy to do, however I am unable to find a good workaround for the missiles spawning outside of the map. Due to the size of the radius its not really viable to CheckSight the potential spawn with the beacon.

DECORATE/ACS/ZSCRIPT is all useable for the fix, but no map stuff, since it is a replacer mod.

Any help is appreciated.
User avatar
Rachael
Posts: 13931
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Checking for Void Space when spawning

Post by Rachael »

If you use a very large (high radius/height) "spawner" actor (using A_SpawnItem or something similar) that sends a message somehow to whatever script needs to check for space, you can check for the lack of presence of said actor to determine that the space you're in is too tight since some of the spawn functions will simply refuse to work if the space is clobbered, unless somehow overridden.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: Checking for Void Space when spawning

Post by krokots »

Maybe if the missile is spawned, check if the floor Z is different from ceiling Z ? I don't know what happens to Z axis "outside" of a map, but I'd reckon the floorZ is equal to ceilingZ, but I'm not sure.
Or maybe they are at some maximum values.
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Re: Checking for Void Space when spawning

Post by Virathas »

Rachael wrote:If you use a very large (high radius/height) "spawner" actor (using A_SpawnItem or something similar) that sends a message somehow to whatever script needs to check for space, you can check for the lack of presence of said actor to determine that the space you're in is too tight since some of the spawn functions will simply refuse to work if the space is clobbered, unless somehow overridden.
I am not sure i fully understand your suggestion. Spawning in a large "checker" actor would prevent spawns in any "tight" places, both outside the map and inside. Yet nothing i tested (both DECORATE and ACS spawn functions) seem to be able to validity of a spawn outside. At best i can try to prevent overlapping spawning with other actors. I could also try doing an enormous sight check from the potential spawn point if it can see any monster or even any item, but that would for sure impact the framerate.

Oh and I am sure that i missed one important aspect of the beacon - it keeps spawning missiles as long as it is active (which is a set duration, but considerable ~1 minute or so), which might cause some solutions to be non-viable.
krokots wrote:Maybe if the missile is spawned, check if the floor Z is different from ceiling Z ? I don't know what happens to Z axis "outside" of a map, but I'd reckon the floorZ is equal to ceilingZ, but I'm not sure.
Or maybe they are at some maximum values.
I honestly hoped for that to work, and was the first thing i checked but alas, the height and ceiling outside is somewhat the same as inside. It is like sectors keep on going infintely, but walls prevent walking through.

At the moment the spawn itself is handled by ACS code called by the beacon once:

Code: Select all

script "AirStrikeTest" (void)
{
	int CenterTID = ActivatorTID();
	int MissileID = UniqueTID();		
	
int timepast = 0;
int failcount = 0	;

	while ( timepast < 400 )
	{
		if  (failcount >= 100)
		{
			failcount = 0;
			delay(5);
			timepast++;
		}

     int x = GetActorX(CenterTID) + random(-768.0, 768.0);
     int y = GetActorY(CenterTID) + random(-768.0, 768.0);
     int z = GetActorCeilingZ(CenterTID);
	if (!(Spawn("Airstrikemissile", x, y, z, MissileID)))
	{
		failcount++;
		continue;
	}
	else
	{
		if ((CheckActorCeilingTexture(MissileID,"F_SKY1")) || (CheckActorCeilingTexture(MissileID,"F_SKY2")) || (CheckActorCeilingTexture(MissileID,"F_SKY3")) || (CheckActorCeilingTexture(MissileID,"F_SKY4")) || (CheckActorCeilingTexture(MissileID,"SKY1")) || (CheckActorCeilingTexture(MissileID,"SKY2")) || (CheckActorCeilingTexture(MissileID,"SKY3")) || (CheckActorCeilingTexture(MissileID,"SKY2A")) || (CheckActorCeilingTexture(MissileID,"SKYFOG")) || (CheckActorCeilingTexture(MissileID,"SKYFOG2")) || (CheckActorCeilingTexture(MissileID,"SKY")) || (CheckActorCeilingTexture(MissileID,"F_SKY")))
		{
			if 	((GetActorCeilingZ (MissileID) - GetActorFloorZ (MissileID)) < 16)
			{
				Thing_Remove(MissileID);
				failcount++;
				Continue;
			}
			else
			{
				SetActorPosition(MissileID, x,y,GetActorCeilingZ(MissileID) - 4.0, 0);
			}
		}
		else
		{
			Thing_Remove(MissileID);
			failcount++;
			Continue;
		}
		Thing_ChangeTID(MissileID, 0);
		delay(5);
		timepast++;
	}
	}
		Thing_Remove(CenterTID);
}
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: Checking for Void Space when spawning

Post by krokots »

I think that ZScript function CheckPosition does work (I just did a quick test). You would spawn this missile actor, within its code you would use CheckPosition(pos.xy) and if it returns 0 that means invalid position (outside of level counts)

Goddamn, no, it doesn't work, it was producing wrong results because the "outside" still counts as a sector, the sector that is bordering the map.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Checking for Void Space when spawning

Post by Arctangent »

"void space" is just not really a concept that exists to the engine. All space is valid play space, regardless of if it's contained within linedefs or not - that's why sector properties "leak" out of those closed areas.

In theory, you should be able to define it on your own by making a ZScript struct or object for closed polygons and used methods like line traces or information from LevelLocals ( via the level global variable ) to define 'em based on map geometry, but needless to say this is no simple feat.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Checking for Void Space when spawning

Post by Xaser »

ZScript seems to have all the pieces available to write a void-check function. An actor's current sector is stored in a class variable ("cursector"), so you can grab that, inspect the linedefs, and use the ray casting algorithm to check if the actor is in bounds (here's a random reference implementation). You'd need to exclude linedefs that have the same front/back sector (since those don't denote a sector boundary), but this algorithm ought to work for all closed sectors (even if not contiguous).

It wouldn't be foolproof since a lot of mapping tricks/hacks involve unclosed sector trickery (i.e. there will be cases in which the test won't work at all), and I shan't promise to write such a thing myself since I don't have a present use for it and am eternally busy/distracted, but hopefully this is of some use to someone. :P


[EDIT] Just to point this out so folks aren't confused: The unusual Doom engine quirk that makes this necessary (which Arctangent hinted at) is that Actors always have a current sector, even if they're in the void -- i.e. an actor's "cursector" var always has something so you can't just do the equivalent of a NULL check on it. If so, this'd be trivial.
User avatar
Rachael
Posts: 13931
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Checking for Void Space when spawning

Post by Rachael »

One thing that can be done to check if the actor is in the void is to check for line of sight to the player. If the actor is behind a wall, even if there's empty space on the other side, this check will always fail.
User avatar
LanHikariDS
Posts: 179
Joined: Tue Aug 04, 2015 11:30 pm
Location: Playing in the snow

Re: Checking for Void Space when spawning

Post by LanHikariDS »

One thing you could do is have the beacon fire out invisible projectiles all around it with various friction variables, so that the projectiles will stop moving at different spots from each others. Give the projectiles the +Shootable +Floorhugger and +Ripper Flags, so long as no actor has the +DontRip flag, and make sure the projectiles have at least 1 health, and are immune to the "None" damagetype, and all damagetypes you've defined thus far. Have the projectiles act as the spawn spot for the airstrike's missiles. Then, when the Beacon is destroyed, have it explode with a new "Beacon" damagetype (or some other name), and have Beacon be the only damagetype that can destroy the projectiles, but all other actors are immune to the Beacon damagetype.

It's a convoluted solution, but it should get the job done right, as Floorhugger projectiles are destroyed by solid walls (i.e. with void behind them), but can still climb over raised floors effortlessly.
jdagenet
Posts: 77
Joined: Tue Aug 09, 2011 10:26 pm

Re: Checking for Void Space when spawning

Post by jdagenet »

Just use A_CheckSight in the beacon’s definition like Rachael mentioned, no need to complicate things with ZScript or spawn 12 invisible projectiles or whatever.
I’ve personally used the sight method in my mod for Zandronum and it works flawlessly.
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: Checking for Void Space when spawning

Post by krokots »

jdagenet wrote:Just use A_CheckSight in the beacon’s definition like Rachael mentioned, no need to complicate things with ZScript or spawn 12 invisible projectiles or whatever.
I’ve personally used the sight method in my mod for Zandronum and it works flawlessly.
This has a drawback, if a missile will spawn behind a column, over a ledge, or any wall/obstacle, which normally is valid for air strike attack, it will fail this check. But right now this is the only "easy" way to do this.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Checking for Void Space when spawning

Post by Xaser »

If I'm understanding the OP's case correctly (a placeable airstrike beacon that spawns the missiles), A_CheckSight itself won't work as intended, since that function checks if actors are within sight of players, when we really want the missiles to test if they're within sight of the beacon.

Having said that, though, ZScript has a general (and confusingly-similarly-named) function called CheckSight that would be of use here. Though that's again ZScript, and I hadn't thought to ask earlier if the OP was targeting Zandronum (since it was mentioned) -- if so, that's a no-go.
User avatar
Virathas
Posts: 254
Joined: Thu Aug 10, 2017 9:38 am

Re: Checking for Void Space when spawning

Post by Virathas »

Thanks for all the answers.
This has a drawback, if a missile will spawn behind a column, over a ledge, or any wall/obstacle, which normally is valid for air strike attack, it will fail this check. But right now this is the only "easy" way to do this.


Yeah, this is the exact reason why the A_CheckSight is not really useful in this particular situation (Though for a similar thing I have, a supply drop, this will be more than enough).

My mod is designed for GZDoom(Originally ZDoom, but since its no longer updated...), so I don't aim for Zandronum compatibility. Unfortunately i am still new to ZScript, and it's not too well documented so I am not able to go with the Ray Tracing method. And i generally don't know much about it, except that it gives tremendous possiblities (and some coding experience I have will help a lot).

Once again, great thanks, I will see if I can get any of this to work, but to be frank, in this case the fix might not be worth the effort...
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: Checking for Void Space when spawning

Post by Xaser »

Though I'd still encourage ZScript tinkering (particularly because working with temporary TIDs in ACS is limited and miserable, comparatively), since you do have a working ACS spawn script already, there's an ACS CheckSight that works with TIDs that you can use for now. Rewriting stuff is a PITA. :P
Post Reply

Return to “Scripting”