(de7949704) Rewrite the leak priority calculations. Ensure that the damage priority is not negative.

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:07:45 +03:00
parent 7f58f30829
commit b51fd32b88
17 changed files with 205 additions and 86 deletions
@@ -1066,6 +1066,8 @@ namespace Barotrauma
private bool IsProperlyLatchedOnSub => LatchOntoAI != null && LatchOntoAI.IsAttachedToSub && SelectedAiTarget?.Entity == wallTarget?.Structure;
private bool IsProperlyLatchedOnSub => LatchOntoAI != null && LatchOntoAI.IsAttachedToSub && SelectedAiTarget?.Entity == wallTarget?.Structure;
//goes through all the AItargets, evaluates how preferable it is to attack the target,
//whether the Character can see/hear the target and chooses the most preferable target within
//sight/hearing range
@@ -39,18 +39,10 @@ namespace Barotrauma
public override float GetPriority(AIObjectiveManager objectiveManager)
{
if (leak.Open == 0.0f) { return 0.0f; }
//float leakSize = (leak.IsHorizontal ? leak.Rect.Height : leak.Rect.Width) * Math.Max(leak.Open, 0.1f);
//float dist = Vector2.DistanceSquared(character.SimPosition, leak.SimPosition);
//dist = Math.Max(dist / 100.0f, 1.0f);
//return Math.Min(leakSize / dist, 40.0f);
float leakSize = (leak.IsHorizontal ? leak.Rect.Height : leak.Rect.Width) * Math.Max(leak.Open, 0.1f);
float dist = Vector2.DistanceSquared(character.SimPosition, leak.SimPosition);
dist = Math.Max(dist / 100.0f, 1.0f);
float priority = AIObjectiveFixLeaks.GetLeakSeverity(leak);
float maxMultiplier = MathHelper.Min(PriorityModifier, 1);
float max = MathHelper.Min((AIObjectiveManager.OrderPriority + 20) * maxMultiplier, 90);
return MathHelper.Clamp(Priority + leakSize / dist, 0, max);
return MathHelper.Clamp(Priority + priority, 0, max);
}
public override bool IsDuplicate(AIObjective otherObjective)
@@ -17,7 +17,7 @@ namespace Barotrauma
protected override void FindTargets()
{
base.FindTargets();
targets.Sort((x, y) => GetGapFixPriority(y).CompareTo(GetGapFixPriority(x)));
targets.Sort((x, y) => GetLeakFixPriority(y).CompareTo(GetLeakFixPriority(x)));
}
protected override bool Filter(Gap gap)
@@ -32,25 +32,27 @@ namespace Barotrauma
return ignore;
}
private float GetGapFixPriority(Gap gap)
private float GetLeakFixPriority(Gap leak)
{
if (gap == null) return 0.0f;
//larger gap -> higher priority
float gapPriority = (gap.IsHorizontal ? gap.Rect.Width : gap.Rect.Height) * gap.Open;
//prioritize gaps that are close
gapPriority /= Math.Max(Vector2.Distance(character.WorldPosition, gap.WorldPosition), 1.0f);
//gaps to outside are much higher priority
if (!gap.IsRoomToRoom) gapPriority *= 10.0f;
return gapPriority;
if (leak == null) { return 0; }
float severity = GetLeakSeverity(leak);
// Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally)
float dist = Math.Abs(character.WorldPosition.X - leak.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - leak.WorldPosition.Y) * 2.0f;
float distanceFactor = MathHelper.Lerp(1, 0.25f, MathUtils.InverseLerp(0, 10000, dist));
return severity * distanceFactor;
}
public static float GetLeakSeverity(Gap leak)
{
if (leak == null) { return 0; }
float sizeFactor = MathHelper.Lerp(1, 10, MathUtils.InverseLerp(0, 200, (leak.IsHorizontal ? leak.Rect.Width : leak.Rect.Height)));
float severity = sizeFactor * leak.Open;
if (!leak.IsRoomToRoom) { severity *= 50; }
return MathHelper.Min(severity, 100);
}
public override bool IsDuplicate(AIObjective otherObjective) => otherObjective is AIObjectiveFixLeaks;
protected override float Average(Gap gap) => gap.Open * 100;
protected override float Average(Gap gap) => GetLeakSeverity(gap);
protected override IEnumerable<Gap> GetList() => Gap.GapList;
protected override AIObjective ObjectiveConstructor(Gap gap) => new AIObjectiveFixLeak(gap, character);
}
@@ -33,7 +33,7 @@ namespace Barotrauma
// Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally)
float dist = Math.Abs(character.WorldPosition.X - Item.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - Item.WorldPosition.Y) * 2.0f;
float distanceFactor = MathHelper.Lerp(1, 0.5f, MathUtils.InverseLerp(0, 10000, dist));
float damagePriority = MathHelper.Lerp(1, 0, (Item.Condition + 10) / Item.MaxCondition);
float damagePriority = MathHelper.Lerp(1, 0, Math.Min((Item.Condition + 10), Item.MaxCondition) / Item.MaxCondition);
float successFactor = MathHelper.Lerp(0, 1, Item.Repairables.Average(r => r.DegreeOfSuccess(character)));
float isSelected = character.SelectedConstruction == Item ? 50 : 0;
float baseLevel = Math.Max(Priority + isSelected, 1);
@@ -2634,6 +2634,10 @@ namespace Barotrauma
GameMain.GameSession?.CrewManager?.RemoveCharacter(this);
#endif
#if CLIENT
GameMain.GameSession?.CrewManager?.RemoveCharacter(this);
#endif
#if CLIENT
GameMain.GameSession?.CrewManager?.RemoveCharacter(this);
#endif