public void Start() { this.draw = true; this.influenceMapDebugMode = 0; this.navMesh = NavigationManager.Instance.NavMeshGraphs[0]; this.Character = new DynamicCharacter(this.gameObject); //initialization of the movement algorithms this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; var steeringPipeline = new Assets.Scripts.IAJ.Unity.SteeringPipeline.SteeringPipeline { MaxAcceleration = 40.0f, MaxConstraintSteps = 2, Character = this.Character.KinematicData, }; this.decomposer = new Assets.Scripts.IAJ.Unity.SteeringPipeline.NodeAStarDecomposer(this.aStarPathFinding); this.Targeter = new Assets.Scripts.IAJ.Unity.SteeringPipeline.TargetPosition(); steeringPipeline.Targeters.Add(this.Targeter); steeringPipeline.Decomposers.Add(this.decomposer); steeringPipeline.Actuator = actuator = new Assets.Scripts.IAJ.Unity.SteeringPipeline.PathFollowingActuator() { movement = new DynamicFollowPath() { MaxAcceleration = 40.0f, PathOffset = 0.05f, Movement = new DynamicCarSeek() { MaxSpeed = this.Character.MaxSpeed, MinSpeed = 4f } }, SecondsToSmooth = 2f }; this.Character.Movement = steeringPipeline; //initialization of the Influence Maps this.RedInfluenceMap = new InfluenceMap(this.navMesh,new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); this.GreenInfluenceMap = new InfluenceMap(this.navMesh, new SimpleUnorderedList(), new ClosedLocationRecordDictionary(), new LinearInfluenceFunction(), 0.1f); //initialization of the GOB decision making //let's start by creating 4 main goals //the eatgoal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.ConquerGoal = new Goal(CONQUER_GOAL, 1.5f) { InsistenceValue = 5.0f }; this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); this.Goals.Add(this.ConquerGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { this.Actions.Add(new PickUpChest(this, chest)); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { this.Actions.Add(new GetArrows(this, tree)); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { this.Actions.Add(new Sleep(this, bed)); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } //flags used for the influence map this.RedFlags = new List<IInfluenceUnit>(); foreach (var redFlag in GameObject.FindGameObjectsWithTag("RedFlag")) { this.RedFlags.Add(new Flag(this.navMesh.QuantizeToNode(redFlag.transform.position, 1.0f), FlagColor.Red)); } this.GreenFlags = new List<IInfluenceUnit>(); foreach (var greenFlag in GameObject.FindGameObjectsWithTag("GreenFlag")) { this.GreenFlags.Add(new Flag(this.navMesh.QuantizeToNode(greenFlag.transform.position, 1.0f), FlagColor.Green)); } this.RedInfluenceMap.Initialize(this.RedFlags); this.GreenInfluenceMap.Initialize(this.GreenFlags); var worldModel = new CurrentStateWorldModel(this.GameManager, this.Actions, this.Goals); this.GOAPDecisionMaking = new DepthLimitedGOAPDecisionMaking(worldModel,this.Actions,this.Goals); }
public void Start() { this.draw = true; this.navMesh = NavigationManager.Instance.NavMeshGraphs [0]; this.Character = new DynamicCharacter(this.gameObject) { Drag = 0.3f}; //initialization of the movement algorithms this.aStarPathFinding = new NodeArrayAStarPathFinding(this.navMesh, new EuclideanDistanceHeuristic()); this.aStarPathFinding.NodesPerSearch = 100; var steeringPipeline = new Assets.Scripts.IAJ.Unity.SteeringPipeline.SteeringPipeline { MaxAcceleration = 40.0f, MaxConstraintSteps = 2, Character = this.Character.KinematicData, }; this.decomposer = new Assets.Scripts.IAJ.Unity.SteeringPipeline.NodeAStarDecomposer(this.aStarPathFinding); this.Targeter = new Assets.Scripts.IAJ.Unity.SteeringPipeline.TargetPosition(); steeringPipeline.Targeters.Add(this.Targeter); steeringPipeline.Decomposers.Add(this.decomposer); var obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); steeringPipeline.Constraints.Add( new Assets.Scripts.IAJ.Unity.SteeringPipeline.ConstraitColisionWithWalls(obstacles, 500.0f) { AvoidMargin = 7f, MaxLookAhead = 5f, MaxWhiskersLookAhead = 7f }); steeringPipeline.Actuator = actuator = new Assets.Scripts.IAJ.Unity.SteeringPipeline.PathFollowingActuator() { movement = new DynamicFollowPath() { MaxAcceleration = 40.0f, PathOffset = 0.05f, Movement = new DynamicCarSeek() { MaxSpeed = this.Character.MaxSpeed, MinSpeed = 4f } }, SecondsToSmooth = 2f }; this.Character.Movement = steeringPipeline; //initialization of the GOB decision making //let's start by creating 4 main goals //the eatgoal is the only goal that increases at a fixed rate per second, it increases at a rate of 0.1 per second this.SurviveGoal = new Goal(SURVIVE_GOAL, 2.0f); this.EatGoal = new Goal(EAT_GOAL, 1.0f) { ChangeRate = 0.1f }; this.GetRichGoal = new Goal(GET_RICH_GOAL, 1.0f) { InsistenceValue = 5.0f, ChangeRate = 0.2f }; this.RestGoal = new Goal(REST_GOAL, 1.0f); this.Goals = new List<Goal>(); this.Goals.Add(this.SurviveGoal); this.Goals.Add(this.EatGoal); this.Goals.Add(this.GetRichGoal); this.Goals.Add(this.RestGoal); //initialize the available actions var restAction = new Rest(this); this.Actions = new List<Action>(); this.Actions.Add(restAction); foreach (var chest in GameObject.FindGameObjectsWithTag("Chest")) { this.Actions.Add(new PickUpChest(this, chest)); } foreach (var tree in GameObject.FindGameObjectsWithTag("Tree")) { this.Actions.Add(new GetArrows(this, tree)); } foreach (var bed in GameObject.FindGameObjectsWithTag("Bed")) { this.Actions.Add(new Sleep(this, bed)); } foreach (var boar in GameObject.FindGameObjectsWithTag("Boar")) { this.Actions.Add(new MeleeAttack(this, boar)); this.Actions.Add(new Shoot(this, boar)); } }