public float CalculateWeight(NeedsBase needInstance) { float currentValue = needInstance.GetValue(); int priority = needInstance.priorityWeight; float internalWeight = (100.0f - currentValue) * (float)priority; int externalWeight = CalculateExternalInfluence(needInstance); float finalWeight = internalWeight + externalWeight; return(finalWeight); }
int CalculateExternalInfluence(NeedsBase needInstance) { int externalWeight = 0; //list of external weights, if the need has been told to consider it the calculation will be made here //Pedators if (needInstance.ConsiderPredators) { //Number of predators nearby predatorCount = predatorCheckScript.CheckPredators(parentObject); if (needInstance.PredatorsPositive) { //this will always calculate a negative value, so it's subtracted here to make it positive externalWeight -= predatorCount * predatorWeightFactor; } else { //calculates the negative value of nearby predators externalWeight += predatorCount * predatorWeightFactor; } } //Night Time if (needInstance.ConsiderNight) { bool sunUp; //WHERE'S THE SUN!? I NEED TO PRAISE IT if (!sun) { sun = GameObject.Find("Sun"); Debug.Log("Found the Sun"); } //Check what angle the sun (directional light) is Quaternion sunRotation = sun.GetComponent <Transform>().rotation; //is the sun up? if (sunRotation.eulerAngles.x < 90 && sunRotation.eulerAngles.x > 0) { sunUp = true; } else { sunUp = false; } //now do calculations based on perameters if (!sunUp) { //is night a positive factor? if (needInstance.NightPositive) { externalWeight -= nightWeightFactor; } else //night is negative { externalWeight += nightWeightFactor; } } } //return final external weight value return(externalWeight); }