(39bf46af8) Don't wait when find safety or combat is active.

This commit is contained in:
Joonas Rikkonen
2019-05-16 06:53:21 +03:00
parent 5453518793
commit f2e936e4d3
12 changed files with 195 additions and 116 deletions
@@ -152,6 +152,32 @@ namespace Barotrauma
} }
if (character.MemLocalState.Count > 120) character.MemLocalState.RemoveRange(0, character.MemLocalState.Count - 120);
character.MemState.Clear();
}
}
partial void ImpactProjSpecific(float impact, Body body)
{
float volume = MathHelper.Clamp(impact - 3.0f, 0.5f, 1.0f);
if (body.UserData is Limb limb && character.Stun <= 0f)
{
if (impact > 3.0f) { PlayImpactSound(limb); }
}
else if (body.UserData is Limb || body == Collider.FarseerBody)
{
if (!character.IsRemotePlayer && impact > ImpactTolerance)
{
SoundPlayer.PlayDamageSound("LimbBlunt", strongestImpact, Collider);
}
}
if (Character.Controlled == character)
{
GameMain.GameScreen.Cam.Shake = Math.Min(Math.Max(strongestImpact, GameMain.GameScreen.Cam.Shake), 3.0f);
}
}
if (character.MemState.Count < 1) return; if (character.MemState.Count < 1) return;
overrideTargetMovement = Vector2.Zero; overrideTargetMovement = Vector2.Zero;
@@ -75,37 +75,25 @@ namespace Barotrauma
public CrewManager(XElement element, bool isSinglePlayer) public CrewManager(XElement element, bool isSinglePlayer)
: this(isSinglePlayer) : this(isSinglePlayer)
{ {
return characterListBox.Rect; guiFrame = new GUIFrame(new RectTransform(Vector2.One, GUICanvas.Instance), null, Color.Transparent)
}
public IEnumerable<Character> GetCharacters()
{
return characterListBox.Rect;
}
public IEnumerable<CharacterInfo> GetCharacterInfos()
{
return characterListBox.Rect;
}
public void AddCharacter(Character character)
{
if (character.Removed)
{ {
DebugConsole.ThrowError("Tried to add a removed character to CrewManager!\n" + Environment.StackTrace); CanBeFocused = false
return; };
}
if (character.IsDead)
{
DebugConsole.ThrowError("Tried to add a dead character to CrewManager!\n" + Environment.StackTrace);
return;
}
if (!characters.Contains(character)) characters.Add(character); Point scrollButtonSize = new Point((int)(200 * GUI.Scale), (int)(30 * GUI.Scale));
if (!characterInfos.Contains(character.Info))
crewArea = new GUIFrame(HUDLayoutSettings.ToRectTransform(HUDLayoutSettings.CrewArea, guiFrame.RectTransform), "", Color.Transparent)
{ {
characterInfos.Add(character.Info); CanBeFocused = false
} };
toggleCrewButton = new GUIButton(new RectTransform(new Point((int)(30 * GUI.Scale), HUDLayoutSettings.CrewArea.Height), guiFrame.RectTransform)
{ AbsoluteOffset = HUDLayoutSettings.CrewArea.Location },
"", style: "UIToggleButton");
toggleCrewButton.OnClicked += (GUIButton btn, object userdata) =>
{
ToggleCrewAreaOpen = !ToggleCrewAreaOpen;
return true;
};
var characterInfo = new CharacterInfo(subElement); var characterInfo = new CharacterInfo(subElement);
characterInfos.Add(characterInfo); characterInfos.Add(characterInfo);
@@ -266,6 +254,11 @@ namespace Barotrauma
} }
public IEnumerable<Character> GetCharacters() public IEnumerable<Character> GetCharacters()
{
return characterListBox.Rect;
}
public IEnumerable<CharacterInfo> GetCharacterInfos()
{ {
if (characterInfos.Contains(characterInfo)) if (characterInfos.Contains(characterInfo))
{ {
@@ -276,17 +269,6 @@ namespace Barotrauma
characterInfos.Add(characterInfo); characterInfos.Add(characterInfo);
} }
public IEnumerable<CharacterInfo> GetCharacterInfos()
{
if (character == null)
{
DebugConsole.ThrowError("Tried to remove a null character from CrewManager.\n" + Environment.StackTrace);
return;
}
characters.Remove(character);
if (removeInfo) characterInfos.Remove(character.Info);
}
public void AddCharacter(Character character) public void AddCharacter(Character character)
{ {
if (character.Removed) if (character.Removed)
@@ -659,41 +641,19 @@ namespace Barotrauma
characterListBox.BarScroll = roundedPos; characterListBox.BarScroll = roundedPos;
} }
var toggleWrongOrderBtn = new GUIButton(new RectTransform(new Point((int)(30 * GUI.Scale), wrongOrderList.Rect.Height), wrongOrderList.Content.RectTransform), CreateCharacterFrame(character, characterListBox.Content);
"", style: "UIToggleButton") characterListBox.Content.RectTransform.SortChildren((c1, c2) => { return c2.NonScaledSize.X - c1.NonScaledSize.X; });
if (character is AICharacter)
{ {
UserData = "togglewrongorder", var ai = character.AIController as HumanAIController;
CanBeFocused = false if (ai == null)
}; {
DebugConsole.ThrowError("Error in crewmanager - attempted to give orders to a character with no HumanAIController");
wrongOrderList.RectTransform.NonScaledSize = new Point( return;
wrongOrderList.Content.Children.Sum(c => c.Rect.Width + wrongOrderList.Spacing), }
wrongOrderList.RectTransform.NonScaledSize.Y); character.SetOrder(ai.CurrentOrder, "", null, false);
wrongOrderList.RectTransform.SetAsLastChild(); }
new GUIFrame(new RectTransform(new Point(
wrongOrderList.Rect.Width - toggleWrongOrderBtn.Rect.Width - wrongOrderList.Spacing * 2,
wrongOrderList.Rect.Height), wrongOrderList.Content.RectTransform),
style: null)
{
CanBeFocused = false
};
//scale to fit the content
orderButtonFrame.RectTransform.NonScaledSize = new Point(
orderButtonFrame.Children.Sum(c => c.Rect.Width + orderButtonFrame.AbsoluteSpacing),
orderButtonFrame.RectTransform.NonScaledSize.Y);
frame.RectTransform.NonScaledSize = new Point(
characterInfoWidth + spacing + (orderButtonFrame.Rect.Width - wrongOrderList.Rect.Width),
frame.RectTransform.NonScaledSize.Y);
characterListBox.RectTransform.NonScaledSize = new Point(
characterListBox.Content.Children.Max(c => c.Rect.Width) + wrongOrderList.Rect.Width,
characterListBox.RectTransform.NonScaledSize.Y);
characterListBox.Content.RectTransform.NonScaledSize = characterListBox.RectTransform.NonScaledSize;
characterListBox.UpdateScrollBarSize();
return frame;
} }
private IEnumerable<object> KillCharacterAnim(GUIComponent component) private IEnumerable<object> KillCharacterAnim(GUIComponent component)
@@ -714,6 +714,8 @@ namespace Barotrauma
private GUILayoutGroup subPreviewContainer; private GUILayoutGroup subPreviewContainer;
private GUILayoutGroup subPreviewContainer;
private GUIButton loadGameButton; private GUIButton loadGameButton;
public Action<Submarine, string, string> StartNewGame; public Action<Submarine, string, string> StartNewGame;
@@ -335,6 +335,32 @@ namespace Barotrauma
{ {
#if DEBUG #if DEBUG
DebugConsole.ThrowError("AIObjectiveFixLeak failed - the item \"" + weldingTool + "\" has no RepairTool component but is tagged as a welding tool"); 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 #endif
abandon = true; abandon = true;
return; return;
@@ -74,36 +74,6 @@ namespace Barotrauma
} }
} }
public override void Update(float deltaTime)
{
if (objectiveManager.CurrentObjective == this)
{
if (randomTimer > 0)
{
randomTimer -= deltaTime;
}
else
{
SetRandom();
}
}
}
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 IsCompleted() => false;
public override bool CanBeCompleted => true; public override bool CanBeCompleted => true;
@@ -18,10 +18,26 @@ namespace Barotrauma
private Character character; private Character character;
private float _waitTimer;
/// <summary> /// <summary>
/// When set above zero, the character will stand still doing nothing until the timer runs out. Does not affect orders. /// When set above zero, the character will stand still doing nothing until the timer runs out. Does not affect orders, find safety or combat.
/// </summary> /// </summary>
public float WaitTimer; public float WaitTimer
{
get { return _waitTimer; }
set
{
if (CurrentObjective is AIObjectiveCombat || CurrentObjective is AIObjectiveFindSafety)
{
_waitTimer = 0;
}
else
{
_waitTimer = value;
}
}
}
public AIObjective CurrentOrder { get; private set; } public AIObjective CurrentOrder { get; private set; }
public AIObjective CurrentObjective { get; private set; } public AIObjective CurrentObjective { get; private set; }
@@ -197,6 +213,7 @@ namespace Barotrauma
} }
else else
{ {
// Wait, if not swimming, climbing, or staying in a forbidden/unsafe hull.
if (character.AIController is HumanAIController humanAI && humanAI.SteeringManager != null) if (character.AIController is HumanAIController humanAI && humanAI.SteeringManager != null)
{ {
if (!character.AnimController.InWater && if (!character.AnimController.InWater &&
@@ -829,6 +829,10 @@ namespace Barotrauma
{ {
isCompleted = true; isCompleted = true;
} }
if (component.AIOperate(deltaTime, character, this))
{
isCompleted = true;
}
} }
else else
{ {
@@ -1145,6 +1145,15 @@ namespace Barotrauma
SmoothedCursorPosition = cursorPosition - smoothedCursorDiff; SmoothedCursorPosition = cursorPosition - smoothedCursorDiff;
} }
if (!(this is AICharacter) || Controlled == this || IsRemotePlayer)
{
//apply some smoothing to the cursor positions of remote players when playing as a client
//to make aiming look a little less choppy
Vector2 smoothedCursorDiff = cursorPosition - SmoothedCursorPosition;
smoothedCursorDiff = NetConfig.InterpolateCursorPositionError(smoothedCursorDiff);
SmoothedCursorPosition = cursorPosition - smoothedCursorDiff;
}
if (!(this is AICharacter) || Controlled == this || IsRemotePlayer) if (!(this is AICharacter) || Controlled == this || IsRemotePlayer)
{ {
if (speedMultipliers.Count == 0) return 1f; if (speedMultipliers.Count == 0) return 1f;
@@ -848,6 +848,25 @@ namespace Barotrauma.Items.Components
} }
} }
if (targetItem.Prefab.DeconstructItems.Any())
{
inputContainer.Inventory.RemoveItem(targetItem);
Entity.Spawner.AddToRemoveQueue(targetItem);
MoveInputQueue();
PutItemsToLinkedContainer();
}
else
{
if (outputContainer.Inventory.Items.All(i => i != null))
{
targetItem.Drop(dropper: null);
}
else
{
outputContainer.Inventory.TryPutItem(targetItem, user: null, createNetworkEvent: true);
}
}
if (targetItem.Prefab.DeconstructItems.Any()) if (targetItem.Prefab.DeconstructItems.Any())
{ {
inputContainer.Inventory.RemoveItem(targetItem); inputContainer.Inventory.RemoveItem(targetItem);
@@ -144,17 +144,6 @@ namespace Barotrauma.Items.Components
} }
} }
public Vector2 SteeringInput
{
get { return steeringInput; }
set
{
if (!MathUtils.IsValid(value)) return;
steeringInput.X = MathHelper.Clamp(value.X, -100.0f, 100.0f);
steeringInput.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f);
}
}
public SteeringPath SteeringPath public SteeringPath SteeringPath
{ {
if (!CanBeSelected) return false; if (!CanBeSelected) return false;
@@ -175,6 +164,12 @@ namespace Barotrauma.Items.Components
set { posToMaintain = value; } set { posToMaintain = value; }
} }
public Vector2? PosToMaintain
{
get { return posToMaintain; }
set { posToMaintain = value; }
}
struct ObstacleDebugInfo struct ObstacleDebugInfo
{ {
public Vector2 Point1; public Vector2 Point1;
@@ -1139,6 +1139,38 @@ namespace Barotrauma
} }
} }
public void UpdateTransform()
{
Submarine prevSub = Submarine;
FindHull();
if (Submarine == null && prevSub != null)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub == null)
{
body.SetTransform(body.SimPosition - Submarine.SimPosition, body.Rotation);
}
else if (Submarine != null && prevSub != null && Submarine != prevSub)
{
body.SetTransform(body.SimPosition + prevSub.SimPosition - Submarine.SimPosition, body.Rotation);
}
Vector2 displayPos = ConvertUnits.ToDisplayUnits(body.SimPosition);
rect.X = (int)(displayPos.X - rect.Width / 2.0f);
rect.Y = (int)(displayPos.Y + rect.Height / 2.0f);
if (Math.Abs(body.LinearVelocity.X) > NetConfig.MaxPhysicsBodyVelocity ||
Math.Abs(body.LinearVelocity.Y) > NetConfig.MaxPhysicsBodyVelocity)
{
body.LinearVelocity = new Vector2(
MathHelper.Clamp(body.LinearVelocity.X, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity),
MathHelper.Clamp(body.LinearVelocity.Y, -NetConfig.MaxPhysicsBodyVelocity, NetConfig.MaxPhysicsBodyVelocity));
}
}
public void UpdateTransform() public void UpdateTransform()
{ {
Submarine prevSub = Submarine; Submarine prevSub = Submarine;
@@ -364,6 +364,25 @@ namespace Barotrauma
} }
} }
public string DisplayName
{
get;
private set;
}
private string roomName;
[Editable, Serialize("", true, translationTextTag: "RoomName.")]
public string RoomName
{
get { return roomName; }
set
{
if (roomName == value) { return; }
roomName = value;
DisplayName = TextManager.Get(roomName, returnNull: true) ?? roomName;
}
}
public override Rectangle Rect public override Rectangle Rect
{ {
get get