SmartLight (POC)

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

SmartLight (POC)

Post by Hey Doomer »

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 all

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 all

	// 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:

Return to “Script Library”