예제 #1
0
        /// <summary>
        /// Create a new building
        /// </summary>
        /// <param name="position">Position of the new building</param>
        /// <param name="size">Size of the new building</param>
        /// <param name="data">Data about the building</param>
        /// <returns>True if the building was able to be created.</returns>
        public bool CreateBuilding(Pair<int> position, Pair<int> size, BuildingData data)
        {
            var newBuilding = new Building(position, size, data);
            this.Add(newBuilding);

            // Place this new building's Guid into the world grid
            var buildingIsoPosition = Geometry.ToIsometricGrid(position);
            for (int y = 0; y < data.Footprint.Length; ++y)
            {
                for (int x = 0; x < data.Footprint[y].Length; ++x)
                {
                    if (data.Footprint[y][x])
                    {
                        int gridX = this.WorldIsoToGridX(buildingIsoPosition.x + x - data.FootprintIndexOffsetX);
                        int gridY = this.WorldIsoToGridY(buildingIsoPosition.y + y - data.FootprintIndexOffsetY);

                        // Sanity checks before we place the building
                        if (gridX < 0 || gridX >= this.grid.Length || gridY < 0 || gridY >= this.grid.Length)
                        {
                            Logger.Log(LogLevel.Error, "Creating a building outside grid limits", string.Format("Trying to build building {0} at position: Iso: {1},{2} World: {3}, {4}. Outside world boundry of {5}", data.Name, gridX, gridY, position.x, position.y, this.grid.Length));
                            continue;
                        }

                        if (this.grid[gridY][gridX] != -1)
                        {
                            Logger.Log(LogLevel.Error, "Creating a building on top of another building", string.Format("Trying to build building {0} at position: Iso: {1},{2} World: {3}, {4}. Building {5} already exists at location.", data.Name, gridX, gridY, position.x, position.y, this.grid[gridY][gridX]));
                        }

                        this.grid[gridY][gridX] = newBuilding.Guid;
                    }
                }
            }

            return true;
        }
예제 #2
0
파일: Building.cs 프로젝트: GoodSky/Sim-U
        /// <summary>
        /// Default constructor for this button
        /// </summary>
        public EditBuildingButton(Building parent)
            : base(Constants.GUI_DEPTH - 1)
        {
            this.image = ImageCatalog.Instance.Get("ScreenElements/EditBuildingButton");
            this.Size = new Pair<int>(this.image.Width, this.image.Height);
            this.Clickable = true;

            parent.AddChild(this);
        }