v0.14.6.0

This commit is contained in:
Joonas Rikkonen
2021-06-17 17:54:52 +03:00
parent 3f324b14e8
commit c27e2ea5ab
348 changed files with 13156 additions and 4266 deletions
@@ -57,6 +57,11 @@ namespace Barotrauma.Items.Components
private Submarine controlledSub;
// AI interfacing
public Vector2 AITacticalTarget { get; set; }
public float AIRamTimer { get; set; }
bool navigateTactically; // this will be removed after rewriting steering to use an enum
private bool showIceSpireWarning;
private List<Submarine> connectedSubs = new List<Submarine>();
@@ -305,7 +310,13 @@ namespace Barotrauma.Items.Components
userSkill = user.GetSkillLevel("helm") / 100.0f;
}
if (AutoPilot)
// override autopilot pathing while the AI rams, and go full speed ahead
if (AIRamTimer > 0f)
{
AIRamTimer -= deltaTime;
TargetVelocity = GetSteeringVelocity(AITacticalTarget, 0f);
}
else if (AutoPilot)
{
UpdateAutoPilot(deltaTime);
float throttle = 1.0f;
@@ -352,6 +363,14 @@ namespace Barotrauma.Items.Components
float velY = MathHelper.Lerp((neutralBallastLevel * 100 - 50) * 2, -100 * Math.Sign(targetVelocity.Y), Math.Abs(targetVelocity.Y) / 100.0f);
item.SendSignal(new Signal(velY.ToString(CultureInfo.InvariantCulture), sender: user), "velocity_y_out");
// if our tactical AI pilot has left, revert back to maintaining position
if (navigateTactically && (user == null || user.SelectedConstruction != item))
{
navigateTactically = false;
AIRamTimer = 0f;
SetMaintainPosition();
}
}
private void IncreaseSkillLevel(Character user, float deltaTime)
@@ -580,13 +599,18 @@ namespace Barotrauma.Items.Components
}
Vector2 target;
if (LevelEndSelected)
if (navigateTactically)
{
target = ConvertUnits.ToSimUnits(Level.Loaded.EndPosition);
target = ConvertUnits.ToSimUnits(AITacticalTarget);
}
else if (LevelEndSelected)
{
target = ConvertUnits.ToSimUnits(Level.Loaded.EndExitPosition);
}
else
{
target = ConvertUnits.ToSimUnits(Level.Loaded.StartPosition);
target = ConvertUnits.ToSimUnits(Level.Loaded.StartExitPosition);
}
steeringPath = pathFinder.FindPath(ConvertUnits.ToSimUnits(controlledSub == null ? item.WorldPosition : controlledSub.WorldPosition), target, errorMsgStr: "(Autopilot, target: " + target + ")");
}
@@ -597,6 +621,7 @@ namespace Barotrauma.Items.Components
MaintainPos = false;
posToMaintain = null;
LevelEndSelected = false;
navigateTactically = false;
if (!LevelStartSelected)
{
LevelStartSelected = true;
@@ -610,6 +635,7 @@ namespace Barotrauma.Items.Components
MaintainPos = false;
posToMaintain = null;
LevelStartSelected = false;
navigateTactically = false;
if (!LevelEndSelected)
{
LevelEndSelected = true;
@@ -617,6 +643,36 @@ namespace Barotrauma.Items.Components
}
}
private void SetDestinationTactical()
{
AutoPilot = true;
MaintainPos = false;
posToMaintain = null;
LevelStartSelected = false;
LevelEndSelected = false;
if (!navigateTactically)
{
navigateTactically = true;
UpdatePath();
}
}
private void SetMaintainPosition()
{
if (!MaintainPos)
{
unsentChanges = true;
MaintainPos = true;
}
if (!posToMaintain.HasValue)
{
unsentChanges = true;
posToMaintain = controlledSub != null ?
controlledSub.WorldPosition :
item.Submarine == null ? item.WorldPosition : item.Submarine.WorldPosition;
}
}
/// <summary>
/// Get optimal velocity for moving towards a position
/// </summary>
@@ -640,6 +696,7 @@ namespace Barotrauma.Items.Components
public override bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective)
{
character.AIController.SteeringManager.Reset();
if (objective.Override)
{
if (user != character && user != null && user.SelectedConstruction == item && character.IsOnPlayerTeam)
@@ -648,6 +705,20 @@ namespace Barotrauma.Items.Components
}
}
user = character;
if (Item.ConditionPercentage <= 0 && AIObjectiveRepairItems.IsValidTarget(Item, character))
{
if (Item.Repairables.Average(r => r.DegreeOfSuccess(character)) > 0.4f)
{
objective.AddSubObjective(new AIObjectiveRepairItem(character, Item, objective.objectiveManager, isPriority: true));
return false;
}
else
{
character.Speak(TextManager.Get("DialogNavTerminalIsBroken"), identifier: "navterminalisbroken", minDurationBetweenSimilar: 30.0f);
}
}
if (!AutoPilot)
{
unsentChanges = true;
@@ -659,18 +730,7 @@ namespace Barotrauma.Items.Components
case "maintainposition":
if (objective.Override)
{
if (!MaintainPos)
{
unsentChanges = true;
MaintainPos = true;
}
if (!posToMaintain.HasValue)
{
unsentChanges = true;
posToMaintain = controlledSub != null ?
controlledSub.WorldPosition :
item.Submarine == null ? item.WorldPosition : item.Submarine.WorldPosition;
}
SetMaintainPosition();
}
break;
case "navigateback":
@@ -681,7 +741,7 @@ namespace Barotrauma.Items.Components
}
if (objective.Override)
{
if (MaintainPos || LevelEndSelected || !LevelStartSelected)
if (MaintainPos || LevelEndSelected || !LevelStartSelected || navigateTactically)
{
unsentChanges = true;
}
@@ -696,13 +756,28 @@ namespace Barotrauma.Items.Components
}
if (objective.Override)
{
if (MaintainPos || !LevelEndSelected || LevelStartSelected)
if (MaintainPos || !LevelEndSelected || LevelStartSelected || navigateTactically)
{
unsentChanges = true;
}
SetDestinationLevelEnd();
}
break;
case "navigatetactical":
if (Level.IsLoadedOutpost) { break; }
if (DockingSources.Any(d => d.Docked))
{
item.SendSignal("1", "toggle_docking");
}
if (objective.Override)
{
if (MaintainPos || LevelEndSelected || LevelStartSelected || !navigateTactically)
{
unsentChanges = true;
}
SetDestinationTactical();
}
break;
}
sonar?.AIOperate(deltaTime, character, objective);
if (!MaintainPos && showIceSpireWarning && character.IsOnPlayerTeam)