void Awake() { //Find the agent movement controller attached _agentPathfinder = GetComponent<AIPath>(); //When an agent spawns, he should start by wandering aState = agentState.Wandering; //When an agent spawns, start updating his hunger level updateHunger(); }
void Start() { aiFollow = GetComponent <AIFollow_07>(); wanderWaypoints = new List <Vector3>(); while (wanderWaypoints.Count < wanderListSize) { wanderWaypoints.Add(new Vector3(Random.Range(0, 160), 0, Random.Range(0, 120))); } workWaypointIndex = 0; wanderWaypointIndex = 0; assignedTarget = false; //When an agent spawns, he should start by wandering aState = agentState.Wandering; }
//IEnumerator AgentHunger() { void AgentHunger() { if(!feeding){ //while(!feeding){ if (hungerValue > 0) { hungerValue--; //yield return new WaitForSeconds(1.0f); } if (hungerValue <= hungerSearch) { aState = agentState.Hungry; //_agentController.hungry = true; //gameObject.GetComponent<TestMovement>().hungry = true; } } //} else{ //while(feeding){ if(hungerValue < 100){ hungerValue++; //yield return new WaitForSeconds(1.0f); } } //} if (hungerValue == 100){ feeding = false; //StartCoroutine(AgentHunger()); } if (hungerValue == 0) { Destroy(this.gameObject); } }
void OnGUI() { if (GUI.Button(new Rect(10,30, 100, 20),"Work")) { aState = agentState.Working; } }
void Awake() { //Find the agent movement controller attached _agentPathfinder = GetComponent<AgentPathfinder>(); WorkWaypoint = GameObject.FindGameObjectWithTag ("WorkWaypoint"); //When an agent spawns, he should start by wandering aState = agentState.Default; //When an agent spawns, start updating his hunger level updateHunger(); }
public void TargetReached() { if (aState == agentState.Wandering){ wanderWaypointIndex = Random.Range(0, wanderWaypoints.Count); aiFollow.target = wanderWaypoints[wanderWaypointIndex]; } else if (aState == agentState.Working){ //workWaypointIndex = Random.Range(0, workWaypoints.Count); StartCoroutine(DelayNewWorkTarget(workWaypoints[workWaypointIndex].transform)); aiFollow.target = workWaypoints[workWaypointIndex].transform.position; } else if (aState == agentState.Hungry){ //Reset hunger level or start replenishing //Todo slowly start decreasing hunger value isHungry = false; //Give the agent 10% of the current food stored //Todo need to figureout a beter method for this algorithm foodStored = 0.10f * gameController.food; gameController.food -= foodStored; if (foodStored > 0) { hungerValue = 0; } else { //The agent is now starving! Debug.Log("Agent is starving!"); } //Tell the agent that they current have food and should not starve hasFood = true; //Todo need to check if there is actually food available for the agent to feed on //ADD HERE //Go back to previous task aState = currentState; //Need to Update the wait length to take into account the % of hunger missing (Higher hunger missing = longer wait time) } /* * if State1 * do this * if State2 * do this * if State3 * do this * if State4 * do this * */ }
void Update() { if (health <= 0) { Destroy(this.gameObject); } switch (aState) { case agentState.Wandering: //Save the current state currentState = aState; //Set the current target to move towards aiFollow.target = wanderWaypoints[wanderWaypointIndex]; //remove this agent from all worker lists //Todo do this with a function call gameController.farmerList.Remove(this.gameObject); break; case agentState.Hungry: aiFollow.target = storageWaypoints[storageWaypointIndex].transform.position; //remove this agent from all worker lists //Todo do this with a function call gameController.farmerList.Remove(this.gameObject); populateList = false; break; case agentState.Working: currentState = aState; //Agent can be assigned various jobs each with their own behaviour switch (jobState) { case jobSubState.Farmer: //Set the agent to move towards the farm waypoints aiFollow.target = workWaypoints[workWaypointIndex].transform.position; //Add the agent to the list of farmers //Todo: Should update this to a function which when called takes a passed value of the substate and adds this agent to the correct list if (!gameController.farmerList.Contains(this.gameObject)) { gameController.farmerList.Add(this.gameObject); //populateList = true; } break; case jobSubState.Medic: aiFollow.target = workWaypoints[workWaypointIndex].transform.position; break; case jobSubState.WaterPurifier: aiFollow.target = workWaypoints[workWaypointIndex].transform.position; break; case jobSubState.PowerWorker: aiFollow.target = workWaypoints[workWaypointIndex].transform.position; if (!populateList) { gameController.powerWorkerList.Add(this.gameObject); populateList = true; } break; case jobSubState.Default: print("Default reached in Working SubState in AgentLogic_07 Update"); break; } break; case agentState.Default: print("Default reached in AgentLogic_07 Update"); break; } }
void Start() { //Init the agent's hunger value to 0 when spawned (they shouldnt be hungry at start) hungerValue = 0; //Init the agent's health to 100 when spawned (they should be perfectly healthy) health = 100; aiFollow = GetComponent<AIFollow_AlphaDemo>(); wanderWaypoints = new List<Vector3>(); //Populate the following waypoints when an agent is spawned while (wanderWaypoints.Count < wanderListSize) { wanderWaypoints.Add(new Vector3(Random.Range(0, 160), 0, Random.Range(0, 120))); } //Get all storage waypoints when the agent is spawned, agent should know a known food source at spawn storageWaypoints = new List<GameObject>(GameObject.FindGameObjectsWithTag("StorageWaypoint")); gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>(); //init all waypoint index's to 0 and set the storage waypoint indext to a random value within the scope of the storage list workWaypointIndex = 0; wanderWaypointIndex = 0; storageWaypointIndex = Random.Range(0, storageWaypoints.Count); //Agent should have no current assigned target assignedTarget = false; //Agent should not have populated any worker lists populateList = false; //When an agent spawns, he should start by wandering aState = agentState.Hungry; //Once everything has been set, begin consuming resources BeginFeeding(); }
//When the agent's hunger % reaches a critial amount, then switch the current state of the agent to hunger state (search for food) void ConsumeResource() { //Todo: need to update this function to take into account the current food the agent has collected... //ie. once they collect 100 food ONLY start increasing the hungerValue once he has finished feeding on that 100 food if (hungerValue >= 100) { health--; } switch (hasFood) { case true: //Check that there still is food stored if (foodStored > 0) { //if yes then decrease the amount of food stored on the agent and increase their health foodStored--; if (health > 100){ //Increase the missing health of the agent when eating food health++; } else { //Do nothing } } else { //if there is no more food stored on the agent, then start starving the agent foodStored = 0; hasFood = false; } break; case false: //check if the agent's hunger% has reached 25%, otherwise keep increasing the hungerValue //Todo update this if statement to check boolean, boolean set based on probability if (hungerValue >= 100){ hungerValue = 100; } else { //Increase the current hunger value of the agent by 1 hungerValue++; } //Bool set if true then change state to hungry if (isHungry) { //if yes then set the agent's state to hungry, but first save the previous state.. //so the agent may return to it after feeding aState = agentState.Hungry; } else { //Todo: need to incorporate a probability factor that is affected by the current hunger value %, higher % = higher probablility to change Astate to hungry //Throw a series of dice at each milestone 25,50,75% hunger, if any dice roll true, then move to the food source switch (hungerValue) { case 25: //if the agent reaches 25% hunger throw a dice with 10% probability of success isHungry = Choose(10); break; case 50: for (amount = 0; amount < 3; amount++) if (!isHungry) { //if the agent reaches 50% hunger throw a dice with 35% probability of success isHungry = Choose(10); } break; case 75: for (amount = 0; amount < 6; amount++) if (!isHungry) { //if the agent reaches 75% hunger throw a dice with 65% probability of success isHungry = Choose(10); } break; case 100: StartCoroutine(CheckFoodSource()); // isHungry = Choose(101); break; } //Choose(hungerValue); } break; default: Debug.Log("Default reached in AgentLogic_07 - ConsumeResource function"); break; } }
void Start() { _audioController = FindObjectOfType<AudioController> ().gameObject.GetComponent<AudioController> (); //_GUIController_SettlerInfo = GameObject.Find ("Folk_Female_Agent").GetComponent<GUIController_SettlerInfo> (); if (newAgent) { Debug.Log("NEW AGENT AS BEEN Triggered"); malePortraitIndex = UnityEngine.Random.Range (0, 12); femalePortraitIndex = UnityEngine.Random.Range (0, 6); //Gender genderArray = new string[2] { "Male", "Female" }; //Name maleFirstNameArray = new string[32] { "Daron", "Bernardo", "Grady", "Willie", "Malcolm", "Trevor", "Ken", "Todd", "Rand", "Jeff", "Kurt", "Alexis", "Vishesh", "Luigi", "Jake", "Reggie", "Loyd", "Darron", "Tyler", "Zachary", "Roderick", "Raiden", "Miguel", "Ender", "Colm", "Phil", "Niko", "Tyson", "Sacha", "Tariq", "Zeph", "Ram" }; femaleFirstNameArray = new string[32] { "Joye", "Argelia", "Sheryll", "Carma", "Sheri", "Anita", "Xuan", "Robyn", "Allie", "Darcie", "Sari", "Shayna", "Thea", "Christie", "Sanora", "Laryssa", "Weri", "Elicia", "Wanda", "Creola", "Heidi", "Irene", "Helene", "Elora", "Joselyn", "Margery", "Oona", "Clair", "Freya", "Yvonne", "Sue", "Miley" }; lastNameArray = new string[35] { "Slate", "Hazlewood", "Beckett", "Polo", "Mordecai", "McKnight", "Kerrigan", "Kellerman", "Stone", "Drake", "Richards", "Allard", "Black", "Steele", "Sparks", "Quan", "Sparrow", "Poehler", "Carnes", "Vivek", "Cumberbatch", "Weaver", "Clay", "Yu", "Keyes", "Baird", "Crane", "Gould", "Valentine", "Frost", "Stark", "McDonald", "Willis", "Kirby", "Goldblum" }; //Create Random Variables randomFirstName = UnityEngine.Random.Range (0, 32); randomLastName = UnityEngine.Random.Range (0, 35); randomGender = Random.Range (0, (genderArray.Length)); wait = Random.Range(1.0f, 3.0f); //Assigns random names and photos according to gender //Variable firstLastName outputs first and last name. variable settlerNameAndRole outputs name, what settler is currently doing, and their assigned role if (gender == "Male"){ firstLastName = (maleFirstNameArray[randomFirstName] + " " + lastNameArray[randomLastName]); portraitIndex = malePortraitIndex; } else { firstLastName = (femaleFirstNameArray[randomFirstName] + " " + lastNameArray[randomLastName]); portraitIndex = femalePortraitIndex; } //Init the agent's hunger value to 0 when spawned (they shouldnt be hungry at start) hungerValue = 0; //Init the agent's health to 100 when spawned (they should be perfectly healthy) health = 100; //Init the agent's happyness to 100 when spawned (they should be perfectly happy) moraleLevel = 100; //Init the agent's perception to 10% when spawned (this is the standard starting value for all agents) perception = 10; //When the agent spawns, there is a 50% chance to spawn idle or wander WanderOrIdle(50.0f); } aiFollow = GetComponent<AIFollow_07> (); wanderWaypoints = new List<Vector3> (); //Populate the following waypoints when an agent is spawned while (wanderWaypoints.Count < wanderListSize) { wanderWaypoints.Add (new Vector3 (Random.Range (-30, 35), 0, Random.Range (-40, 10))); } //Get all storage waypoints when the agent is spawned, agent should know a known food source at spawn storageWaypoints = new List<GameObject> (GameObject.FindGameObjectsWithTag ("StorageWaypoint")); agentAnim = GetComponent<Animator>(); gameController = GameObject.FindGameObjectWithTag ("GameController").GetComponent<GameController> (); //init all waypoint index's to 0 and set the storage waypoint indext to a random value within the scope of the storage list workWaypointIndex = 0; wanderWaypointIndex = 0; storageWaypointIndex = Random.Range (0, storageWaypoints.Count); //Agent should have no current assigned target assignedTarget = false; //Agent should not have populated any worker lists populateList = false; if (aState == null){ //When an agent spawns, he should start by wandering if there is no starting state aState = agentState.Wandering; } if(aState != agentState.Working) { //if (jobState == jobSubState.Default) { //When the agent spawns, there is a 50% chance to spawn idle or wander WanderOrIdle(50.0f); } //Once everything has been set, begin consuming resources BeginFeeding(); }
void LateUpdate() { /** ADDED BY TYLER NOTIFICATION CONTROLLER EXAMPLE **/ if (hungerValue > 75 && !canCallHungerNotification) { canCallHungerNotification = true; // set this to true so that you don't spam the notification panel gameController.notificationController.CreateNewNotification (firstLastName + " is getting hungry"); } else if (hungerValue < 75) { canCallHungerNotification = false; // if agent hunger is back below 75 reset the boolean so the notification can be called again later. // this would probably be better served by a time buffer or something but this conditional statement will do for now } if (aState == agentState.Working) { settlerNameAndRole = firstLastName + " the " + jobState + " (" + aState + ")"; } else { //Resetting random name and attributes settlerNameAndRole = firstLastName + " (" + aState + ")"; } //Check if the agent has run out of health if (health <= 0 && isDead == false) { _audioController.playAudioClipOnce (10, Vector3.zero, 500); //play Sound //Stop the agent from moving aiFollow.Stop(); aiFollow.Reset(); aState = agentState.Dead; //Play a death animation agentAnim.SetTrigger("Dead"); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); agentAnim.SetBool("Walking", false); gameController.population.Remove (this.gameObject); health = 0; //Ensure the agent only triggers this logic once isDead = true; //Destroy(this.gameObject); } switch (aState) { case agentState.Idle: //Save the current state currentState = aState; agentAnim.SetBool("Walking", false); agentAnim.SetBool("Idle", true); aiFollow.Reset(); if (!gameController.unAssignedPopulation.Contains(this.gameObject)) { gameController.unAssignedPopulation.Add(this.gameObject); } //yield return new WaitForSeconds(3.0f); if (wait > 0) { wait -= Time.deltaTime; //print("wait" + wait); } else { WanderOrIdle(50.0f); wait = Random.Range(3, 10); } break; case agentState.Wandering: //Save the current state currentState = aState; agentAnim.SetBool("Walking", true); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); //Set the current target to move towards aiFollow.target = wanderWaypoints[wanderWaypointIndex]; if (!gameController.unAssignedPopulation.Contains(this.gameObject)) { gameController.unAssignedPopulation.Add(this.gameObject); } //remove this agent from all worker lists //Todo do this with a function call gameController.farmerList.Remove(this.gameObject); gameController.waterWorkerList.Remove(this.gameObject); gameController.powerWorkerList.Remove(this.gameObject); gameController.traineeList.Remove(this.gameObject); break; case agentState.Hungry: agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); if (!isDead) { aiFollow.canMove = true; aiFollow.target = storageWaypoints[storageWaypointIndex].transform.position; } else { aState = agentState.Dead; } //remove this agent from all worker lists //Todo do this with a function call gameController.farmerList.Remove(this.gameObject); populateList = false; break; case agentState.Injured: agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); aiFollow.target = storageWaypoints[storageWaypointIndex].transform.position; break; case agentState.Dead: currentState = aState; agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); agentAnim.SetBool("Walking", false); aiFollow.Reset(); aiFollow.Stop(); break; case agentState.Working: currentState = aState; agentAnim.SetBool("Idle", false); //Agent can be assigned various jobs each with their own behaviour switch (jobState) { case jobSubState.Farmer: //Set the agent to move towards the farm waypoints //aiFollow.Reset(); aiFollow.target = workWaypoints[workWaypointIndex].transform.position; if (workerPathCompleted ) { aiFollow.target = workWaypoints[workWaypointIndex].transform.position; agentAnim.SetBool("Walking", true); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); workerPathCompleted = false; } //Add the agent to the list of farmers //Todo: Should update this to a function which when called takes a passed value of the substate and adds this agent to the correct list if (!gameController.farmerList.Contains(this.gameObject)) { gameController.farmerList.Add(this.gameObject); gameController.unAssignedPopulation.Remove(this.gameObject); //populateList = true; } break; case jobSubState.Medic: aiFollow.target = workWaypoints[workWaypointIndex].transform.position; if (workerPathCompleted) { aiFollow.target = workWaypoints[workWaypointIndex].transform.position; agentAnim.SetBool("Walking", true); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); workerPathCompleted = false; } break; case jobSubState.Hydrologist: aiFollow.target = workWaypoints[workWaypointIndex].transform.position; if (workerPathCompleted) { aiFollow.target = workWaypoints[workWaypointIndex].transform.position; agentAnim.SetBool("Walking", true); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); workerPathCompleted = false; } if (!gameController.waterWorkerList.Contains(this.gameObject)) { gameController.waterWorkerList.Add(this.gameObject); gameController.unAssignedPopulation.Remove(this.gameObject); //populateList = true; } break; case jobSubState.PowerWorker: //aiFollow.Reset(); aiFollow.target = workWaypoints[workWaypointIndex].transform.position; if (workerPathCompleted) { aiFollow.target = workWaypoints[workWaypointIndex].transform.position; agentAnim.SetBool("Walking", true); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); workerPathCompleted = false; } if (!populateList) { gameController.powerWorkerList.Add(this.gameObject); gameController.unAssignedPopulation.Remove(this.gameObject); populateList = true; } break; case jobSubState.Trainee: aiFollow.target = workWaypoints[workWaypointIndex].transform.position; if (workerPathCompleted) { aiFollow.target = workWaypoints[workWaypointIndex].transform.position; agentAnim.SetBool("Walking", true); agentAnim.SetBool("Idle", false); agentAnim.SetBool("Working", false); workerPathCompleted = false; } if (!populateList) { gameController.traineeList.Add(this.gameObject); gameController.unAssignedPopulation.Remove(this.gameObject); populateList = true; } break; case jobSubState.Default: print("Default reached in Working SubState in AgentLogic_07 Update"); break; } break; case agentState.Default: print("Default reached in AgentLogic_07 Update"); break; } }
//When the agent's hunger % reaches a critial amount, then switch the current state of the agent to hunger state (search for food) void ConsumeResource() { //Todo: need to update this function to take into account the current food the agent has collected... //ie. once they collect 100 food ONLY start increasing the hungerValue once he has finished feeding on that 100 food if (hungerValue >= 100 && health >= 0) { health--; } if (hasFood) { // if (health < ( 100 - ( 5 * (int)consumeRate)) ) { //Increase the missing health of the agent when eating food //Now based on double what ever the agent's consumption rate health += (5 * (int)consumeRate); } else { health = 100; } } /*if (health > 100) { health = 100; }*/ /*switch (hasFood) { case true: //Check that there still is food stored if (foodStored > 0) { //if yes then decrease the amount of food stored on the agent and increase their health foodStored--; //InvokeRepeating("ReduceFoodInventory", 1, 10); if (health < 100) { //Increase the missing health of the agent when eating food //Now based on double what ever the agent's consumption rate health += (2 * (int)consumeRate); } else { //Do nothing } } else { //if there is no more food stored on the agent, then start starving the agent foodStored = 0; hasFood = false; } break; case false:*/ //check if the agent's hunger% has reached 25%, otherwise keep increasing the hungerValue //Todo update this if statement to check boolean, boolean set based on probability if (!hasFood) { if (hungerValue >= 100) { hungerValue = 100; } else { //Increase the current hunger value of the agent by 1 hungerValue++; } //Bool set if true then change state to hungry if (isHungry) { //if yes then set the agent's state to hungry, but first save the previous state.. //so the agent may return to it after feeding aState = agentState.Hungry; } else { //Todo: need to incorporate a probability factor that is affected by the current hunger value %, higher % = higher probablility to change Astate to hungry //Throw a series of dice at each milestone 25,50,75% hunger, if any dice roll true, then move to the food source switch (hungerValue) { case 25: if (!isDead) { //Play hunger animation //Pause the ai pathfinding to play an animation, pass anim state name StartCoroutine(PlayAnimPauseAI("Hungry")); //if the agent reaches 25% hunger throw a dice with 10% probability of success isHungry = Choose(perception); } break; case 50: if (!isDead) { //Play hunger animation //Pause the ai pathfinding to play an animation, pass anim state name StartCoroutine(PlayAnimPauseAI("Hungry")); for (amount = 0; amount < 3; amount++) if (!isHungry) { //if the agent reaches 50% hunger throw a dice with 35% probability of success isHungry = Choose(perception); } } break; case 75: if (!isDead) { //Play hunger animation //Pause the ai pathfinding to play an animation, pass anim state name StartCoroutine(PlayAnimPauseAI("Hungry")); for (amount = 0; amount < 6; amount++) if (!isHungry) { //if the agent reaches 75% hunger throw a dice with 65% probability of success isHungry = Choose(perception); } } break; case 100: if (!isDead) { StartCoroutine(CheckFoodSource()); } // isHungry = Choose(101); break; } //Choose(hungerValue); } /*break; default: Debug.Log("Default reached in AgentLogic_07 - ConsumeResource function"); break;*/ } }
//When the agent's hunger % reaches a critial amount, then switch the current state of the agent to hunger state (search for food) void CheckIfInjured() { //Todo: need to update this function to take into account the current food the agent has collected... //ie. once they collect 100 food ONLY start increasing the hungerValue once he has finished feeding on that 100 food if (!isDead) { if (isInjured) { //if yes then set the agent's state to hungry, but first save the previous state.. //so the agent may return to it after feeding aState = agentState.Injured; } else { //Todo: need to incorporate a probability factor that is affected by the current hunger value %, higher % = higher probablility to change Astate to hungry //Throw a series of dice at each milestone 25,50,75% hunger, if any dice roll true, then move to the food source switch (health) { case 75: if (!isDead) { //Play hunger animation //Pause the ai pathfinding to play an animation, pass anim state name //StartCoroutine(PlayAnimPauseAI("Hungry")); //if the agent reaches 25% hunger throw a dice with 10% probability of success isInjured = Choose(perception); } break; case 50: if (!isDead) { //Play hunger animation //Pause the ai pathfinding to play an animation, pass anim state name //StartCoroutine(PlayAnimPauseAI("Hungry")); for (amount = 0; amount < 3; amount++) if (!isInjured) { //if the agent reaches 50% hunger throw a dice with 35% probability of success isInjured = Choose(perception); } } break; case 25: if (!isDead) { //Play hunger animation //Pause the ai pathfinding to play an animation, pass anim state name //StartCoroutine(PlayAnimPauseAI("Hungry")); for (amount = 0; amount < 6; amount++) if (!isInjured) { //if the agent reaches 75% hunger throw a dice with 65% probability of success isInjured = Choose(perception); } } break; case 5: if (!isDead) { StartCoroutine(CheckMedic()); } // isHungry = Choose(101); break; } //Choose(hungerValue); } } }
public void TargetReached() { if (aState == agentState.Wandering){ //50% chance when target is reached, to stop and idle or find a new target if (Choose(50.0f)){ aState = agentState.Idle; } else{ wanderWaypointIndex = Random.Range(0, wanderWaypoints.Count); aiFollow.target = wanderWaypoints[wanderWaypointIndex]; } } else if (aState == agentState.Working){ //workWaypointIndex = Random.Range(0, workWaypoints.Count); //StartCoroutine(DelayNewWorkTarget(workWaypoints[workWaypointIndex].transform)); //if (currentlyWorking == true) //{ //DelayNewWorkTarget(workWaypoints[workWaypointIndex].transform); //currentlyWorking = false; //} //else { //workWaypointIndex = Random.Range(0, workWaypoints.Count); //aiFollow.target = workWaypoints[workWaypointIndex].transform.position; // currentlyWorking = true; //} if (workWait > 0) { workWait -= Time.deltaTime; agentAnim.SetBool("Walking", false); agentAnim.SetBool("Working", true); Vector3 targetPostition = new Vector3(workWaypoints[workWaypointIndex].transform.parent.parent.gameObject.transform.position.x, this.transform.position.y, workWaypoints[workWaypointIndex].transform.parent.parent.gameObject.transform.position.z); this.transform.LookAt(targetPostition); aiFollow.canMove = false; aiFollow.Reset(); workerPathCompleted = false; //print("workWait: " + workWait); } else { workWaypointIndex = Random.Range(0, workWaypoints.Count); aiFollow.target = workWaypoints[workWaypointIndex].transform.position; aiFollow.canMove = true; workWait = 2.0f; workerPathCompleted = true; } } else if (aState == agentState.Hungry){ //Reset hunger level or start replenishing //Todo slowly start decreasing hunger value isHungry = false; //Give the agent 10% of the current food stored //Todo need to figureout a beter method for this algorithm if (gameController.food > 0) { //foodStored = gameController.food/10; foodStored = 5; /// Making Hunger a Flat rate for testing - Tyler if( gameController.food < foodStored ){ foodStored = gameController.food; } gameController.food -= foodStored; } else { Debug.Log(gameObject.name + " tried to collect food, but none was found."); } if (foodStored > 0) { hungerValue = 0; } else { //The agent is now starving! Debug.Log("Agent is starving!"); } //Tell the agent that they current have food and should not starve hasFood = true; //Todo need to check if there is actually food available for the agent to feed on //ADD HERE //Go back to previous task aState = currentState; //Need to Update the wait length to take into account the % of hunger missing (Higher hunger missing = longer wait time) } else if (aState == agentState.Injured) { //Reset health level or start replenishing //Todo slowly start decreasing health value isHungry = false; /* Apply healing algorithm here */ if (gameController.food > 0) { foodStored = gameController.food / 10; gameController.food -= foodStored; } else { Debug.Log(gameObject.name + " tried to collect food, but none was found."); } //Go back to previous task aState = currentState; } /* * if State1 * do this * if State2 * do this * if State3 * do this * if State4 * do this * */ }
//Choose between idle or wander with a given chance agentState WanderOrIdle(float chance) { if (Choose(chance)) { //print("IDELASSKDHAKSJDH"); return aState = agentState.Idle; } else { return aState = agentState.Wandering; } //WaitForSeconds(wait); }
void Update() { switch (aState) { case agentState.Wandering: Wander(); aState = agentState.Wandering; break; case agentState.Hungry: if(!feeding && hungerValue <= hungerSearch){ _agentController.hungry = true; } break; case agentState.Working: if(hasFinished2 == false){ _agentController.target = WorkWaypoint.transform.position; hasFinished2 = true; aState = agentState.Working; } if(transform.position == WorkWaypoint.transform.position) _agentController.OnTargetReached(); //aState = agentState.Working; break; case agentState.Default: print("Default reached in AgentFSM Update"); break; } }
void Start() { aiFollow = GetComponent<AIFollow_07>(); wanderWaypoints = new List<Vector3>(); while (wanderWaypoints.Count < wanderListSize) { wanderWaypoints.Add(new Vector3(Random.Range(0, 160), 0, Random.Range(0, 120))); } workWaypointIndex = 0; wanderWaypointIndex = 0; assignedTarget = false; //When an agent spawns, he should start by wandering aState = agentState.Wandering; }
void Start() { aiFollow = GetComponent<AIFollow>(); workWaypoints = new List<GameObject>(GameObject.FindGameObjectsWithTag("WorkWaypoint")); wanderWaypoints = new List<Vector3>(); while (wanderWaypoints.Count < wanderListSize) { wanderWaypoints.Add(new Vector3(Random.Range(-50, 50), 0, Random.Range(-50, 50))); } workWaypointIndex = 0; wanderWaypointIndex = 0; assignedTarget = false; //When an agent spawns, he should start by wandering aState = agentState.Wandering; }