/// <summary> /// Shrinks a map matrix to its exact needed coordinate bounds /// </summary> /// <param name="map"></param> /// <returns></returns> public static long[,,] ShrinkMap(long[,,] map) { //We take a "full slice" of the map to shrink it return(TakeSliceOfMap(new Tuple <int, int>(map.GetLowerBound(0), map.GetUpperBound(0)) , new Tuple <int, int>(map.GetLowerBound(1), map.GetUpperBound(1)) , new Tuple <int, int>(map.GetLowerBound(2), map.GetUpperBound(2)) , map, true)); }
/// <summary> /// Finds the central room of a given map /// </summary> /// <param name="map">the map x,y,z</param> /// <param name="zIndex">If > -1 we're looking for the x,y center of the single plane as opposed to the actual x,y,z center of the whole map</param> /// <returns>the central room</returns> public static IRoomTemplate FindCenterOfMap(long[,,] map, int zIndex = -1) { int zCenter = zIndex; //If we want a specific z index thats fine, otherwise we find the middle Z if (zIndex == -1) { zCenter = (map.GetUpperBound(2) - map.GetLowerBound(2)) / 2 + map.GetLowerBound(2); } int xCenter = (map.GetUpperBound(0) - map.GetLowerBound(0)) / 2 + map.GetLowerBound(0); int yCenter = (map.GetUpperBound(1) - map.GetLowerBound(1)) / 2 + map.GetLowerBound(1); long roomId = map[xCenter, yCenter, zCenter]; if (roomId < 0) { for (int variance = 1; variance <= xCenter - map.GetLowerBound(0) && variance <= map.GetUpperBound(0) - xCenter && variance <= yCenter - map.GetLowerBound(1) && variance <= map.GetUpperBound(1) - yCenter ; variance++) { //Check around it if (map[xCenter - variance, yCenter, zCenter] >= 0) { roomId = map[xCenter - variance, yCenter, zCenter]; } else if (map[xCenter + variance, yCenter, zCenter] >= 0) { roomId = map[xCenter + variance, yCenter, zCenter]; } else if (map[xCenter, yCenter - variance, zCenter] >= 0) { roomId = map[xCenter, yCenter - variance, zCenter]; } else if (map[xCenter, yCenter + variance, zCenter] >= 0) { roomId = map[xCenter, yCenter + variance, zCenter]; } else if (map[xCenter - variance, yCenter - variance, zCenter] >= 0) { roomId = map[xCenter - variance, yCenter - variance, zCenter]; } else if (map[xCenter - variance, yCenter + variance, zCenter] >= 0) { roomId = map[xCenter - variance, yCenter + variance, zCenter]; } else if (map[xCenter + variance, yCenter - variance, zCenter] >= 0) { roomId = map[xCenter + variance, yCenter - variance, zCenter]; } else if (map[xCenter + variance, yCenter + variance, zCenter] >= 0) { roomId = map[xCenter + variance, yCenter + variance, zCenter]; } if (roomId >= 0) { break; } } } //Well, no valid rooms on this Z so try another Z unless all we got was this one Z if (roomId < 0 && zIndex == -1) { IRoomTemplate returnRoom = null; for (int variance = 1; variance < zCenter - map.GetLowerBound(2) && variance < map.GetUpperBound(2) - zCenter ; variance++) { returnRoom = FindCenterOfMap(map, zCenter - variance); if (returnRoom != null) { break; } returnRoom = FindCenterOfMap(map, zCenter + variance); if (returnRoom != null) { break; } } return(returnRoom); } return(TemplateCache.Get <IRoomTemplate>(roomId)); }
/// <summary> /// Is this coordinate out of bounds of the map /// </summary> /// <param name="boundings">a 3d coordinate x,y,z</param> /// <param name="map">the 3d map in question</param> /// <returns>whether it is out of bounds of the map</returns> public static bool IsOutOfBounds(Coordinate boundings, long[,,] map) { return(map.GetUpperBound(0) < boundings.X || map.GetLowerBound(0) > boundings.X || map.GetUpperBound(1) < boundings.Y || map.GetLowerBound(1) > boundings.Y || map.GetUpperBound(2) < boundings.Z || map.GetLowerBound(2) > boundings.Z); }