public void AssignSquadJobs() { //Debug.Log("is squad null? " + (CurrentSquad == null) + " members " + CurrentSquad.Members.Count + " squad is " + CurrentSquad.ID); if (CurrentSquad == null || MaxOccupants <= 0 || CurrentSquad.Members.Count <= 0) { return; } //Debug.Log("Starting Assign Squad Job to " + CurrentSquad.Faction + " character type " + GameManager.Inst.NPCManager.GetFactionData(CurrentSquad.Faction).CharacterType); if (GameManager.Inst.NPCManager.GetFactionData(CurrentSquad.Faction).CharacterType != CharacterType.Human) { foreach (Character mutant in CurrentSquad.Members) { mutant.MyAI.BlackBoard.PatrolLoc = transform.position; mutant.MyAI.BlackBoard.PatrolRange = PatrolRange; mutant.MyAI.BlackBoard.CombatRange = CombatRange; mutant.MyAI.BlackBoard.HasPatrolInfo = true; } return; } else { //Debug.Log("Starting Assign Squad Job for humans. guard locs count " + GuardLocs.Count); //first set patrol range for everyone foreach (Character member in CurrentSquad.Members) { member.MyAI.BlackBoard.PatrolLoc = transform.position; member.MyAI.BlackBoard.PatrolRange = PatrolRange; member.MyAI.BlackBoard.CombatRange = CombatRange; member.MyAI.BlackBoard.HasPatrolInfo = true; member.MyJobs.Clear(); member.MyJobs.Add(NPCJobs.None); member.MyAI.SetDynamicyGoal(GameManager.Inst.NPCManager.DynamicGoalChill, 5); } if (GuardLocs.Count > 0) { int guardsCount = CurrentSquad.GetNumberOfGuards(); int i = 0; while (GuardLocs.Count > guardsCount && i < CurrentSquad.Members.Count) { if (CurrentSquad.Members[i].MyJobs.Contains(NPCJobs.None) && !CurrentSquad.Members[i].IsCommander) { int guardLocIndex = GetVacantGuardLocID(); if (guardLocIndex < 0) { //can't find vacant guard loc break; } else { //assign a new guard CurrentSquad.Members[i].MyJobs.Clear(); CurrentSquad.Members[i].MyJobs.Add(NPCJobs.Guard); CurrentSquad.Members[i].MyAI.ClearDynamicGoal(5); CurrentSquad.Members[i].MyAI.BlackBoard.PatrolLoc = GuardLocs[guardLocIndex].transform.position; CurrentSquad.Members[i].MyAI.BlackBoard.GuardDirection = GuardLocs[guardLocIndex].transform.forward; CurrentSquad.Members[i].MyAI.BlackBoard.CombatRange = new Vector3(10, 10, 10); CurrentSquad.Members[i].MyAI.BlackBoard.HasPatrolInfo = true; CurrentSquad.Members[i].MyAI.BlackBoard.PatrolNodeIndex = -1; CurrentSquad.Members[i].MyAI.SetDynamicyGoal(GameManager.Inst.NPCManager.DynamicGoalGuard, 5); CurrentSquad.Members[i].MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, GuardLocs[guardLocIndex].transform.forward); GuardLocs[guardLocIndex].Guard = CurrentSquad.Members[i]; guardsCount++; } } i++; } } if (PatrolNodes.Count > 0) { int patrolsCount = CurrentSquad.GetNumberOfPatrols(); int i = 0; //Debug.LogError("Current patrols count " + CurrentSquad.GetNumberOfPatrols()); while (GuardLocs.Count > patrolsCount && i < CurrentSquad.Members.Count) { if (CurrentSquad.Members[i].MyJobs.Contains(NPCJobs.None) && !CurrentSquad.Members[i].IsCommander) { //assign a new guard CurrentSquad.Members[i].MyJobs.Clear(); CurrentSquad.Members[i].MyJobs.Add(NPCJobs.Patrol); CurrentSquad.Members[i].MyAI.ClearDynamicGoal(5); CurrentSquad.Members[i].MyAI.BlackBoard.PatrolLoc = transform.position; CurrentSquad.Members[i].MyAI.BlackBoard.PatrolRange = PatrolRange; CurrentSquad.Members[i].MyAI.BlackBoard.CombatRange = CombatRange; CurrentSquad.Members[i].MyAI.BlackBoard.HasPatrolInfo = true; CurrentSquad.Members[i].MyAI.BlackBoard.PatrolNodeIndex = UnityEngine.Random.Range(0, PatrolNodes.Count); CurrentSquad.Members[i].MyAI.SetDynamicyGoal(GameManager.Inst.NPCManager.DynamicGoalPatrol, 5); patrolsCount++; } i++; } } } }