public void StartTree() { DTAction action = root.MakeDecision(); if (action != null) { action.Run(); } }
// Walk the structure and call the resulting action (if any) // anull means no action is required. public object walk() { DTAction result = root.Walk(); if (result != null) { return(result.Action(null)); } return(null); }
void Update() { actionNew.activated = false; actionOld = actionNew; actionNew = root.MakeDecision() as DTAction; if (actionNew == null) { actionNew = actionOld; } actionNew.activated = true; }
void Start() { DTDecision d1 = new DTDecision(Nearest); DTAction azione1 = new DTAction(FollowNearest); DTAction azione2 = new DTAction(WalkRandomly); d1.AddLink(true, azione1); d1.AddLink(false, azione2); dt = new DecisionTree(d1); nav = gameObject.GetComponent <NavMeshAgent>(); StartCoroutine(Patrol()); }
// Use this for initialization void Start() { board1 = GameObject.Find("Board1").transform; board2 = GameObject.Find("Board2").transform; anim = GetComponent <Animator>(); bb1 = board1.GetComponent <BoardBehaviour>(); bb2 = board2.GetComponent <BoardBehaviour>(); pf = GetComponent <PlayerFollower>(); playerTags.Add("Bean"); playerTags.Add("Eal"); playerTags.Add("Loin"); playerTags.Add("Sage"); //DTAction a1 = new DTAction(FollowPlayer); //dt = new DecisionTree(a1); if (isServer) { //define decisions DTDecision d1 = new DTDecision(IsABoardActiveFor2Seconds); DTDecision d2 = new DTDecision(MoleIsAlive); DTDecision d3 = new DTDecision(IsABoardActiveFor5Seconds); DTDecision d4 = new DTDecision(AtLeastOneInAreaA); DTDecision d5 = new DTDecision(AtLeastTwoInAreaB); DTDecision d6 = new DTDecision(AtLeastOneInAreaC); DTDecision d7 = new DTDecision(AtLeastTwoInAreaC); DTDecision d8 = new DTDecision(MoleIsAlive); DTDecision d9 = new DTDecision(MoleIsAlive); //define actions DTAction a1 = new DTAction(TpAtActiveBoard); DTAction a2 = new DTAction(LoadRoundAttack); DTAction a3 = new DTAction(LoadFrontAttack); DTAction a4 = new DTAction(FollowClosestPlayer); DTAction a5 = new DTAction(FollowPlayerWithLessLives); DTAction a6 = new DTAction(FollowPlayerWithLessLivesInAreaC); d1.AddLink(true, d2); d1.AddLink(false, d4); d2.AddLink(true, d3); d2.AddLink(false, a1); d3.AddLink(true, a1); d3.AddLink(false, d4); d4.AddLink(true, d5); d4.AddLink(false, d6); d5.AddLink(true, a2); d5.AddLink(false, a3); d6.AddLink(true, d7); d6.AddLink(false, d8); d7.AddLink(true, d9); d7.AddLink(false, a4); d8.AddLink(true, a4); d8.AddLink(false, a5); d9.AddLink(true, a4); d9.AddLink(false, a6); dt = new DecisionTree(d1); StartCoroutine(Patrol()); } }
// Use this for initialization void Start() { float RandomPersonality = Random.value; Debug.Log(gameObject.name + ": " + RandomPersonality); if (RandomPersonality < 0.2f) { Personality = HenPersonalities.AGGRESSIVE; } if (RandomPersonality >= 0.2f && RandomPersonality < 0.5f) { Personality = HenPersonalities.COWARD; } if (RandomPersonality >= 0.5f && RandomPersonality < 0.9f) { Personality = HenPersonalities.PROTECTIVE; } if (RandomPersonality >= 0.9f) { Personality = HenPersonalities.UNLIKABLE; } CurrentStatus = HenStatus.ROAMING; movAgent = GetComponent <NavMeshAgent>(); // DT Decisions DTDecision decAnimationStop = new DTDecision(AnimationStop); DTDecision decDistantFromRooster = new DTDecision(DistantFromRooster); DTDecision decPlayerInFOV = new DTDecision(PlayerInFOV); DTDecision decPlayerInAttackRange = new DTDecision(PlayerInAttackRange); DTDecision decChickInAttackRange = new DTDecision(ChickInAttackRange); DTDecision decNearerToTheChick = new DTDecision(NearerToTheChick); DTDecision decCowardHen = new DTDecision(CowardHen); DTDecision decUnlikableHen = new DTDecision(UnlikableHen); DTDecision decProtectiveHen = new DTDecision(ProtectiveHen); // DT Actions DTAction actWait = new DTAction(Wait); DTAction actChaseRooster = new DTAction(ChaseRooster); DTAction actFlee = new DTAction(Flee); DTAction actProtect = new DTAction(Protect); DTAction actEngageChick = new DTAction(EngageChick); DTAction actEngagePlayer = new DTAction(EngagePlayer); DTAction actChasePlayer = new DTAction(ChasePlayer); DTAction actRoam = new DTAction(Roam); // DT Links decAnimationStop.AddLink(true, actWait); decAnimationStop.AddLink(false, decDistantFromRooster); decDistantFromRooster.AddLink(true, actChaseRooster); decDistantFromRooster.AddLink(false, decPlayerInFOV); decPlayerInFOV.AddLink(true, decCowardHen); decPlayerInFOV.AddLink(false, decUnlikableHen); decPlayerInAttackRange.AddLink(true, actEngagePlayer); decPlayerInAttackRange.AddLink(false, decProtectiveHen); decChickInAttackRange.AddLink(true, actEngageChick); decChickInAttackRange.AddLink(false, actRoam); decNearerToTheChick.AddLink(true, actProtect); decNearerToTheChick.AddLink(false, actChasePlayer); decCowardHen.AddLink(true, actFlee); decCowardHen.AddLink(false, decPlayerInAttackRange); decUnlikableHen.AddLink(true, decChickInAttackRange); decUnlikableHen.AddLink(false, actRoam); decProtectiveHen.AddLink(true, decNearerToTheChick); decProtectiveHen.AddLink(false, actChasePlayer); // Setup DT dt = new DecisionTree(decAnimationStop); }
// Use this for initialization void Start() { float RandomPersonality = Random.value; Debug.Log(gameObject.name + ": " + RandomPersonality); if (RandomPersonality < 0.1f) { Personality = ChickPersonalities.COCKY; } if (RandomPersonality >= 0.1f && RandomPersonality < 0.45f) { Personality = ChickPersonalities.COWARD; } if (RandomPersonality >= 0.45f && RandomPersonality < 0.6f) { Personality = ChickPersonalities.CURIOUS; } if (RandomPersonality >= 0.6f && RandomPersonality < 0.7f) { Personality = ChickPersonalities.SISSY; } if (RandomPersonality >= 0.7f) { Personality = ChickPersonalities.SLY; } movAgent = GetComponent <NavMeshAgent>(); CurrentStatus = ChickStatus.ROAMING; // DT Decisions DTDecision decAnimationStop = new DTDecision(AnimationStop); DTDecision decDistantFromRooster = new DTDecision(DistantFromRooster); DTDecision decHenInFOV = new DTDecision(NearAHen); DTDecision decPlayerInFOV = new DTDecision(PlayerInFOV); DTDecision decPlayerInAlarmRange = new DTDecision(PlayerInAlarmRange); DTDecision decCockyChick = new DTDecision(CockyChick); DTDecision decCuriousChick = new DTDecision(CuriousChick); DTDecision decSissyChick = new DTDecision(SissyChick); DTDecision decSlyChick = new DTDecision(SlyChick); // DT Actions DTAction actWait = new DTAction(Wait); DTAction actChaseRooster = new DTAction(ChaseRooster); DTAction actChasePlayer = new DTAction(ChasePlayer); DTAction actChaseHen = new DTAction(ChaseHen); DTAction actStareAtPlayer = new DTAction(StareAtPlayer); DTAction actFleeFromPlayer = new DTAction(FleeFromPlayer); DTAction actFleeFromHen = new DTAction(FleeFromHen); DTAction actAlarm = new DTAction(Alarm); DTAction actRoam = new DTAction(Roam); // DT Links decAnimationStop.AddLink(true, actWait); decAnimationStop.AddLink(false, decDistantFromRooster); decDistantFromRooster.AddLink(true, actChaseRooster); decDistantFromRooster.AddLink(false, decPlayerInFOV); decPlayerInFOV.AddLink(true, decPlayerInAlarmRange); decPlayerInFOV.AddLink(false, decSissyChick); decPlayerInAlarmRange.AddLink(true, actAlarm); decPlayerInAlarmRange.AddLink(false, decCockyChick); decCockyChick.AddLink(true, actChasePlayer); decCockyChick.AddLink(false, decCuriousChick); decCuriousChick.AddLink(true, actStareAtPlayer); decCuriousChick.AddLink(false, decSlyChick); decSissyChick.AddLink(true, actFleeFromHen); decSissyChick.AddLink(false, actRoam); decSlyChick.AddLink(true, decHenInFOV); decSlyChick.AddLink(false, actFleeFromPlayer); decHenInFOV.AddLink(true, actChaseHen); decHenInFOV.AddLink(false, actChaseRooster); // Setup DT dt = new DecisionTree(decAnimationStop); RoosterCollider[0] = Rooster.GetComponent <Collider>(); }