/// <summary> /// Gets the structure under mouse. /// </summary> /// <returns>The structure under mouse.</returns> public Models.Structures GetStructureUnderMouse() { Models.Structures structureModel; Models.Surfaces surfaceModel = GetSurfaceUnderMouse(); if (surfaceModel != null && surfaceModel.hasStructure() == true) { structureModel = GetSurfaceUnderMouse().Structure; return(structureModel); } else { return(null); } }
//Checks if the current position of a structure is valid //For structures larger than 1x1, it checks its neighbors as well //Function returns true only if all surfaces under consideration don'e have structures on them public bool isPositionValidOnSurface(Models.Surfaces surfaceModel) { for (int x = surfaceModel.X; x < surfaceModel.X + this.width; x++) { for (int y = surfaceModel.Y; y < surfaceModel.Y + this.height; y++) { Models.Surfaces surface = surfaceModel.Level.GetSurfaceAt(x, y); //Return false if the floor is empty if (surface.Terrain == Surfaces.TerrainType.Empty) { return(false); } //return false if there is already a structure on the surface if (surface.hasStructure() == true) { return(false); } } } 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); }