示例#1
0
    /// <summary>
    /// Sets a model for the class
    /// In addition to the army movement order itself it needs to know where does the movement arrow start and end
    /// </summary>
    /// <param name="order">Army movement order</param>
    /// <param name="start">Start point of the movement arrow</param>
    /// <param name="end">End point of the movement arrow</param>
    public void SetModel(ArmyMovementOrder order, Vector3 start, Vector3 end)
    {
        // set the model proper
        _model          = order;
        _model.Updated += OnModelUpdated;

        // place the head of the movement arrow
        _arrowheadImage.transform.position = new Vector3((1 + _arrowHeadShift) * end.x - _arrowHeadShift * start.x,
                                                         (1 + _arrowHeadShift) * end.y - _arrowHeadShift * start.y,
                                                         end.z);
        _arrowheadImage.transform.rotation = Quaternion.FromToRotation(Vector3.down, end - start);

        // select army image and update the number of units field
        Update();

        // place the army image on the screen
        _armyImage.transform.position = new Vector3(0.5f * (start.x + end.x) - 1f, 0.5f * (start.y + end.y) + 1f, 0.5f * (start.z + end.z));

        // the player can edit an army movement order by clicking on the army image
        _armyImage.GetComponentInChildren <MouseClickListener>().MouseClickDetected += OnArmyImageClicked;

        // place the number of units info on the screen
        _quantityField.transform.position = new Vector3(0.5f * (start.x + end.x) - 1f, 0.5f * (start.y + end.y) + 3.5f, 0.5f * (start.z + end.z));

        // set line renderer parameters (for the movement arrow)
        //_lineRenderer.SetWidth(_startWidth, _endWidth);
        _lineRenderer.startWidth = _startWidth;
        _lineRenderer.endWidth   = _endWidth;
        //_lineRenderer.SetVertexCount(2);
        _lineRenderer.positionCount = 2;
        _lineRenderer.SetPosition(0, start);
        _lineRenderer.SetPosition(1, end);
    }
 /// <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>
    /// 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);
        }
    }
示例#4
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));
    }
示例#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());
     }
 }