void CreateBuilding(CityBuildingModel prefab, BuildGridReference location) { CityBuildingModel model = Instantiate(prefab, new Vector3(location.X, 0f, location.Z), Quaternion.identity, transform).GetComponent <CityBuildingModel>(); model.Place(); UpdateBuildAreas(model); }
void SpawnNewRandomCityBuilding() { // TODO: need to find a fit for the tile specified (e.g. if 2x2 and only 1x1 area to build in, go for small building) CityBuildingModel randomModel = CityBuildingStore.GetRandomCityBuilding(); // TODO: definitely inefficient List <BuildGridReference> gridRefs = new List <BuildGridReference>(expansionAreas); for (int i = 0; i < 20; i++) { BuildGridReference spawnReference = Curveball.Utilities.SelectRandomlyFromList(gridRefs); if (BuildGridManager.CanBuildAt(spawnReference, randomModel.Size)) { CreateBuilding(randomModel, spawnReference); return; } } // was unable to spawn a building: set spawn timer to 0f to try again next frame spawnTimer = 0f; }
void UpdateBuildAreas(CityBuildingModel model) { BuildGridReference modelGridRef = Utilities.GetGridReference(model.transform.position); BuildGridArea gridArea = Utilities.GetArea(modelGridRef, model.Size); // remove expansion areas where building is now occupying foreach (BuildGridReference gridRef in Utilities.GetGridReferences(modelGridRef.X, modelGridRef.Z, model.Size)) { expansionAreas.Remove(gridRef); } // add expansion areas in one tile radius (minus corners) around new building for (int x = gridArea.MinX; x <= gridArea.MaxX; x++) { CreateExpansionEntry(new BuildGridReference(x, gridArea.MinZ - 1)); CreateExpansionEntry(new BuildGridReference(x, gridArea.MaxZ + 1)); } for (int z = gridArea.MinZ; z <= gridArea.MaxZ; z++) { CreateExpansionEntry(new BuildGridReference(gridArea.MinX - 1, z)); CreateExpansionEntry(new BuildGridReference(gridArea.MaxX + 1, z)); } }
public CityBuildingPlacedEvent(CityBuildingModel placedModel) { PlacedModel = placedModel; }