//================================================================= // HandleTownHallBuilding() //================================================================= private void HandleTownHallBuilding() { if (townHallMode == true) { GameObject hitObject = GetHitObject(); if (hitObject == null) { return; } LandTile tile = hitObject.GetComponentInParent <LandTile>(); if (tile && Input.GetMouseButtonDown(0)) { if (tile.TileOccupied == false) { float x = hitObject.transform.position.x; float z = hitObject.transform.position.z; GameObject tempBuilding = Instantiate(townHallPrefab, new Vector3(x, yOffsetTownHall, z), Quaternion.identity); tile.Building = tempBuilding; tempBuilding.GetComponentInParent <Building>().Tile = hitObject; townHall = tempBuilding.GetComponent <TownHall>(); closedSet.Add(tile); foreach (GameObject neighbour in tile.GetNeighbours()) { LandTile neighbourTile = neighbour.GetComponent <LandTile>(); if (neighbourTile && !closedSet.Contains(neighbourTile) && !openSet.Contains(neighbourTile)) { openSet.Add(neighbourTile); } else { WaterTile waterTile = neighbour.GetComponent <WaterTile>(); if (waterTile && !openWaterSet.Contains(waterTile) && !closedWaterSet.Contains(waterTile)) { openWaterSet.Add(waterTile); } } } ExpandVillage(5, 0); TimeManager.OnNextDayAction += OnLevelStart; ///TODO: REMAP THIS TO NEXT LEVEL INSTEAD OF NEXT DAY. townHallMode = false; gameManager.CurrentStage = GameManager.GameStage.GAME; } } } }
//================================================================= // ExpandVillage(uint houses, uint farms) //================================================================= void ExpandVillage(uint houses, uint farms) { if (openSet.Count == 0) { if (!TraverseWater()) { return; } } List <LandTile> placementSet = new List <LandTile>(openSet); for (uint i = 0; i < houses; i++) { if (placementSet.Count == 0) { if (openSet.Count == 0) { if (!TraverseWater()) { return; } } placementSet = new List <LandTile>(openSet); } LandTile tile = placementSet[Random.Range(0, placementSet.Count)]; SpawnHouse(tile); openSet.Remove(tile); placementSet.Remove(tile); closedSet.Add(tile); foreach (GameObject neighbour in tile.GetNeighbours()) { LandTile neighbourTile = neighbour.GetComponent <LandTile>(); if (neighbourTile && !closedSet.Contains(neighbourTile) && !openSet.Contains(neighbourTile)) { openSet.Add(neighbourTile); } else { WaterTile waterTile = neighbour.GetComponent <WaterTile>(); if (waterTile && !openWaterSet.Contains(waterTile) && !closedWaterSet.Contains(waterTile)) { openWaterSet.Add(waterTile); } } } } for (uint i = 0; i < farms; i++) { if (placementSet.Count == 0) { if (openSet.Count == 0) { if (!TraverseWater()) { return; } } placementSet = new List <LandTile>(openSet); } LandTile tile = placementSet[Random.Range(0, placementSet.Count)]; SpawnFarm(tile); openSet.Remove(tile); placementSet.Remove(tile); closedSet.Add(tile); foreach (GameObject neighbour in tile.GetNeighbours()) { LandTile neighbourTile = neighbour.GetComponent <LandTile>(); if (neighbourTile && !closedSet.Contains(neighbourTile) && !openSet.Contains(neighbourTile)) { openSet.Add(neighbourTile); } else { WaterTile waterTile = neighbour.GetComponent <WaterTile>(); if (waterTile && !openWaterSet.Contains(waterTile) && !closedWaterSet.Contains(waterTile)) { openWaterSet.Add(waterTile); } } } } }