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:
parent
89e9871092
commit
a5fd8f1d1d
3 changed files with 107 additions and 8 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue