Exemplo n.º 1
0
    public UrbAction PickAction(UrbTestCategory Test, float Result = 0, UrbTestCategory Exclude = UrbTestCategory.None)
    {
        if (mAgent.AvailableActions == null || mAgent.AvailableActions.Length == 0)
        {
            return(null);
        }

        s_PickAction_p.Begin();

        UrbAction ChosenAction = null;
        float     BestCost     = float.MaxValue;

        for (int i = 0; i < mAgent.AvailableActions.Length; i++)
        {
            bool Valid = (Test & mAgent.AvailableActions[i].Category) == Test &&
                         (Exclude == UrbTestCategory.None || (Exclude & mAgent.AvailableActions[i].Category) == 0);
            if (!Valid)
            {
                continue;
            }

            float ActionCost = mAgent.AvailableActions[i].CostEstimate(mAgent);

            if (ActionCost > Result && ActionCost < BestCost)
            {
                BestCost     = ActionCost;
                ChosenAction = mAgent.AvailableActions[i];
            }
        }

        s_PickAction_p.End();
        return(ChosenAction);
    }
Exemplo n.º 2
0
    public float PerformTest(UrbTestCategory Test, float Modifier = 0, bool Execute = false)
    {
        UrbAction ChosenAction = PickAction(Test);

        if (ChosenAction == null)
        {
            return(0.0f);
        }

        return(ChosenAction.Test(mAgent, Modifier));
    }
Exemplo n.º 3
0
    public UrbAction PickAction(UrbTestCategory Test, float Result = 0, UrbTestCategory Exclude = UrbTestCategory.None)
    {
        using (s_PickAction_p.Auto())
        {
            if (Removing)
            {
                logger.Log("Chose not to pick an action because removing", this);
                return(null);
            }

            if (HasAction(Test))
            {
                logger.Log($"No actions of type {Test} Found", this);
                return(null);
            }

            if (!IsMindNull)
            {
                logger.Log($"Use Mind to pick action {Test}");
                return(Mind.PickAction(Test, Result, Exclude));
            }

            if (AvailableActions == null)
            {
                logger.Log($"No actions are available", this);
                return(null);
            }

            for (int i = 0; i < AvailableActions.Length; i++)
            {
                bool Valid = (Test & AvailableActions[i].Category) == Test &&
                             (Exclude == UrbTestCategory.None || (Exclude & AvailableActions[i].Category) == 0);
                if (Valid)
                {
                    return(AvailableActions[i]);
                }
            }

            logger.Log($"No actions of type {Test} Found", this);
            return(null);
        }
    }
Exemplo n.º 4
0
 public virtual bool HasAction(UrbTestCategory Test)
 {
     return((ValidActionCategories & Test) == Test);
 }