Esempio n. 1
0
        // Tries to upgrade the tower on the selected tile
        // Returns false if unsuccessful
        public bool TryUpgrade()
        {
            // Make sure we have a selected tile (this should never happen)
            if (m_SelectedTile != null && m_SelectedTile.Tower != null)
            {
                Objects.Tower t = m_SelectedTile.Tower;

                // Can't upgrade if it's not active
                if (!t.IsRunning)
                {
                    m_UIGameplay.ShowErrorMessage(Localization.Get().Text("ui_err_building"));
                    return(false);
                }

                // We can't upgrade if we're at the max level already
                if (t.Level == t.MaxLevel)
                {
                    m_UIGameplay.ShowErrorMessage(Localization.Get().Text("ui_err_level"));
                    return(false);
                }

                // Make sure we can afford it
                if (t.GetUpgradeCost() > Money)
                {
                    m_UIGameplay.ShowErrorMessage(Localization.Get().Text("ui_err_money"));
                    return(false);
                }

                // Do the upgrade
                t.Upgrade();
                SoundManager.Get().PlaySoundCue("Build");
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
 public void PreviewBuild(Tower tower)
 {
     m_Tower = tower;
     m_Tower.Position = Position;
 }
Esempio n. 3
0
 public void ClearTower(bool destroying = false)
 {
     m_Tower = null;
     m_bBuildable = true;
     // If the tower is being destroyed, move the tile back down
     if (destroying)
     {
         m_State = eTileState.Down;
     }
 }
Esempio n. 4
0
        public void Build(Tower tower, bool bLoad = true)
        {
            if (bLoad)
            {
                tower.Load();
            }

            m_Tower = tower;
            m_Tower.Position = Position;
            m_Tower.Spawned = true;
            m_Tower.Build(this);

            m_bInUse = true;
            m_bBuildable = false;

            // When we build, move the tile up
            m_State = eTileState.Up;
        }
Esempio n. 5
0
 public void PreviewBuild(Tower tower)
 {
     m_Tower          = tower;
     m_Tower.Position = Position;
 }
Esempio n. 6
0
        // Try to build the specified tower at the current tile.
        // Returns true if succeeds
        public bool TryBuild(eTowerType type)
        {
            // Check and make sure we can afford this building
            int BuildCost = 0;

            switch (type)
            {
            case (eTowerType.Projectile):
                BuildCost = Balance.ProjectileTower[0].BuildCost;
                break;

            case (eTowerType.Slow):
                BuildCost = Balance.SlowTower[0].BuildCost;
                break;
            }
            if (BuildCost > Money)
            {
                m_UIGameplay.ShowErrorMessage(Localization.Get().Text("ui_err_money"));
                return(false);
            }

            // Create the tower
            // We don't use SpawnGameObject here because the Tower is a child of its Tile
            Objects.Tower tower = null;
            switch (type)
            {
            case (eTowerType.Projectile):
                tower = new Objects.ProjectileTower(m_Game);
                break;

            case (eTowerType.Slow):
                tower = new Objects.SlowTower(m_Game);
                break;
            }

            tower.Load();

            // Check whether or not there still is a route for enemies to take
            // before building this!
            m_SelectedTile.PreviewBuild(tower);
            if (!Pathfinder.Get().ComputeAStar())
            {
                m_UIGameplay.ShowErrorMessage(Localization.Get().Text("ui_err_block"));

                // Clear out this tower and recompute old path
                m_SelectedTile.ClearTower();

                Pathfinder.Get().ComputeAStar();
                return(false);
            }
            else
            {
                // Any active enemies need to compute new paths, in case the old one is blocked
                foreach (Objects.Enemy e in m_Enemies)
                {
                    Pathfinder.Get().ComputeAStar(e);
                }

                m_SelectedTile.Build(tower, false);
                m_UIGameplay.FinishBuild();
            }

            return(true);
        }