Ejemplo n.º 1
0
 /// <summary>
 /// Initialises a new instance of the Building class.
 /// </summary>
 /// <param name="size">The size in tiles of the building.</param>
 /// <param name="buildingTiles">A 2D array containing all the building tiles.</param>
 /// <param name="requiredMaterials">The materials required for building.</param>
 /// <param name="owner">The owning game world.</param>
 public Building(Point size, BuildingTile[,] buildingTiles, List <string> requiredMaterials, GameWorld owner) : base(owner)
 {
     Size               = size;
     _buildingTiles     = buildingTiles;
     _requiredMaterials = requiredMaterials;
     _constructionItems = new List <Item>();
     _buildingState     = BuildingStates.None;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Starts construction of this building.
 /// </summary>
 public void StartBuilding()
 {
     _buildingState = BuildingStates.UnderConstruction;
     foreach (BuildingTile buildingTile in _buildingTiles)
     {
         EnvironmentTile targetTile = Owner.Environment[_position.X + buildingTile.Position.X, _position.Y + buildingTile.Position.Y];
         targetTile.CanAccess = false;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Completes construction of this building.
 /// </summary>
 public void CompleteBuilding()
 {
     _buildingState = BuildingStates.Ready;
     foreach (BuildingTile buildingTile in _buildingTiles)
     {
         EnvironmentTile targetTile = Owner.Environment[_position.X + buildingTile.Position.X, _position.Y + buildingTile.Position.Y];
         targetTile.CanAccess    = buildingTile.CanAccess;
         targetTile.BuildingTile = buildingTile;
     }
 }
Ejemplo n.º 4
0
    void Awake()
    {
        roomFill = gameObject.GetComponent <RoomFiller> ();

        buildProgress = BuildingStates.building;
//Room too big?
        roomWidth = Random.Range(5, 8);
        roomDepth = Random.Range(5, 8);

        CreateParents();
    }
 /// <summary>
 /// Check the healthPoints of this building and update
 /// </summary>
 protected virtual void UpdateIntegrity()
 {
     if (healthPoints <= 0)
     {
         this.State = BuildingStates.Destroyed;
     }
     else
     {
         this.State = BuildingStates.Intact;
     }
 }
Ejemplo n.º 6
0
 public Building(Vector2 position, BuildingData bd, Type_Data <BuildingTypes> bt)
     : base(position, bd.Size, bt.Texture, bt.H_texture, bt.C_texture, 0, bt.Animations)
 {
     data              = bd;
     type              = bt;
     corners           = new Dictionary <Corner, Vector2>();
     state             = BuildingStates.Building;
     this.stats        = bd;
     base.CurrentState = "Building";
     CalculateCorners();
     statusBar        = new StatusBar(new Point(bd.Size.X, bd.Size.Y / 5), (int)stats.Health, statusBarTexture);
     this.temp_health = this.GetBuildingData().Health;
     this.GetBuildingData().Health = 1;
 }
Ejemplo n.º 7
0
        void Build(GameTime gt, Architech arch, Grid grid, List <Rectangle> units, Player player, UiMaster ui)
        {
            bool impassable = false;

            foreach (Rectangle rect in units)
            {
                if (this.Box.Intersects(rect))
                {
                    impassable = true;
                    break;
                }
            }

            float tc_inc = GetBuildingData().Cost / 10;

            if ((Options.GetTick && !impassable && player.Energy >= tc_inc) || temp_cost >= GetBuildingData().Cost)
            {
                if (temp_cost < GetBuildingData().Cost)
                {
                    temp_cost += tc_inc;
                    var pct = Extensions.Extensions.PercentAofB(temp_cost, GetBuildingData().Cost) / 100;
                    GetBuildingData().Health = pct * temp_health;
                    player.IncreaseEnergy   -= tc_inc;
                }

                else
                {
                    this.GetBuildingData().Health = temp_health;
                    //finish building
                    state = BuildingStates.Production;                     //start producing
                    arch.BuildComplete(this, grid, ui);
                    base.CurrentState = "Production";
                }
            }

            else if (Options.GetTick && player.Energy <= tc_inc && !impassable)
            {
                float count    = Math.Abs(player.IncreaseEnergy);
                float increase = 1 / (count == 0 ? 1 : count);
                temp_cost += player.Energy + 1 / (Math.Abs(player.IncreaseEnergy) + 1);

                var pct = Extensions.Extensions.PercentAofB(temp_cost, GetBuildingData().Cost) / 100;
                GetBuildingData().Health = pct * temp_health;

                player.IncreaseEnergy -= player.Energy + 1 / (Math.Abs(player.IncreaseEnergy) + 1);
            }
        }
Ejemplo n.º 8
0
    //	建造状态下
    private void Build()
    {
        //	获取从摄像机发出经过鼠标当前位置的射线
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        //	获取碰撞信息
        RaycastHit [] hitInfos = Physics.RaycastAll(ray);
        //	遍历所有碰撞信息
        foreach (RaycastHit hitInfo in hitInfos)
        {
            //	如果跟地面碰撞
            if (hitInfo.transform.tag == "Ground")
            {
                //	重新设置当前建筑物位置
                transform.position = hitInfo.point;
            }
        }
        //	根据建筑物当前位置计算出相对的格子位置
        Vector3 fixedPos = Global.GetLocalPos(transform.position);
        //	获取当前建筑物的参考格子下标
        int tempI = w / 2;
        int tempJ = l / 2;

        //	重置能否建造的状态
        canBuild = true;
        //	依次更新每个格子的相对位置
        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < l; j++)
            {
                //	获取格子
                Grid g = grids [i, j];
                //	更新格子相对位置
                g.pos = new Vector3(fixedPos.x + i - tempI, 0f, fixedPos.z + j - tempJ);
                //	更新格子是否有效
                g.enable = bc.InspectGrid(g.pos);
                //	更新建筑物能否建造的状态
                if (!g.enable)
                {
                    canBuild = false;
                }
            }
        }
        //	获取下标为 [0, 0] 的格子中心点
        Vector3 tempPos = Global.GetGlobalPos(grids [0, 0].pos);

        //	获取所有格子的中心位置
        tempPos.x = tempPos.x + w / 2f - 0.5f;
        tempPos.z = tempPos.z + l / 2f - 0.5f;
        //	更新建筑物的位置
        transform.position = tempPos;
        //	如果当前尚未绘制格子
        if (!didDraw)
        {
            //	绘制格子
            gridsID = draw.AddGrids(grids);
            //	更新绘制状态
            didDraw = true;
        }
        //	按下鼠标左键建造
        if (Input.GetMouseButtonDown(0) && canBuild)
        {
            if (Global.money >= price && Global.wood >= wood)
            {
                //	扣除金钱
                Global.money -= price;
                Global.wood  -= wood;
                //	设置游戏状态为正常状态
                Global.state = GlobalStates.Normal;
                //	停止绘制格子
                draw.RemoveGrids(gridsID);
                didDraw = false;
                //	设置建筑物状态为正常状态
                state = BuildingStates.Normal;
                //	加入到建筑物控制器
                bc.buildings.Add(this);
            }
            else
            {
                GameController gc = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ();
                if (Global.money < price)
                {
                    gc.MoneyAlert();
                }
                if (Global.wood < wood)
                {
                    gc.WoodAlert();
                }
            }
        }
        //	按下鼠标右键取消建造
        if (Input.GetMouseButtonDown(1))
        {
            //	设置游戏状态为正常状态
            Global.state = GlobalStates.Normal;
            //	停止绘制格子
            draw.RemoveGrids(gridsID);
            didDraw = false;
            //	销毁当前建筑物
            Destroy(gameObject);
        }
    }