public DirectionType CalculateDeadEndCorridorDirection(CellLocation location) { if (!IsDeadEnd(location)) { throw new InvalidOperationException(); } if (this.cells[location.x, location.y - 1].Type == VirtualCell.CellType.EmptyPassage) { return(DirectionType.South); } if (this.cells[location.x, location.y + 1].Type == VirtualCell.CellType.EmptyPassage) { return(DirectionType.North); } if (this.cells[location.x - 1, location.y].Type == VirtualCell.CellType.EmptyPassage) { return(DirectionType.West); } if (this.cells[location.x + 1, location.y].Type == VirtualCell.CellType.EmptyPassage) { return(DirectionType.East); } throw new InvalidOperationException(); }
// Returns true if this passage cell can be removed from the map (i.e. not shown) public bool IsPassageRemovable(CellLocation l) { VirtualCell cell = this.GetCell(l); if (cell.IsWall() || cell.IsEmpty()) { // We count how many valid neighs are floors, and how many are nones int validNeigh = 0; int floorCount = 0; int noneCount = 0; CellLocation n; foreach (DirectionType dir in directions) { n = GetNeighbourCellLocation(l, dir); if (!LocationIsOutsideBounds(n)) { validNeigh++; VirtualCell neigh_cell = GetCell(n); if (neigh_cell.IsFloor()) { floorCount++; } else if (neigh_cell.IsNone() || neigh_cell.IsRock()) { noneCount++; } } } //Debug.Log(l + " Valid neighs: " + validNeigh + " floorCount: " + floorCount + " noneCount: " + noneCount); return(floorCount == 0); } return(false); }
// Get a random visited cell public CellLocation GetRandomVisitedCell(CellLocation location) { List <CellLocation> tempCells = new List <CellLocation>(visitedCells); //tempCells.Remove(starting_location); // NOTE: when does visistedAndBlockedCells get populated??? foreach (CellLocation l in visitedAndBlockedCells) { tempCells.Remove(l); } foreach (CellLocation l in roomCells) { tempCells.Remove(l); } if (tempCells.Count == 0) { return(new CellLocation(-1, -1)); } int index = DungeonGenerator.Random.Instance.Next(0, tempCells.Count - 1); return(tempCells[index]); }
public bool CellsAreInTheSameRoom(CellLocation l1, CellLocation l2) { VirtualRoom room1 = null, room2 = null; foreach (VirtualRoom room in this.rooms) { if (room.containsLocation(l1)) { room1 = room; // Debug.Log ("ROOM 1: " + room1); break; } } foreach (VirtualRoom room in this.rooms) { if (room.containsLocation(l2)) { room2 = room; // Debug.Log ("ROOM 2: " + room2); break; } } // if (room1 == room2) Debug.Log ("SAME ROOM!"); // else Debug.Log ("NOT SAME!"); return(room1 == room2); }
public void MarkAsVisited(CellLocation l) { VirtualCell cell = GetCell(l); cell.visited = true; visitedCells.Add(l); }
// Is this cell's neighbour marked as Visited? public bool AdjacentCellInDirectionIsVisited(CellLocation location, DirectionType direction) { if (HasAdjacentCellInDirection(location, direction)) { switch (direction) { case DirectionType.South: return(this.GetCell(location.x, location.y - 2).visited); case DirectionType.West: return(this.GetCell(location.x - 2, location.y).visited); case DirectionType.North: return(this.GetCell(location.x, location.y + 2).visited); case DirectionType.East: return(this.GetCell(location.x + 2, location.y).visited); default: throw new InvalidOperationException(); } } return(false); }
/// <summary> /// Iterates through neighboring cells to determine if there are any connect fours /// from the starting cell along the plane of the location specified. /// </summary> /// <param name="startingCell">The cell to start searching for connects.</param> /// <param name="location">The location/direction to look.</param> /// <returns>The length of the connections in that location plane.</returns> public int GetConnectLength(GridCell startingCell, CellLocation location) { var length = 0; var player = startingCell.OccupyingPlayer; var direction = location; var reverseDirection = (CellLocation)(((int)location + 4) % 8); // check first direction GridCell firstMostCell = startingCell.Traverse(player, direction); // check reverse direction var lastMostCell = startingCell.Traverse(player, reverseDirection); // get the connection length length = firstMostCell.X - lastMostCell.X; // if we are looking vertically, we have to use Y diff instead of X if (direction == CellLocation.Above || direction == CellLocation.Below) { length = firstMostCell.Y - lastMostCell.Y; } return(Math.Abs(length) + 1); }
public void CellLocation_AfterCalled_XandYHaveProperValues() { var cellLocation = new CellLocation(2, 7); Assert.AreEqual(2, cellLocation.Row); Assert.AreEqual(7, cellLocation.Column); }
override public void StartDigging(VirtualMap map, CellLocation starting_location, int directionChangeModifier) { CellLocation currentLocation = starting_location; map.MarkAsVisited(currentLocation); // Pick a starting previous direction VirtualMap.DirectionType previousDirection = VirtualMap.DirectionType.North; List <CellLocation> previousLocations = new List <CellLocation>(); // Repeat until all cells have been visited while (!map.AllCellsVisited) { // Get a starting direction DirectionPicker directionPicker = new DirectionPicker(map, currentLocation, directionChangeModifier, previousDirection); VirtualMap.DirectionType direction = directionPicker.GetNextDirection(map, currentLocation); if (direction != VirtualMap.DirectionType.None) { // Create a corridor in the current cell and flag it as visited previousLocations.Add(currentLocation); previousDirection = direction; currentLocation = map.CreateCorridor(currentLocation, direction); map.FlagCellAsVisited(currentLocation); } else { // Backtrack currentLocation = previousLocations[previousLocations.Count - 1]; previousLocations.RemoveAt(previousLocations.Count - 1); } } }
internal void IsAt(CellLocation expectedLocation) { if (_ghost.Location != expectedLocation) { throw new Exception($"Ghost should be at {expectedLocation} not {_ghost.Location}"); } }
private bool CheckSkipDoorToCorridor(VirtualMap map, VirtualRoom r, CellLocation end_floor_loc) { // Note that 'dont skip' takes precedence! //Debug.Log(r + " to " + end_floor_loc); // At default, we do not skip bool skip = false; // Already connected: we should skip it skip = r.IsConnectedToCorridor(); //Debug.Log("Connected already? " + skip); // If 3 walls, we instead do not skip it skip = skip && !map.IsDeadEnd(end_floor_loc, alsoConsiderDoors: true); /*if (r.leftCorner.x == 9 && r.leftCorner.y == 3) * { * Debug.Log(r + " to " + end_floor_loc); * Debug.Log("3 walls? " + map.IsDeadEnd(end_floor_loc, alsoConsiderDoors: true)); * }*/ // If 4 walls, we instead do not skip it skip = skip && !map.IsSurroundedByWalls(end_floor_loc); //Debug.Log("4 walls? " + map.IsSurroundedByWalls(end_floor_loc)); // We do not skip if we request more doors skip = skip && !(DungeonGenerator.Random.Instance.Next(0, 100) < doorsDensityModifier); //Debug.Log("More doors? " + moreDoors); return(skip); }
/******************** * Door creation ********************/ // Create doors for a given room public void CreateDoors_Post(VirtualMap map, VirtualRoom r) { List <CellLocation> borderFloors = new List <CellLocation> (); // Examine borderFloors, create a list of border floors for (int i = 0; i < r.Width; i++) { for (int j = 0; j < r.Height; j++) { if (i == 0 || j == 0 || i == r.Width - 1 || j == r.Height - 1) { CellLocation l = new CellLocation(r.leftCorner.x + 2 * i, r.leftCorner.y + 2 * j); borderFloors.Add(l); } } } // Create doors close to the borders, where wall passages are CellLocation target_passage; foreach (CellLocation l in borderFloors) { foreach (VirtualMap.DirectionType dir in map.directions) { target_passage = map.GetNeighbourCellLocation(l, dir); if (map.GetCell(target_passage).IsWall()) { CheckDoorCreation(map, r, l, dir); } } } }
internal void IsAt(CellLocation expectedLocation) { if (_pacMan.Location != expectedLocation) { throw new Exception($"PacMan should be at {expectedLocation} not {_pacMan.Location}"); } }
private CellLocation GetPreviousInProgressCellLocation(CellLocation currentCellLocation) { do { if (currentCellLocation.Row <= 0 && currentCellLocation.Column <= 0) { // No more previous cells. throw new Exception("No more previous cells, you are at the beginning of cell"); } var previousCellLocation = new CellLocation() { Row = currentCellLocation.Row, Column = currentCellLocation.Column - 1 }; if (previousCellLocation.Column == -1) { previousCellLocation.Column = SizeOfSudoku - 1; previousCellLocation.Row = currentCellLocation.Row - 1; } if (cellBoard[previousCellLocation.Row, previousCellLocation.Column].State == CellState.InProgress) { return(previousCellLocation); } currentCellLocation = previousCellLocation; } while (true); }
private bool ExistsPathBetweenLocationsRecursive(CellLocation s, CellLocation e, List <CellLocation> visited) { //Debug.Log("Visiting " + s); visited.Add(s); VirtualCell s_cell = GetCell(s); foreach (CellLocation c in s_cell.connectedCells) { if (c == e) { //Debug.Log("Found the end!"); return(true); // Found this! } else { if (!visited.Contains(c)) { bool foundEnd = ExistsPathBetweenLocationsRecursive(c, e, visited); //if (foundEnd) Debug.Log("Found the end in child!"); if (foundEnd) { return(true); // Found connected! } } } } return(false); // Not here! }
/// <summary> /// All the void cells. /// </summary><returns> /// The void cells.</returns> public List<Void> AllVoidCells() { // All the void cells List<Void> allVoidCells = new List<Void> (); for (int i = 1; i < dungeonGenerator.numCellsX - 1; i++) { for (int k = 1; k < dungeonGenerator.numCellsZ - 1; k++) { if (CellIsVoid (dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, k])) { // Void location CellLocation voidLocation = new CellLocation (i, dungeonGenerator.floorNumber, k); // Void cell Void voidCell = new Void (voidLocation); // Add the void cell to all void cells allVoidCells.Add (voidCell); } } } // Return all of the void cells return allVoidCells; }
public void GetHashCode_WhenObjectsEqual_HashCodesEqual() { var cellLocation1 = new CellLocation(0, 3); var cellLocation2 = new CellLocation(0, 3); Assert.AreEqual(cellLocation1.GetHashCode(), cellLocation2.GetHashCode()); }
public Dictionary <string, CellLocation> GenerateSurroundingCellLocations(CellLocation cellLocation) { var cellLocationOfNeighbouringCells = new Dictionary <string, CellLocation>(); IterateXAndYCoordinates(cellLocation, cellLocationOfNeighbouringCells); return(cellLocationOfNeighbouringCells); }
public bool HasDir(CellLocation location, Dir dir) { CellType testType; if (dir == Dir.North) testType = caveCellGrid[location.x, location.y, location.z + 1]; else if (dir == Dir.South) testType = caveCellGrid[location.x, location.y, location.z - 1]; else if (dir == Dir.East) testType = caveCellGrid[location.x + 1, location.y, location.z]; else if (dir == Dir.West) testType = caveCellGrid[location.x - 1, location.y, location.z]; else if (dir == Dir.NorthEast) testType = caveCellGrid[location.x + 1, location.y, location.z + 1]; else if (dir == Dir.NorthWest) testType = caveCellGrid[location.x - 1, location.y, location.z + 1]; else if (dir == Dir.SouthEast) testType = caveCellGrid[location.x + 1, location.y, location.z - 1]; else testType = caveCellGrid[location.x - 1, location.y, location.z - 1]; if (testType == CellType.RockFloor) { return true; } return false; }
private List <Direction> GetAvailableMovesForLocation(CellLocation location, IReadOnlyCollection <CellLocation> walls) { var result = new List <Direction>(4); if (!walls.Contains(location.Above)) { result.Add(Direction.Up); } if (!walls.Contains(location.Below)) { result.Add(Direction.Down); } if (!walls.Contains(location.Left)) { result.Add(Direction.Left); } if (!walls.Contains(location.Right)) { result.Add(Direction.Right); } return(result); }
public void GivenEmptyCellLocationThenReturnDefaultCellLocation() { var cellLocation = new CellLocation(); var result = cellLocation.ToString(); Assert.Equal("0,0", result); }
public void GivenCellLocationThenReturnCellLocation() { var cellLocation = new CellLocation(1, 2); var result = cellLocation.ToString(); Assert.Equal("1,2", result); }
public Cell MakeConnection(Cell currentCell) { List <int> randomizedCellDirections = CellDirections.GetRandomizedCellDirections; // e.g [2, 1, 0, 3] for (int i = 0; i < randomizedCellDirections.Count; i++) { // The random direction from the current cell CellDirection direction = (CellDirection)randomizedCellDirections[i]; // The neighbor cell location from the direction CellLocation nextLocation = currentCell.Location + direction.ToRelativeCellLocation(); if (CanPlaceCell(nextLocation)) { CellDirection fromDirection = direction.GetOpposite(); Cell nextCell = PlaceCell(nextLocation, fromDirection); currentCell.AddConnection(direction); // Direction that connects it to the newly generated cell currentCell.name += "_" + direction; return(nextCell); } } return(null); }
public Cell PlaceCell(CellLocation location, CellDirection fromDirection) { Cell cell = PlaceCell(location); cell.AddConnection(fromDirection); return(cell); }
bool CellLocationHasSouth(CellLocation testLocation) { if (testLocation.z == 0) { return(false); } BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z]; switch (testType) { case BuildingBlockType.WNES: case BuildingBlockType.NS: case BuildingBlockType.WS: case BuildingBlockType.ES: case BuildingBlockType.WES: case BuildingBlockType.NES: case BuildingBlockType.WNS: case BuildingBlockType.Sx: return(true); default: return(false); } }
bool CellLocationHasNorth(CellLocation testLocation) { if (testLocation.z == NumBuildingBlocksUp - 1) { return(false); } BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z]; switch (testType) { case BuildingBlockType.WNES: case BuildingBlockType.NS: case BuildingBlockType.NE: case BuildingBlockType.WN: case BuildingBlockType.WNE: case BuildingBlockType.NES: case BuildingBlockType.WNS: case BuildingBlockType.Nx: return(true); default: return(false); } }
bool CellLocationHasEast(CellLocation testLocation) { if (testLocation.x == NumBuildingBlocksAcross - 1) { return(false); } BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z]; switch (testType) { case BuildingBlockType.WNES: case BuildingBlockType.WE: case BuildingBlockType.NE: case BuildingBlockType.ES: case BuildingBlockType.WNE: case BuildingBlockType.WES: case BuildingBlockType.NES: case BuildingBlockType.Ex: return(true); default: return(false); } }
public void ConvertToDungeonPerimeter() { for (var i = 0; i < dungeonGenerator.numCellsX; i++) { for (var j = 0; j < dungeonGenerator.numCellsZ; j++) { CellType testType = dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j]; if (testType == CellType.Blocked || testType == CellType.Empty || testType == CellType.Perimeter || testType == CellType.StairsPerimeter) { CellLocation location = new CellLocation(i, dungeonGenerator.floorNumber, j); if (dungeonGenerator.HasDir (location, Dir.North) || dungeonGenerator.HasDir (location, Dir.South) || dungeonGenerator.HasDir (location, Dir.East) || dungeonGenerator.HasDir (location, Dir.West) || dungeonGenerator.HasDir (location, Dir.NorthEast) || dungeonGenerator.HasDir (location, Dir.NorthWest) || dungeonGenerator.HasDir (location, Dir.SouthEast) || dungeonGenerator.HasDir (location, Dir.SouthWest) ) { dungeonGenerator.cellTypeGrid[location.x, location.y, location.z] = CellType.DungeonPerimeter; } } } } }
public async Task GhostShouldScatterToStartWith() { _gameSettings.InitialGameStatus = GameStatus.Initial; _gameSettings.PacMan = new PacMan((10, 10), Direction.Left); var startingLocation = new CellLocation(3, 1); var scatterLocation = new CellLocation(1, 1); var strategy = new GhostGoesRightStrategy(); _gameSettings.Ghosts.Add(new Ghost("Ghost1", startingLocation, Direction.Right, scatterLocation, strategy)); var game = new Game(_gameClock, _gameSettings); game.StartGame(); await _gameClock.Tick(); await _gameClock.Tick(); await _gameClock.Tick(); game.Ghosts.Values.First() .Should().BeEquivalentTo(new { Location = new { X = scatterLocation.X, Y = scatterLocation.Y } }); }
private List <CellInstance> instances; // Instances of this cell. The first one is the main. public VirtualCell(bool visited, CellLocation location) { this.visited = visited; this.location = location; //this.index_from_root = -1; instances = new List <CellInstance>(); connectedCells = new List <CellLocation>(); }
public CellActor(CellLocation location) { Location = location; Receive <ClearMessage>(Clear); Receive <PrepareToSpawnMessage>(PrepareToSpawn); Receive <TurnHavePassedMessage>(Update); }
private static void CreateGliderPattern(GameEngine myGame, CellLocation location) { myGame.CurrentWorld.AddCell(new CellLocation(location, 3, 1)); myGame.CurrentWorld.AddCell(new CellLocation(location, 1, 2)); myGame.CurrentWorld.AddCell(new CellLocation(location, 3, 2)); myGame.CurrentWorld.AddCell(new CellLocation(location, 2, 3)); myGame.CurrentWorld.AddCell(new CellLocation(location, 3, 3)); }
override public MetricLocation GetWorldLocation(CellLocation l, int storey) { MetricLocation actual_location = this.virtual_maps[0].GetActualLocation(l, storey); actual_location.x *= 2; // Double, since a tilemap is two times as big actual_location.y *= 2; return(actual_location); }
public void InstantiatePrefab(Transform prefabToMake, CellLocation location, int rotation) { float instantiateXPosition = transform.position.x + (location.x * prefabCellWidth); float instantiateYPosition = transform.position.y - (location.y * floorHeight); float instantiateZPosition = transform.position.z + (location.z * prefabCellHeight); Transform createPrefab = (Transform)Instantiate(prefabToMake, new Vector3(instantiateXPosition, instantiateYPosition, instantiateZPosition), Quaternion.identity); createPrefab.Rotate (0, rotation, 0); //ChangeMaterial(createPrefab); createPrefab.parent = dungeonGenerator.OtherStuffParent; }
public void AddCavesToDungeon(Floor floor) { for (int i = 0; i < dungeonGenerator.numCellsX; i++) { for (int j = 0; j < dungeonGenerator.numCellsZ; j++) { CellType testType = dungeonGenerator.cellTypeGrid[i, floor.floorNumber, j]; if (CavesCanReplace (testType)) { CellLocation location = new CellLocation(i, floor.floorNumber, j); dungeonGenerator.cellTypeGrid[location.x, location.y, location.z] = caveCellGrid[location.x, location.y, location.z]; } } } }
public void GenerateStairsUp(Floor floor) { if (floor.floorNumber != 0) { foreach (Stairs stairsDown in dungeonGenerator.floors[dungeonGenerator.floorNumber - 1].allStairsDown) { CellLocation location = new CellLocation (stairsDown.location.x, dungeonGenerator.floorNumber, stairsDown.location.z); Stairs stairsUp = new Stairs (location, 0); stairsUp.direction = stairsDown.direction; stairsUp.rotation = stairsDown.rotation; AddStairsUp (stairsUp); } } }
public Room(CellLocation setLocation, IntVector3 setSize) { location = setLocation; size = setSize; northMost = location.z + (size.z - 1) / 2; southMost = location.z - (size.z - 1) / 2; eastMost = location.x + (size.x - 1) / 2; westMost = location.x - (size.x - 1) / 2; for (int i = westMost; i < eastMost + 1; i++) { for (int k = southMost; k < northMost + 1; k++) { CellLocation cellLocation = new CellLocation (i, location.y, k); cellLocations.Add (cellLocation); } } }
public void CarveFloor() { float mapRes = terrain.terrainData.heightmapResolution; float cellRes = mapRes / dungeonGenerator.numCellsX; List<CellLocation> carveLocations = new List<CellLocation> (); float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight]; heights = terrain.terrainData.GetHeights (0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight); for (var i = 0; i < dungeonGenerator.numCellsX; i++) { for (var j = 0; j < dungeonGenerator.numCellsZ; j++) { CellType testType = dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j]; if (testType == CellType.Room || testType == CellType.Corridor || testType == CellType.Entrance || testType == CellType.StairsDown || testType == CellType.StairsUp) { CellLocation location = new CellLocation(i, dungeonGenerator.floorNumber, j); carveLocations.Add (location); } } } foreach (CellLocation location in carveLocations) { for (var i = (int)((float)location.z * cellRes); i < (int)((float)location.z * cellRes + cellRes) + 1; i++) { for (var j = (int)((float)location.x * cellRes); j < (int)((float)location.x * cellRes + cellRes) + 1; j++) { heights[i, j] = 0f; } } } terrain.terrainData.SetHeights (0, 0, heights); }
protected void AddStairsPerimeter(CellLocation location) { dungeonGenerator.cellTypeGrid[location.x, location.y, location.z] = CellType.StairsPerimeter; }
public Chest(CellLocation setLocation) { location = setLocation; }
void SetHeroLocation(CellLocation newLocation) { heroLocation = newLocation; prefabBuildingBlockWidth = PrefabBuildingBlock_WNES.localScale.x; prefabBuildingBlockHeight = PrefabBuildingBlock_WNES.localScale.z; float heroPositionX = transform.position.x + (newLocation.x * prefabBuildingBlockWidth); float heroPositionZ = transform.position.z + (newLocation.z * prefabBuildingBlockHeight); Hero.transform.position = new Vector3(heroPositionX, 1.0f, heroPositionZ); }
private void InstantiateStairs(CellLocation chosenUp, CellLocation chosenDown) { prefabBuildingBlockWidth = PrefabBuildingBlock_WNES.localScale.x; prefabBuildingBlockHeight = PrefabBuildingBlock_WNES.localScale.z; int stairsUpGridX = chosenUp.x; int stairsUpGridZ = chosenUp.z; float stairsUpLocX = transform.position.x + (stairsUpGridX * prefabBuildingBlockWidth); float stairsUpLocZ = transform.position.z + (stairsUpGridZ * prefabBuildingBlockHeight); Transform createStairsUp = (Transform)Instantiate(PrefabStairsUp, new Vector3(stairsUpLocX, 0.0f, stairsUpLocZ), Quaternion.identity); int stairsDownGridX = chosenDown.x; int stairsDownGridZ = chosenDown.z; float stairsDownLocX = transform.position.x + (stairsDownGridX * prefabBuildingBlockWidth); float stairsDownLocZ = transform.position.z + (stairsDownGridZ * prefabBuildingBlockHeight); Transform createStairsDown = (Transform)Instantiate(PrefabStairsDown, new Vector3(stairsDownLocX, 0.0f, stairsDownLocZ), Quaternion.identity); stairsUpLocation = new CellLocation(stairsUpGridX, stairsUpGridZ); stairsDownLocation = new CellLocation(stairsDownGridX, stairsDownGridZ); createStairsUp.parent = OtherStuffParent; createStairsDown.parent = OtherStuffParent; }
BuildingBlockType ChooseValidBuildingBlockType(CellLocation location) { bool hasWest = false; bool hasNorth = false; bool hasEast = false; bool hasSouth = false; bool noWest = false; bool noNorth = false; bool noEast = false; bool noSouth = false; if (location.x > 0 && buildingBlockTypeGrid[location.x - 1, location.z] != BuildingBlockType.Empty) { if (CellLocationHasEast(new CellLocation(location.x - 1, location.z))) { hasWest = true; } else { noWest = true; } } if (location.x < NumBuildingBlocksAcross - 1 && buildingBlockTypeGrid[location.x + 1, location.z] != BuildingBlockType.Empty) { if (CellLocationHasWest(new CellLocation(location.x + 1, location.z))) { hasEast = true; } else { noEast = true; } } if (location.z > 0 && buildingBlockTypeGrid[location.x, location.z - 1] != BuildingBlockType.Empty) { if (CellLocationHasNorth(new CellLocation(location.x, location.z - 1))) { hasSouth = true; } else { noSouth = true; } } if (location.z < NumBuildingBlocksUp - 1 && buildingBlockTypeGrid[location.x, location.z + 1] != BuildingBlockType.Empty) { if (CellLocationHasSouth(new CellLocation(location.x, location.z + 1))) { hasNorth = true; } else { noNorth = true; } } return GetQualifyingBlockType(location.x, location.z, hasWest, hasNorth, hasEast, hasSouth, noWest, noNorth, noEast, noSouth, false); }
protected void Generate(Floor floor) { for (var i = 1; i < dungeonGenerator.numCellsX - 1; i++) { for (var j = 1; j < dungeonGenerator.numCellsZ - 1; j++) { CellLocation location = new CellLocation (i, floor.floorNumber, j); int numRocks = 0; if (caveCellGrid[location.x, location.y, location.z] == CellType.Rock) numRocks++; if (!HasDir (location, Dir.North)) numRocks++; if (!HasDir (location, Dir.South)) numRocks++; if (!HasDir (location, Dir.East)) numRocks++; if (!HasDir (location, Dir.West)) numRocks++; if (!HasDir (location, Dir.NorthEast)) numRocks++; if (!HasDir (location, Dir.NorthWest)) numRocks++; if (!HasDir (location, Dir.SouthEast)) numRocks++; if (!HasDir (location, Dir.SouthWest)) numRocks++; if (numRocks > 4) { caveCellGrid[location.x, location.y, location.z] = CellType.Rock; } else caveCellGrid[location.x, location.y, location.z] = CellType.RockFloor; } } }
/// <summary> /// Potential entrance locations. /// </summary> /// <returns>The entrance locations.</returns> /// <param name='room'>Room.</param> /// <param name='ignoreReflection'>Ignore reflection.</param> protected List<CellLocation> PotentialEntranceLocations(Room room, List<Dir> directions, bool ignoreReflection) { // All of the potential entrance locations List<CellLocation> potentialEntranceLocations = new List<CellLocation> (); foreach (Dir direction in directions) { if (direction == Dir.North) { for (var i = room.location.x - (room.size.x - 1) / 2; i < room.location.x + (room.size.x + 1) / 2; i += 2) { // The potential northern location CellLocation potentialNorthLocation = new CellLocation(i, room.location.y, room.location.z + (room.size.z + 2) / 2); if (WithinSpawnArea (potentialNorthLocation) || ignoreReflection) // Add to the potential northern entrance location potentialEntranceLocations.Add (potentialNorthLocation); } } if (direction == Dir.South) { for (var i = room.location.x - (room.size.x - 1) / 2; i < room.location.x + (room.size.x + 1) / 2; i += 2) { // The potential southern location CellLocation potentialSouthLocation = new CellLocation(i, room.location.y, room.location.z - (room.size.z + 1) / 2); if (WithinSpawnArea (potentialSouthLocation) || ignoreReflection) // Add to the potential southern entrance location potentialEntranceLocations.Add (potentialSouthLocation); } } if (direction == Dir.East) { for (var j = room.location.z - (room.size.z - 1) / 2; j < room.location.z + (room.size.z + 1) / 2; j += 2) { // The potential eastern location CellLocation potentialEastLocation = new CellLocation(room.location.x + (room.size.x + 2) / 2, room.location.y, j); if (WithinSpawnArea (potentialEastLocation) || ignoreReflection) // Add to the potential eastern entrance locations potentialEntranceLocations.Add (potentialEastLocation); } } if (direction == Dir.West) { for (var j = room.location.z - (room.size.z - 1) / 2; j < room.location.z + (room.size.z + 1) / 2; j += 2) { // The potential western location CellLocation potentialWestLocation = new CellLocation(room.location.x - (room.size.x + 1) / 2, room.location.y, j); if (WithinSpawnArea (potentialWestLocation) || ignoreReflection) // Add to the potential western entrance locations potentialEntranceLocations.Add (potentialWestLocation); } } } // Return all of the potential entrance locations in direction return potentialEntranceLocations; }
bool CellLocationHasEast(CellLocation testLocation) { if (testLocation.x == NumBuildingBlocksAcross - 1) { return false; } BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z]; switch (testType) { case BuildingBlockType.WNES: case BuildingBlockType.WE: case BuildingBlockType.NE: case BuildingBlockType.ES: case BuildingBlockType.WNE: case BuildingBlockType.WES: case BuildingBlockType.NES: case BuildingBlockType.Ex: return true; default: return false; } }
bool CellConnectedToCell(int startLocX, int startLocZ, int goalLocX, int goalLocZ, ref ArrayList knownExistingConnections) { ArrayList alreadySearchedList = new ArrayList(); ArrayList toSearchList = new ArrayList(); bool foundPath = false; bool doneWithSearch = false; toSearchList.Add(new CellLocation(startLocX, startLocZ)); while (!doneWithSearch) { if (toSearchList.Count == 0) { doneWithSearch = true; break; } CellLocation toSearch = (CellLocation)toSearchList[0]; toSearchList.RemoveAt(0); if (alreadySearchedList.Contains(toSearch) == false) { alreadySearchedList.Add(toSearch); } if ((toSearch.x == goalLocX && toSearch.z == goalLocZ) || knownExistingConnections.Contains(toSearch)) { doneWithSearch = true; foundPath = true; foreach (CellLocation pos in alreadySearchedList) { knownExistingConnections.Add(pos); } foreach (CellLocation pos in toSearchList) { knownExistingConnections.Add(pos); } break; } else { if (CellLocationHasEast(new CellLocation(toSearch.x, toSearch.z))) { CellLocation newLocation = new CellLocation(toSearch.x + 1, toSearch.z); if (toSearchList.Contains(newLocation) == false && alreadySearchedList.Contains(newLocation) == false) { toSearchList.Add(newLocation); } } if (CellLocationHasWest(new CellLocation(toSearch.x, toSearch.z))) { CellLocation newLocation = new CellLocation(toSearch.x - 1, toSearch.z); if (toSearchList.Contains(newLocation) == false && alreadySearchedList.Contains(newLocation) == false) { toSearchList.Add(newLocation); } } if (CellLocationHasNorth(new CellLocation(toSearch.x, toSearch.z))) { CellLocation newLocation = new CellLocation(toSearch.x, toSearch.z + 1); if (toSearchList.Contains(newLocation) == false && alreadySearchedList.Contains(newLocation) == false) { toSearchList.Add(newLocation); } } if (CellLocationHasSouth(new CellLocation(toSearch.x, toSearch.z))) { CellLocation newLocation = new CellLocation(toSearch.x, toSearch.z - 1); if (toSearchList.Contains(newLocation) == false && alreadySearchedList.Contains(newLocation) == false) { toSearchList.Add(newLocation); } } } } return foundPath; }
protected void RandomlyDistrabute(Floor floor, int percentage) { List<CellLocation> locationsToModify = new List<CellLocation> (); for (var i = 1; i < dungeonGenerator.numCellsX - 1; i++) { for (var j = 1; j < dungeonGenerator.numCellsZ - 1; j++) { CellLocation location = new CellLocation(i, floor.floorNumber, j); int numRocks = 0; if (caveCellGrid[location.x, location.y, location.z] == CellType.Rock) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.North)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.South)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.East)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.West)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.NorthEast)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.NorthWest)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.SouthEast)) numRocks++; if (!dungeonGenerator.HasDir (location, Dir.SouthWest)) numRocks++; if (numRocks == 0 || numRocks == 9) { locationsToModify.Add (location); } } } foreach (CellLocation location in locationsToModify) { int rnd = Random.Range (1, 100); if (rnd < percentage) { if (caveCellGrid[location.x, location.y, location.z] == CellType.RockFloor) caveCellGrid[location.x, location.y, location.z] = CellType.Rock; else if (caveCellGrid[location.x, location.y, location.z] == CellType.Rock) caveCellGrid[location.x, location.y, location.z] = CellType.RockFloor; } } }
public void CarveTerrain() { float mapRes = terrain.terrainData.heightmapResolution; float cellRes = mapRes / dungeonGenerator.numCellsX; List<CellLocation> carveLocations = new List<CellLocation> (); List<CellLocation> rockLocations = new List<CellLocation> (); float[,] heights = new float[terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight]; heights = terrain.terrainData.GetHeights (0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight); for (var i = 0; i < dungeonGenerator.numCellsX; i++) { for (var j = 0; j < dungeonGenerator.numCellsZ; j++) { CellType testType = dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j]; if (testType == CellType.Room || testType == CellType.Corridor || testType == CellType.Entrance || testType == CellType.StairsDown || testType == CellType.StairsUp) { CellLocation location = new CellLocation(i, dungeonGenerator.floorNumber, j); carveLocations.Add (location); } } } foreach (CellLocation location in carveLocations) { for (var i = (int)((float)location.z * cellRes); i < (int)((float)location.z * cellRes + cellRes) + 1; i++) { for (var j = (int)((float)location.x * cellRes); j < (int)((float)location.x * cellRes + cellRes) + 1; j++) { heights[i, j] = 0.5f; } } } for (var i = 0; i < dungeonGenerator.numCellsX; i++) { for (var j = 0; j < dungeonGenerator.numCellsZ; j++) { CellType testType = dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j]; if (testType == CellType.DungeonPerimeter) { CellLocation location = new CellLocation(i, dungeonGenerator.floorNumber, j); rockLocations.Add (location); } } } foreach (CellLocation location in rockLocations) { int startX; int startZ; int widthX; int widthZ; if (location.z != 0) startX = (int)((float)location.z * cellRes) - 1; else startX = (int)((float)location.z * cellRes); if (location.x != 0) startZ = (int)((float)location.x * cellRes) - 1; else startZ = (int)((float)location.x * cellRes); if (location.z != dungeonGenerator.numCellsZ - 1) widthX = (int)cellRes + 2; else widthX = (int)cellRes; if (location.x != dungeonGenerator.numCellsX - 1) widthZ = (int)cellRes + 2; else widthZ = (int)cellRes; for (var i = startX; i < startX + widthX + 1; i++) { for (var j = startZ; j < startZ + widthZ + 1; j++) { heights[i, j] = 1; } } } terrain.terrainData.SetHeights (0, 0, heights); }
protected void RandomFloor(Floor floor, int percentage) { List<CellLocation> locationsChosen = new List<CellLocation> (); List<CellLocation> possibleLocations = new List<CellLocation> (); for (var i = 1; i < dungeonGenerator.numCellsX - 1; i++) { for (var j = 1; j < dungeonGenerator.numCellsZ - 1; j++) { CellLocation possibleLocation = new CellLocation(i, floor.floorNumber, j); possibleLocations.Add (possibleLocation); } } int locationsNeeded = (int)((float)possibleLocations.Count * (float)(percentage) / 100); int possibleLocationsLeft = possibleLocations.Count; foreach (CellLocation location in possibleLocations) { int probability = (int)((float)locationsNeeded * 100 / (float)possibleLocationsLeft); int rnd = Random.Range (0, 100); if (rnd < probability) { locationsChosen.Add (location); locationsNeeded--; } possibleLocationsLeft--; if (locationsNeeded == 0) break; } foreach (CellLocation location in locationsChosen) { caveCellGrid[location.x, location.y, location.z] = CellType.RockFloor; } }
// ENTRANCE SPAWN AREA: /// <summary> /// The spawn area. /// </summary> /// <returns>The area.</returns> protected EntranceSpawnArea SpawnArea() { // Spawn area location CellLocation spawnAreaLocation = new CellLocation (1, dungeonGenerator.floorNumber, 1); // Spawn area size IntVector3 spawnAreaSize = new IntVector3 (dungeonGenerator.numCellsX - 2, 1, dungeonGenerator.numCellsZ - 2); // Half the size in x if (reflectX) spawnAreaSize.x = (spawnAreaSize.x + 1) / 2; // Half the size in z if (reflectZ) spawnAreaSize.z = (spawnAreaSize.z + 1) / 2; // The spawn area EntranceSpawnArea spawnArea = new EntranceSpawnArea(spawnAreaLocation, spawnAreaSize); // Return the spawn area return spawnArea; }
bool CellLocationHasNorth(CellLocation testLocation) { if (testLocation.z == NumBuildingBlocksUp - 1) { return false; } BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z]; switch (testType) { case BuildingBlockType.WNES: case BuildingBlockType.NS: case BuildingBlockType.NE: case BuildingBlockType.WN: case BuildingBlockType.WNE: case BuildingBlockType.NES: case BuildingBlockType.WNS: case BuildingBlockType.Nx: return true; default: return false; } }
/// <summary> /// Generates the entrance to stairs. /// </summary> /// <param name='stairs'>Stairs.</param> public void GenerateEntranceToStairs(Stairs stairs) { // The entrance location CellLocation entranceLocation; if (stairs.stairsUp) { if (stairs.direction == Dir.North) // Set the entrance location north of the upward stairs entranceLocation = new CellLocation (stairs.location.x, stairs.location.y, stairs.location.z + 1); else if (stairs.direction == Dir.South) // Set the entrance location south of the upward stairs entranceLocation = new CellLocation (stairs.location.x, stairs.location.y, stairs.location.z - 1); else if (stairs.direction == Dir.East) // Set the entrance location east of the upward stairs entranceLocation = new CellLocation (stairs.location.x + 1, stairs.location.y, stairs.location.z); else // Set the entrance location west of the upward stairs entranceLocation = new CellLocation (stairs.location.x - 1, stairs.location.y, stairs.location.z); } else { if (stairs.direction == Dir.North) // Set the entrance location north of the downward stairs entranceLocation = new CellLocation (stairs.location.x, stairs.location.y, stairs.location.z - 1); else if (stairs.direction == Dir.South) // Set the entrance location south of the downward stairs entranceLocation = new CellLocation (stairs.location.x, stairs.location.y, stairs.location.z + 1); else if (stairs.direction == Dir.East) // Set the entrance location east of the downward stairs entranceLocation = new CellLocation (stairs.location.x - 1, stairs.location.y, stairs.location.z); else // Set the entrance location west of the downward stairs entranceLocation = new CellLocation (stairs.location.x + 1, stairs.location.y, stairs.location.z); } // The entrance Entrance entrance = new Entrance (entranceLocation); // State that it is an entrance to stairs entrance.entranceToStairs = true; // Add the entrance AddEntrance (entrance); }
bool CellLocationHasWest(CellLocation testLocation) { if (testLocation.x == 0) { return false; } BuildingBlockType testType = buildingBlockTypeGrid[testLocation.x, testLocation.z]; switch (testType) { case BuildingBlockType.WNES: case BuildingBlockType.WE: case BuildingBlockType.WN: case BuildingBlockType.WS: case BuildingBlockType.WNE: case BuildingBlockType.WES: case BuildingBlockType.WNS: case BuildingBlockType.Wx: return true; default: return false; } }
/// <summary> /// Reflects the z. /// </summary> protected void ReflectZ() { // The entrances to reflect List<Entrance> entrancesToReflect = new List<Entrance> (); foreach (Entrance entrance in allEntrances) { if (!entrance.entranceToStairs) { // Add entrance to the entrances to reflect entrancesToReflect.Add (entrance); } } foreach (Entrance entrance in entrancesToReflect) { // The reflection location CellLocation reflectionLocation = new CellLocation (entrance.location.x, dungeonGenerator.floorNumber, dungeonGenerator.numCellsZ - entrance.location.z - 1); // The reflected entrance Entrance reflectedEntrance = new Entrance (reflectionLocation); // Add the reflected entrance AddEntrance (reflectedEntrance); } }
public Void(CellLocation setLocation) { location = setLocation; }
/// <summary> /// Within the spawn area. /// </summary> /// <returns>Within spawn area.</returns> /// <param name='location'>If set to <c>true</c> location.</param> protected bool WithinSpawnArea(CellLocation location) { if (location.x >= SpawnArea ().location.x && location.x < SpawnArea ().location.x + SpawnArea ().size.x) { if (location.z >= SpawnArea ().location.z && location.z < SpawnArea ().location.z + SpawnArea ().size.z) { // Within the spawn area return true; } } // Outside of the spawn area return false; }
protected void GenerateCorridor(CellLocation location) { Corridor corridor = new Corridor (location); AddCorridor (corridor); Dir wayToGo = Dir.None; List<Dir> possibleDirections = new List<Dir> (); if (CorridorCanGo (corridor, Dir.North)) possibleDirections.Add (Dir.North); if (CorridorCanGo (corridor, Dir.South)) possibleDirections.Add (Dir.South); if (CorridorCanGo (corridor, Dir.East)) possibleDirections.Add (Dir.East); if (CorridorCanGo (corridor, Dir.West)) possibleDirections.Add (Dir.West); if (possibleDirections.Count > 0) { int randomIndex = Random.Range (1, possibleDirections.Count) - 1; wayToGo = possibleDirections[randomIndex]; } if (wayToGo != Dir.None) { CellLocation newLocation; CellLocation middleLocation; Corridor middleCorridor; if (wayToGo == Dir.North) { newLocation = new CellLocation(location.x, location.y, location.z + 2); middleLocation = new CellLocation(location.x, location.y, location.z + 1); } else if (wayToGo == Dir.South) { newLocation = new CellLocation(location.x, location.y, location.z - 2); middleLocation = new CellLocation(location.x, location.y, location.z - 1); } else if (wayToGo == Dir.East) { newLocation = new CellLocation(location.x + 2, location.y, location.z); middleLocation = new CellLocation(location.x + 1, location.y, location.z); } else { newLocation = new CellLocation(location.x - 2, location.y, location.z); middleLocation = new CellLocation(location.x - 1, location.y, location.z); } middleCorridor = new Corridor (middleLocation); AddCorridor (middleCorridor); GenerateCorridor (newLocation); } else { StartNewCorridor (); } }
public void InstantiateWallsFromGrid() { for (int i = 1; i < dungeonGenerator.numCellsX - 1; i++) { for (int j = 1; j < dungeonGenerator.numCellsZ - 1; j++) { bool hasNorth = false; bool hasSouth = false; bool hasEast = false; bool hasWest = false; bool hasNorthEast = false; bool hasNorthWest = false; bool hasSouthEast = false; bool hasSouthWest = false; CellLocation location = new CellLocation(i, dungeonGenerator.floorNumber, j); if (dungeonGenerator.HasDir(location, Dir.North)) hasNorth = true; if (dungeonGenerator.HasDir(location, Dir.South)) hasSouth = true; if (dungeonGenerator.HasDir(location, Dir.East)) hasEast = true; if (dungeonGenerator.HasDir(location, Dir.West)) hasWest = true; if (dungeonGenerator.HasDir(location, Dir.NorthEast)) hasNorthEast = true; if (dungeonGenerator.HasDir(location, Dir.NorthWest)) hasNorthWest = true; if (dungeonGenerator.HasDir(location, Dir.SouthEast)) hasSouthEast = true; if (dungeonGenerator.HasDir(location, Dir.SouthWest)) hasSouthWest = true; if (dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.StairsUp || dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.StairsDown) { if (hasNorth || hasSouth) { InstantiatePrefab (Cell_Wall, location, 0); InstantiatePrefab (Cell_Wall, location, 180); } if (hasEast || hasWest) { InstantiatePrefab (Cell_Wall, location, 90); InstantiatePrefab (Cell_Wall, location, 270); } } if (dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.Room || dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.Corridor || dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.Entrance) { // Walls if (!hasNorth) InstantiatePrefab (Cell_Wall, location, 90); if (!hasSouth) InstantiatePrefab (Cell_Wall, location, 270); if (!hasEast) InstantiatePrefab (Cell_Wall, location, 180); if (!hasWest) InstantiatePrefab (Cell_Wall, location, 0); // Corners if (!hasNorthEast) { if (hasNorth && hasEast) InstantiatePrefab (Cell_Wall_Corner, location, 90); if (!hasNorth && !hasEast) InstantiatePrefab (Cell_Wall_Corner, location, 90); if (hasNorth && hasWest && !hasEast && !hasSouth && !hasNorthWest) InstantiatePrefab (Cell_Wall_Corner, location, 90); if (!hasNorth && !hasWest && hasEast && hasSouth && !hasSouthEast) InstantiatePrefab (Cell_Wall_Corner, location, 90); } if (!hasNorthWest) { if (hasNorth && hasWest) InstantiatePrefab (Cell_Wall_Corner, location, 0); if (!hasNorth && !hasWest) InstantiatePrefab (Cell_Wall_Corner, location, 0); if (hasNorth && hasEast && !hasWest && !hasSouth && !hasNorthEast) InstantiatePrefab (Cell_Wall_Corner, location, 0); if (!hasNorth && !hasEast && hasWest && hasSouth && !hasSouthWest) InstantiatePrefab (Cell_Wall_Corner, location, 0); } if (!hasSouthEast) { if (hasSouth && hasEast) InstantiatePrefab (Cell_Wall_Corner, location, 180); if (!hasSouth && !hasEast) InstantiatePrefab (Cell_Wall_Corner, location, 180); if (hasSouth && hasWest && !hasEast && !hasNorth && !hasSouthWest) InstantiatePrefab (Cell_Wall_Corner, location, 180); if (!hasSouth && !hasWest && hasEast && hasNorth && !hasNorthEast) InstantiatePrefab (Cell_Wall_Corner, location, 180); } if (!hasSouthWest) { if (hasSouth && hasWest) InstantiatePrefab (Cell_Wall_Corner, location, 270); if (!hasSouth && !hasWest) InstantiatePrefab (Cell_Wall_Corner, location, 270); if (hasSouth && hasEast && !hasWest && !hasNorth && !hasSouthEast) InstantiatePrefab (Cell_Wall_Corner, location, 270); if (!hasSouth && !hasEast && hasWest && hasNorth && !hasNorthWest) InstantiatePrefab (Cell_Wall_Corner, location, 270); } } // Doors if (dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.Entrance) { if (hasNorth && hasSouth && !hasEast && !hasWest) InstantiatePrefab (Cell_Door, location, 90); if (!hasNorth && !hasSouth && hasEast && hasWest) InstantiatePrefab (Cell_Door, location, 0); } // Arches if (dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.Corridor) { if (hasNorth && hasSouth && !hasEast && !hasWest) InstantiatePrefab (Cell_Arch, location, 90); if (!hasNorth && !hasSouth && hasEast && hasWest) InstantiatePrefab (Cell_Arch, location, 0); } if (dungeonGenerator.cellTypeGrid[i, dungeonGenerator.floorNumber, j] == CellType.Room) { // Torches // if (i % 2 == 0 && j % 2 != 0) { // if (!hasNorth) InstantiatePrefab (Cell_Torch, location, 90); // if (!hasSouth) InstantiatePrefab (Cell_Torch, location, 270); // if (!hasEast) InstantiatePrefab (Cell_Torch, location, 180); // if (!hasWest) InstantiatePrefab (Cell_Torch, location, 0); // } // if (i % 2 != 0 && j % 2 == 0) { // if (!hasNorth) InstantiatePrefab (Cell_Torch, location, 90); // if (!hasSouth) InstantiatePrefab (Cell_Torch, location, 270); // if (!hasEast) InstantiatePrefab (Cell_Torch, location, 180); // if (!hasWest) InstantiatePrefab (Cell_Torch, location, 0); // } } } } }
protected List<CellLocation> PotentialCorridorLocations() { List<CellLocation> potentialCorridorLocations = new List<CellLocation> (); for (var i = 1; i < dungeonGenerator.numCellsX - 1; i+= 2) { for (var j = 1; j < dungeonGenerator.numCellsZ - 1; j += 2) { CellLocation location = new CellLocation (i, dungeonGenerator.floorNumber, j); potentialCorridorLocations.Add (location); } } return potentialCorridorLocations; }