Esempio n. 1
0
    /// <summary>
    /// Updates the image of the army and the number of units in it
    /// Usually called after the underlying model is updated
    /// </summary>
    private void Update()
    {
        UnitType armyRepresentative = GameUtils.GetRepresentative(_model.GetUnits());

        _armyImage.material.mainTexture = SpriteCollectionManager.GetTextureByName(armyRepresentative.GetName());
        _quantityField.text             = _model.GetUnitsCount().ToString();
    }
Esempio n. 2
0
    /// <summary>
    /// Add an army movement order to the current collection of orders
    /// </summary>
    /// <param name="order">The new army movement order</param>
    /// <returns>Whether the order was added successfully</returns>
    public bool AddArmyMovementOrder(ArmyMovementOrder order)
    {
        // clone order's units as removing them from their location
        // may result in the order's unit list to become empty
        List <Unit> orderUnits  = order.GetUnits();
        List <Unit> movingUnits = new List <Unit>();

        for (int i = 0; i < orderUnits.Count; i++)
        {
            movingUnits.Add(new Unit(orderUnits[i]));
        }

        order.GetOrigin().RemoveUnits(order.GetUnits());

        order.SetUnits(movingUnits);
        return(_movementOrders.AddArmyMovementOrder(order));
    }
 /// <summary>
 /// Add an army movement order to the collection
 /// </summary>
 /// <param name="order">Army movement order to add to the collection</param>
 /// <returns>True if the order was added, false if another order with the same origin and destination was found and updated</returns>
 public bool AddArmyMovementOrder(ArmyMovementOrder order)
 {
     for (int i = 0; i < _orders.Count; i++)
     {
         if (_orders[i].GetOrigin() == order.GetOrigin() && _orders[i].GetDestination() == order.GetDestination())
         {
             _orders[i].AddUnits(order.GetUnits());
             return(false);
         }
     }
     _orders.Add(order);
     return(true);
 }
Esempio n. 4
0
    /// <summary>
    /// Update an existing army movement order with a new list of units
    /// </summary>
    /// <param name="order">The army movement order</param>
    /// <param name="newUnits">The list of units to include into the army movement order</param>
    /// <param name="totalQty">The total number of combatants among the new units</param>
    /// totalQty is added to save time calculating it - the caller can just pass it in
    public void UpdateArmyMovementOrderUnits(ArmyMovementOrder order, List <Unit> newUnits, int totalQty)
    {
        // return units back to the province they were leaving
        order.GetOrigin().AddUnits(order.GetUnits());

        if (totalQty > 0)
        {
            // remove new units from the provine and add them to the move order
            order.GetOrigin().RemoveUnits(newUnits);
            order.SetUnits(newUnits);
        }
        else
        {
            // no units involved - just nix the order
            _movementOrders.GetAllOrders().Remove(order);
        }
    }
Esempio n. 5
0
 /// <summary>
 /// Add an army movement order to the attack plan
 /// </summary>
 /// <param name="order">Movement order for an army joining the attack</param>
 public void AddMovementOrder(ArmyMovementOrder order)
 {
     if (_province == order.GetDestination())
     {
         _orders.Add(order);
         if (!_areHeroesInvolved)
         {
             List <Unit> attackers = order.GetUnits();
             for (int i = 0; i < attackers.Count; i++)
             {
                 _areHeroesInvolved = _areHeroesInvolved || attackers[i].GetUnitType().IsHero();
             }
         }
     }
     else
     {
         FileLogger.Error("AI", "Trying to add an order to move to " + order.GetDestination().GetName() + " to a plan to attack " + _province.GetName());
     }
 }