/// <summary> /// We connect areatypes based on their positions for the purpose off the pathfinding /// </summary> private void LinkLocationTypes() { // Variables we need to link locationtypes to eachother LocationType current = null; LocationType next = null; // We use those numbers to make the programm more dynamically int maxYposHotel = Facilities.Max(element => element.Position.Y); // get the max height from hotel that is : the position.Y = 6 int maxXposHotel = Facilities.Max(element => element.Position.X); // get the max with from hotel that is : the position.X = 9 int minXposHotel = Facilities.Min(element => element.Position.X); // get the minimum width from hotel that is : the position.X = 0 int minYposHotel = Facilities.Min(element => element.Position.Y); // get the minimum height from hotel that is : the position.Y = 0 int biggestXDimension = Facilities.Max(element => element.Dimension.X); // get the location type with the biggest Dimension.X = 8; // Count from the smallest Y position till the biggest Y position (from floor 0, till highest floor) for (int heightHotel = minYposHotel; heightHotel <= maxYposHotel; heightHotel++) { // Count from the smallest X position till the highest X position for (int widthHotel = (minXposHotel); widthHotel <= maxXposHotel; widthHotel++) { // When current is zero, and it becomes zero when we looped a full row if (current == null) { // Current becomes the first possible item in a row, it will keep searching with the forloop, so eventually i'll find it's position current = SearchLocationType(widthHotel, heightHotel); } // When current is not zero else { // current Dimension is one, because we want to search the next item and the next item might not be 1 position ahead but maybe 8, because Dimensions will take some space for (int currentDimensionCount = 1; currentDimensionCount <= biggestXDimension; currentDimensionCount++) { // Search for next item by adding to it's position 1 untill the the number is as big as the biggest Dimension and in the meanwhile there is a chance we will find the next item next = SearchLocationType((current.Position.X + currentDimensionCount), current.Position.Y); // next becomes the next item. Example lobby : 1 + 8 = 9 (next is stairs) if (next != null) { // When we found the next item, let's get out of this loop, for performance reasons break; } } // When we have found the next item if (next != null) { // Check if it's an elevatorshaft, because if (current is ElevatorShaft) // if position from current is 9 { // Get the upper Neighbor LocationType aboveNeighbor = SearchLocationType(current.Position.X, current.Position.Y + 1); // Get the neighbor below LocationType underNeighbor = SearchLocationType(current.Position.X, current.Position.Y - 1); // Add the neighbors if (aboveNeighbor != null) { current.SetNeighbor(aboveNeighbor, 1); } if (underNeighbor != null) { current.SetNeighbor(underNeighbor, 1); } } // We place this here because elevatorshaft can have a next neighbor, while staircase can't have that. current.Neighbor.Add(next, next.Position.X - current.Position.X); // add the next item to the current one next.Neighbor.Add(current, next.Position.X - current.Position.X); // add the current item to the next one current = next; // current becomes the next one, we now count from there if (current is Staircase) // if position from current is 9 { // Get the upper Neighbor LocationType aboveNeighbor = SearchLocationType(current.Position.X, current.Position.Y + 1); // Get the neighbor below LocationType underNeighbor = SearchLocationType(current.Position.X, current.Position.Y - 1); // Add the neighbors if (aboveNeighbor != null) { current.SetNeighbor(aboveNeighbor, 3); } if (underNeighbor != null) { current.SetNeighbor(underNeighbor, 3); } } } else { widthHotel = maxXposHotel; } } } current = null; // current should become null, because we want to give it a new position, one row higher } // For testing purposes foreach (var item in Facilities) { //Console.WriteLine(); //Console.WriteLine(item.AreaType + " : " + item.Position); //foreach (var itemm in item.NeighBor) //{ // Console.WriteLine(itemm.Key.AreaType + " : " + itemm.Key.Position); //} //Console.WriteLine(); } }