public HouseData GenerateInnerDoors(HouseData houseData) { houseData.roomPairs = new List <RoomPair> (); for (int x = 2; x < houseData.floorPlan.roomData.GetLength(0) - 2; x++) { for (int z = 2; z < houseData.floorPlan.roomData.GetLength(1) - 2; z++) { if (houseData.floorPlan.area [x, z] == UnitType.INNERWALL_DOWN) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x, z - 1] == UnitType.INNERWALL_UP) //Angrenzendes Feld ist das Gegenstück zur Wand { RoomPair roomPair = GetExistingRoomPair(ref houseData.roomPairs, new RoomPair(houseData.floorPlan.roomData[x, z], houseData.floorPlan.roomData[x, z - 1])); roomPair.doorPoints.Add(new Point2DTupel(x, z, x, z - 1)); } } else if (houseData.floorPlan.area [x, z] == UnitType.INNERWALL_UP) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x, z + 1] == UnitType.INNERWALL_DOWN) //Angrenzendes Feld ist das Gegenstück zur Wand { RoomPair roomPair = GetExistingRoomPair(ref houseData.roomPairs, new RoomPair(houseData.floorPlan.roomData[x, z], houseData.floorPlan.roomData[x, z + 1])); roomPair.doorPoints.Add(new Point2DTupel(x, z, x, z + 1)); } } else if (houseData.floorPlan.area [x, z] == UnitType.INNERWALL_LEFT) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x + 1, z] == UnitType.INNERWALL_RIGHT) //Angrenzendes Feld ist das Gegenstück zur Wand { RoomPair roomPair = GetExistingRoomPair(ref houseData.roomPairs, new RoomPair(houseData.floorPlan.roomData[x, z], houseData.floorPlan.roomData[x + 1, z])); roomPair.doorPoints.Add(new Point2DTupel(x, z, x + 1, z)); } } else if (houseData.floorPlan.area [x, z] == UnitType.INNERWALL_RIGHT) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x - 1, z] == UnitType.INNERWALL_LEFT) //Angrenzendes Feld ist das Gegenstück zur Wand { RoomPair roomPair = GetExistingRoomPair(ref houseData.roomPairs, new RoomPair(houseData.floorPlan.roomData[x, z], houseData.floorPlan.roomData[x - 1, z])); roomPair.doorPoints.Add(new Point2DTupel(x, z, x - 1, z)); } } } } foreach (RoomPair rp in houseData.roomPairs) { Point2DTupel doorPlaces = rp.doorPoints [randomGenerator.Next(rp.doorPoints.Count)]; houseData.floorPlan.doorInfo.Add((double)doorPlaces.point1.x * (double)1000 + (double)doorPlaces.point1.z / (double)1000, houseData.floorPlan.area [doorPlaces.point1.x, doorPlaces.point1.z]); houseData.floorPlan.doorInfo.Add((double)doorPlaces.point2.x * (double)1000 + (double)doorPlaces.point2.z / (double)1000, houseData.floorPlan.area [doorPlaces.point2.x, doorPlaces.point2.z]); houseData.floorPlan.area [doorPlaces.point1.x, doorPlaces.point1.z] = UnitType.DOOR; houseData.floorPlan.area [doorPlaces.point2.x, doorPlaces.point2.z] = UnitType.DOOR; } return(houseData); }
public HouseData GenerateWindowsAndOuterDoors(HouseData houseData) { Dictionary <RoomData, List <Point2DTupel> > dictionary = new Dictionary <RoomData, List <Point2DTupel> > (); for (int x = 0; x < houseData.floorPlan.roomData.GetLength(0); x++) { for (int z = 0; z < houseData.floorPlan.roomData.GetLength(1); z++) { if (houseData.floorPlan.area [x, z] == UnitType.OUTERWALL_DOWN) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x, z - 1] == UnitType.INNERWALL_UP && CheckDownContainsDoor(x, z, houseData)) //Angrenzendes Feld ist das Gegenstück zur Wand { List <Point2DTupel> roomTupels; if (!dictionary.ContainsKey(houseData.floorPlan.roomData[x, z - 1])) { roomTupels = new List <Point2DTupel> (); } else { roomTupels = dictionary [houseData.floorPlan.roomData [x, z - 1]]; } roomTupels.Add(new Point2DTupel(x, z, x, z - 1)); dictionary [houseData.floorPlan.roomData [x, z - 1]] = roomTupels; } } else if (houseData.floorPlan.area [x, z] == UnitType.OUTERWALL_UP) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x, z + 1] == UnitType.INNERWALL_DOWN && CheckUpContainsDoor(x, z, houseData)) //Angrenzendes Feld ist das Gegenstück zur Wand { List <Point2DTupel> roomTupels; if (!dictionary.ContainsKey(houseData.floorPlan.roomData[x, z + 1])) { roomTupels = new List <Point2DTupel> (); } else { roomTupels = dictionary [houseData.floorPlan.roomData [x, z + 1]]; } roomTupels.Add(new Point2DTupel(x, z, x, z + 1)); dictionary [houseData.floorPlan.roomData [x, z + 1]] = roomTupels; } } else if (houseData.floorPlan.area [x, z] == UnitType.OUTERWALL_LEFT) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x + 1, z] == UnitType.INNERWALL_RIGHT && CheckLeftContainsDoor(x, z, houseData)) //Angrenzendes Feld ist das Gegenstück zur Wand { List <Point2DTupel> roomTupels; //if (dictionary [houseData.floorPlan.roomData [x+1, z]] == null) { if (!dictionary.ContainsKey(houseData.floorPlan.roomData[x + 1, z])) { roomTupels = new List <Point2DTupel> (); } else { roomTupels = dictionary [houseData.floorPlan.roomData [x + 1, z]]; } roomTupels.Add(new Point2DTupel(x, z, x + 1, z)); dictionary [houseData.floorPlan.roomData [x + 1, z]] = roomTupels; } } else if (houseData.floorPlan.area [x, z] == UnitType.OUTERWALL_RIGHT) //Mögliche Wand für eine Tür { if (houseData.floorPlan.area [x - 1, z] == UnitType.INNERWALL_LEFT && CheckRightContainsDoor(x, z, houseData)) //Angrenzendes Feld ist das Gegenstück zur Wand { List <Point2DTupel> roomTupels; if (!dictionary.ContainsKey(houseData.floorPlan.roomData[x - 1, z])) { roomTupels = new List <Point2DTupel> (); } else { roomTupels = dictionary [houseData.floorPlan.roomData [x - 1, z]]; } roomTupels.Add(new Point2DTupel(x, z, x - 1, z)); dictionary [houseData.floorPlan.roomData [x - 1, z]] = roomTupels; } } } } List <RoomData> roomsWithDoors = new List <RoomData> (); int doorCount = randomGenerator.Next(houseData.houseConfig.entranceDoorCount - 1) + 1; for (int i = 0; i < doorCount; i++) { RoomData key = dictionary.Keys.ElementAt(randomGenerator.Next(dictionary.Count)); if (!roomsWithDoors.Contains(key)) { roomsWithDoors.Add(key); List <Point2DTupel> doorPoints = dictionary [key]; Point2DTupel doorPlaces = doorPoints [randomGenerator.Next(doorPoints.Count)]; houseData.floorPlan.area [doorPlaces.point1.x, doorPlaces.point1.z] = UnitType.DOOR; houseData.floorPlan.area [doorPlaces.point2.x, doorPlaces.point2.z] = UnitType.DOOR; doorPoints.Remove(doorPlaces); dictionary [key] = doorPoints; } } for (int k = 0; k < dictionary.Keys.Count; k++) { RoomData key = dictionary.Keys.ElementAt(k); List <Point2DTupel> windowPoints = dictionary [key]; int windowCount = randomGenerator.Next((int)(windowPoints.Count * houseData.houseConfig.windowProbability)); for (int i = 0; i < windowCount; i++) { Point2DTupel doorPlaces = windowPoints [randomGenerator.Next(windowPoints.Count - 1) + 1]; houseData.floorPlan.area [doorPlaces.point1.x, doorPlaces.point1.z] = UnitType.WINDOW; houseData.floorPlan.area [doorPlaces.point2.x, doorPlaces.point2.z] = UnitType.WINDOW; windowPoints.Remove(doorPlaces); dictionary [key] = windowPoints; } } return(houseData); }