Building a Smarter Flashlight [Update 1/7/22]

Projects that alter game functions but do not include new maps belong here.
Forum rules
The Projects forums are ONLY for YOUR 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.

Building a Smarter Flashlight [Update 1/7/22]

Postby Hey Doomer » Thu Dec 30, 2021 1:12 pm

Let me get this straight. Doomguy runs into a dark hallway carrying a hundred pounds of weapons and ammo, gripping a shotgun in his hands with a finger on its trigger, and he has to turn on a flashlight? Shouldn't his flashlight be smart enough to do that on its own? If a cheap smartphone can auto adjust screen brightness to avoid blinding a user in the dark that seems to be the least to ask of futuristic survival accessories. So this is my take on that, called SmartLight.

Screenshot:
Spoiler:


What this does is simple enough. It senses the light level the player is facing or walking into and turns on a flashlight. This flashlight does have a chance to alert photosensitive monsters and can be toggled with the G key. An on screen indicator shows the status of the flashlight (on, off, or disabled/missing).

The SmartLight reads light levels, not minds. It doesn't know where a player will turn next and may be overzealous in turning on. (I'm working on that.) However, the Settings menu can change the light level trigger, effective radius, and other parameters. The flashlight itself is a simple static beam. (Again, Doomguy can modify color, inner and outer angles, and other things no engineer would think of adding to a commercial product but he has to turn on the flashlight. Just messing with you. I really do like flashlight mods.)

Update:
Spoiler:

Update 1/6/22:
Spoiler:

Update 1/7/22:
Spoiler:


Optimization Update:
Spoiler:


Now at v1.3
Last edited by Hey Doomer on Fri Jan 07, 2022 8:31 am, edited 5 times in total.
Hey Doomer
 
Joined: 25 Sep 2021

Re: Building a Smarter Flashlight

Postby Enjay » Thu Dec 30, 2021 5:55 pm

Neat idea.

A couple of glitches:
Code: Select allExpand view
Script warning, "smartlight.pk3:smartlight_events.zs" line 135:
Truncation of floating point value


And the flashlight beam can put enemies into their pain state. So you can actually use it to make the game easier - you are more likely to immobilise an enemy by keeping it in pain if you are using the flashight.


I'm certainly not a fan of flashlights where the batteries only last a few seconds. I know it's a gameplay mechanic but I have never had a flashlight that runs out in a few seconds and modern Cree flashlights can last for months on a single set of batteries. So this is a plus for this mod.

However, there should be a disadvantage for relying on a flashlight IMO. For me, the most obvious one is that it should alert enemies. Sneaking around in a dark area with a light should draw attention to you. I don't know if you have done anything like that in this mod (perhaps that's what the pain thing is about?) but I have done it in the past both by making the flashlight itself alert monsters when active but also (if it is done by a tracer that spawns a puff) have the puff alert monsters. So, whenever the light is active, any enemies that do not have their ambush flag set in the same sound zone as the player, or a sound zone that the light is shining into, will wake up and come looking for the player. Perhaps it could also nullify the invisibility powerup?
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: Building a Smarter Flashlight

Postby Hey Doomer » Thu Dec 30, 2021 6:40 pm

Enjay wrote:For me, the most obvious one is that it should alert enemies. Sneaking around in a dark area with a light should draw attention to you. I don't know if you have done anything like that in this mod (perhaps that's what the pain thing is about?) but I have done it in the past both by making the flashlight itself alert monsters when active but also (if it is done by a tracer that spawns a puff) have the puff alert monsters. So, whenever the light is active, any enemies that do not have their ambush flag set in the same sound zone as the player, or a sound zone that the light is shining into, will wake up and come looking for the player. Perhaps it could also nullify the invisibility powerup?


The tracer idea would do the trick, I think. I puzzled about this, trying a few things, and ended up with a "photon projectile," which unfortunately has to have minimal damage to rouse the monsters.

I tried also doing this with A_AlertMonsters on the projectile itself without success, and so I am intrigued. How does the tracer and puff alert the monsters?

Update:
Looking at this again, it looks like NoiseAlert() does it. Thank you for comments and suggestions.
Hey Doomer
 
Joined: 25 Sep 2021

Re: Building a Smarter Flashlight

Postby eviltechno » Thu Dec 30, 2021 7:50 pm

Idea is nice. Unfortunately it lags my game like crazy when it turn on.
eviltechno
 
Joined: 04 Oct 2020

Re: Building a Smarter Flashlight

Postby Hey Doomer » Fri Dec 31, 2021 2:28 am

eviltechno wrote:Idea is nice. Unfortunately it lags my game like crazy when it turn on.


Version 1.1 may be better. I don't see any difference in fps.

Update: Version 1.2 completely revamps placement of light polling points in sectors. I can't imagine this has any lag.
Hey Doomer
 
Joined: 25 Sep 2021

Re: Building a Smarter Flashlight [Update 1/6/22]

Postby Hey Doomer » Thu Jan 06, 2022 4:11 am

I have posted a major update that scraps the iterator code for a simple line trace. Here's what it looks like in action:

Screenshot_Doom_20220106_050326-576x324.png

Screenshot_Doom_20220106_050334-576x324.png


In the top screenshot, the flashlight is pointed into a sector with a light of 192 but does not turn off, since the player is still in darkness.

The bottom screenshot shows the player is now in the brighter sector, and the light turns off.

So in that sense this is much smarter in "knowing" what the player is looking at. It polls the light around the player and then polls light at the end of the line trace or where it hits a wall.
Hey Doomer
 
Joined: 25 Sep 2021

Re: Building a Smarter Flashlight [Update 1/6/22]

Postby Enjay » Thu Jan 06, 2022 1:00 pm

Very nice - this is indeed a cool idea and the smart aspect of it seems to be working very well.

For my tastes, I think I'll set it to require things to be a bit darker than the default. IMO 128 is still bright enough to see easily so I'd rather have the light off under those conditions rather than wake up the enemies and miss being able to ambush them. You've made it easy to configure though, so I just need to find a suitable value. I don't suppose it will be much lower though because mappers generally don't tend to go much below 96. So it'll be a compromise to find a nice sweet spot of on often enough but not too often.

Oh, and:
Code: Select allExpand view
Script warning, "smartlight.pk3:smartlight_events.zs" line 94:
Accessing deprecated member variable X - deprecated since 2.3.0, Use Pos.X instead
Script warning, "smartlight.pk3:smartlight_events.zs" line 94:
Accessing deprecated member variable Y - deprecated since 2.3.0, Use Pos.Y instead
script parsing took 200.04 ms
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: Building a Smarter Flashlight [Update 1/7/22]

Postby Hey Doomer » Fri Jan 07, 2022 8:50 am

SmartLight now detects dynamic lights bound to light sources:

Screenshot_Doom_20220107_092807-576x324.png

Screenshot_Doom_20220107_092816-576x324.png


The top screenshot shows the player flashlight on moving toward the dark area. When it gets close enough to the lamp, SmartLight turns itself off.

Caveats:

  • ZScript reads the first GLDEFS lump in the load order. So if you want to use lights.pk3, for example, make certain that is loaded before other GLDEF lumps.
  • Certain actors are excluded from being a light source: monsters, missiles, and anything with a NOGRAVITY flag set.
  • This doesn't detect lights that are attached to actor states in DECORATE or ZScript. Currently only looks at static sources in GLDEFS.
  • This assumes light sources aren't subtractive.

Other than this, my beta testing looks good. I've added options to enable or disable this as it may cause a performance hit. I've added an option for the minimal light size to trigger the SmartLight (default is 64). Currently this only looks at the first size option in a definition, so it will ignore barrel explosions, for example. Also, it looks at each light source independently of each other and doesn't consider cumulative dynamic lights.

I'm not convinced CheckSight() correctly sees these objects, but I'm trying this before going to scripted solutions assuming a native function is faster. Generally that may not matter.

That's about it. Please let me know what you think!
Hey Doomer
 
Joined: 25 Sep 2021

Re: Building a Smarter Flashlight [Update 1/7/22]

Postby Enjay » Fri Jan 07, 2022 4:24 pm

That's very neat. I haven't had a chance to test it on a map that has map-placed dynamic light objects of the various types yet. Does it detect those too (e.g. the 9800 light, 9830 Attenuated light etc)?

And, just to update this one, your changes have obviously moved the line numbers of this warning:
Code: Select allExpand view
Script warning, "smartlight.pk3:smartlight_events.zs" line 100:
Accessing deprecated member variable X - deprecated since 2.3.0, Use Pos.X instead
Script warning, "smartlight.pk3:smartlight_events.zs" line 100:
Accessing deprecated member variable Y - deprecated since 2.3.0, Use Pos.Y instead
script parsing took 203.19 ms
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
 
 
Joined: 15 Jul 2003
Location: Scotland

Re: Building a Smarter Flashlight [Update 1/7/22]

Postby Hey Doomer » Fri Jan 07, 2022 5:55 pm

Enjay wrote:That's very neat. I haven't had a chance to test it on a map that has map-placed dynamic light objects of the various types yet. Does it detect those too (e.g. the 9800 light, 9830 Attenuated light etc)?


For now this detects actors that have a binding dynamic light defined in GLDEFS. I'll have to look into others next.
Hey Doomer
 
Joined: 25 Sep 2021


Return to Gameplay Mods

Who is online

Users browsing this forum: No registered users and 20 guests