/**
     * Updates the movement direction (see NavAgentHelper) according to the
     * pheromones located near the agent.
     *
     * Combat/Harvest pheromones are only taken into account, if the task of the agent
     * is combat and harvest respectively.
     *
     * Also: Combat/Harvest pheromones are ignored in certain states. Repellant pheromones
     * are taken into account in every state.
     */
    void Update()
    {
        _currentSmellAngleCos = Mathf.Cos(_agentConfiguration.smellAngle);

        UpdatePheromoneSensor();

        Vector3 attractionDirection = new Vector3();

        if (_states.IsIdling())
        {
            _previousState = EAntStates.Idle;
        }

        // Only take harvest/combat pheromones into account if the agent is idling or following pheromones.
        if (_states.IsIdling() || _states.IsFollowingPheromone())
        {
            if (_states.GetTask() == EAntTasks.HarvestFood && _previousState != EAntStates.ReturnToBase)
            {
                attractionDirection = AggregateMovementDirection(EPheromoneTypes.Food);
            }
            else if (_states.GetTask() == EAntTasks.Attack)
            {
                attractionDirection = AggregateMovementDirection(EPheromoneTypes.Attack);
            }
        }

        // Always take repellant pheromones into account.
        Vector3 repulsionDirection = AggregateMovementDirection(EPheromoneTypes.Repellant);

        // If pheromones influence movement direction, set this direction and switch
        // to pheromone following state if necessary.
        if (attractionDirection.sqrMagnitude > 0f || repulsionDirection.sqrMagnitude > 0f)
        {
            _navHelper.SetDirection(0.01f * attractionDirection + 0.99f * repulsionDirection);

            if (!_states.IsFollowingPheromone())
            {
                // Save the current state so we can restore status quo lateron.
                _previousState       = _states.currentState;
                _states.currentState = EAntStates.FollowPheromone;
            }
        }
        // Switch back to previous state, if no longer following pheromones.
        else if (_states.IsFollowingPheromone())
        {
            _states.currentState = _previousState;
        }

//		Debug.DrawLine (transform.position, transform.position + Quaternion.Euler(0f, GlobalAntConfiguration.smellAngle * Mathf.Rad2Deg, 0f) * transform.forward * _currentSmellDistance);
//		Debug.DrawLine (transform.position, transform.position + Quaternion.Euler(0f, -GlobalAntConfiguration.smellAngle * Mathf.Rad2Deg, 0f) * transform.forward * _currentSmellDistance);
    }