Пример #1
0
        /// <summary>
        /// Builds a unit of the specified type. Automatically consumes resources if possible (fails otherwise), and can only execute as often as permitted by the build cooldown (0.5 seconds).
        /// </summary>
        /// <param name="type">The type of unit to spawn.</param>
        public void SpawnUnit(UnitType type)
        {
            if (type == UnitType.None)
            {
                Debug.LogError(this.ToString() + " cannot build units of type 'None'");
                return;
            }

            var cost = UnitCostManager.GetCost(type);

            if (cost > _currentResources)
            {
                // AI cannot afford the unit
                return;
            }

            var time = Time.time;

            if (time - _lastBuild < _buildCooldown)
            {
                // cooldown still in effect
                return;
            }

            _lastBuild         = time;
            _currentResources -= cost;
            InternalBuildUnit(type);
        }
Пример #2
0
        public override float Score(IAIContext context)
        {
            var c         = (ControllerContext)context;
            var resources = c.controller.nest.currentResources;
            var cost      = UnitCostManager.GetCost(this.unitType);

            if (resources >= cost)
            {
                return(this.score);
            }

            return(0f);
        }