Page 1 of 1

Cast Shadows

PostPosted: Wed Nov 03, 2021 3:50 am
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 allExpand view
// 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 allExpand view
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: