void AssignTasks(ObjectiveTasks CurrentObj) { bool villagerFree = true; // at this point all tasks and paths are ready for(int i = 0; i < CurrentObj.Stepsneeded.Count; i++) { // we will add a list of callbacks to the stepsneeded struct, // these callbacks when all true will update the step as complete if (CurrentObj.Stepsneeded[i].complete) continue; // move to next task foreach (var vill in CurrentObj.Stepsneeded[i].villager) if (vill.CurrentAction != Villager.Actions.None) { villagerFree = false; break; } if (!villagerFree) continue; for (int j = 0; j < CurrentObj.Stepsneeded[i].villager.Count;j++ ) { var Vill = CurrentObj.Stepsneeded[i].villager[j]; // here we are ready, the correct task is selected and all the villagers required are free if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Walk) { // quck check due to position assignments in pddl , due to villager start being the vil pos and no comparison to objective pos if (CurrentObj.Stepsneeded[i].Path.Start == CurrentObj.Stepsneeded[i].Path.End) { // no walk needed CurrentObj.Stepsneeded[i].complete = true; return; } // only one villager, give the path Vill.AddPath(CurrentObj.Stepsneeded[i].Path.Path); Vill.SetAction(CurrentObj.Stepsneeded[i].Action); } else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Build) { if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Barracks) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 30.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Blacksmith) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 30.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.House) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 15.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Market) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 5.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Mine) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 50.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Quarry) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 10.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Sawmill) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 30.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.School) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 30.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Smelter) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 20.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Storage) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 20.0f); else if (CurrentObj.Stepsneeded[i].ToBeBuilt == Building.BuildingType.Turf) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 10.0f); } else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Buy_Sell) Vill.SetAction(CurrentObj.Stepsneeded[i].Action, 1.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Combat) Vill.SetAction(CurrentObj.Stepsneeded[i].Action, 1.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Store) Vill.SetAction(CurrentObj.Stepsneeded[i].Action, 1.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Cut_Tree) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].TreeInUse, 5.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Educate) Vill.SetAction(CurrentObj.Stepsneeded[i].Action, 100.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Educate_Barracks) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 30.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Family) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 20.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Family_House) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 20.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Make_Tool) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse,CurrentObj.Stepsneeded[i].ItemRequired, 10.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Mine) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 5.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Pickup) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse,CurrentObj.Stepsneeded[i].ItemRequired); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Putdown) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse,CurrentObj.Stepsneeded[i].ItemRequired); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Quarry) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 5.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Saw_Wood) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 10.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Smelt) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 5.0f); else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Train) Vill.SetAction(CurrentObj.Stepsneeded[i].Action,CurrentObj.Stepsneeded[i].BuildingInUse, 50.0f); } // we put special cases like ... skills to learn CurrentObj.Stepsneeded[i].villager[0].ActionCallback = CurrentObj.Stepsneeded[i].SetComplete; if(CurrentObj.Stepsneeded[i].Action == Villager.Actions.Train || CurrentObj.Stepsneeded[i].Action == Villager.Actions.Educate) { // should be two JiC first found with labourer skill if (CurrentObj.Stepsneeded[i].villager[0].Skill == Villager.Skills.Labourer) { CurrentObj.Stepsneeded[i].villager[0].LearnSkill(CurrentObj.Stepsneeded[i].SkillToBeLearnt, CurrentObj.Stepsneeded[i].villager[1]); } } if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Family) CurrentObj.Stepsneeded[i].villager[0].Preg = AddVillager; else if (CurrentObj.Stepsneeded[i].Action == Villager.Actions.Family_House) { CurrentObj.Stepsneeded[i].villager[0].Preg = AddVillager; CurrentObj.Stepsneeded[i].villager[1].Preg = AddVillager; } } }
bool ObjectiveCompleted(ObjectiveTasks Current) { if (Current.Stepsneeded.Count == 0) return false; foreach (var steps in Current.Stepsneeded) if (steps.complete != true) return false; Current.complete = true; return true; }
bool ObjectiveReady(ObjectiveTasks Current) { if (Current.Stepsneeded.Count == 0 || Current.Stepsneeded == null) return false; foreach (var Steps in Current.Stepsneeded) if (Steps.Path.Complete == false) return false; return true; }
void PassGoal(GoalState goal, ObjectiveTypes Type) { ObjectiveTasks newTask = new ObjectiveTasks(); newTask.Type = Type; newTask.PathID = -1; newTask.TaskID = TaskPlanner.RequestTask(goal); newTask.BuildingSite = goal.Site; newTask.Stepsneeded = new List<TaskPlanning.Task>(); Debug.Log("new task created Type : " + Type.ToString()); CurrentObj.Add(newTask); }