diff --git a/Assets/Resources/Aetheria.inputactions b/Assets/Resources/Aetheria.inputactions index a09980439..c5e3153a6 100644 --- a/Assets/Resources/Aetheria.inputactions +++ b/Assets/Resources/Aetheria.inputactions @@ -86,6 +86,15 @@ "interactions": "", "initialStateCheck": false }, + { + "name": "Toggle Stance", + "type": "Button", + "id": "708d5aa5-3d0e-4ffe-920e-a4c95179d99c", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, { "name": "Override Shutdown", "type": "Button", @@ -320,6 +329,17 @@ "isComposite": false, "isPartOfComposite": false }, + { + "name": "", + "id": "1f8c8f5e-4078-4066-b780-67d9c2261e46", + "path": "/n", + "interactions": "", + "processors": "", + "groups": "Keyboard&Mouse", + "action": "Toggle Stance", + "isComposite": false, + "isPartOfComposite": false + }, { "name": "", "id": "8e8b5d19-20fd-43f3-88cf-6246f374e7cf", diff --git a/Assets/Scripts/AetheriaInput.cs b/Assets/Scripts/AetheriaInput.cs index 15a4432f0..c6eb618c2 100644 --- a/Assets/Scripts/AetheriaInput.cs +++ b/Assets/Scripts/AetheriaInput.cs @@ -182,6 +182,16 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable ""initialStateCheck"": false, ""priority"": 0 }, + { + ""name"": ""Toggle Stance"", + ""type"": ""Button"", + ""id"": ""708d5aa5-3d0e-4ffe-920e-a4c95179d99c"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false, + ""priority"": 0 + }, { ""name"": ""Override Shutdown"", ""type"": ""Button"", @@ -421,6 +431,17 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable ""isComposite"": false, ""isPartOfComposite"": false }, + { + ""name"": """", + ""id"": ""1f8c8f5e-4078-4066-b780-67d9c2261e46"", + ""path"": ""/n"", + ""interactions"": """", + ""processors"": """", + ""groups"": ""Keyboard&Mouse"", + ""action"": ""Toggle Stance"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, { ""name"": """", ""id"": ""8e8b5d19-20fd-43f3-88cf-6246f374e7cf"", @@ -1159,6 +1180,7 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable m_Player_TargetNearest = m_Player.FindAction("Target Nearest", throwIfNotFound: true); m_Player_ToggleHeatsinks = m_Player.FindAction("Toggle Heatsinks", throwIfNotFound: true); m_Player_ToggleShield = m_Player.FindAction("Toggle Shield", throwIfNotFound: true); + m_Player_ToggleStance = m_Player.FindAction("Toggle Stance", throwIfNotFound: true); m_Player_OverrideShutdown = m_Player.FindAction("Override Shutdown", throwIfNotFound: true); m_Player_Ping = m_Player.FindAction("Ping", throwIfNotFound: true); m_Player_HideUI = m_Player.FindAction("Hide UI", throwIfNotFound: true); @@ -1274,6 +1296,7 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable private readonly InputAction m_Player_TargetNearest; private readonly InputAction m_Player_ToggleHeatsinks; private readonly InputAction m_Player_ToggleShield; + private readonly InputAction m_Player_ToggleStance; private readonly InputAction m_Player_OverrideShutdown; private readonly InputAction m_Player_Ping; private readonly InputAction m_Player_HideUI; @@ -1327,6 +1350,10 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable /// public InputAction @ToggleShield => m_Wrapper.m_Player_ToggleShield; /// + /// Provides access to the underlying input action "Player/ToggleStance". + /// + public InputAction @ToggleStance => m_Wrapper.m_Player_ToggleStance; + /// /// Provides access to the underlying input action "Player/OverrideShutdown". /// public InputAction @OverrideShutdown => m_Wrapper.m_Player_OverrideShutdown; @@ -1399,6 +1426,9 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable @ToggleShield.started += instance.OnToggleShield; @ToggleShield.performed += instance.OnToggleShield; @ToggleShield.canceled += instance.OnToggleShield; + @ToggleStance.started += instance.OnToggleStance; + @ToggleStance.performed += instance.OnToggleStance; + @ToggleStance.canceled += instance.OnToggleStance; @OverrideShutdown.started += instance.OnOverrideShutdown; @OverrideShutdown.performed += instance.OnOverrideShutdown; @OverrideShutdown.canceled += instance.OnOverrideShutdown; @@ -1452,6 +1482,9 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable @ToggleShield.started -= instance.OnToggleShield; @ToggleShield.performed -= instance.OnToggleShield; @ToggleShield.canceled -= instance.OnToggleShield; + @ToggleStance.started -= instance.OnToggleStance; + @ToggleStance.performed -= instance.OnToggleStance; + @ToggleStance.canceled -= instance.OnToggleStance; @OverrideShutdown.started -= instance.OnOverrideShutdown; @OverrideShutdown.performed -= instance.OnOverrideShutdown; @OverrideShutdown.canceled -= instance.OnOverrideShutdown; @@ -1945,6 +1978,13 @@ public partial class @AetheriaInput: IInputActionCollection2, IDisposable /// void OnToggleShield(InputAction.CallbackContext context); /// + /// Method invoked when associated input action "Toggle Stance" is either , or . + /// + /// + /// + /// + void OnToggleStance(InputAction.CallbackContext context); + /// /// Method invoked when associated input action "Override Shutdown" is either , or . /// /// diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 8916d52b1..4ac68c248 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -361,37 +361,48 @@ public class ActionGameManager : MonoBehaviour } }; + // Flips the player's own stance on the current target between hostile and neutral. Going + // neutral mid-fight safes weapons (Weapon.StanceAllowsFire); an unmarked/undetected target + // reads as non-hostile here, so the first press declares hostile. + Input.Player.ToggleStance.performed += context => + { + var target = CurrentEntity.Target.Value; + if (target == null) return; + CurrentEntity.SetIff(target, !CurrentEntity.IsHostileTo(target)); + }; + #region Targeting Input.Player.TargetReticle.performed += context => { - if (!CurrentEntity.VisibleEnemies.Any()) return; - var underReticle = CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity) + if (!CurrentEntity.VisibleEntities.Any()) return; + var underReticle = CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity) .MaxBy(x => dot(normalize(x.Position - CurrentEntity.Position), CurrentEntity.LookDirection)); CurrentEntity.Target.Value = CurrentEntity.Target.Value == underReticle ? null : underReticle; }; + // Nearest is enemies-only (it drives weapon lock), and picks the closest target, not the farthest. Input.Player.TargetNearest.performed += context => { if(CurrentEntity.VisibleEnemies.Any()) { CurrentEntity.Target.Value = CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity) - .MaxBy(x => length(x.Position - CurrentEntity.Position)); + .MinBy(x => length(x.Position - CurrentEntity.Position)); } }; Input.Player.TargetNext.performed += context => { - if (!CurrentEntity.VisibleEnemies.Any()) return; - var targets = CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity).OrderBy(x => length(x.Position - CurrentEntity.Position)).ToArray(); + if (!CurrentEntity.VisibleEntities.Any()) return; + var targets = CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity).OrderBy(x => length(x.Position - CurrentEntity.Position)).ToArray(); var currentTargetIndex = Array.IndexOf(targets, CurrentEntity.Target.Value); CurrentEntity.Target.Value = targets[(currentTargetIndex + 1) % targets.Length]; }; Input.Player.TargetPrevious.performed += context => { - if (!CurrentEntity.VisibleEnemies.Any()) return; - var targets = CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity).OrderBy(x => length(x.Position - CurrentEntity.Position)).ToArray(); + if (!CurrentEntity.VisibleEntities.Any()) return; + var targets = CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity).OrderBy(x => length(x.Position - CurrentEntity.Position)).ToArray(); var currentTargetIndex = Array.IndexOf(targets, CurrentEntity.Target.Value); CurrentEntity.Target.Value = targets[(currentTargetIndex + targets.Length - 1) % targets.Length]; }; @@ -547,6 +558,34 @@ public class ActionGameManager : MonoBehaviour //Temporary, or not ConsoleController.AddCommand("tow", _ => TowShip()); + // Manual IFF override for the player's current target, for hand-testing combat. + // "iff hostile"/"iff neutral" force a stance; "iff clear" restores the derived faction rule. + ConsoleController.AddCommand("iff", args => + { + var console = ConsoleController.Instance; + var target = _currentEntity?.Target.Value; + if (target == null) { console.AppendLogLine("iff: no target selected"); return; } + var mode = args.Length > 0 ? args[0] : ""; + if (mode != "hostile" && mode != "neutral" && mode != "clear") + { + console.AppendLogLine("usage: iff hostile|neutral|clear"); + return; + } + switch (mode) + { + case "hostile": + _currentEntity.SetIff(target, true); + break; + case "neutral": + _currentEntity.SetIff(target, false); + break; + case "clear": + _currentEntity.SetIff(target, null); + break; + } + console.AppendLogLine($"{target.Name}: {(_currentEntity.IsHostileTo(target) ? "hostile" : "neutral")}"); + }); + // Editor only: capturepreset "" [replace] writes the piloted ship as a catalog preset. A multi-word name must // be quoted; any other second argument than replace is refused rather than dropped. if (Application.isEditor) @@ -1243,7 +1282,7 @@ public class ActionGameManager : MonoBehaviour foreach (var (targetLock, indicator, spin) in _lockingIndicators) { - var showLockingIndicator = targetLock.Lock > .01f && CurrentEntity.Target.Value != null && CurrentEntity.Target.Value.IsHostileTo(CurrentEntity); + var showLockingIndicator = targetLock.Lock > .01f && CurrentEntity.Target.Value != null && CurrentEntity.IsHostileTo(CurrentEntity.Target.Value); indicator.gameObject.SetActive(showLockingIndicator); if(showLockingIndicator) {