(d9fd52f40) Change the priority calculations for charge batteries and pump water loops. Tweak the operate item priority calculation.

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:17:42 +03:00
parent c9bfc21880
commit cbfef49e9d
11 changed files with 389 additions and 72 deletions
@@ -1,7 +1,9 @@
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
@@ -34,10 +36,30 @@ namespace Barotrauma
if (item.Submarine.TeamID != character.TeamID) { return false; }
if (item.ConditionPercentage <= 0) { return false; }
if (character.Submarine != null && !character.Submarine.IsEntityFoundOnThisSub(item, true)) { return false; }
if (Option == "charge")
{
if (battery.RechargeRatio >= PowerContainer.aiRechargeTargetRatio) { return false; }
}
else
{
if (battery.RechargeRatio <= 0) { return false; }
}
return true;
}
protected override float TargetEvaluation() => targets.Max(t => 100 - t.ChargePercentage);
protected override float TargetEvaluation()
{
if (Option == "charge")
{
return targets.Max(t => MathHelper.Lerp(100, 0, Math.Abs(PowerContainer.aiRechargeTargetRatio - t.RechargeRatio)));
}
else
{
return targets.Max(t => MathHelper.Lerp(0, 100, t.RechargeRatio));
}
}
protected override IEnumerable<PowerContainer> GetList()
{
if (batteryList == null)
@@ -51,7 +51,7 @@ namespace Barotrauma
return AIObjectiveManager.OrderPriority;
}
float devotion = MathHelper.Min(10, Priority);
float value = (devotion + AIObjectiveManager.OrderPriority / 2) * PriorityModifier;
float value = devotion + AIObjectiveManager.OrderPriority * PriorityModifier;
float max = MathHelper.Min((AIObjectiveManager.OrderPriority - 1), 90);
return MathHelper.Clamp(value, 0, max);
}
@@ -1,4 +1,5 @@
using Barotrauma.Items.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
@@ -38,11 +39,10 @@ namespace Barotrauma
else
{
if (!pump.Item.InWater) { return false; }
if (pump.IsActive && pump.FlowPercentage <= -90.0f) { return false; }
if (pump.IsActive && pump.FlowPercentage <= -100.0f) { return false; }
}
return true;
}
protected override float TargetEvaluation() => targets.Max(t => MathHelper.Lerp(100, 0, t.CurrFlow / t.MaxFlow));
protected override IEnumerable<Pump> GetList()
{
if (pumpList == null)
@@ -53,5 +53,16 @@ namespace Barotrauma
}
protected override AIObjective ObjectiveConstructor(Pump pump) => new AIObjectiveOperateItem(pump, character, objectiveManager, Option, false) { IsLoop = false };
protected override float TargetEvaluation()
{
if (Option == "stoppumping")
{
return targets.Max(t => MathHelper.Lerp(0, 100, Math.Abs(t.FlowPercentage / 100)));
}
else
{
return targets.Max(t => MathHelper.Lerp(100, 0, Math.Abs(-t.FlowPercentage / 100)));
}
}
}
}