public void SetTargets(int box, int hole) { // Set box and hole targets boxTarget = world.GetBoxes()[box].transform; holeTarget = world.GetTargets()[hole].transform; // PathPlanning plan = new PathPlanning(); Vector3 position = new Vector3(Mathf.RoundToInt(transform.position.x), transform.position.y, Mathf.RoundToInt(transform.position.z)); path = plan.PlanRoute(position, boxTarget.position, holeTarget.position, world.GetWorldLayout(), world.GetGridSize()); if (path == null) { print("New world"); print("null path"); print("position: " + position); print("box: " + boxTarget.position); print("hole: " + holeTarget.position); world.NewWorld(); } else { currentTarget = 0; targetMark = (GameObject)Resources.Load("Prefabs/TargetMark", typeof(GameObject)); boxMark = Instantiate(targetMark, boxTarget.position, new Quaternion(), boxTarget); Instantiate(targetMark, holeTarget.position, new Quaternion(), holeTarget); currentState = STATE.MOVING; } }
protected void PickTarget() { if (player) { player.Stop(); } currentState = STATE.PICKING_TARGET; List <GameObject> holes = world.GetTargets(); if (holes.Count < 1) { currentState = STATE.END; return; } // Pick box and hole targets Transform[] targets = Strategy(world.GetBoxes(), holes); while (targets == null && currentState == STATE.PICKING_TARGET) { world.UpdateLists(); targets = Strategy(world.GetBoxes(), world.GetTargets()); } boxTarget = targets[0]; holeTarget = targets[1]; // PathPlanning plan = new PathPlanning(); Vector3 position = new Vector3(Mathf.RoundToInt(transform.position.x), transform.position.y, Mathf.RoundToInt(transform.position.z)); path = plan.PlanRoute(position, boxTarget.position, holeTarget.position, world.GetWorldLayout(), world.GetGridSize()); if (path == null) { print("New world"); print("null path"); print("position: " + position); print("box: " + boxTarget.position); print("hole: " + holeTarget.position); world.NewWorld(); } else { currentTarget = 0; targetMark = (GameObject)Resources.Load("Prefabs/TargetMark", typeof(GameObject)); boxMark = Instantiate(targetMark, boxTarget.position, new Quaternion(), boxTarget); Instantiate(targetMark, holeTarget.position, new Quaternion(), holeTarget); currentState = STATE.MOVING; } }
public void Initialise(Vector2 StartingPos_,int VillageNum_,AI_Bias bias,TreeManager TreeMgr_,ref char[,] AiMap_, VillageGen.Scenario NewScenario = new VillageGen.Scenario()) { if(VillageNum_ == 0) { MaleVillager = Resources.Load<GameObject>("Characters/Prefabs/Male 1"); FemaleVillager = Resources.Load<GameObject>("Characters/Prefabs/Female 1"); } else if (VillageNum_ == 1) { MaleVillager = Resources.Load<GameObject>(Application.dataPath + "Characters/Prefabs/Male 2.prefab"); FemaleVillager = Resources.Load<GameObject>(Application.dataPath + "Characters/Prefabs/Female 2.prefab"); } else if (VillageNum_ == 2) { MaleVillager = Resources.Load<GameObject>(Application.dataPath + "Characters/Prefabs/Male 3.prefab"); FemaleVillager = Resources.Load<GameObject>(Application.dataPath + "Characters/Prefabs/Female 3.prefab"); } else if (VillageNum_ == 3) { MaleVillager = Resources.Load<GameObject>(Application.dataPath + "Characters/Prefabs/Male 4.prefab"); FemaleVillager = Resources.Load<GameObject>(Application.dataPath + "Characters/Prefabs/Female 4.prefab"); } VillageNum = VillageNum_; TaskPlanner = new TaskPlanning(); TaskPlanner.Initialise(); PathPlanner = new PathPlanning(); PathPlanner.Initialise(ref AiMap_); CurrentObj = new List<ObjectiveTasks>(); CurrentBias = bias; AiMap = AiMap_; Villagers = new List<Villager>(); AvailableVillagers = new List<Villager>(); Buildings = new List<Building>(); TreeMgr = TreeMgr_; if (!NewScenario.Created) { Villagers.Add((GameObject.Instantiate(MaleVillager, new Vector3(StartingPos_.x, StartingPos_.y), Quaternion.identity) as GameObject).GetComponent<Villager>()); Villagers.Add((GameObject.Instantiate(FemaleVillager, new Vector3(StartingPos_.x, StartingPos_.y), Quaternion.identity) as GameObject).GetComponent<Villager>()); StartingPos = StartingPos_; foreach (var vill in Villagers) vill.Initialise(StartingPos_); AvailableVillagers.AddRange(Villagers); Initialised = true; } else { StartingPos = new Vector2(NewScenario.Xpos, NewScenario.Ypos); // gen scenario for (int i = 0; i < NewScenario.Barracks; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Barracks)); for (int i = 0; i < NewScenario.BlackS; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Blacksmith)); for (int i = 0; i < NewScenario.House; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.House)); for (int i = 0; i < NewScenario.Market; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Market)); for (int i = 0; i < NewScenario.Mine; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Mine)); for (int i = 0; i < NewScenario.Quarry; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Quarry)); for (int i = 0; i < NewScenario.Saw; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Sawmill)); for (int i = 0; i < NewScenario.School; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.School)); for (int i = 0; i < NewScenario.Smelter; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Smelter)); for (int i = 0; i < NewScenario.Storage; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Storage)); for (int i = 0; i < NewScenario.Turf; i++) Buildings.Add(GenerateBuildingSite(Building.BuildingType.Turf)); for (int i = 0; i < NewScenario.Villagers; i++) Villagers.Add((GameObject.Instantiate(MaleVillager, new Vector3(StartingPos_.x, StartingPos_.y), Quaternion.identity) as GameObject).GetComponent<Villager>()); } }
public void SetPath(PathPlanning.PathInfo newPath) { Path = newPath; }