diff --git a/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg b/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg index 279894262..687a31cc6 100644 Binary files a/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg and b/Subsurface/Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg differ diff --git a/Subsurface/Source/Characters/AI/CrewCommander.cs b/Subsurface/Source/Characters/AI/CrewCommander.cs index f0c16c399..7840b6b54 100644 --- a/Subsurface/Source/Characters/AI/CrewCommander.cs +++ b/Subsurface/Source/Characters/AI/CrewCommander.cs @@ -15,6 +15,8 @@ namespace Barotrauma GUIFrame frame; //GUIListBox characterList; + private int characterFrameBottom; + public GUIFrame Frame { get { return IsOpen ? frame : null; } @@ -29,7 +31,6 @@ namespace Barotrauma public CrewCommander(CrewManager crewManager) { this.crewManager = crewManager; - } public void ToggleGUIFrame() @@ -47,20 +48,19 @@ namespace Barotrauma { frame = new GUIFrame(Rectangle.Empty, Color.Black * 0.6f); frame.Padding = new Vector4(200.0f, 100.0f, 200.0f, 100.0f); - + //UpdateCharacters(); int buttonWidth = 130; int spacing = 20; - int y = 250; + int y = 50; for (int n = 0; n<2; n++) - { - + { List orders = (n==0) ? Order.PrefabList.FindAll(o => o.ItemComponentType == null) : - Order.PrefabList.FindAll(o=> o.ItemComponentType!=null); + Order.PrefabList.FindAll(o=> o.ItemComponentType != null); int startX = (int)-(buttonWidth * orders.Count + spacing * (orders.Count - 1)) / 2; @@ -117,7 +117,7 @@ namespace Barotrauma public void UpdateCharacters() { - if (frame == null) CreateGUIFrame(); + CreateGUIFrame(); List prevCharacterFrames = new List(); foreach (GUIComponent child in frame.children) @@ -134,18 +134,19 @@ namespace Barotrauma List aliveCharacters = crewManager.characters.FindAll(c => !c.IsDead); + characterFrameBottom = 0; + int charactersPerRow = 4; int spacing = 5; - int rows = (int)Math.Ceiling((double)aliveCharacters.Count / charactersPerRow); int i = 0; foreach (Character character in aliveCharacters) { int rowCharacterCount = Math.Min(charactersPerRow, aliveCharacters.Count); - if (aliveCharacters.Count - i < charactersPerRow-1) rowCharacterCount = aliveCharacters.Count % charactersPerRow; + //if (i >= aliveCharacters.Count - charactersPerRow && aliveCharacters.Count % charactersPerRow > 0) rowCharacterCount = aliveCharacters.Count % charactersPerRow; // rowCharacterCount = Math.Min(rowCharacterCount, aliveCharacters.Count - i); int startX = (int)-(150 * rowCharacterCount + spacing * (rowCharacterCount - 1)) / 2; @@ -159,12 +160,13 @@ namespace Barotrauma characterButton.UserData = character; characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); - characterButton.Color = Character.Controlled == character ? Color.Gold * 0.3f : Color.Black * 0.5f; + characterButton.Color = Character.Controlled == character ? Color.Gold * 0.2f : Color.Black * 0.5f; characterButton.HoverColor = Color.LightGray * 0.5f; - characterButton.SelectedColor = Color.Gold * 0.5f; + characterButton.SelectedColor = Color.Gold * 0.6f; characterButton.OutlineColor = Color.LightGray * 0.8f; - + characterFrameBottom = Math.Max(characterFrameBottom, characterButton.Rect.Bottom); + string name = character.Info.Name; if (character.Info.Job != null) name += '\n' + "(" + character.Info.Job.Name + ")"; @@ -187,6 +189,16 @@ namespace Barotrauma i++; } + + foreach (GUIComponent child in frame.children) + { + if (!(child.UserData is Order)) continue; + + Rectangle rect = child.Rect; + rect.Y += characterFrameBottom; + + child.Rect = rect; + } } private bool SetOrder(GUIButton button, object userData) @@ -225,12 +237,22 @@ namespace Barotrauma var existingOrder = characterFrame.children.Find(c => c.UserData as Order != null); if (existingOrder != null) characterFrame.RemoveChild(existingOrder); - var orderFrame = new GUIFrame(new Rectangle(0, characterFrame.Rect.Height, 0, 30 + order.Options.Length * 15), null, characterFrame); - orderFrame.OutlineColor = Color.LightGray * 0.8f; + var orderFrame = new GUIFrame(new Rectangle(-5, characterFrame.Rect.Height, characterFrame.Rect.Width, 30 + order.Options.Length * 15), null, characterFrame); + orderFrame.OutlineColor = Color.LightGray * 0.5f; orderFrame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); orderFrame.UserData = order; + + var img = new GUIImage(new Rectangle(0, 0, 20, 20), order.SymbolSprite, Alignment.TopLeft, orderFrame); + img.Scale = 20.0f / img.SourceRect.Width; + img.Color = order.Color; + img.CanBeFocused = false; + new GUITextBlock(new Rectangle(0, 0, 0, 20), order.DoingText, GUI.Style, Alignment.TopLeft, Alignment.TopCenter, orderFrame); + + + + var optionList = new GUIListBox(new Rectangle(0, 20, 0, 80), Color.Transparent, null, orderFrame); optionList.UserData = order; diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 071b31981..b25c80a05 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -289,7 +289,7 @@ namespace Barotrauma updateTargetsTimer = Math.Min(updateTargetsTimer, 0.1f); coolDownTimer *= 0.1f; - if (amount > 1.0f && attackWhenProvoked) + if (amount > 0.1f && attackWhenProvoked) { attackHumans = 100.0f; attackRooms = 100.0f; diff --git a/Subsurface/Source/Characters/AI/HumanAIController.cs b/Subsurface/Source/Characters/AI/HumanAIController.cs index 33254c705..8cd603126 100644 --- a/Subsurface/Source/Characters/AI/HumanAIController.cs +++ b/Subsurface/Source/Characters/AI/HumanAIController.cs @@ -38,6 +38,14 @@ namespace Barotrauma objectiveManager.AddObjective(new AIObjectiveIdle(c)); updateObjectiveTimer = Rand.Range(0.0f, UpdateObjectiveInterval); + + if (GameMain.GameSession!=null && GameMain.GameSession.CrewManager!=null) + { + CurrentOrder = Order.PrefabList.Find(o => o.Name.ToLower() == "dismissed"); + objectiveManager.SetOrder(CurrentOrder, ""); + GameMain.GameSession.CrewManager.SetCharacterOrder(Character, CurrentOrder); + } + } public override void Update(float deltaTime) @@ -87,6 +95,8 @@ namespace Barotrauma if (Character.IsKeyDown(InputType.Aim)) { Character.AnimController.TargetDir = Character.CursorPosition.X > Character.Position.X ? Direction.Right : Direction.Left; + if (Character.SelectedConstruction != null) Character.SelectedConstruction.SecondaryUse(deltaTime, Character); + } else if (Math.Abs(Character.AnimController.TargetMovement.X) > 0.1f && !Character.AnimController.InWater) { @@ -110,6 +120,8 @@ namespace Barotrauma CurrentOrderOption = option; CurrentOrder = order; objectiveManager.SetOrder(order, option); + + GameMain.GameSession.CrewManager.SetCharacterOrder(Character, order); } public override void SelectTarget(AITarget target) diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs index 27f3f894c..e841ebea6 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGetItem.cs @@ -101,6 +101,9 @@ namespace Barotrauma { currSearchIndex++; + //don't try to get items from outside the sub + if (Item.ItemList[currSearchIndex].CurrentHull == null) continue; + if (!Item.ItemList[currSearchIndex].HasTag(itemName) && Item.ItemList[currSearchIndex].Name != itemName) continue; if (IgnoreContainedItems && Item.ItemList[currSearchIndex].Container != null) continue; if (Item.ItemList[currSearchIndex].Inventory is CharacterInventory) continue; diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs index 9bc4de679..a77535b64 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs @@ -59,7 +59,12 @@ namespace Barotrauma protected override void Act(float deltaTime) { - if (target == character) return; + if (target == character) + { + character.AIController.SteeringManager.Reset(); + + return; + } waitUntilPathUnreachable -= deltaTime; @@ -116,7 +121,7 @@ namespace Barotrauma completed = completed || Vector2.Distance(target != null ? target.SimPosition : targetPos, character.SimPosition) < allowedDistance; - if (completed) character.AIController.SteeringManager.SteeringManual(0.0f, -character.AIController.Steering); + if (completed) character.AIController.SteeringManager.Reset(); return completed; } diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs index a374efec6..2f32477d3 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveManager.cs @@ -70,6 +70,8 @@ namespace Barotrauma public void SetOrder(Order order, string option) { + if (order == null) return; + currentObjective = null; switch (order.Name.ToLower()) diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs index a820b237f..443a0079e 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveOperateItem.cs @@ -9,7 +9,7 @@ namespace Barotrauma { class AIObjectiveOperateItem : AIObjective { - private ItemComponent component; + private ItemComponent component, controller; private Entity operateTarget; @@ -33,14 +33,14 @@ namespace Barotrauma public AIObjectiveOperateItem(ItemComponent item, Character character, string option, Entity operateTarget = null, bool useController = false) :base (character, option) { - component = item; + this.component = item; this.operateTarget = operateTarget; if (useController) { var controllers = item.Item.GetConnectedComponents(); - if (controllers.Any()) component = controllers[0]; + if (controllers.Any()) controller = controllers[0]; } @@ -49,21 +49,23 @@ namespace Barotrauma protected override void Act(float deltaTime) { - if (component.CanBeSelected) + ItemComponent target = controller == null ? component : controller; + + if (target.CanBeSelected) { - if (Vector2.Distance(character.Position, component.Item.Position) < component.Item.PickDistance - || component.Item.IsInsideTrigger(character.WorldPosition)) + if (Vector2.Distance(character.Position, target.Item.Position) < target.Item.PickDistance + || target.Item.IsInsideTrigger(character.WorldPosition)) { - if (character.SelectedConstruction != component.Item && component.CanBeSelected) + if (character.SelectedConstruction != target.Item && target.CanBeSelected) { - component.Item.Pick(character, false, true); + target.Item.Pick(character, false, true); } if (component.AIOperate(deltaTime, character, this)) isCompleted = true; return; } - AddSubObjective(new AIObjectiveGoTo(component.Item, character)); + AddSubObjective(new AIObjectiveGoTo(target.Item, character)); } else { diff --git a/Subsurface/Source/Characters/AI/SteeringManager.cs b/Subsurface/Source/Characters/AI/SteeringManager.cs index d523e492e..e61202d60 100644 --- a/Subsurface/Source/Characters/AI/SteeringManager.cs +++ b/Subsurface/Source/Characters/AI/SteeringManager.cs @@ -55,6 +55,11 @@ namespace Barotrauma steering += velocity; } + public void Reset() + { + steering = Vector2.Zero; + } + public virtual void Update(float speed = 1.0f) { float steeringSpeed = steering.Length(); diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index da1716e5d..bc658485a 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -553,10 +553,12 @@ namespace Barotrauma if (newHull == null && currentHull.Submarine != null) { SetPosition(refLimb.SimPosition + ConvertUnits.ToSimUnits(currentHull.Submarine.Position)); + character.CursorPosition += currentHull.Submarine.Position; } else if (currentHull == null && newHull != null && newHull.Submarine != null) { SetPosition(refLimb.SimPosition - ConvertUnits.ToSimUnits(newHull.Submarine.Position)); + character.CursorPosition -= newHull.Submarine.Position; } } diff --git a/Subsurface/Source/GUI/GUIImage.cs b/Subsurface/Source/GUI/GUIImage.cs index 0ec950dd9..1fb92135a 100644 --- a/Subsurface/Source/GUI/GUIImage.cs +++ b/Subsurface/Source/GUI/GUIImage.cs @@ -71,8 +71,8 @@ namespace Barotrauma this.sourceRect = sourceRect; - if (parent != null) - parent.AddChild(this); + if (parent != null) parent.AddChild(this); + this.parent = parent; } public override void Draw(SpriteBatch spriteBatch) diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index 2d36c0708..d5d39643d 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -16,7 +16,7 @@ namespace Barotrauma private int money; private GUIFrame guiFrame; - private GUIListBox listBox; + private GUIListBox listBox, orderListBox; private bool crewFrameOpen; private GUIButton crewButton; @@ -37,11 +37,15 @@ namespace Barotrauma guiFrame = new GUIFrame(new Rectangle(0, 50, 150, 450), Color.Transparent); - listBox = new GUIListBox(new Rectangle(0, 30, 150, 0), Color.Transparent, null, guiFrame); + listBox = new GUIListBox(new Rectangle(45, 30, 150, 0), Color.Transparent, null, guiFrame); listBox.ScrollBarEnabled = false; listBox.OnSelected = SelectCharacter; - crewButton = new GUIButton(new Rectangle(0, 00, 100, 20), "Crew", GUI.Style, guiFrame); + orderListBox = new GUIListBox(new Rectangle(5, 30, 30, 0), Color.Transparent, null, guiFrame); + orderListBox.ScrollBarEnabled = false; + orderListBox.OnSelected = SelectCharacterOrder; + + crewButton = new GUIButton(new Rectangle(5, 0, 100, 20), "Crew", GUI.Style, guiFrame); crewButton.OnClicked = ToggleCrewFrame; commander = new CrewCommander(this); @@ -78,6 +82,31 @@ namespace Barotrauma return false; } + public void SetCharacterOrder(Character character, Order order) + { + if (order == null) return; + + var characterFrame = listBox.FindChild(character); + + if (characterFrame == null) return; + + int characterIndex = listBox.children.IndexOf(characterFrame); + + orderListBox.children[characterIndex].ClearChildren(); + + var img = new GUIImage(new Rectangle(0, 0, 30, 30), order.SymbolSprite, Alignment.Center, orderListBox.children[characterIndex]); + img.Scale = 30.0f / img.SourceRect.Width; + img.Color = order.Color; + img.ToolTip ="Order: "+ order.Name; + } + + public bool SelectCharacterOrder(GUIComponent component, object selection) + { + GameMain.GameSession.CrewManager.commander.ToggleGUIFrame(); + + return false; + } + public void AddCharacter(Character character) { characters.Add(character); @@ -94,11 +123,16 @@ namespace Barotrauma character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character); - //GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, listBox); - //frame.UserData = character; + GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 40, 40), Color.Transparent, null, orderListBox); + frame.UserData = character; //frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); - //frame.HoverColor = Color.LightGray * 0.5f; - //frame.SelectedColor = Color.Gold * 0.5f; + frame.HoverColor = Color.LightGray * 0.5f; + frame.SelectedColor = Color.Gold * 0.5f; + + var ai = character.AIController as HumanAIController; + SetCharacterOrder(character, ai.CurrentOrder); + + //string name = character.Info.Name.Replace(' ', '\n'); @@ -118,8 +152,17 @@ namespace Barotrauma { guiFrame.Update(deltaTime); - if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.C)) + + if (GameMain.Config.KeyBind(InputType.CrewOrders).IsHit()) { + //deselect construction unless it's the ladders the character is climbing + if (!commander.IsOpen && Character.Controlled != null && + Character.Controlled.SelectedConstruction != null && + Character.Controlled.SelectedConstruction.GetComponent() == null) + { + Character.Controlled.SelectedConstruction = null; + } + //only allow opening the command UI if there are AICharacters in the crew if (commander.IsOpen || characters.Any(c => c is AICharacter)) commander.ToggleGUIFrame(); } @@ -143,7 +186,6 @@ namespace Barotrauma //} } - public void CreateCrewFrame(List crew) { int width = 600, height = 400; diff --git a/Subsurface/Source/GameSession/InfoTextManager.cs b/Subsurface/Source/GameSession/InfoTextManager.cs index 6571baefa..fceb62e5a 100644 --- a/Subsurface/Source/GameSession/InfoTextManager.cs +++ b/Subsurface/Source/GameSession/InfoTextManager.cs @@ -57,10 +57,7 @@ namespace Barotrauma if (GameMain.GameSession != null && GameMain.GameSession.Map != null) { if (GameMain.GameSession.Map.CurrentLocation!=null) - text = text.Replace("[location1]", GameMain.GameSession.Map.CurrentLocation.Name); - - if (GameMain.GameSession.Map.SelectedLocation!= null) - text = text.Replace("[location2]", GameMain.GameSession.Map.SelectedLocation.Name); + text = text.Replace("[location]", GameMain.GameSession.Map.CurrentLocation.Name); } return text; diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index 7d94e8179..9c42d788d 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -136,7 +136,11 @@ namespace Barotrauma keyMapping[(int)InputType.Left] = new KeyOrMouse(Keys.A); keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D); keyMapping[(int)InputType.Run] = new KeyOrMouse(Keys.LeftShift); - keyMapping[(int)InputType.Chat] = new KeyOrMouse(Keys.Tab); + + + keyMapping[(int)InputType.Chat] = new KeyOrMouse(Keys.Tab); + keyMapping[(int)InputType.CrewOrders] = new KeyOrMouse(Keys.C); + keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E); keyMapping[(int)InputType.Use] = new KeyOrMouse(0); diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index 3da90f043..63fd6fb92 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -64,7 +64,7 @@ namespace Barotrauma.Items.Components if (powerConsumption == 0.0f) voltage = 1.0f; Force = MathHelper.Lerp(force, (voltage < minVoltage) ? 0.0f : targetForce, 0.1f); - if (Force > 1.0f) + if (Math.Abs(Force) > 1.0f) { Vector2 currForce = new Vector2((force / 100.0f) * maxForce * (voltage / minVoltage), 0.0f); diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index f7862c71e..079a168d6 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -244,7 +244,7 @@ namespace Barotrauma.Items.Components { var mission = GameMain.GameSession.Mission; - if (!string.IsNullOrWhiteSpace(mission.RadarLabel)) + if (!string.IsNullOrWhiteSpace(mission.RadarLabel) && mission.RadarPosition != Vector2.Zero) { DrawMarker(spriteBatch, mission.RadarLabel, diff --git a/Subsurface/Source/Items/Components/Machines/Steering.cs b/Subsurface/Source/Items/Components/Machines/Steering.cs index c0d43603f..2ae6cf44b 100644 --- a/Subsurface/Source/Items/Components/Machines/Steering.cs +++ b/Subsurface/Source/Items/Components/Machines/Steering.cs @@ -27,6 +27,8 @@ namespace Barotrauma.Items.Components private bool valueChanged; private float autopilotRayCastTimer; + + private float neutralBallastLevel; bool AutoPilot { @@ -47,6 +49,17 @@ namespace Barotrauma.Items.Components } } + + [Editable, HasDefaultValue(0.5f, true)] + public float NeutralBallastLevel + { + get { return neutralBallastLevel; } + set + { + neutralBallastLevel = MathHelper.Clamp(value, 0.0f, 1.0f); + } + } + private Vector2 TargetVelocity { get { return targetVelocity;} @@ -115,7 +128,11 @@ namespace Barotrauma.Items.Components item.SendSignal(targetVelocity.X.ToString(CultureInfo.InvariantCulture), "velocity_x_out"); - item.SendSignal((-targetVelocity.Y).ToString(CultureInfo.InvariantCulture), "velocity_y_out"); + float targetLevel = -targetVelocity.Y; + + targetLevel += (neutralBallastLevel - 0.5f) * 100.0f; + + item.SendSignal(targetLevel.ToString(CultureInfo.InvariantCulture), "velocity_y_out"); } public override void DrawHUD(SpriteBatch spriteBatch, Character character) diff --git a/Subsurface/Source/Items/Components/Turret.cs b/Subsurface/Source/Items/Components/Turret.cs index ce1f197fe..c1bff1e81 100644 --- a/Subsurface/Source/Items/Components/Turret.cs +++ b/Subsurface/Source/Items/Components/Turret.cs @@ -174,6 +174,8 @@ namespace Barotrauma.Items.Components projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation); projectiles[0].Use(deltaTime); + projectiles[0].User = character; + if (projectile.Container != null) projectile.Container.RemoveContained(projectile); return true; @@ -236,7 +238,7 @@ namespace Barotrauma.Items.Components //ignore humans and characters that are inside the sub if (enemy.IsDead || enemy.SpeciesName == "human" || enemy.AnimController.CurrentHull != null) continue; - float dist = Vector2.Distance(enemy.Position, item.Position); + float dist = Vector2.Distance(enemy.WorldPosition, item.WorldPosition); if (dist < closestDist) { closestEnemy = enemy; @@ -246,18 +248,29 @@ namespace Barotrauma.Items.Components if (closestEnemy == null) return false; - character.CursorPosition = closestEnemy.Position; - SecondaryUse(deltaTime, character); + character.CursorPosition = closestEnemy.WorldPosition; + if (item.Submarine!=null) character.CursorPosition -= item.Submarine.Position; + character.SetInput(InputType.Aim, false, true); + //Vector2 receive - float enemyAngle = MathUtils.VectorToAngle(closestEnemy.Position-item.Position); - float turretAngle = -(rotation - MathHelper.TwoPi); + //Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y); - if (Math.Abs(enemyAngle - turretAngle) > 0.01f) return false; + //Vector2 offset = receivedPos - centerPos; + //offset.Y = -offset.Y; - var pickedBody = Submarine.PickBody(item.SimPosition, closestEnemy.SimPosition, null); + //targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset)); + + float enemyAngle = MathUtils.VectorToAngle(closestEnemy.WorldPosition-item.WorldPosition); + float turretAngle = -rotation; + + + + if (Math.Abs(MathUtils.GetShortestAngle(enemyAngle, turretAngle)) > 0.01f) return false; + + var pickedBody = Submarine.PickBody(ConvertUnits.ToSimUnits(item.WorldPosition), closestEnemy.SimPosition, null); if (pickedBody != null && pickedBody.UserData as Limb == null) return false; - Use(deltaTime, character); + if (objective.Option.ToLower()=="fire at will") Use(deltaTime, character); return false; diff --git a/Subsurface/Source/Map/EntityGrid.cs b/Subsurface/Source/Map/EntityGrid.cs index 6641c2a82..df8c3f666 100644 --- a/Subsurface/Source/Map/EntityGrid.cs +++ b/Subsurface/Source/Map/EntityGrid.cs @@ -72,6 +72,8 @@ namespace Barotrauma public List GetEntities(Vector2 position) { + if (!MathUtils.IsValid(position)) new List(); + if (Submarine.Loaded != null) position -= Submarine.HiddenSubPosition; if (position.X < limits.X || position.Y > limits.Y || @@ -81,7 +83,7 @@ namespace Barotrauma } Point indices = GetIndices(position); - + return entities[indices.X, indices.Y]; } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 21b4dd180..574a5355d 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -553,15 +553,8 @@ namespace Barotrauma foreach (Gap gap in Gap.GapList) { if (gap.Open < 0.01f) continue; - if (gap.linkedTo.Count == 0) continue; - var gapHull = gap.linkedTo[0] as Hull; - if (gapHull == this) gaps.Add(gap); - - if (gap.linkedTo.Count < 2) continue; - - gapHull = gap.linkedTo[1] as Hull; - if (gapHull == this) gaps.Add(gap); + if (gap.linkedTo.Contains(this)) gaps.Add(gap); } return gaps; diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index 0083c1369..50f8130bf 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -212,26 +212,28 @@ namespace Barotrauma { if (targetPosition != null && targetPosition != Position) { - //Vector2 targetSimPos = ConvertUnits.ToSimUnits((Vector2)targetPosition); - float dist = Vector2.Distance((Vector2)targetPosition, Position); if (dist > 1000.0f) { Vector2 moveAmount = ConvertUnits.ToSimUnits((Vector2)targetPosition) - body.Position; + Vector2 displayerMoveAmount = ConvertUnits.ToDisplayUnits(moveAmount); body.SetTransform(body.Position + moveAmount, 0.0f); + if (Character.Controlled != null) Character.Controlled.CursorPosition += displayerMoveAmount; - GameMain.GameScreen.Cam.Position += ConvertUnits.ToDisplayUnits(moveAmount); + GameMain.GameScreen.Cam.Position += displayerMoveAmount; targetPosition = null; } else if (dist > 50.0f) { Vector2 moveAmount = Vector2.Normalize((Vector2)targetPosition - Position); moveAmount *= ConvertUnits.ToSimUnits(Math.Min(dist, 100.0f)); + Vector2 displayerMoveAmount = ConvertUnits.ToDisplayUnits(moveAmount); body.SetTransform(body.Position + moveAmount * deltaTime, 0.0f); - GameMain.GameScreen.Cam.Position += ConvertUnits.ToDisplayUnits(moveAmount * deltaTime); + GameMain.GameScreen.Cam.Position += displayerMoveAmount * deltaTime; + if (Character.Controlled != null) Character.Controlled.CursorPosition += displayerMoveAmount; } else { @@ -351,7 +353,7 @@ namespace Barotrauma { Vector2 normal = Vector2.Normalize(body.Position - limb.SimPosition); - normal *= limb.Mass/100.0f; + normal *= Math.Min(limb.Mass,100)/100.0f; ApplyImpact(normal, contact); } @@ -382,20 +384,34 @@ namespace Barotrauma FixedArray2 points; contact.GetWorldManifold(out normal2, out points); - Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] + limb.LinearVelocity * ((float)Physics.step)); + Vector2 normalizedVel = limb.character.AnimController.RefLimb.LinearVelocity == Vector2.Zero ? + Vector2.Zero : Vector2.Normalize(limb.character.AnimController.RefLimb.LinearVelocity); + + Vector2 targetPos = ConvertUnits.ToDisplayUnits(points[0] + normalizedVel); Hull newHull = Hull.FindHull(targetPos, null); - if (newHull == null) return true; + if (newHull == null) + { + targetPos = ConvertUnits.ToDisplayUnits(points[0] - normalizedVel); + + newHull = Hull.FindHull(targetPos, null); + + if (newHull == null) return true; + } var gaps = newHull.FindGaps(); + targetPos = limb.character.WorldPosition; + bool gapFound = false; - foreach (Gap gap in gaps) + foreach (Gap gap in Gap.GapList) { + if (gap.Open == 0.0f || gap.IsRoomToRoom) continue; if (gap.isHorizontal) { - if (targetPos.Y < gap.WorldRect.Y && targetPos.Y > gap.WorldRect.Y - gap.WorldRect.Height) + if (targetPos.Y < gap.WorldRect.Y && targetPos.Y > gap.WorldRect.Y - gap.WorldRect.Height && + Math.Abs(gap.WorldRect.Center.X-targetPos.X)<200.0f) { gapFound = true; break; @@ -403,7 +419,8 @@ namespace Barotrauma } else { - if (targetPos.X > gap.WorldRect.X && targetPos.X < gap.WorldRect.Right) + if (targetPos.X > gap.WorldRect.X && targetPos.X < gap.WorldRect.Right && + Math.Abs(gap.WorldRect.Y - gap.WorldRect.Height/2 - targetPos.Y) < 200.0f) { gapFound = true; break; diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index c545b22ca..12dedae1e 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -10,7 +10,8 @@ namespace Barotrauma Use, Aim, Up, Down, Left, Right, - Run, Chat + Run, + Chat, CrewOrders } public class KeyOrMouse diff --git a/Subsurface/Source/Sounds/SoundPlayer.cs b/Subsurface/Source/Sounds/SoundPlayer.cs index 683090a97..66f666de7 100644 --- a/Subsurface/Source/Sounds/SoundPlayer.cs +++ b/Subsurface/Source/Sounds/SoundPlayer.cs @@ -219,7 +219,7 @@ namespace Barotrauma if (musicClips == null) return; Task criticalTask = null; - if (GameMain.GameSession!=null) + if (GameMain.GameSession!=null && GameMain.GameSession.TaskManager != null) { foreach (Task task in GameMain.GameSession.TaskManager.Tasks) { diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 6a847a724..3c2e71c93 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ