SmartLight (POC)

Post your example zscripts/ACS scripts/etc here.

SmartLight (POC)

Postby Hey Doomer » Wed Dec 29, 2021 5:18 am

There are several very, very good flashlight mods. This isn't an attempt to replace those. Rather, it strikes me as comical that Doomguy runs around in the dark holding weapons and ammo, his finger on the trigger, all the while fumbling with a flashlight. Why can't the flashlight just turn on and off by itself? If a cheap smartphone can auto adjust screen brightness, that doesn't seem like a stretch. This is my attempt called SmartLight.

Screenshot:
Spoiler:


The idea is simple. Light points are spawned in a sector in visible corners. As the player moves through a sector the nearest and darkest light point is found. If the light level is 128 or less the flashlight snaps on, otherwise it turns off. The flashlight itself is a basic GLDEF light attached and removed from the player. This is nothing fancy but it gets the job done.

GLDEFS:
Code: Select allExpand view
pointlight flight1
{
   Color 1.0 1.0 1.0
   Size 512
   Offset 0 36 0
   Spot 8 12
   dontlightself 1
   attenuate 1
}
pointlight flight2
{
   Color 1.0 1.0 1.0
   Size 256
   Offset 0 36 0
   Spot 16 32
   dontlightself 1
   attenuate 1
}


ZScript (logic to find the best "SmartLight" point):
Code: Select allExpand view
   // find SL_Point based on proximity and orientation
   SL_Point findSmartLighter(vector3 v3)
   {
      ThinkerIterator SL_PointFinder;
      SL_PointFinder = ThinkerIterator.Create("SL_Point");
      SL_Point idpoint;
      SL_Point ptr = null;
      int nearest = 1024; // check distance
      int darkest = 256;
   
      while (idpoint = SL_Point(SL_PointFinder.Next()))
      {
         double pl2id = player.mo.Distance2D(idpoint);
         int light = getBrightest(idpoint);

         if (pl2id < nearest && player.mo.CheckSight(idpoint))
         {
            if (isfacing(idpoint) && light < darkest)
            {
               ptr = idpoint;
               darkest = light;
               nearest = pl2id;
            }
         }
      }
      return ptr;
   }


This is pretty rough at present but demonstrates the concept well enough. At present it is a Frankenstein of bits from Flankers and Ambushers and has not been optimized. But the idea is more or less the opposite of Ambushers in that we want to adjust darkness by convex corners instead of monsters deliberately avoiding convex corners. Obviously the light level triggers, angles, distances, etc. are all candidates for settings. (I haven't added a settings menu yet.)

Heck I don't think the flashlight looks bad either and does the job.

Update:
Spoiler:
You do not have the required permissions to view the files attached to this post.
User avatar
Hey Doomer
 
Joined: 25 Sep 2021
Operating System: Windows 11
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD with Vulkan Support

Return to Script Library

Who is online

Users browsing this forum: No registered users and 1 guest