Skip to content

Bump up delay to end game back to 3 seconds#7050

Merged
lL1l1 merged 5 commits intoFAForever:developfrom
Garanas:Fix/campaign-end-of-operation-issue
Mar 29, 2026
Merged

Bump up delay to end game back to 3 seconds#7050
lL1l1 merged 5 commits intoFAForever:developfrom
Garanas:Fix/campaign-end-of-operation-issue

Conversation

@Garanas
Copy link
Copy Markdown
Member

@Garanas Garanas commented Feb 22, 2026

Description of the proposed changes

As posted on Discord, this fixes the bug where a campaign mission no longer shows the 'Operation Complete/Failed' dialog. It takes three seconds for the dialog to show, this is likely for dramatic effect. In #6965 the delay before the game ends was reduced from 3 seconds to 1 second, as a result the operation data was not synced and therefore the dialog would never show.

Testing done on the proposed changes

Run using the init of coop in dev-mode by pointing to the repositories and confirm that the dialog shows with the changes made.

Additional context

Checklist

Summary by CodeRabbit

  • Bug Fixes

    • Increased post-victory wait time (1s → 3s) so campaign and co-op missions conclude cleanly and the “continue” dialog no longer reappears after the score/dialogue screens.
    • Added a shutdown safeguard to prevent unit removal/transfer during end-of-game processing, avoiding post-victory side effects.
  • Documentation

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 21c2c75f-491b-4c64-b951-0f9510cd4ad1

📥 Commits

Reviewing files that changed from the base of the PR and between a6cfd40 and 6761821.

📒 Files selected for processing (2)
  • lua/SimUtils.lua
  • lua/sim/VictoryCondition/AbstractVictoryCondition.lua
🚧 Files skipped from review as they are similar to previous changes (1)
  • lua/sim/VictoryCondition/AbstractVictoryCondition.lua

📝 Walkthrough

Walkthrough

Added a global SimUtils.GameIsEnding flag and set it when ending a game; increased AbstractVictoryCondition.DelayBeforeGameEnds from 1→3 seconds; unit-kill routines (KillArmy, KillRecalledArmy) short-circuit after the end-game grace period when GameIsEnding is true.

Changes

Cohort / File(s) Summary
Victory Condition
lua/sim/VictoryCondition/AbstractVictoryCondition.lua
DelayBeforeGameEnds changed from 13; EndGame now sets SimUtils.GameIsEnding = true before forking EndGameThread.
Sim Utilities / Kill Logic
lua/SimUtils.lua
Added GameIsEnding = false flag; KillArmy and KillRecalledArmy return early after WaitSeconds(EndGameGracePeriod) when GameIsEnding is true to avoid post-victory share/transfer and kills.
Changelog
changelog/snippets/fix.7050.md
New snippet documenting fix #7050 for campaign/coop missions incorrectly re-showing continue dialog after completion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Simplify defeat backend #6965: Touches the same defeat/endgame code paths and timing (DelayBeforeGameEnds / SimUtils endgame flag) — strong code-level overlap.

Poem

🐰 I thumped my foot, three seconds true,
The end rolls in with kinder cue.
Flags raised high, no final fright,
Units sleep through closing night.
Hooray — the mission ends polite. 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: bumping the game-end delay from 1 second back to 3 seconds, which is the core modification in the changeset.
Description check ✅ Passed The description comprehensively covers all required sections: clear explanation of changes (restores 3-second delay to fix campaign dialog bug), specific testing done (coop init verification), context (references PR #6965), and mostly completes the checklist (missing reviewer requests).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lua/sim/VictoryCondition/AbstractVictoryCondition.lua (1)

46-49: DelayBeforeGameEnds = 3 lacks safety margin against the documented minimum.

The comment requires "at least three seconds," but the value is set to exactly three with no buffer. DelayBeforeVictory = 5 demonstrates the codebase already uses buffers for timing-sensitive operations; DelayBeforeGameEnds should follow the same pattern. Bump to 4 or 5 to provide headroom against timing drift (e.g., tick-rate variance or future changes to ScenarioFramework.EndOperation). Document why the chosen value provides adequate margin.

Additionally, since this is a public field, a future concrete subclass could override it to a value below 3 and reintroduce the bug. Document this constraint in the field's comment or add a runtime assertion in subclasses to enforce it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/sim/VictoryCondition/AbstractVictoryCondition.lua` around lines 46 - 49,
Increase DelayBeforeGameEnds from 3 to 5 (matching DelayBeforeVictory's buffer)
and update its comment to state it must be >= 3 and why the extra margin is used
(tick drift / ScenarioFramework.EndOperation timing); also add a runtime check
in AbstractVictoryCondition (e.g., in the initializer or validation method) that
asserts self.DelayBeforeGameEnds >= 3 to prevent subclasses from accidentally
lowering it below the documented minimum, referencing DelayBeforeGameEnds,
DelayBeforeVictory and ScenarioFramework.EndOperation so reviewers can find the
related symbols.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lua/sim/VictoryCondition/AbstractVictoryCondition.lua`:
- Around line 46-49: Increase DelayBeforeGameEnds from 3 to 5 (matching
DelayBeforeVictory's buffer) and update its comment to state it must be >= 3 and
why the extra margin is used (tick drift / ScenarioFramework.EndOperation
timing); also add a runtime check in AbstractVictoryCondition (e.g., in the
initializer or validation method) that asserts self.DelayBeforeGameEnds >= 3 to
prevent subclasses from accidentally lowering it below the documented minimum,
referencing DelayBeforeGameEnds, DelayBeforeVictory and
ScenarioFramework.EndOperation so reviewers can find the related symbols.

@speed2CZ
Copy link
Copy Markdown
Member

I think the delay was to ensure the final score is fully synced, since syncing doesnt happen every tick

@speed2CZ
Copy link
Copy Markdown
Member

iirc this wasnt the case just for the coop, but generally for all games. There was a bug when the final stats didnt match the game, since they were not fully synced. That was a long time ago, maybe things has changed a lot since then in how the score or game ending works, but thats what I remember.

@Garanas
Copy link
Copy Markdown
Member Author

Garanas commented Feb 22, 2026

Maybe we should hardcode the delay then, to prevent regression in the future?

@lL1l1
Copy link
Copy Markdown
Contributor

lL1l1 commented Feb 23, 2026

All the defeat/end-of-game stuff is overly complicated timing-wise because the victory thread and ai brain callback threads are too separated. The reason the delay was decreased was because the unit transfer thread could finishing waiting while the game is over and then it would kill all units because the game was over and no valid allies were left over. #6965 (review)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lua/sim/VictoryCondition/AbstractVictoryCondition.lua (1)

46-49: Fix looks correct; consider documenting the timing coupling more explicitly.

The restoration of the 3-second delay fixes the campaign sync issue. The comment helpfully references ScenarioFramework.EndOperation, but the dependency is implicit—EndOperationThread also uses WaitSeconds(3) and both need to complete before Sync.GameEnded is set.

To prevent future regressions (as discussed in the PR comments), consider either:

  1. Referencing the shared constant from a single source, or
  2. Adding a cross-reference comment in ScenarioFramework.lua pointing back here.

This would make the coupling explicit and reduce the risk of one value being changed without the other.

,

💡 Optional: Add a cross-reference note
     --- Once the game is guaranteed to end, it will take this many seconds to end the game. This needs
     --- to be three or more seconds for campaign/coop to end gracefully. It takes three seconds for 
-    --- an operation (campaign/coop) to end via `ScenarioFramework.EndOperation`.
+    --- an operation (campaign/coop) to end via `ScenarioFramework.EndOperation`. Note: The
+    --- `EndOperationThread` in ScenarioFramework.lua also waits 3 seconds—keep these in sync.
     DelayBeforeGameEnds = 3,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/sim/VictoryCondition/AbstractVictoryCondition.lua` around lines 46 - 49,
DelayBeforeGameEnds is coupled with
ScenarioFramework.EndOperation/EndOperationThread which also uses WaitSeconds(3)
before setting Sync.GameEnded; make that coupling explicit by either exposing
and referencing a single shared constant (e.g., move DelayBeforeGameEnds to a
shared constant module and update
ScenarioFramework.EndOperation/EndOperationThread to use it) or by adding a
clear cross-reference comment in ScenarioFramework.lua that points back to
DelayBeforeGameEnds in AbstractVictoryCondition.lua and explains both must
match; update all references (DelayBeforeGameEnds,
ScenarioFramework.EndOperation, EndOperationThread, WaitSeconds, and
Sync.GameEnded) accordingly so future changes remain synchronized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lua/sim/VictoryCondition/AbstractVictoryCondition.lua`:
- Around line 46-49: DelayBeforeGameEnds is coupled with
ScenarioFramework.EndOperation/EndOperationThread which also uses WaitSeconds(3)
before setting Sync.GameEnded; make that coupling explicit by either exposing
and referencing a single shared constant (e.g., move DelayBeforeGameEnds to a
shared constant module and update
ScenarioFramework.EndOperation/EndOperationThread to use it) or by adding a
clear cross-reference comment in ScenarioFramework.lua that points back to
DelayBeforeGameEnds in AbstractVictoryCondition.lua and explains both must
match; update all references (DelayBeforeGameEnds,
ScenarioFramework.EndOperation, EndOperationThread, WaitSeconds, and
Sync.GameEnded) accordingly so future changes remain synchronized.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3aa8863b-55c6-463f-83d0-cedc153992a7

📥 Commits

Reviewing files that changed from the base of the PR and between 4882000 and a6cfd40.

📒 Files selected for processing (2)
  • changelog/snippets/fix.7050.md
  • lua/sim/VictoryCondition/AbstractVictoryCondition.lua
✅ Files skipped from review due to trivial changes (1)
  • changelog/snippets/fix.7050.md

@lL1l1 lL1l1 merged commit 5eb0c30 into FAForever:develop Mar 29, 2026
6 checks passed
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.

3 participants