public static BuildGridArea GetArea(int fromX, int fromZ, int size) { BuildGridArea gridArea = new BuildGridArea { MinX = fromX, MaxX = fromX + size - 1, MinZ = fromZ, MaxZ = fromZ + size - 1 }; return(gridArea); }
public static List <BuildGridReference> GetGridReferences(int x, int z, int size) { List <BuildGridReference> gridReferences = new List <BuildGridReference>(); BuildGridArea gridArea = GetArea(x, z, size); for (int ax = gridArea.MinX; ax <= gridArea.MaxX; ax++) { for (int az = gridArea.MinZ; az <= gridArea.MaxZ; az++) { gridReferences.Add(new BuildGridReference(ax, az)); } } return(gridReferences); }
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 static void OccupyTiles(BuildGridArea area, TileOccupant occupantType) { OccupyTiles(area.MinX, area.MinZ, area.Size, occupantType); }