private float StabilityScore( IEnumerable <State> state, Character host, InfluencedInteraction interaction, ICollection <IEntity> targets, BrainRepository repo ) { float ownScore = 0f; int count = 0; foreach (State s in state) { State.TransformedInstance currState = host[s] as State.TransformedInstance; ownScore += currState.TransformedState; count++; } ownScore /= count; float ease = .3f; if (ownScore < LOW_STABILITY) { ease = .5f; } else { if (ownScore > HI_STABILITY) { ease = .1f; } } var func = Transformations.EaseSquaredAtValue(ease); var effects = ChooseStronglyInfluencedEffects(repo, interaction, host); //List<FloatModifier> modifiers = new List<FloatModifier>(); float modifyVal = 0f; foreach (Effect e in effects) { float currMod = 0f; foreach (IModifier m in e.Modifiers) { FloatModifier floatMod = m as FloatModifier; currMod = Math.Abs(floatMod.offset); if (floatMod.Attribute.Equals(repo.GetState("anger"))) { } } if (e.Modifiers.Count != 0) { currMod /= e.Modifiers.Count; } modifyVal += currMod; } if (effects.Count != 0) { modifyVal /= effects.Count; } ownScore = func(modifyVal); if (targets == null) { //BehaviorEngine.Debug.Logger.Log("Score: " + ownScore); return(ownScore); } float otherScore = 0f; foreach (IEntity target in targets) { var attrs = target.GetAttributeInstances(); float stabilityValue = 0f; float weight = 1f; foreach (IAttributeInstance a in attrs) { NormalizedAttribute.Instance attr = a as NormalizedAttribute.Instance; stabilityValue += attr.State; } stabilityValue /= attrs.Count; weight = .3f; if (stabilityValue <= LOW_STABILITY) { weight = .5f; } else { weight = .1f; } var f = Transformations.EaseSquaredAtValue(weight); otherScore += f(modifyVal); // Attempt to bias interaction towards people that crew will vote for var crewmember = target as Character; var hostCrew = host as Crewmember; if (crewmember != null && hostCrew != null) { var chooseVote = hostCrew.ChooseVote(); //Will be null if relationship does not exist if (chooseVote != null) { if (hostCrew.ChooseVote().Equals(crewmember)) { otherScore *= 2; //Debug.Logger.Log("Doubled, found vote"); } } } } if (targets.Count != 0) { otherScore /= targets.Count; } float score = (ownScore + otherScore) / 2; //BehaviorEngine.Debug.Logger.Log("Score: " + score); return(score); }