Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WaterLevel detour #81

Open
Cpt-Hazama opened this issue Dec 20, 2022 · 3 comments
Open

WaterLevel detour #81

Cpt-Hazama opened this issue Dec 20, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@Cpt-Hazama
Copy link

Would it be possible to detour WaterLevel with your custom water system so that aquatic-based NPCs can at least swim around? They also utilize the MASK_WATER filter when moving, Im not sure if that's something that could be added into your water system or not tho

@meetric1
Copy link
Owner

its unlikely I will add this detour because im not sure how to write it

@meetric1
Copy link
Owner

like, im not sure how source handles their water

@Cpt-Hazama
Copy link
Author

Cpt-Hazama commented Dec 22, 2022

Looking at Source's sauce, the CPP function operates as such

// Search for water transition along a vertical line
float UTIL_WaterLevel( const Vector &position, float minz, float maxz )
{
	Vector midUp = position;
	midUp.z = minz;

	if ( !(UTIL_PointContents(midUp) & MASK_WATER) )
		return minz;

	midUp.z = maxz;
	if ( UTIL_PointContents(midUp) & MASK_WATER )
		return maxz;

	float diff = maxz - minz;
	while (diff > 1.0)
	{
		midUp.z = minz + diff/2.0;
		if ( UTIL_PointContents(midUp) & MASK_WATER )
		{
			minz = midUp.z;
		}
		else
		{
			maxz = midUp.z;
		}
		diff = maxz - minz;
	}

	return midUp.z;
}

This should be replicatable in the sense that the trace position would be detoured like everything else, WaterLevel in lua has no arguments but the required information can easily be set and ran with a code similar to this instead of the default WaterLevel running

@meetric1 meetric1 added the enhancement New feature or request label Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants