private void GetGOAPPlaning() { StopAllCoroutines(); _queueActions.Clear(); var actions = CreateActions(); var initialState = new Map <GOAPKeyEnum, object>() { { GOAPKeyEnum.life, Life }, { GOAPKeyEnum.isAttacking, false }, { GOAPKeyEnum.isInMeleeRange, IsInMeleeRange() }, { GOAPKeyEnum.medikitNearby, IsMedikitNearby() }, { GOAPKeyEnum.playerIsAlive, IsPlayerAlive() }, { GOAPKeyEnum.haveCriticalLife, IsInCriticalLife() } }; var goal = new Map <GOAPKeyEnum, Func <object, bool> >() { { GOAPKeyEnum.isAttacking, x => (bool)x == true }, }; var plan = new GOAPPlan(actions, initialState, goal, heuristic); foreach (var action in plan.Execute()) { _queueActions.Enqueue(action.Name.ToString()); } GoGoGOAP(); }
public override bool Activate(GOAPPlan plan) { // FIXME: Is that logic correct? The following line locks all the available positions in the cover but few moments later // the GOAPActionCoverEnter::Activate locks the BlackBoard.Desires.CoverPosition... // Why is this lock required? To disallow two defferent AIs to plan to go for specific cover? // disabled for testing //Owner.BlackBoard.Desires.CoverSelected.OccupyPosition(E_CoverDirection.Unknown, Owner); Cover c = Owner.BlackBoard.Desires.CoverSelected; Vector3 posOnCover = c.GetNearestPointOnCover(Owner.Position); if (c.IsRightAllowed && Vector3.Magnitude(posOnCover - c.RightEdge) < 0.3f) { Owner.BlackBoard.Desires.CoverPosition = E_CoverDirection.Right; } else if (c.IsLeftAllowed && Vector3.Magnitude(posOnCover - c.LeftEdge) < 0.3f) { Owner.BlackBoard.Desires.CoverPosition = E_CoverDirection.Left; } else { Owner.BlackBoard.Desires.CoverPosition = E_CoverDirection.Unknown; } return(base.Activate(plan)); }
/** * Gets the most relevant goal at the moment * * GOAPGoal GetMostRelevantGoal(bool recalculate) * { * GOAPGoal maxGoal = null; * float highestRelevancy = 0.0f; * float currentTime = Time.timeSinceLevelLoad; * float nextEvalTime; * * float goalRelevance = 0.0f; * for (int i = 0; i < m_GoalSet.Count; i++) * { //First check for timing checks?! * //Don't recalculate the goal relevancy if not asked to do so * * if (recalculate) * { * nextEvalTime = m_GoalSet[i].NextEvaluationTime; * * if (currentTime < nextEvalTime) * { //clear relevancy , we dont want to select these goals * m_GoalSet[i].ClearGoalRelevancy(); * } * else if (!m_GoalSet[i].GetReEvalOnSatisfication() && m_GoalSet[i].IsWSSatisfied(Ai.GetWorldState())) * { * m_GoalSet[i].ClearGoalRelevancy(); * } * else * {// recalculate goal relevancy !!!! * m_GoalSet[i].CalculateGoalRelevancy(); * //m_GoalSet[i].SetNewEvaluationTime(); * //set new timing check time?! * * } * } * // check all goal relevancy * goalRelevance = m_GoalSet[i].GoalRelevancy; * if (goalRelevance > highestRelevancy) * { * highestRelevancy = goalRelevance; * maxGoal = m_GoalSet[i]; * } * * } * return maxGoal; * }*/ /** * Builds a new plan for this agent * @param the agent to build the plan for * @return true if the plan builds successfully, false otherwise */ public GOAPPlan BuildPlan(GOAPGoal goal) { if (goal == null) { return(null); } //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + goal.ToString() + " - build plan"); //initialize shit Map.Initialise(Owner); Goal.Initialise(Owner, Map, goal); Storage.ResetStorage(Map); AStar.End = -1; AStar.RunAStar(Owner); AStarNode currNode = AStar.CurrentNode; if (currNode == null || currNode.NodeID == -1) { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + " - FAILED , no node "); return(null); //Building of plan failed } GOAPPlan plan = new GOAPPlan(); //create a new plan GOAPAction action; /** * We need to push each new plan step onto the list of steps until we reach the last action * Which is going to be the goal node and of no use */ //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + goal.ToString() + " current node id :" + currNode.NodeID); while (currNode.NodeID != -1) { action = Map.GetAction(currNode.NodeID); if (action == null) //If we tried to cast an node to an action that can't be done, quit out { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + ": canot find action (" + currNode.NodeID + ")"); return(null); } plan.PushBack(action); currNode = currNode.Parent; } //Finally tell the ai what its plan is if (plan.IsDone()) { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + ": plan is already done !!! (" + plan.CurrentStepIndex + "," + plan.NumberOfSteps + ")"); return(null); } return(plan); }
void CreatePlan(GOAPGoal goal) { GOAPPlan plan = BuildPlan(goal); if (plan == null) { if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " BUILD PLAN - " + goal.ToString() + " FAILED !!! " + Owner.WorldState.ToString(), Owner); } goal.SetDisableTime(); return; } if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " BUILD " + goal.ToString() + " - " + plan.ToString() + " " + Owner.WorldState.ToString(), Owner); foreach (KeyValuePair <E_GOAPGoals, GOAPGoal> pair in Goals) { if (pair.Value != goal && pair.Value.GoalRelevancy > 0) { Debug.Log(pair.Value.ToString()); } } } CurrentGoal = goal; CurrentGoal.Activate(plan); }
public override bool Activate(GOAPPlan plan) { Owner.BlackBoard.DesiredAttacker = Owner.BlackBoard.DesiredTarget; GoalRelevancy = Owner.BlackBoard.GOAP_BlockRelevancy; return(base.Activate(plan)); }
public virtual bool Activate(GOAPPlan plan) { UID = ++id; Active = true; Plan = plan; return(Plan.Activate(Owner, this)); }
public override bool Activate(GOAPPlan plan) { GoalRelevancy = Owner.BlackBoard.GOAP_KillTargetRelevancy; Owner.Sound.PlayPrepareAttack(); MissionBlackBoard.Instance.LastAttackTime = Time.timeSinceLevelLoad; return(base.Activate(plan)); }
public virtual void ReplanReset() { Active = false; if (Plan != null) { Plan.Deactivate(); } Plan = null; //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - replan Reset"); }
void CreatePlan(GOAPGoal goal) { GOAPPlan plan = BuildPlan(goal); if (plan == null) { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + " - BUILD PLAN FAILED !!!"); return; } CurrentGoal = goal; CurrentGoal.Activate(plan); }
/* * do some cleaning shit here */ public virtual void Deactivate() { Active = false; if (Plan != null) { Plan.Deactivate(); } Plan = null; ClearGoalRelevancy(); SetDisableTime(); //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - Deactivated"); }
public virtual void Reset() { Active = false; if (Plan != null) { Plan.Deactivate(); } Plan = null; ClearGoalRelevancy(); NextEvaluationTime = 0; if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - Reset"); } }
bool ReplanCurrentGoal() { if (CurrentGoal == null) { return(false); } CurrentGoal.ReplanReset(); GOAPPlan plan = BuildPlan(CurrentGoal); if (plan == null) { //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - REPLAN failed"); return(false); } CurrentGoal.Activate(plan); return(true); }
public override bool Activate(GOAPPlan plan) { Owner.WorldState.SetWSProperty(E_PropKey.E_LOOKING_AT_TARGET, false); return(base.Activate(plan)); }
public override bool Activate(GOAPPlan plan) { Owner.WorldState.SetWSProperty(E_PropKey.TargetNode, AdvancePos); return(base.Activate(plan)); }
protected override void Awake() { base.Awake(); planner = FindObjectOfType <GOAPPlan>(); }
//public abstract void MakeSatisfied(WorldState worldState); protected GOAPGoal(GOAPGoalType type, Agent owner) { GoalType = type; _owner = owner; Plan = new GOAPPlan(_owner); }
public virtual void Activate(GOAPPlan plan) { curPlan = plan; }