Let the player target and mark neutrals, and fix the HUD lock direction

TargetReticle, TargetNext and TargetPrevious now consider all visible
entities except self (hostile and neutral), not just VisibleEnemies, so a
neutral wanderer can be selected. TargetNearest stays enemies-only (it drives
weapon lock) but now picks the nearest target: it was using MaxBy, which
picked the farthest.

Adds a "Toggle Stance" input action (bound to the N key; report names which)
that flips the player's own stance on the current target between hostile and
neutral via Entity.SetIff -- one button for the whole affordance, per the
operator's request. Also keeps the "iff hostile"/"iff neutral"/"iff clear"
console commands next to the existing ones, since they cost nothing extra
alongside the hotkey.

Fixes the HUD lock indicator's hostility check, which read
Target.IsHostileTo(CurrentEntity) instead of CurrentEntity.IsHostileTo(Target)
-- the same backwards direction as LockWeapon, fixed in the prior commit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-17 14:01:15 +02:00
commit a5fd8f1d1d
3 changed files with 107 additions and 8 deletions

View file

@ -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": "<Keyboard>/n",
"interactions": "",
"processors": "",
"groups": "Keyboard&Mouse",
"action": "Toggle Stance",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "8e8b5d19-20fd-43f3-88cf-6246f374e7cf",

View file

@ -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"": ""<Keyboard>/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
/// </summary>
public InputAction @ToggleShield => m_Wrapper.m_Player_ToggleShield;
/// <summary>
/// Provides access to the underlying input action "Player/ToggleStance".
/// </summary>
public InputAction @ToggleStance => m_Wrapper.m_Player_ToggleStance;
/// <summary>
/// Provides access to the underlying input action "Player/OverrideShutdown".
/// </summary>
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
/// <seealso cref="UnityEngine.InputSystem.InputAction.canceled" />
void OnToggleShield(InputAction.CallbackContext context);
/// <summary>
/// Method invoked when associated input action "Toggle Stance" is either <see cref="UnityEngine.InputSystem.InputAction.started" />, <see cref="UnityEngine.InputSystem.InputAction.performed" /> or <see cref="UnityEngine.InputSystem.InputAction.canceled" />.
/// </summary>
/// <seealso cref="UnityEngine.InputSystem.InputAction.started" />
/// <seealso cref="UnityEngine.InputSystem.InputAction.performed" />
/// <seealso cref="UnityEngine.InputSystem.InputAction.canceled" />
void OnToggleStance(InputAction.CallbackContext context);
/// <summary>
/// Method invoked when associated input action "Override Shutdown" is either <see cref="UnityEngine.InputSystem.InputAction.started" />, <see cref="UnityEngine.InputSystem.InputAction.performed" /> or <see cref="UnityEngine.InputSystem.InputAction.canceled" />.
/// </summary>
/// <seealso cref="UnityEngine.InputSystem.InputAction.started" />

View file

@ -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 "<name>" [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)
{