meetric1 / gmod-infinite-map

GNU General Public License v3.0
181 stars 30 forks source link

WaterLevel detour #81

Open Cpt-Hazama opened 1 year ago

Cpt-Hazama commented 1 year ago

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 commented 1 year ago

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

meetric1 commented 1 year ago

like, im not sure how source handles their water

Cpt-Hazama commented 1 year ago

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