Cast Shadows

Post your example zscripts/ACS scripts/etc here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Hey Doomer
Posts: 283
Joined: Sat Sep 25, 2021 3:38 am

Cast Shadows

Post by Hey Doomer »

CASTSPRITESHADOW offers control over what casts a shadow, so here's my take on implementing this with inclusion and exclusion arrays:

Code: Select all

// caster_events.zs

class caster_EventHandler : EventHandler
{
	Array<string> shadows;
	Array<string> noshadows;

	bool noshadow(string s)
	{
		if (noshadows.Size()==0)
		{
			noshadows.Push("Column");
			noshadows.Push("BurningBarrel");
			noshadows.Push("ExplosiveBarrel");
			noshadows.Push("TechLamp");
			noshadows.Push("TechLamp2");
			noshadows.Push("TechPillar");
		}
		return (noshadows.Find(s) != noshadows.Size());
	}

	bool shadow(string s)
	{
		if (shadows.Size()==0)
		{
			shadows.Push("NonsolidMeat2");
			shadows.Push("NonsolidMeat3");
			shadows.Push("NonsolidMeat4");
			shadows.Push("NonsolidMeat5");
			shadows.Push("NonsolidTwitch");
			shadows.Push("DoomPlayer");
		}
		return (shadows.Find(s) != shadows.Size());
	}

	override
	void WorldThingSpawned(WorldEvent e)
	{
		string cn = e.thing.GetReplacee(e.thing.GetClassName()).GetClassName();
		e.thing.bCastSpriteShadow = (e.thing.bSolid && CVar.GetCVar("cast_solid"))
			|| (e.thing.bMissile && CVar.GetCVar("cast_missile"))
			|| (e.thing.bCorpse && CVar.GetCVar("cast_corpse")) || shadow(cn) || !noshadow(cn);
	}
}
This presents a few more options if the GZDoom menu option is "Default," controlled by CVars:

Code: Select all

user bool cast_solid = true;
user bool cast_corpse = true;
user bool cast_missile = true;
Rather than select all monsters I have chosen SOLID actors, and what doesn't cast can be excluded. Still playing around with this, but that's the idea.

Update 11/30/21
Spoiler:

Return to “Script Library”