Example #1
0
        protected virtual bool CanDoNow(GoapAgent agent, IStateful target)
        {
            var worldState = WorldState.Borrow();

            worldState[agent]  = agent.GetState();
            worldState[target] = target.GetState();
            // Since the action is a part of the plan, its preconditions on the agent
            // should apply.
            var doesApply = worldState.IsGoalState(GetIndependentPreconditions(agent));

            // NOTE: If the agent's state is volatile and can change outside of the
            // agent's plan, comment out this assertion.
            DebugUtils.AssertWarning(
                doesApply,
                "WARNING: Possible bug in definition of " + name
                + ". The agent " + agent.name + " planned to do it but now its state does not allow it");
            // Need to check that the target's state still apply to the preconditions
            // defined by the action.
            doesApply = doesApply && worldState.IsGoalState(GetDependentPreconditions(agent, target));
            worldState.ReturnSelf();
            return(doesApply);
        }