/// <summary> /// Makes contestants plan their combat actions and exectute them /// </summary> /// <param name="team"> current team </param> public IEnumerator PlayTurn(Team team) { List <HumanoidContestant> contestants = new List <HumanoidContestant>(team.fieldContestants); // do not handle of dead guys contestants.RemoveAll(c => c.isDead); foreach (var contestant in contestants) { AIAgent agent = CreateConstestantAgent(contestant); Queue <AIAction> actionSequence = new Queue <AIAction>(); List <AIAction> availibleActions = CreateContestantActions(contestant); bool result = AIPlanner.Plan(agent, availibleActions, actionSequence); if (!result) { Debug.Log("failed to build plan for " + contestant.fighter.fighterName); continue; } else { //DebugPrettyPrintPlan(actionSequence, contestant.fighter.fighterName); } yield return(agent.PerformActionSequence(actionSequence)); } }
public void RemoveAIEntity(AIPlanner ai) { for (int i = 0; i < ai.fleetCount; i++) { RemovePointOfInterest(ai.fleets[i]); } _aiPlanners.Remove(ai); }
private void InitialiseNodeLists(AIAgent agent, AIPlanner planner) { nullNodes = new List <AINode>(); openNodes = new List <AINode>(); closedNodes = new List <AINode>(); currentNode = new AINode(agent, planner); closedNodes.Add(currentNode); foreach (var action in agent.GetActions()) { nullNodes.Add(new AINode(agent, planner, action)); } }
protected virtual void Awake() { Planner = new AIPlanner(this); CurrentActions = new Queue <AIPlannerIAction>(); AvailableActions = new HashSet <AIPlannerIAction>(); WorldState = new State(); Backpack = new Backpack(WorldState); GoalState = new State(); foreach (var a in gameObject.GetComponents <AIActionBase>()) { AvailableActions.Add(a); } IdleState = new IdleState(this); MoveState = new MoveState(this); ActState = new ActState(this); StateMachine = new FSM(); StateMachine.PushState(IdleState); Navigation = gameObject.GetComponent <NavigationSystem>(); }
public bool FindActionPlan(AIAgent agent, AIPlanner planner) { InitialiseNodeLists(agent, planner); while (!currentNode.ConditionsMet()) { FindNeighbouringNodes(); if (openNodes.Count == 0) { return(false); } currentNode = FindCheapestNode(); closedNodes.Add(currentNode); openNodes.Remove(currentNode); } return(true); }
static void GenerateEnemyFleet() { AIPlanner ap; if (RuntimeData.system.aiEntities.Count == 0) { ap = new AIPlanner(); RuntimeData.system.aiEntities.Add(ap); } else { ap = RuntimeData.system.aiEntities[0]; } //generate fleet List <Ship> ships = new List <Ship>(); int shipCount = _random.Next(0, ap.fleetCount) + 1; var choices = Resources.LoadAll <ShipData>("Data/Premade Ships/") .Where(sd => (int)sd.hull.size <= shipCount) .ToArray(); for (int i = 0; i < shipCount; i++) { ships.Add(new Ship(choices.RandomItem())); } string efn = RuntimeData.save.data.enemy.name + " " + (shipCount < 4 ? (shipCount < 2 ? "Scout" : "Vanguard") : "Invasion Fleet"); Fleet ef = new Fleet( "<color=red>" + efn + "</color>", RuntimeData.system.GetRandomLocation(), new Random(RuntimeData.system.seed), 1, ships); RuntimeData.system.AddPointOfInterest(ef); ap.AddFleet(ef); LogManager.getInstance.AddEntry("A " + efn + " has entered the system.", 15f, EntryType.Combat); }
public AINode(AIAgent agent, AIPlanner planner, AIAction action = null, AINode parent = null) { this.agent = agent; this.planner = planner; this.action = action; this.parent = parent; if (action == null) { // This is a goal node state = new AIState(planner.GetGoal(), agent.GetMemory().CloneState()); state.AddUnmetPreconditions(planner.GetGoal().GetConditions()); g = 0; } else { // Initialise Action node state = new AIState(); g = float.MaxValue; } }
// Update is called once per frame void Update() { if (teamMembers.Count < 3) //At the start this will call so that we can find the game objects { FindGameObject(); } for (int i = 0; i < teamMembers.Count; i++) //Checks If any AI is Dead { if (teamMembers[i] == null) //If any AI is dead { FindGameObject(); } } for (int i = 0; i < goals.Count; i++) //Go Through the Goals { if (CheckGoalIsDesired(goals[i])) //Check if the Goal is worth going for { chosenTeamMember = ChooseTeamMember(); //choose a team memeber if (chosenTeamMember != allMembersBusy) //If there isn't a team member that isn't busy { planner = new AIPlanner(); //Make a new plan teamMembers[chosenTeamMember].GetComponent <AI>().aiBusy = true; //Set the team member to busy plan.Add(new List <AIAction>(planner.GeneratePlan(teamMembers[chosenTeamMember], goals[i]))); //Generate a plan for the AI to do planner = null; // removes the plan so that we can make new plans } else //If all team members are currently busy { for (int q = 0; q < plan.Count; q++) //Go through the different plans currently made { if (plan[q][CURRENT_ACTION].isDone()) //is the current action of that plan done { Debug.Log(plan[q][CURRENT_ACTION].action.actionName + " IS DONE"); //The plan is done, now change the values and stuff plan[q][CURRENT_ACTION].UpdateState(states); //Update the state if (plan[q].Count == 1) //If this is the final step to the plan { plan[q][CURRENT_ACTION].agent.GetComponent <AI>().aiBusy = false; //Set the AI to no longer busy plan.RemoveAt(q); //remove the plan so that since we don't need to update it again } else { plan[q].RemoveAt(CURRENT_ACTION); //remove that action from the plan, now the next CURRENT_ACTION will be played. } } //Crashes with this, no idea what to do /* * planner = new AIPlanner(); * planner.ChangeOfPlan(plan[q], plan[q][CURRENT_ACTION].agent); * planner = null; */ } //Check all the current actions in the plan //if the action is finished, remove action from the plan and move to next action //change state to action effects //if the plan is now empty, the AI is no longer busy //All teamMembers busy, make a default } if (plan.Count > 0) //If there is currently a plan { for (int k = 0; k < plan.Count; k++) //go through all the plans { plan[k][CURRENT_ACTION].PlayAction(); //Play the first action of each plan. Once this action is complete it will be removed so they can play the next plan } } } } }
public void AddAIEntity(AIPlanner ai) { _aiPlanners.Add(ai); }