// Self explanatory private void DetermineSuricateGender(Suricate suricate) { // I guess it's 1/2 male/female if (Random.value < 0.5) { suricate.SetGender(Suricate.Gender.Male); } else { suricate.SetGender(Suricate.Gender.Female); } }
// We got called to replace a sentinel public void OnSentinelDuty(Suricate sentinel) { // A sentinel doesn't have kids to look after youths.Clear(); predecessor = sentinel; myPost = sentinel.GetPost(); suricateType = Type.Sentinel; animator.SetBool("hunter", false); animator.SetBool("sentinel", true); animator.ResetTrigger(wanderHash); animator.ResetTrigger(chaseHash); // Only if we aren't under attack if (!alert) { animator.SetTrigger(herdHash); } gameObject.name = "Suricate " + suricateID + " " + suricateType + " " + suricateGender; }
// A suricate died, we need to take action if it was a sentinel or an alpha private void SuricateDied(Suricate suricate) { aliveSuricates--; // This way the suricate is seen as dead by the game straight away suricate.tag = "Untagged"; // If an alpha died we need to elect a new one if (suricate.IsAlpha()) { // If it's a male, the first male suricate becomes the new alpha if (suricate.GetGender().Equals(Suricate.Gender.Male)) { foreach (GameObject candidat in GameObject.FindGameObjectsWithTag("Suricate")) { if (candidat.GetComponent <Suricate>().GetGender().Equals(suricate.GetGender()) && !candidat.GetComponent <Suricate>().IsDead()) { candidat.GetComponent <Suricate>().IsAlpha(true); candidat.name += " Alpha"; candidat.GetComponent <Renderer>().material = alphaMaleMaterial; return; } } } // If it's a female we need to get the biggest female to replace her else { GameObject newAlphaFemale = null; foreach (GameObject candidat in GameObject.FindGameObjectsWithTag("Suricate")) { if (candidat.GetComponent <Suricate>().GetGender().Equals(suricate.GetGender()) && !candidat.GetComponent <Suricate>().IsDead()) { if (newAlphaFemale == null) { newAlphaFemale = candidat; } // If the candidat ate more it's bigger! else if (candidat.GetComponent <Suricate>().GetAmountEaten() > newAlphaFemale.GetComponent <Suricate>().GetAmountEaten()) { newAlphaFemale = candidat; } } } // If we found a female if (newAlphaFemale != null) { newAlphaFemale.GetComponent <Suricate>().IsAlpha(true); newAlphaFemale.name += " Alpha"; newAlphaFemale.GetComponent <Renderer>().material = alphaFemaleMaterial; } } } // A sentinel died, we have to get a new one! if (suricate.GetSuricateType().Equals(Suricate.Type.Sentinel)) { foreach (GameObject candidat in GameObject.FindGameObjectsWithTag("Suricate")) { if (candidat.GetComponent <Suricate>().GetSuricateType().Equals(Suricate.Type.Hunter) && !candidat.GetComponent <Suricate>().IsAlpha()) { // We only want to have 2 sentinels at the same time if (GetNumberOfPostedSentinels() < 2) { candidat.GetComponent <Suricate>().OnSentinelDuty(suricate); } return; } } } }