public float CalculateChanceOfMakingAttempt() { float administrativeLoad = _sourceTribe.CalculateAdministrativeLoad(); if (float.IsPositiveInfinity(administrativeLoad)) { return(0); } float numFactors = 0; float contactStrength = _sourceTribe.CalculateContactStrength(_targetTribe) * ContactStrengthFactor; numFactors++; float isolationPreferenceValue = _sourceTribe.GetPreferenceValue(CulturalPreference.IsolationPreferenceId); numFactors++; float cohesionPreferenceValue = _sourceTribe.GetPreferenceValue(CulturalPreference.CohesionPreferenceId); numFactors++; float relationshipValue = _sourceTribe.GetRelationshipValue(_targetTribe); numFactors++; float modIsolationPreferencValue = isolationPreferenceValue * 2; float modCohesionPreferenceValue = (cohesionPreferenceValue - 0.5f) * 2; float modRelationshipValue = (relationshipValue - 0.5f) * 2; /// NOTE: Move administrative load stuff to a separate general function float authorityPreferenceValue = _targetTribe.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId); float cohesionPrefFactor = 2 * cohesionPreferenceValue; cohesionPrefFactor = Mathf.Pow(cohesionPrefFactor, 4); float authorityPrefFactor = 2 * authorityPreferenceValue; authorityPrefFactor = Mathf.Pow(authorityPrefFactor, 4); Agent sourceTribeLeader = _sourceTribe.CurrentLeader; float modMinAdministrativeLoad = MinAdministrativeLoad * cohesionPrefFactor; float modMaxAdministrativeLoad = modMinAdministrativeLoad + (DeltaAdministrativeLoad * sourceTribeLeader.Wisdom * sourceTribeLeader.Charisma * authorityPrefFactor * MaxAdministrativeLoadChanceFactor); float administrativeLoadFactor = (administrativeLoad - modMinAdministrativeLoad) / (modMaxAdministrativeLoad - modMinAdministrativeLoad); numFactors++; /// End of NOTE relevant code float chance = ((1 - modIsolationPreferencValue) + modCohesionPreferenceValue + modRelationshipValue + contactStrength + (1 - administrativeLoadFactor)) / numFactors; return(Mathf.Clamp01(chance)); }
public float CalculateChanceOfMakingAttempt() { float numFactors = 0; float contactStrength = _sourceTribe.CalculateContactStrength(_targetTribe) * ContactStrengthFactor; numFactors++; float isolationPreferenceValue = _sourceTribe.GetPreferenceValue(CulturalPreference.IsolationPreferenceId); numFactors++; float relationshipValue = _sourceTribe.GetRelationshipValue(_targetTribe); numFactors++; // average factors float chance = ((1 - isolationPreferenceValue) + (1 - relationshipValue) + contactStrength) / numFactors; return(Mathf.Clamp01(chance)); }