/// <summary> /// Given a certain starting point, this method will scan blocks above and below the starting point, and look for a suitable place to spawn a new corpse. /// <para>The algorithm does <i>not</i> account for existing corpse blocks, its only purpose is to find a suitable 'ground level'.</para> /// </summary> /// <param name="startingPoint">The starting location to begin searching for ground from.</param> /// <returns>The ground position for the given starting point, or -1 if no reasonable position could be found.</returns> public int FindPositionAboveGroundAt(Vector3i startingPoint) { int groundPosition = -1; if (cache.GetGroundPositionFor(startingPoint, out groundPosition)) { return(groundPosition); } Vector3i airBlock = GetAirBlockForLocation(startingPoint); groundPosition = FindGroundBelow(airBlock); if (groundPosition < minHeight) { cache.CacheGroundPositionForLocation(startingPoint, -1); return(-1); } groundPosition++; if (airBlock.y < startingPoint.y) { startingPoint.y = maxHeight; } cache.CacheGroundPositionForLocation(startingPoint, groundPosition); return(groundPosition); }
public void WhenGroundPositionIsCachedForACertainLocationThenItCanBeRecalled() { int groundHeight = 27; Vector3i startingPosition = new Vector3i(2, 3, 7); cache.CacheGroundPositionForLocation(startingPosition, groundHeight); int cachedHeight = -1; bool valueExists = cache.GetGroundPositionFor(startingPosition, out cachedHeight); Assert.That(valueExists, Is.True); Assert.That(cachedHeight, Is.EqualTo(groundHeight)); }