protected void Awake() { // Build the Finite State Machine characterController = this.GetComponent <CharacterController>(); //target = GameObject.FindGameObjectWithTag(Tags.FriendlyAI); ttm = this.gameObject.GetComponent <TargetTrackingManager>(); senses = this.gameObject.GetComponent <Senses>(); animator = this.GetComponent <Animator>(); aiGunLogic = AIGun.GetComponent <AIGunLogic>(); health = this.GetComponent <Health>(); imageBehaviour = this.GetComponent <ImageBehaviour>(); alertImage = imageBehaviour.alertImage.gameObject; chaseImage = imageBehaviour.chaseImage.gameObject; tacticalStateMachine = new FSM <TacticalStates>(displayFSMTransitions); tacticalStateMachine.AddState(new Goto <TacticalStates>(TacticalStates.Goto, this, 0f)); tacticalStateMachine.AddState(new Animate <TacticalStates>(TacticalStates.Animate, this, 0f)); tacticalStateMachine.AddState(new UseSmartObject <TacticalStates>(TacticalStates.UseSmartObject, this, 0f)); tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.Animate); tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.UseSmartObject); tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.Goto); tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.Goto); tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.UseSmartObject); tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.Animate); tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.Goto); tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.Animate); tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.UseSmartObject); actions = new List <Action>(); Action idle = new Idle("idle", 1, this, TacticalStates.Goto); idle.SetEffect(Atom.OnGuard, true); idle.destination = patrolPoints[destinationPoint]; actions.Add(idle); Action GetInRangeOfPlayer = new getInRangeOfPlayer("Get in range of the player", 1, this, TacticalStates.Goto); GetInRangeOfPlayer.SetPreCondition(Atom.KnowledgeOfPlayer, true); GetInRangeOfPlayer.SetEffect(Atom.CanSeePlayer, true); GetInRangeOfPlayer.SetEffect(Atom.InRange, true); GetInRangeOfPlayer.destination = GameObject.FindGameObjectWithTag(Tags.Player).transform; actions.Add(GetInRangeOfPlayer); Action attackWithGun = new AttackWithGun("Attack with gun", 1, this, TacticalStates.Goto); attackWithGun.SetPreCondition(Atom.InRange, true); attackWithGun.SetPreCondition(Atom.CanSeePlayer, true); attackWithGun.SetEffect(Atom.PlayerDead, true); attackWithGun.destination = searchPos.transform; actions.Add(attackWithGun); // set the current world state startWS = new WorldState(); // what the ai knows about the enviornment startWS.SetValue(Atom.KnowledgeOfPlayer, false); startWS.SetValue(Atom.CanSeePlayer, false); goals = new List <Goal>(); Goal idleGoal = new Goal(1); idleGoal.condition.SetValue(Atom.OnGuard, true); goals.Add(idleGoal); Goal combatGoal = new Goal(10); //combatGoal.condition.SetValue(Atom.HaveGun, true); //combatGoal.condition.SetValue(Atom.HaveAmmo, true); combatGoal.condition.SetValue(Atom.PlayerDead, true); goals.Add(combatGoal); // Goal getInRangeGoal = new Goal(20); // getInRangeGoal.condition.SetValue(Atom.InRange, true); // goals.Add(getInRangeGoal); /*Goal findTargetGoal = new Goal(5); * //combatGoal.condition.SetValue(Atom.HaveGun, true); * //combatGoal.condition.SetValue(Atom.HaveAmmo, true); * findTargetGoal.condition.SetValue(Atom.CanSeePlayer, true); * goals.Add(findTargetGoal);*/ }
protected void Awake() { ttm = GetComponent <TargetTrackingManager>(); base.Awake(); actions = new List <Action>(); startWS = new Ws(); //set the worlds states for the start of the game startWS.SetVal(Wstates.KnowledgeOfTree, true); startWS.SetVal(Wstates.KnowledgeOfNails, true); startWS.SetVal(Wstates.KnowledgeOfHouse, true); startWS.SetVal(Wstates.KnowledgeOfTent, true); startWS.SetVal(Wstates.KnowledgeOfWeapon, true); // creating all of the actions that the AI will need to complete its neccassary goal. each action will be initilised with the name, cost, object and type of action. //Along with its preconditions and effects to the world state. //Action being created Action GetWood = new GetWood("GetWood", 1, this, TacticalStates.Goto); GetWood.SetPreCondition(Wstates.KnowledgeOfTree, true); GetWood.SetEffect(Wstates.LocatedAtTree, true); GetWood.destination = GameObject.FindGameObjectWithTag("Tree").transform; actions.Add(GetWood); //Action being created Action CutTree = new CutTree("CutTree", 1, this, TacticalStates.Goto); CutTree.SetPreCondition(Wstates.KnowledgeOfTree, true); CutTree.SetPreCondition(Wstates.LocatedAtTree, true); CutTree.SetEffect(Wstates.HasWood, true); CutTree.destination = GameObject.FindGameObjectWithTag("Tree").transform; actions.Add(CutTree); //Action being created Action getNails = new GetNails("GoToNails", 1, this, TacticalStates.Goto); getNails.SetPreCondition(Wstates.HasWood, true); getNails.SetPreCondition(Wstates.KnowledgeOfNails, true); getNails.SetEffect(Wstates.LocatedAtNails, true); getNails.destination = GameObject.FindGameObjectWithTag("Nails").transform; actions.Add(getNails); //Action being created Action pickUpNails = new PickupNails("Getting nails", 1, this, TacticalStates.Goto); pickUpNails.SetPreCondition(Wstates.KnowledgeOfNails, true); pickUpNails.SetPreCondition(Wstates.LocatedAtNails, true); pickUpNails.SetEffect(Wstates.HasNails, true); pickUpNails.destination = GameObject.FindGameObjectWithTag("Nails").transform; actions.Add(pickUpNails); //Action being created Action goHouse = new GoHouse("GoTo House", 1, this, TacticalStates.Goto); goHouse.SetPreCondition(Wstates.KnowledgeOfHouse, true); goHouse.SetPreCondition(Wstates.HasNails, true); goHouse.SetPreCondition(Wstates.HasWood, true); goHouse.SetEffect(Wstates.LocatedAtHouse, true); goHouse.destination = GameObject.FindGameObjectWithTag("house").transform; actions.Add(goHouse); //Action being created Action BuildHouse = new buildHouse("Build house", 1, this, TacticalStates.Goto); goHouse.SetPreCondition(Wstates.KnowledgeOfHouse, true); BuildHouse.SetPreCondition(Wstates.HasNails, true); BuildHouse.SetPreCondition(Wstates.HasWood, true); BuildHouse.SetPreCondition(Wstates.LocatedAtHouse, true); BuildHouse.SetEffect(Wstates.HouseIsBuilt, true); BuildHouse.destination = GameObject.FindGameObjectWithTag("house").transform; actions.Add(BuildHouse); //Action being created Action GoToTent = new GoToTent("Tent", 1, this, TacticalStates.Goto); GoToTent.SetPreCondition(Wstates.KnowledgeOfTent, true); GoToTent.SetPreCondition(Wstates.HouseIsBuilt, true); GoToTent.SetEffect(Wstates.LocatedAtTent, true); GoToTent.destination = GameObject.FindGameObjectWithTag("Tent").transform; actions.Add(GoToTent); //Action being created Action GoToWeapon = new GetWeapon("Weapon", 1, this, TacticalStates.Goto); GoToWeapon.SetPreCondition(Wstates.KnowledgeOfWeapon, true); GoToWeapon.SetPreCondition(Wstates.CanSeeBear, true); GoToWeapon.SetEffect(Wstates.HasWeapon, true); GoToWeapon.destination = GameObject.FindGameObjectWithTag("Weapon").transform; actions.Add(GoToWeapon); //Action being created Action GoBear = new GoToBear("GoBear", 1, this, TacticalStates.Goto); GoBear.SetPreCondition(Wstates.HasWeapon, true); GoBear.SetPreCondition(Wstates.CanSeeBear, true); GoBear.SetEffect(Wstates.LocatedAtBear, true); GoBear.destination = GameObject.FindGameObjectWithTag("Bear").transform; actions.Add(GoBear); //Action being created Action killBear = new KillBear("killing", 1, this, TacticalStates.Goto); killBear.SetPreCondition(Wstates.CanSeeBear, true); killBear.SetPreCondition(Wstates.LocatedAtBear, true); killBear.SetEffect(Wstates.BearDead, true); actions.Add(killBear); goals = new List <Goal>(); //creating the goals for the AI, each goal will be initilised with a priotity and the world state conditions that will need to be met, for the AI to complete the goal //Goal being created Goal BuildGoal = new Goal(10); BuildGoal.condition.SetVal(Wstates.LocatedAtTree, true); BuildGoal.condition.SetVal(Wstates.HasWood, true); BuildGoal.condition.SetVal(Wstates.LocatedAtNails, true); BuildGoal.condition.SetVal(Wstates.HasNails, true); BuildGoal.condition.SetVal(Wstates.LocatedAtHouse, true); BuildGoal.condition.SetVal(Wstates.HouseIsBuilt, true); BuildGoal.condition.SetVal(Wstates.LocatedAtTent, true); goals.Add(BuildGoal); //Goal being created Goal KillBear = new Goal(9); KillBear.condition.SetVal(Wstates.CanSeeBear, true); KillBear.condition.SetVal(Wstates.HasWeapon, true); KillBear.condition.SetVal(Wstates.BearDead, true); goals.Add(KillBear); // Build the Finite State Machine tacticalStateMachine = new FSM <TacticalStates>(displayFSMTransitions); tacticalStateMachine.AddState(new Goto <TacticalStates>(TacticalStates.Goto, this, 0f)); tacticalStateMachine.AddState(new Animate <TacticalStates>(TacticalStates.Animate, this, 0f)); tacticalStateMachine.AddState(new UseSmartObject <TacticalStates>(TacticalStates.UseSmartObject, this, 0f)); tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.Animate); tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.UseSmartObject); tacticalStateMachine.AddTransition(TacticalStates.Goto, TacticalStates.Goto); tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.Goto); tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.UseSmartObject); tacticalStateMachine.AddTransition(TacticalStates.Animate, TacticalStates.Animate); tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.Goto); tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.Animate); tacticalStateMachine.AddTransition(TacticalStates.UseSmartObject, TacticalStates.UseSmartObject); }