/// <summary> /// Places the roads between rooms one after another. At first places horizontal /// road, then vertical. /// </summary> /// <returns> /// List of roads. /// </returns> /// <param name='rooms'> /// Ordered list of rooms in dungeon. /// </param> private static List <DungeonRoad> PlaceRoads(List <DungeonRoom> rooms) { List <DungeonRoad> ret = new List <DungeonRoad> (); // for every pair of room for (int i = 1; i < rooms.Count; i++) { DungeonRoad horRoad = new DungeonRoad(); DungeonRoad vertRoad = new DungeonRoad(); // Parent room is a room which starts a horizontal road int parentRoomIndex = i; // Child room is a room in the end of vertical road int childRoomIndex = i; if (Random.value > 0.5f) { parentRoomIndex -= 1; } else { childRoomIndex -= 1; } // road starts in parent room and pulled left or right to acheieve X of child room int hx1 = rooms [parentRoomIndex].CenterX; int hy1 = rooms [parentRoomIndex].CenterY; int hx2 = rooms [childRoomIndex].CenterX; int hy2 = hy1; // road starts in the end of horizontal road and pulled up or down to end in child room int vx1 = rooms [childRoomIndex].CenterX; int vy1 = rooms [parentRoomIndex].CenterY; int vx2 = vx1; int vy2 = rooms [childRoomIndex].CenterY; // Horizontal roads carved from left to right horRoad.x1 = Mathf.Min(hx1, hx2); horRoad.y1 = Mathf.Min(hy1, hy2); horRoad.x2 = Mathf.Max(hx1, hx2); horRoad.y2 = Mathf.Max(hy1, hy2); // Vertical roads carved from top to bottom vertRoad.x1 = Mathf.Min(vx1, vx2); vertRoad.y1 = Mathf.Min(vy1, vy2); vertRoad.x2 = Mathf.Max(vx1, vx2); vertRoad.y2 = Mathf.Max(vy1, vy2); ret.Add(horRoad); ret.Add(vertRoad); } return(ret); }
/// <summary> /// Prepares the coridors decoration. /// </summary> /// <param name='dungeon'> /// Dungeon data. /// </param> public static void PrepareCoridorsDecoration(DungeonData dungeon) { List <DungeonRoad> roads = dungeon.Roads; for (int c = 0; c < roads.Count; c++) { DungeonRoad corridor = roads [c]; // for every tile in corridor for (int j = corridor.y1; j <= corridor.y2; j++) { for (int i = corridor.x1; i <= corridor.x2; i++) { int code = DungeonUtils.GetCodeOfTileByIndex(i, j); #region Lights // 50% to create a torchlight if (Random.value > 0.5f) { DungeonDataTile tile = dungeon.Tiles [code]; //if it is a corridor if (tile.room == null) { for (int o = 0; o < tile.Objects.Count; o++) { if (tile.Objects [o].type == DungeonObjectType.Wall) { DungeonObject newTorch = new DungeonObject(code, DungeonObjectType.LightSource, "Torch"); newTorch.offset = tile.Objects [o].offset; newTorch.rotation = tile.Objects [o].rotation; tile.Objects.Add(newTorch); break; } } } } #endregion } } } }