예제 #1
0
        private void ProduceOrder(Order order)
        {
            // If the unit is told to build a structure far away, and he is not in range yet
            if (CanMove() && order.targetPosition != null && order.targetPosition.Distance(position) > 1)
            {
                MoveTowards(order.targetPosition);
                return;
            }

            status = Status.Producing;
            // If the player does not has enough moneyz
            if (owner.gold < order.unitTypeBuild.goldCost ||
                owner.iron < order.unitTypeBuild.ironCost ||
                owner.manaCystals < order.unitTypeBuild.manaCrystalsCost)
            {
                // Try again later
                engine.ScheduleUpdate(buildRetryCooldown, this);
                return;
            }

            // Find place to put unit
            Position targetLocation = position;
            Position producePosition = null;
            if (order.targetPosition == null)
            {
                foreach (var testPosition in Pathfinder.BreadthFirst(engine, targetLocation, distance: 1))
                {
                    if (engine.GetUnitAt(testPosition) == null)
                    {
                        producePosition = testPosition;
                        break;
                    }
                }
            }
            else
            {
                producePosition = order.targetPosition;
            }
            if (producePosition == null)
            {
                // Try again in the future
                engine.ScheduleUpdate(buildRetryCooldown, this);
                return;
            }

            // Subtract resources
            owner.gold -= order.unitTypeBuild.goldCost;
            owner.iron -= order.unitTypeBuild.ironCost;
            owner.manaCystals -= order.unitTypeBuild.manaCrystalsCost;

            // Create the unit
            Unit u = engine.AddUnit(order.unitTypeBuild, producePosition, owner);
            if (order.targetPosition != null && u.CanMove())
            {
                // Tell the produced unit to go to the rally point
                engine.OrderMove(u, order.targetPosition);
            }
            else if (u.type.name.Equals("GoldMine"))
            {
                engine.OrderGather(u, u.position);
            }

            NextOrder();
            engine.ScheduleUpdate(buildCooldown, this);
        }
예제 #2
0
 private void GatherOrder(Order order)
 {
     if (!position.Equals(order.targetPosition))
     {
         // Move to resource
         MoveTowards(order.targetPosition);
         return;
     }
     status = Status.Producing;
     // TODO: / ASSUPTION We have infinate resources, is that okay?
     var tileResoure = engine.map.tiles[order.targetPosition.x, order.targetPosition.y].tileType.resourceType;
     if (tileResoure == TileType.ResourceType.Gold)
     {
         owner.gold += type.gatherRate;
     }
     else if (tileResoure == TileType.ResourceType.Iron)
     {
         owner.iron += type.gatherRate;
     }
     else if (tileResoure == TileType.ResourceType.ManaCrystals)
     {
         owner.manaCystals += type.gatherRate;
     }
     engine.ScheduleUpdate(gatherCooldown, this);
     if (orders.Count > 1)
     {
         NextOrder();
     }
 }
예제 #3
0
 private void MoveOrder(Order order)
 {
     // Check for goal reached
     if (position.Equals(order.targetPosition))
     {
         NextOrder();
         Update();
         return;
     }
     MoveTowards(order.targetPosition);
 }
예제 #4
0
        private void AttackOrder(Order order)
        {
            // Check for goal reached
            if (order.targetUnit.status == Status.Dead)
            {
                NextOrder();
                Update();
                return;
            }

            var targetPosition = order.targetUnit.position;
            if (position.Distance(targetPosition) > type.attackRange)
            {
                // Move into range
                MoveTowards(targetPosition);
                return;
            }

            status = Status.Attacking;
            engine.Attack(this, order.targetUnit);
            direction = CalculateDirection(targetPosition - position);
            engine.ScheduleUpdate(GetAttackCooldown(), this);
        }