Example #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);
        }
    }
Example #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));
    }