(fc5e081d3) Fixed: Hull names not saving properly in submarineditor

This commit is contained in:
Joonas Rikkonen
2019-05-16 06:31:32 +03:00
parent 50dc08fb56
commit fc22eb5088
24 changed files with 350 additions and 782 deletions
@@ -91,7 +91,8 @@ namespace Barotrauma
}
else
{
if (!character.CanInteractWith(container.Item, out _, checkLinked: false))
if (container.Item.CurrentHull != character.CurrentHull ||
(Vector2.DistanceSquared(character.Position, container.Item.Position) > Math.Pow(container.Item.InteractDistance, 2) && !container.Item.IsInsideTrigger(character.WorldPosition)))
{
TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(container.Item, character, objectiveManager));
return;
@@ -78,7 +78,7 @@ namespace Barotrauma
}
if (itemToDecontain.OwnInventory != character.Inventory && itemToDecontain.ParentInventory != character.Inventory)
{
if (!character.CanInteractWith(container.Item, out _, checkLinked: false))
if (Vector2.DistanceSquared(character.Position, container.Item.Position) > MathUtils.Pow(container.Item.InteractDistance, 2) && !container.Item.IsInsideTrigger(character.WorldPosition))
{
TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(container.Item, character, objectiveManager));
return;
@@ -114,13 +114,12 @@ namespace Barotrauma
{
goToObjective = null;
}
TryAddSubObjective(ref goToObjective,
constructor: () => new AIObjectiveGoTo(bestHull, character, objectiveManager, getDivingGearIfNeeded: false)
TryAddSubObjective(ref goToObjective, () =>
new AIObjectiveGoTo(bestHull, character, objectiveManager, getDivingGearIfNeeded: false)
{
// If we need diving gear, we should already have it, if possible.
AllowGoingOutside = HumanAIController.HasDivingSuit(character)
},
onAbandon: () => unreachable.Add(goToObjective.Target as Hull));
// If we need diving gear, we should already have it, if possible.
AllowGoingOutside = HumanAIController.HasDivingSuit(character)
}, onAbandon: () => unreachable.Add(goToObjective.Target as Hull));
}
}
if (goToObjective != null) { return; }
@@ -725,6 +725,32 @@ namespace Barotrauma
{
#if DEBUG
DebugConsole.ThrowError("AIObjectiveFixLeak failed - the item \"" + weldingTool + "\" has no RepairTool component but is tagged as a welding tool");
#endif
abandon = true;
return;
}
Vector2 gapDiff = Leak.WorldPosition - character.WorldPosition;
// TODO: use the collider size/reach?
if (!character.AnimController.InWater && Math.Abs(gapDiff.X) < 100 && gapDiff.Y < 0.0f && gapDiff.Y > -150)
{
HumanAIController.AnimController.Crouching = true;
}
float reach = ConvertUnits.ToSimUnits(repairTool.Range);
bool canOperate = ConvertUnits.ToSimUnits(gapDiff.Length()) < reach * 1.5f;
if (canOperate)
{
TryAddSubObjective(ref operateObjective, () => new AIObjectiveOperateItem(repairTool, character, objectiveManager, option: "", requireEquip: true, operateTarget: Leak));
}
else
{
TryAddSubObjective(ref gotoObjective, () => new AIObjectiveGoTo(ConvertUnits.ToSimUnits(GetStandPosition()), character, objectiveManager) { CloseEnough = reach * 0.75f });
}
if (subObjectives.Any()) { return; }
var repairTool = weldingTool.GetComponent<RepairTool>();
if (repairTool == null)
{
#if DEBUG
DebugConsole.ThrowError("AIObjectiveFixLeak failed - the item \"" + weldingTool + "\" has no RepairTool component but is tagged as a welding tool");
#endif
abandon = true;
return;
@@ -100,7 +100,8 @@ namespace Barotrauma
objectiveManager.GetObjective<AIObjectiveIdle>()?.Wander(deltaTime);
return;
}
if (character.CanInteractWith(targetItem, out _, checkLinked: false))
if (moveToTarget.CurrentHull == character.CurrentHull &&
Vector2.DistanceSquared(character.Position, moveToTarget.Position) < MathUtils.Pow(targetItem.InteractDistance, 2))
{
if (IsTakenBySomeone(targetItem))
{
@@ -16,11 +16,6 @@ namespace Barotrauma
private float waitUntilPathUnreachable;
private bool getDivingGearIfNeeded;
public Func<bool> customCondition;
/// <summary>
/// Sim units
/// </summary>
public float CloseEnough { get; set; } = 0.5f;
public bool IgnoreIfTargetDead { get; set; }
public bool AllowGoingOutside { get; set; }
@@ -181,35 +176,19 @@ namespace Barotrauma
private bool isCompleted;
public override bool IsCompleted()
{
// First check the distance
// Then the custom condition
// And finally check if can interact (heaviest)
if (repeat) { return false; }
if (isCompleted) { return true; }
bool closeEnough = Vector2.DistanceSquared(Target != null ? Target.SimPosition : targetPos, character.SimPosition) < CloseEnough * CloseEnough;
if (closeEnough)
bool completed = false;
if (Target is Item item)
{
if (customCondition == null || customCondition())
{
if (Target is Item item)
{
if (character.CanInteractWith(item, out _, checkLinked: false)) { isCompleted = true; }
}
else if (Target is Character targetCharacter)
{
if (character.CanInteractWith(targetCharacter, ConvertUnits.ToDisplayUnits(CloseEnough))) { isCompleted = true; }
}
else
{
isCompleted = true;
}
}
if (item.IsInsideTrigger(character.WorldPosition)) { completed = true; }
}
if (isCompleted)
else if (Target is Character targetCharacter)
{
character.AIController.SteeringManager.Reset();
if (character.CanInteractWith(targetCharacter)) { completed = true; }
}
return isCompleted;
completed = completed || Vector2.DistanceSquared(Target != null ? Target.SimPosition : targetPos, character.SimPosition) < CloseEnough * CloseEnough;
if (completed) { character.AIController.SteeringManager.Reset(); }
return completed;
}
public override bool IsDuplicate(AIObjective otherObjective)
@@ -88,6 +88,21 @@ namespace Barotrauma
}
}
public override void Update(float deltaTime)
{
if (objectiveManager.CurrentObjective == this)
{
if (randomTimer > 0)
{
randomTimer -= deltaTime;
}
else
{
SetRandom();
}
}
}
public override bool IsCompleted() => false;
public override bool CanBeCompleted => true;
@@ -316,8 +331,16 @@ namespace Barotrauma
{
if (hull == null) { return true; }
string hullName = hull.RoomName?.ToLowerInvariant();
if (hullName == null) { return false; }
return hullName.Contains("ballast") || hullName.Contains("airlock");
bool isForbidden = hullName == "ballast" || hullName == "airlock";
foreach (Item item in Item.ItemList)
{
if (item.CurrentHull == hull && (item.HasTag("ballast") || item.HasTag("airlock")))
{
isForbidden = true;
break;
}
}
return isForbidden;
}
public override bool IsDuplicate(AIObjective otherObjective)
@@ -67,7 +67,9 @@ namespace Barotrauma
}
if (target.CanBeSelected)
{
if (character.CanInteractWith(target.Item, out _, checkLinked: false))
bool inSameRoom = character.CurrentHull == target.Item.CurrentHull;
bool withinReach = target.Item.IsInsideTrigger(character.WorldPosition) || Vector2.DistanceSquared(character.Position, target.Item.Position) < MathUtils.Pow(target.Item.InteractDistance, 2);
if (inSameRoom && withinReach)
{
if (character.SelectedConstruction != target.Item)
{
@@ -529,6 +531,10 @@ namespace Barotrauma
{
isCompleted = true;
}
if (component.AIOperate(deltaTime, character, this))
{
isCompleted = true;
}
}
else
{
@@ -113,7 +113,7 @@ namespace Barotrauma
return;
}
}
if (character.CanInteractWith(Item, out _, checkLinked: false))
if (character.CurrentHull == Item.CurrentHull && character.CanInteractWith(Item))
{
if (repairTool != null)
{