/// <summary> /// Switch the npAgent's navigation back to path finding /// </summary> /// <returns></returns> public void switchModeToPathFinding() { mode = 0; path = terrian_path; }
/// <summary> /// Create a NPC. /// AGXNASK distribution has npAgent move following a Path. /// </summary> /// <param name="theStage"> the world</param> /// <param name="label"> name of </param> /// <param name="pos"> initial position </param> /// <param name="orientAxis"> initial rotation axis</param> /// <param name="radians"> initial rotation</param> /// <param name="meshFile"> Direct X *.x Model in Contents directory </param> public NPAgent(Stage theStage, string label, Vector3 pos, Vector3 orientAxis, float radians, string meshFile) : base(theStage, label, pos, orientAxis, radians, meshFile) { // change names for on-screen display of current camera first.Name = "npFirst"; follow.Name = "npFollow"; above.Name = "npAbove"; // path is built to work on specific terrain terrian_path = new Path(stage, makePath(), Path.PathType.REVERSE); // continuous search path stage.Components.Add(terrian_path); Random rnd = new Random(); if (rnd.Next() % 2 == 0) { // Reverse the path terrian_path.reverse(); } path = terrian_path; // start off in path finding mode nextGoal = path.NextNode; // get first path goal agentObject.turnToFace(nextGoal.Translation); // orient towards the first path goal Debug.WriteLine("Wake Up Agent"); }
/// <summary> /// Switch the npAgent's navigation mode to either treasure or path finding /// 0: Path Finding Mode /// 1: Treasure Finding Mode /// </summary> /// <returns></returns> public void switchMode() { switch (mode) { case 0: // Switch to Mode: EM --> TM Debug.WriteLine("Switching Mode: Explore Mode --> Treasure Mode (" + mode + " --> "+ (mode+1) % 3 +" )"); mode = 1; // Save EM goal savedGoal = nextGoal; // Set current treasure finding path to closest treasure Treasure treasure = chooseClosestTreasure(stage.Treasures); // if treasure found find it by setting path nextGoal if (treasure != null) { Debug.WriteLine("Treasure Path Generated"); // Generate Path from treasure position to agent treasure_path = stage.graph.GetAStarPath(treasure.position, new Vector3(agentObject.Translation.X, 0, agentObject.Translation.Z)); stage.Components.Add(treasure_path); path = treasure_path; nextGoal = path.NextNode; agentObject.turnToFace(nextGoal.Translation); restart(); // Start moving again incase we are stopped } else { Debug.WriteLine("No treasures found, stop"); base.reset(); } break; case 1: // Switch to Mode: TM --> RM Debug.WriteLine("Switching Mode: Treasure Mode --> Return Mode (" + mode + " --> " + (mode + 1) % 3 + " )"); mode = 2; path.reverse(); nextGoal = path.NextNode; agentObject.turnToFace(nextGoal.Translation); restart(); break; case 2: // Switch to Mode: RM --> EM Debug.WriteLine("Switching Mode: Return Mode --> Explore Mode (" + mode + " --> " + (mode + 1) % 3 + " )"); mode = 0; stage.Components.Remove(treasure_path); // Remove waypoints from ASTAR path = terrian_path; // Set path back to Explore Mode Path nextGoal = savedGoal; agentObject.turnToFace(nextGoal.Translation); restart(); break; default: Debug.WriteLine("Bad Toggle Mode"); break; } }