Skip to content

Fix nav deselection with unselect-nav - #8080

Open
AdmiralTolwyn wants to merge 1 commit into
scp-fs2open:masterfrom
AdmiralTolwyn:nav-deselect
Open

AdmiralTolwyn wants to merge 1 commit into
scp-fs2open:masterfrom
AdmiralTolwyn:nav-deselect

Conversation

@AdmiralTolwyn

Copy link
Copy Markdown
Contributor

unselect-nav is documented as "Deselects any navpoint selected.", but since it was added in 2012 DeselectNav() has set CurrentNav to 0 instead of -1, the no-selection value everything else checks. So the SEXP selects the first nav point: the HUD nav marker jumps to it and autopilot targets it.

This sets -1. Clearing the selection while autopilot is engaged would leave the autopilot code indexing Navs[-1], so if autopilot is engaged it is ended first, through EndAutoPilot(), while the selected nav is still valid. The SEXP help now says so.

What mission designers could notice:

  • After unselect-nav no nav is selected: the HUD nav marker disappears, and the autopilot key reports that no nav is selected until the mission calls select-nav or the player cycles to a nav.
  • If autopilot is engaged, unselect-nav now ends it, including cinematic autopilot and when autopilot.tbl sets +No_Autopilot_Interrupt. Before, autopilot kept flying with the selection pointing at the first nav.

Not changed here: when the nav of a destroyed ship is removed while autopilot is engaged (autopilot.cpp:1106-1108), the selection is also cleared without ending autopilot. That is a separate, pre-existing path.

Testing

  • New tests in test/src/autopilot/test_nav_deselect.cpp: deselecting clears each selection, CanAutopilot() stays false with nothing selected, and deselecting while engaged ends autopilot and returns control to the player. Against master's DeselectNav() all three fail.

  • macOS arm64, Release: 375 passed, 1 skipped (OptionsManagerOverride.ShadowRenderMethodDefaultFollowsTheGlobal, unrelated).

  • Retail FS2 data, a test mission with two nav points that selects the second and runs unselect-nav, once with autopilot off and once engaged; the engine state was read back after each call:

    After unselect-nav master this PR
    autopilot off first nav selected no nav selected
    autopilot engaged first nav selected, autopilot still engaged no nav selected, autopilot ended, player in control

    Both games kept running and exited cleanly.

The slot-0 assignment dates to the 2012 addition of the SEXP. Make unselect-nav leave no nav selected.

End engaged autopilot, including cinematic autopilot, before clearing the selection because autopilot shutdown indexes the selected nav.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant