コード例 #1
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);
        }
    }
コード例 #2
0
 /// <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);
 }
コード例 #3
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));
    }
コード例 #4
0
 /// <summary>
 /// Returns the province from which the movement order originated
 /// </summary>
 /// <returns>The province from which the movement order originated</returns>
 public Province GetOriginProvince()
 {
     return(_model.GetOrigin());
 }