private MapInfoBuilder GetStandardMapInfoBuilderForTemplates() { var builder = new MapInfoBuilder(); var l1ConnectivityMap = new ConnectivityMap(); l1ConnectivityMap.AddRoomConnection(1, 2); l1ConnectivityMap.AddRoomConnection(2, 3); var corridor1 = new RoomTemplateTerrain[1, 3]; var corridor2 = new RoomTemplateTerrain[3, 1]; var room1 = new RoomTemplateTerrain[4, 4]; var l1RoomList = new List <TemplatePositioned>(); l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(corridor1), 0)); l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(corridor2), 1)); l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(room1), 2)); var l1DoorDict = new Dictionary <Connection, Point>(); l1DoorDict.Add(new Connection(2, 3), new Point(5, 5)); builder.AddConstructedLevel(0, l1ConnectivityMap, l1RoomList, l1DoorDict, 1); return(builder); }
private RoomTemplateTerrain OverrideFloorTerrain(RoomTemplateTerrain originTerrain, RoomTemplateTerrain newTerrain) { if (originTerrain == RoomTemplateTerrain.Transparent) { return(newTerrain); } else if (newTerrain == RoomTemplateTerrain.Transparent) { return(originTerrain); } else { //Can overlap identical terrain if (newTerrain == originTerrain) { return(originTerrain); } //Can replace floor with new terrain if (originTerrain == RoomTemplateTerrain.Floor) { return(newTerrain); } //Mismatched terrain throws exception throw new ApplicationException("Can't overlap terrain"); } }
/// <summary> /// Merge in terrain at location, ignoring using transparent requirement /// </summary> /// <param name="location"></param> /// <param name="terrain"></param> public void AddOverrideTerrain(Point location, RoomTemplateTerrain terrain) { RoomTemplateTerrain[,] terrainToAdd = new RoomTemplateTerrain[1, 1]; terrainToAdd[0, 0] = terrain; mapCache.MergeArea(location, terrainToAdd, OverrideTerrain); }
public void ReplaceConnectedDoorsWithTerrain(RoomTemplateTerrain roomTemplateTerrain) { foreach (var door in ConnectionDoors) { mapBuilder.AddOverrideTerrain(door.Value.MapCoords, roomTemplateTerrain); } }
/// <summary> /// Ensure that rooms can't completely overlap (which passes - is any terrain different - test) /// by requiring some different terrain (which implicitally must be transparent) /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> /// <returns></returns> private bool CheckNotCompletelyOverlapping(RoomTemplateTerrain arg1, RoomTemplateTerrain arg2) { if (arg1 != arg2) { return(true); } return(false); }
public void ReplaceUnconnectedDoorsWithTerrain(RoomTemplateTerrain roomTemplateTerrain) { foreach (var door in PotentialDoors) { mapBuilder.AddOverrideTerrain(door.MapCoords, roomTemplateTerrain); } PotentialDoors.Clear(); }
private RoomTemplateTerrain MergeTerrain(RoomTemplateTerrain originTerrain, RoomTemplateTerrain newTerrain) { if (originTerrain == RoomTemplateTerrain.Transparent) { return(newTerrain); } else if (newTerrain == RoomTemplateTerrain.Transparent) { return(originTerrain); } else { //Can overlap indentical terrain if (newTerrain == originTerrain) { return(originTerrain); } //Mismatched terrain throws exception throw new ApplicationException("Can't overlap terrain"); } }
private void SetMapRelatedMembers(RoomTemplateTerrain[,] terrain) { this.terrainMap = (RoomTemplateTerrain[,])terrain.Clone(); Width = terrainMap.GetLength(0); Height = terrainMap.GetLength(1); }
private static RoomTemplateTerrain[,] RotateTerrainRight(RoomTemplateTerrain[,] matrix) { int w = matrix.GetLength(0); int h = matrix.GetLength(1); RoomTemplateTerrain[,] ret = new RoomTemplateTerrain[h, w]; for (int i = 0; i < w; ++i) { for (int j = h - 1; j >= 0; j--) { ret[h - 1 - j, i] = matrix[i, j]; } } return ret; }
/// <summary> /// Returns terrain, start of corridor, end of corridor /// </summary> /// <param name="xOffset"></param> /// <param name="yOffset"></param> /// <param name="corridorTemplate"></param> /// <returns></returns> private static Tuple<RoomTemplateTerrain[, ], Point, Point> GenerateBaseCorridorLShaped(int xOffset, int yOffset, RoomTemplate corridorTemplate) { var absXOffset = Math.Abs(xOffset); var absYOffset = Math.Abs(yOffset); var leftFromCentre = (int)Math.Floor((corridorTemplate.Width - 1) / 2.0); var rightFromCentre = corridorTemplate.Width - 1 - leftFromCentre; var width = absXOffset + leftFromCentre + 1; var height = absYOffset + corridorTemplate.Width - 1; var openSquares = corridorTemplate.Width - 2; var newRoom = new RoomTemplateTerrain[width, height]; //Down left for (int j = 0; j <= yOffset; j++) { for (int i = 0; i < corridorTemplate.Width; i++) { newRoom[i, j] = corridorTemplate.terrainMap[i, 0]; } } //Cap for (int i = 0; i < corridorTemplate.Width; i++) { //Use the outside character (should be solid) newRoom[i, yOffset + 1] = corridorTemplate.terrainMap[0, 0]; } //Overlay rotated cross-corridor. Always prefer open to closed for (int j = 1; j <= absXOffset + 1; j++) { for (int i = 0; i < corridorTemplate.Width; i++) { if (newRoom[j, yOffset - 1 + i] == RoomTemplateTerrain.Transparent || corridorTemplate.terrainMap[i, 0] == RoomTemplateTerrain.Floor) newRoom[j, yOffset - 1 + i] = corridorTemplate.terrainMap[i, 0]; } } return new Tuple<RoomTemplateTerrain[,], Point, Point>(newRoom, new Point(leftFromCentre, 0), new Point(absXOffset + leftFromCentre, absYOffset)); }
/// <summary> /// Return a new template with terrain set to all Transparent /// </summary> public static TemplatePositioned TransparentTemplate(TemplatePositioned templateToReplace) { var newTerrain = new RoomTemplateTerrain [templateToReplace.Room.Width, templateToReplace.Room.Height]; for (int i = 0; i < templateToReplace.Room.Width; i++) { for (int j = 0; j < templateToReplace.Room.Height; j++) { newTerrain[i, j] = RoomTemplateTerrain.Transparent; } } return new TemplatePositioned(templateToReplace.X, templateToReplace.Y, templateToReplace.Z, new RoomTemplate(newTerrain), templateToReplace.RoomIndex); }
/// <summary> /// Returns point in map coords of this level in the required room of terrain /// </summary> /// <param name="roomIndex"></param> /// <param name="terrainToFind"></param> /// <returns></returns> public Point GetRandomPointInRoomOfTerrain(int roomIndex, RoomTemplateTerrain terrainToFind) { var roomRelativePoint = RoomTemplateUtilities.GetRandomPointWithTerrain(rooms[roomIndex].Room, terrainToFind); return new Point(rooms[roomIndex].Location + roomRelativePoint); }
public void TransparentTemplateReturnsAFullyTransparentTemplate() { RoomTemplate baseTemplate = LoadTemplateFromAssemblyFile("DDRogueTest.testdata.vaults.testalignmentroom1.room"); var originalTemplatePositioned = new TemplatePositioned(1, 2, 3, baseTemplate, 0); var transparentTemplatePositioned = RoomTemplateUtilities.TransparentTemplate(originalTemplatePositioned); Assert.AreEqual(1, transparentTemplatePositioned.X); Assert.AreEqual(2, transparentTemplatePositioned.Y); Assert.AreEqual(3, transparentTemplatePositioned.Z); Assert.AreEqual(0, transparentTemplatePositioned.RoomIndex); var expectedTerrain = new RoomTemplateTerrain[originalTemplatePositioned.Room.Width, originalTemplatePositioned.Room.Height]; for (int i = 0; i < originalTemplatePositioned.Room.Width; i++) { for (int j = 0; j < originalTemplatePositioned.Room.Height; j++) { expectedTerrain[i, j] = RoomTemplateTerrain.Transparent; } } CollectionAssert.AreEqual(expectedTerrain, transparentTemplatePositioned.Room.terrainMap); }
public RoomTemplate(RoomTemplateTerrain[,] terrain, bool isCorridor) { SetMapRelatedMembers(terrain); IsCorridor = isCorridor; }
public static Tuple<RoomTemplate, Point> ExpandCorridorTemplateLShaped(int xOffset, int yOffset, bool horizontalFirst, RoomTemplate corridorTemplate) { if (corridorTemplate.Height > 1) throw new ApplicationException("Only corridor templates of height 1 supported"); //I think the code is getting there for #..# but I don't want to put the time in now if (corridorTemplate.Width != 3) throw new ApplicationException("Only corridor templates of width 3 supported"); if(Math.Abs(xOffset) < 1 || Math.Abs(yOffset) < 1) throw new ApplicationException("offset must be at least 1"); int mirroring = 0; RoomTemplateTerrain[,] newRoom; bool useEndPoint = false; if (xOffset < 0 && yOffset < 0) { mirroring = horizontalFirst ? 0 : 2; useEndPoint = horizontalFirst ? true : false; } if (xOffset > 0 && yOffset > 0) { mirroring = horizontalFirst ? 2 : 0; useEndPoint = horizontalFirst ? true : false; } if (xOffset < 0 && yOffset > 0) { mirroring = horizontalFirst ? 3 : 1; useEndPoint = horizontalFirst ? true : false; } if (xOffset > 0 && yOffset < 0) { mirroring = horizontalFirst ? 1 : 3; useEndPoint = horizontalFirst ? true : false; } var roomAndStartPoint = GenerateBaseCorridorLShaped(Math.Abs(xOffset), Math.Abs(yOffset), corridorTemplate); newRoom = roomAndStartPoint.Item1; var startPoint = roomAndStartPoint.Item2; var endPoint = roomAndStartPoint.Item3; RoomTemplate mapToReturn = null; Point startPointMirror = null; Point endPointMirror = null; if (mirroring == 0) { mapToReturn = new RoomTemplate(newRoom, true); startPointMirror = startPoint; endPointMirror = endPoint; } //Horizontal reflection if (mirroring == 1) { var mirrorRoom = new RoomTemplateTerrain[newRoom.GetLength(0), newRoom.GetLength(1)]; for (int i = 0; i < newRoom.GetLength(0); i++) { for (int j = 0; j < newRoom.GetLength(1); j++) { mirrorRoom[newRoom.GetLength(0) - 1 - i, j] = newRoom[i, j]; } } mapToReturn = new RoomTemplate(mirrorRoom, true); startPointMirror = new Point(newRoom.GetLength(0) - 1 - startPoint.x, startPoint.y); endPointMirror = new Point(newRoom.GetLength(0) - 1 - endPoint.x, endPoint.y); } //Y=-X mirror if (mirroring == 2) { var mirrorRoom = new RoomTemplateTerrain[newRoom.GetLength(0), newRoom.GetLength(1)]; for (int i = 0; i < newRoom.GetLength(0); i++) { for (int j = 0; j < newRoom.GetLength(1); j++) { mirrorRoom[i, j] = newRoom[newRoom.GetLength(0) - 1 - i, newRoom.GetLength(1) - 1 - j]; } } mapToReturn = new RoomTemplate(mirrorRoom, true); startPointMirror = new Point(newRoom.GetLength(0) - 1 - startPoint.x, newRoom.GetLength(1) - 1 - startPoint.y); endPointMirror = new Point(newRoom.GetLength(0) - 1 - endPoint.x, newRoom.GetLength(1) - 1 - endPoint.y); } //Vertical reflection if (mirroring == 3) { var mirrorRoom = new RoomTemplateTerrain[newRoom.GetLength(0), newRoom.GetLength(1)]; for (int i = 0; i < newRoom.GetLength(0); i++) { for (int j = 0; j < newRoom.GetLength(1); j++) { mirrorRoom[i, newRoom.GetLength(1) - 1 - j] = newRoom[i, j]; } } mapToReturn = new RoomTemplate(mirrorRoom, true); startPointMirror = new Point(startPoint.x, newRoom.GetLength(1) - 1 - startPoint.y); endPointMirror = new Point(endPoint.x, newRoom.GetLength(1) - 1 - endPoint.y); } if(useEndPoint) return new Tuple<RoomTemplate, Point>(mapToReturn, endPointMirror); else return new Tuple<RoomTemplate, Point>(mapToReturn, startPointMirror); }
/** Stretches a corridor template into a full sized corridor of length. * Template must be n x 1 (1 row deep).*/ public static RoomTemplate ExpandCorridorTemplate(bool switchToHorizontal, int length, RoomTemplate corridorTemplate) { if (corridorTemplate.Height > 1) throw new ApplicationException("Only corridor templates of height 1 supported"); RoomTemplateTerrain[,] newRoom; if (switchToHorizontal) { newRoom = new RoomTemplateTerrain[length, corridorTemplate.Width]; for (int j = 0; j < length; j++) { for (int i = 0; i < corridorTemplate.Width; i++) { newRoom[j, i] = corridorTemplate.terrainMap[i, 0]; } } } else { newRoom = new RoomTemplateTerrain[corridorTemplate.Width, length]; for (int j = 0; j < length; j++) { for (int i = 0; i < corridorTemplate.Width; i++) { newRoom[i, j] = corridorTemplate.terrainMap[i, 0]; } } } return new RoomTemplate(newRoom, true); }
public void ReplaceConnectedDoorsWithTerrain(RoomTemplateTerrain roomTemplateTerrain) { foreach (var door in ConnectionDoors) { mapBuilder.AddOverrideTerrain(door.Value.MapCoords, roomTemplateTerrain); } }
public void ReplaceUnconnectedDoorsWithTerrain(RoomTemplateTerrain roomTemplateTerrain) { foreach (var door in PotentialDoors) { mapBuilder.AddOverrideTerrain(door.MapCoords, roomTemplateTerrain); } PotentialDoors.Clear(); }
/// <summary> /// Returns point in map coords of this level in the required room of terrain /// </summary> /// <param name="roomIndex"></param> /// <param name="terrainToFind"></param> /// <returns></returns> public Point GetRandomPointInRoomOfTerrain(int roomIndex, RoomTemplateTerrain terrainToFind) { var roomRelativePoint = RoomTemplateUtilities.GetRandomPointWithTerrain(rooms[roomIndex].Room, terrainToFind); return(new Point(rooms[roomIndex].Location + roomRelativePoint)); }
private RoomTemplateTerrain OverrideTerrain(RoomTemplateTerrain originTerrain, RoomTemplateTerrain newTerrain) { return(newTerrain); }
/** Loads template from a file stream. Throws exception on failure */ public static RoomTemplate LoadTemplateFromFile(Stream fileStream, Dictionary<char, RoomTemplateTerrain> terrainMapping) { StreamReader reader = new StreamReader(fileStream); string thisLine; List<string> mapRows = new List<string>(); while ((thisLine = reader.ReadLine()) != null) { mapRows.Add(thisLine); } //Calculate dimensions int width = 0; int height = 0; foreach (string mapRow in mapRows) { if (mapRow.Length > width) width = mapRow.Length; height++; } if (width == 0) { LogFile.Log.LogEntry("No data in room template file stream"); throw new ApplicationException("No data in room template file - width is 0"); } //Build a 2d representation of the room RoomTemplateTerrain[,] roomMap = new RoomTemplateTerrain[width, height]; List<RoomTemplate.PotentialDoor> potentialDoors = new List<RoomTemplate.PotentialDoor>(); for (int y = 0; y < mapRows.Count; y++) { int x; for (x = 0; x < mapRows[y].Length; x++) { char inputTerrain = mapRows[y][x]; if (!terrainMapping.ContainsKey(inputTerrain)) { LogFile.Log.LogEntryDebug("No mapping for char : " + inputTerrain + " in file", LogDebugLevel.High); roomMap[x, y] = RoomTemplateTerrain.Transparent; } roomMap[x, y] = terrainMapping[inputTerrain]; } //Fill all rows to width length for (; x < width; x++) { roomMap[x, y] = RoomTemplateTerrain.Transparent; } } return new RoomTemplate(roomMap); }
private RoomTemplateTerrain MergeTerrain(RoomTemplateTerrain originTerrain, RoomTemplateTerrain newTerrain) { if (originTerrain == RoomTemplateTerrain.Transparent) { return newTerrain; } else if(newTerrain == RoomTemplateTerrain.Transparent) { return originTerrain; } else { //Can overlap indentical terrain if (newTerrain == originTerrain) return originTerrain; //Mismatched terrain throws exception throw new ApplicationException("Can't overlap terrain"); } }
public RoomTemplate(RoomTemplateTerrain[,] terrain) { SetMapRelatedMembers(terrain); }
private RoomTemplateTerrain OverrideTerrain(RoomTemplateTerrain originTerrain, RoomTemplateTerrain newTerrain) { return newTerrain; }
public static RoomTemplate BuildRectangularRoom(int width, int height, List<Point> doors) { var newRoom = new RoomTemplateTerrain[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { newRoom[i, j] = RoomTemplateTerrain.Floor; } } for (int i = 0; i < width; i++) { newRoom[i, 0] = RoomTemplateTerrain.Wall; newRoom[i, height - 1] = RoomTemplateTerrain.Wall; } for (int i = 1; i < height - 1; i++) { newRoom[0, i] = RoomTemplateTerrain.Wall; newRoom[width - 1, i] = RoomTemplateTerrain.Wall; } foreach (Point p in doors) { newRoom[p.x, p.y] = RoomTemplateTerrain.WallWithPossibleDoor; } return new RoomTemplate(newRoom); }
public IEnumerable <Point> GetAllPointsInRoomOfTerrain(int roomIndex, RoomTemplateTerrain terrainToFind) { var roomRelativePoints = RoomTemplateUtilities.GetPointsInRoomWithTerrain(rooms[roomIndex].Room, terrainToFind); return(roomRelativePoints.Select(p => new Point(rooms[roomIndex].Location + p))); }
/// <summary> /// Returns the template and the offset onto the template of the start points (where the offsets are relative to) /// </summary> public static Tuple<RoomTemplate, Point> ExpandCorridorTemplateBend(int xOffset, int yOffset, int lTransition, bool switchToHorizontal, RoomTemplate corridorTemplate) { if (corridorTemplate.Height > 1) throw new ApplicationException("Only corridor templates of height 1 supported"); //I think the code is getting there for #..# but I don't want to put the time in now if (corridorTemplate.Width != 3) throw new ApplicationException("Only corridor templates of width 3 supported"); if (Math.Abs(lTransition) < 1) throw new ApplicationException("transition must be at least 1"); if(Math.Abs(xOffset) < 2 && switchToHorizontal) throw new ApplicationException("Need x-offset of at least 2 for horizontal corridor"); if (Math.Abs(yOffset) < 2 && !switchToHorizontal) throw new ApplicationException("Need y-offset of at least 2 for vertical corridor"); int mirroring = 0; RoomTemplateTerrain[,] newRoom; bool useEndPoint = false; if (xOffset < 0 && yOffset < 0) { useEndPoint = switchToHorizontal ? false : true; } if (xOffset > 0 && yOffset > 0) { useEndPoint = switchToHorizontal ? true : false; } if (xOffset < 0 && yOffset > 0) { useEndPoint = switchToHorizontal ? true : false; } if (xOffset > 0 && yOffset < 0) { useEndPoint = switchToHorizontal ? false : true; } Point startPoint; Point endPoint; if (switchToHorizontal) { if (xOffset < 0 && lTransition > 0 || xOffset > 0 && lTransition < 0) throw new ApplicationException("Transition is not within corridor"); //Horizontal mirroring = 2; int transition = lTransition > 0 ? Math.Abs(xOffset) - lTransition : -lTransition; if (xOffset * yOffset < 0) { mirroring = 3; transition = lTransition > 0 ? lTransition : Math.Abs(xOffset) + lTransition; } var corridorBend = GenerateBaseCorridorBend(yOffset, xOffset, transition, corridorTemplate); newRoom = corridorBend.Item1; startPoint = corridorBend.Item2; endPoint = corridorBend.Item3; } else { if (yOffset < 0 && lTransition > 0 || yOffset > 0 && lTransition < 0) throw new ApplicationException("Transition is not within corridor"); //Vertical int transition = lTransition > 0 ? lTransition : Math.Abs(yOffset) + lTransition; if (xOffset * yOffset < 0) mirroring = 1; var corridorBend = GenerateBaseCorridorBend(xOffset, yOffset, transition, corridorTemplate); newRoom = corridorBend.Item1; startPoint = corridorBend.Item2; endPoint = corridorBend.Item3; } RoomTemplate templateToReturn = null; Point startPointToRet = null; Point endPointToRet = null; if (mirroring == 0) { templateToReturn = new RoomTemplate(newRoom, true); startPointToRet = startPoint; endPointToRet = endPoint; } //Horizontal reflection if (mirroring == 1) { var mirrorRoom = new RoomTemplateTerrain[newRoom.GetLength(0), newRoom.GetLength(1)]; for (int i = 0; i < newRoom.GetLength(0); i++) { for (int j = 0; j < newRoom.GetLength(1); j++) { mirrorRoom[newRoom.GetLength(0) - 1 - i, j] = newRoom[i, j]; } } templateToReturn = new RoomTemplate(mirrorRoom, true); startPointToRet = new Point(newRoom.GetLength(0) - 1 - startPoint.x, startPoint.y); endPointToRet = new Point(newRoom.GetLength(0) - 1 - endPoint.x, endPoint.y); } //X-Y mirror if (mirroring == 2) { var mirrorRoom = new RoomTemplateTerrain[newRoom.GetLength(1), newRoom.GetLength(0)]; for (int i = 0; i < newRoom.GetLength(0); i++) { for (int j = 0; j < newRoom.GetLength(1); j++) { mirrorRoom[newRoom.GetLength(1) - 1 - j, newRoom.GetLength(0) - 1 - i] = newRoom[i, j]; } } templateToReturn = new RoomTemplate(mirrorRoom, true); startPointToRet = new Point(newRoom.GetLength(1) - 1 - startPoint.y, newRoom.GetLength(0) - 1 - startPoint.x); endPointToRet = new Point(newRoom.GetLength(1) - 1 - endPoint.y, newRoom.GetLength(0) - 1 - endPoint.x); } //X-Y mirror, Y reflect if (mirroring == 3) { var mirrorRoom = new RoomTemplateTerrain[newRoom.GetLength(1), newRoom.GetLength(0)]; for (int i = 0; i < newRoom.GetLength(0); i++) { for (int j = 0; j < newRoom.GetLength(1); j++) { mirrorRoom[j, newRoom.GetLength(0) - 1 - i] = newRoom[i, j]; } } templateToReturn = new RoomTemplate(mirrorRoom, true); startPointToRet = new Point(startPoint.y, newRoom.GetLength(0) - 1 - startPoint.x); endPointToRet = new Point(endPoint.y, newRoom.GetLength(0) - 1 - endPoint.x); } if (useEndPoint) return new Tuple<RoomTemplate, Point>(templateToReturn, endPointToRet); else return new Tuple<RoomTemplate, Point>(templateToReturn, startPointToRet); }
private MapInfoBuilder GetStandardMapInfoBuilderForTemplates() { var builder = new MapInfoBuilder(); var l1ConnectivityMap = new ConnectivityMap(); l1ConnectivityMap.AddRoomConnection(1, 2); l1ConnectivityMap.AddRoomConnection(2, 3); var corridor1 = new RoomTemplateTerrain[1,3]; var corridor2 = new RoomTemplateTerrain[3, 1]; var room1 = new RoomTemplateTerrain[4, 4]; var l1RoomList = new List<TemplatePositioned>(); l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(corridor1), 0)); l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(corridor2), 1)); l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(room1), 2)); var l1DoorDict = new Dictionary<Connection, Point>(); l1DoorDict.Add(new Connection(2, 3), new Point(5, 5)); builder.AddConstructedLevel(0, l1ConnectivityMap, l1RoomList, l1DoorDict, 1); return builder; }
/// <summary> /// Ensure that rooms can't completely overlap (which passes - is any terrain different - test) /// by requiring some different terrain (which implicitally must be transparent) /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> /// <returns></returns> private bool CheckNotCompletelyOverlapping(RoomTemplateTerrain arg1, RoomTemplateTerrain arg2) { if (arg1 != arg2) return true; return false; }
public static List<Point> GetPointsInRoomWithTerrain(RoomTemplate room, RoomTemplateTerrain terrainToFind) { var candidatePoints = new List<Point>(); for (int i = 0; i < room.Width; i++) { for (int j = 0; j < room.Height; j++) { if (room.terrainMap[i, j] == terrainToFind) candidatePoints.Add(new Point(i, j)); } } return candidatePoints; }
private RoomTemplateTerrain OverrideFloorTerrain(RoomTemplateTerrain originTerrain, RoomTemplateTerrain newTerrain) { if (originTerrain == RoomTemplateTerrain.Transparent) { return newTerrain; } else if (newTerrain == RoomTemplateTerrain.Transparent) { return originTerrain; } else { //Can overlap identical terrain if (newTerrain == originTerrain) return originTerrain; //Can replace floor with new terrain if (originTerrain == RoomTemplateTerrain.Floor) return newTerrain; //Mismatched terrain throws exception throw new ApplicationException("Can't overlap terrain"); } }
public static Point GetRandomPointWithTerrain(RoomTemplate room, RoomTemplateTerrain terrainToFind) { var candidatePoints = GetPointsInRoomWithTerrain(room, terrainToFind); return candidatePoints[Game.Random.Next(candidatePoints.Count)]; }
/// <summary> /// Merge in terrain at location, ignoring using transparent requirement /// </summary> /// <param name="location"></param> /// <param name="terrain"></param> public void AddOverrideTerrain(Point location, RoomTemplateTerrain terrain) { RoomTemplateTerrain[,] terrainToAdd = new RoomTemplateTerrain[1,1]; terrainToAdd[0, 0] = terrain; mapCache.MergeArea(location, terrainToAdd, OverrideTerrain); }
public IEnumerable<Point> GetAllPointsInRoomOfTerrain(int roomIndex, RoomTemplateTerrain terrainToFind) { var roomRelativePoints = RoomTemplateUtilities.GetPointsInRoomWithTerrain(rooms[roomIndex].Room, terrainToFind); return roomRelativePoints.Select(p => new Point(rooms[roomIndex].Location + p)); }