Example #1
0
    /// <summary>
    /// DO NOT USE FOR SIMULATION!!
    /// It's intended use is to render things, like units, above the map, respecting the map height visual.
    /// </summary>
    public static float GetElevationOfPosition(FractionalHex position, ActiveMap customActiveMap = null)
    {
        ActiveMap activeMap;

        if (customActiveMap == null)
        {
            activeMap = MapManager.ActiveMap;
            Debug.Assert(activeMap != null, "The Active Map is null!!!");
        }
        else
        {
            activeMap = customActiveMap;
        }


        Hex            standingHex = position.Round();
        GeographicTile geographicTile;

        if (!activeMap.map.GeographicMapValues.TryGetValue(standingHex, out geographicTile))
        {
            Debug.LogWarning($"There is no map hex on the {position} of the map! returning 0 extra height");
            return(0);
        }
        if (!geographicTile.IsSlope)
        {
            int level = GeographicTile.GetValueOfHeight(geographicTile.heightLevel);
            return(level * activeMap.heightPerElevationUnit);
        }
        var slopeData = geographicTile.slopeData;

        bool isSimpleSlope;
        SimpleSlopeDirection simpleSlopeDirection;
        DoubleSlopeDirection doubleSlopeDirection;

        GetTheDirectionAndTypeOfSlope(slopeData, out isSimpleSlope, out simpleSlopeDirection, out doubleSlopeDirection);


        var positionRelativeToHex = position - (FractionalHex)standingHex;

        if (isSimpleSlope)
        {
            int bottomLevel;
            int upperLevel;
            GetHeightLevels(simpleSlopeDirection, slopeData, out bottomLevel, out upperLevel);
            float lerpFactor = GetInterpolationValue(simpleSlopeDirection, positionRelativeToHex);

            return(Mathf.Lerp((float)bottomLevel, (float)upperLevel, lerpFactor) * activeMap.heightPerElevationUnit);
        }
        else
        {
            int bottomLevel;
            int upperLevel;
            GetHeightLevels(doubleSlopeDirection, slopeData, out bottomLevel, out upperLevel);
            float lerpFactor = GetInterpolationValue(doubleSlopeDirection, positionRelativeToHex);


            return(Mathf.Lerp((float)bottomLevel, (float)upperLevel, lerpFactor) * activeMap.heightPerElevationUnit);
        }
    }
Example #2
0
    private static void GetHeightLevels(DoubleSlopeDirection doubleSlopeDirection, SlopeData slopeData, out int bottomLevel, out int upperLevel)
    {
        switch (doubleSlopeDirection)
        {
        case DoubleSlopeDirection.UDEFINDED:
            bottomLevel = 0;
            upperLevel  = 0;
            Debug.LogError("The double slope direction is undefined. You may want to use the simple slope directions instead");
            break;

        case DoubleSlopeDirection.TOP_LEFT:
            bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_1r);
            upperLevel  = GeographicTile.GetValueOfHeight(slopeData.heightSide_4l);
            break;

        case DoubleSlopeDirection.TOP:
            bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_2dr);
            upperLevel  = GeographicTile.GetValueOfHeight(slopeData.heightSide_5tl);
            break;

        case DoubleSlopeDirection.TOP_RIGHT:
            bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_3dl);
            upperLevel  = GeographicTile.GetValueOfHeight(slopeData.heightSide_0tr);
            break;

        case DoubleSlopeDirection.DOWN_RIGHT:
            bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_4l);
            upperLevel  = GeographicTile.GetValueOfHeight(slopeData.heightSide_1r);
            break;

        case DoubleSlopeDirection.DOWN:
            bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_5tl);
            upperLevel  = GeographicTile.GetValueOfHeight(slopeData.heightSide_2dr);
            break;

        case DoubleSlopeDirection.DOWN_LEFT:
            bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_0tr);
            upperLevel  = GeographicTile.GetValueOfHeight(slopeData.heightSide_3dl);
            break;

        default:
            bottomLevel = 0;
            upperLevel  = 0;
            Debug.LogError("The double slope direction is undefined. You may want to use the simple slope directions instead");
            break;
        }
    }