/// <summary> /// Determine whether goals have changed or plans have failed, and /// replan if necessary. Then execute the plan. /// </summary> internal void update() { bool differencesFlag = !Goal.areSame(previousGoal_, AI_.CurrentGoal_); if (AI_.CurrentGoal_ != null && (differencesFlag || currentPlan_.Count == 0 || HasFailed_)) { cleanupPlan(currentPlan_); HasFailed_ = false; IndividualPlanner planner = new IndividualPlanner(actions_); planner.execute(getInitialState(), AI_.CurrentGoal_.getNode()); currentPlan_ = planner.getResult(); if (currentPlan_ != null && currentPlan_.Count > 0) { reservePlan(currentPlan_); currentPlan_[0].initialize(); } else { HasFailed_ = true; } } previousGoal_ = AI_.CurrentGoal_; executePlan(); if (HasFailed_) { AI_.CurrentGoal_.HasFailed_ = true; } }
/// <summary> /// Add a goal for the agent to consider. /// </summary> /// <param name="goal">Goal to be considered.</param> internal void addGoal(Goal goal) { goals_.Add(goal); }
/// <summary> /// Determine whether two goals are identical. /// </summary> /// <param name="lhs">First goal.</param> /// <param name="rhs">Second goal.</param> /// <returns>True if the two goals might accomplish the same end state, false otherwise.</returns> internal static bool areSame(Goal lhs, Goal rhs) { if (lhs == null && rhs == null) return true; if (lhs == null || rhs == null) return false; return (lhs.handle_ == rhs.handle_) && testNodeEquality(lhs.node_, rhs.node_); }