// Use this for initialization void Start () { // int width = 20; int height = 20; level.RegisterStructurePlacedCallBack (OnStructurePlacedOnSurface); // level.RegisterSurfaceChangedCallBack (OnSurfaceTerrainCreated); level.CreateEmptyLevel(width, height); //surfaceViews = new Views.Surfaces[width * height]; //Create Dictionary Maps surfaceModelViewMap = new Dictionary<Models.Surfaces, Surfaces>(); structureModelViewMap = new Dictionary<Models.Structures, Structures> (); for (int x = 0; x < level.Width; x++) { for (int y = 0; y < level.Height; y++) { //Get Surface Model Models.Surfaces surfaceModel = level.GetSurfaceAt (x, y); this.OnSurfaceTerrainCreated (surfaceModel); } } //Tell the level model about any changes to individual surfaces instead of registering with each surface level.RegisterSurfaceChangedCallBack (OnSurfaceTerrainChanged); }
public bool PlaceStructure(Models.Structures structureModel) { if (structureModel == null) { //Removing object from surface this.structure = null; return(true); } if (structureModel.isPositionValidOnSurface(structureModel.SurfaceModel) == false) { Debug.Log("Models.Surfaces --> PlaceStructureOnSurface : structure at " + X + ", " + Y + " already exists"); return(false); } else { for (int a = X; a < X + structureModel.Width; a++) { for (int b = Y; b < Y + structureModel.Height; b++) { level.GetSurfaceAt(a, b).structure = structureModel; } } //FIXME: placeholder cause the compiler throws a tantrum return(true); } }
public static Models.Structures PlaceStructureOnSurface(Models.Structures structureModel, Models.Surfaces surfaceModel) { if (structureModel.PositionValidationFunctions(surfaceModel) == false) { Debug.Log("Models.Structures --> place structure on surface : cannot place the structure here"); return(null); } Models.Structures structure = new Models.Structures(); structure.type = structureModel.type; structure.movemenCost = structureModel.movemenCost; structure.width = structureModel.width; structure.height = structureModel.height; structure.linksToNeighbor = structureModel.linksToNeighbor; structure.SurfaceModel = surfaceModel; if (surfaceModel.hasStructure()) { Console.Write("Models.Structure -> placeStructureOnSurface : surface has pre-existing structure on it"); return(null); } else { Debug.Log("Models.Structure -> placeStructureOnSurface : structure added to surface"); surfaceModel.PlaceStructure(structure); } int x = structure.SurfaceModel.X; int y = structure.SurfaceModel.Y; Models.Levels levelModel = Models.Levels.Instance; if (structure.linksToNeighbor == true) { //North if (x < levelModel.Width - 1 && levelModel.GetSurfaceAt(x + 1, y).Structure != null && levelModel.GetSurfaceAt(x + 1, y).Structure.Type == structure.type) { levelModel.GetSurfaceAt(x + 1, y).Structure.StructureCallBacks(levelModel.GetSurfaceAt(x + 1, y).Structure); } //East if (y > 0 && levelModel.GetSurfaceAt(x, y - 1).Structure != null && levelModel.GetSurfaceAt(x, y - 1).Structure.Type == structure.type) { levelModel.GetSurfaceAt(x, y - 1).Structure.StructureCallBacks(levelModel.GetSurfaceAt(x, y - 1).Structure); } //South if (x > 0 && levelModel.GetSurfaceAt(x - 1, y).Structure != null && levelModel.GetSurfaceAt(x - 1, y).Structure.Type == structure.type) { levelModel.GetSurfaceAt(x - 1, y).Structure.StructureCallBacks(levelModel.GetSurfaceAt(x - 1, y).Structure); } //West if (y < levelModel.Height - 1 && levelModel.GetSurfaceAt(x, y + 1).Structure != null && levelModel.GetSurfaceAt(x, y + 1).Structure.Type == structure.type) { levelModel.GetSurfaceAt(x, y + 1).Structure.StructureCallBacks(levelModel.GetSurfaceAt(x, y + 1).Structure); } } return(structure); }