Skip to content

feat(gui): Add Random button to LAN and Online game lobbies - #421

Open
bill-rich wants to merge 8 commits into
GeneralsOnlineDevelopmentTeam:mainfrom
bill-rich:go_random_button
Open

bill-rich wants to merge 8 commits into
GeneralsOnlineDevelopmentTeam:mainfrom
bill-rich:go_random_button

Conversation

@bill-rich

@bill-rich bill-rich commented Mar 26, 2026 •

Copy link
Copy Markdown

Adds a host-only "Random" button to the LAN and Online game setup screens that assigns random factions, colors, and start positions for all players currently set to "Random" or unset values.

A common way to get random factions and start positions is the "in-and-out" method: everyone sets their faction and location to random, the host starts the game so the engine assigns them, then everyone quits, creates a new lobby, and manually sets the assigned factions and positions. This is tedious and, in online lobbies, risky since getting the same group of players back together is not guaranteed. This button lets the host resolve all random assignments directly in the lobby, removing the need for the in-and-out workaround entirely and saving considerable time since the game start, quit, and rejoin cycle is eliminated.

The randomization logic mirrors the existing populateRandomSideAndColor and populateRandomStartPosition algorithms from GameLogic.cpp:

  • Assigns factions only to slots set to PLAYERTEMPLATE_RANDOM
  • Respects locked generals and the "old factions only" setting
  • Assigns colors only to slots without a color selected
  • Places opponents far apart and teammates close together using the map's start position waypoints
  • Resets the accepted state so players can review before starting

The button is disabled for non-host players. Manually chosen factions, colors, and positions are not overwritten. Team assignments are not changed.

New files:

  • RandomAssign.h / RandomAssign.cpp: Shared randomization module used by both LAN and Online menus

Changed files:

  • LanGameOptionsMenu.cpp: Hooks up the Random button for LAN lobbies
  • WOLGameSetupMenu.cpp: Hooks up the Random button for Online lobbies
  • Window/Menus/GameSpyGameOptionsMenu.wnd: Randomize button added
  • Window/Menus/LanGameOptionsMenu.wnd: Randomize button added
  • Data/English/generals.csf: GUI:Randomize -> RANDOMIZE
Screenshot From 2026-03-26 10-47-16 Screenshot From 2026-03-26 10-47-47

wnd and csf files:
https://drive.google.com/file/d/1sKVIkG2xaKD4z6PKnbosr9BV1IYMOniT/view?usp=sharing

Depends on: GeneralsOnlineDevelopmentTeam/Services#13

@tintinhamans

Copy link
Copy Markdown

Should probably be presented differently imo, maybe as a tournament mode or something.

As is it's not ideal for casual play due to host being able to re-room until they get their desired army.

@bill-rich

bill-rich commented Mar 28, 2026 •

Copy link
Copy Markdown
Author

What are you thinking for how else it could be done? The main goal is to just skip the in-and-out.

The idea was that since it just does what the game does once the match starts, you'd wait until everyone was in, hit the button, and then just play as though everyone got their factions and locations and then quit and rejoined. The host would have to either fully quit out and create a new room or set themselves to random and run again. At that point, I would think they would have just set themselves to whatever they want anyway.

Happy to adjust as needed.

@tintinhamans

tintinhamans commented Aug 7, 2026 •

Copy link
Copy Markdown

At that point, I would think they would have just set themselves to whatever they want anyway.

Issue is that they can fill the lobby with computer slots, click random and then see how the lobby would turn out before setting everything back to "normal".

Anyone who joins the lobby afterwards is none the wiser but the host has the advantage of knowing this info.

@WildCoyoteCigar

WildCoyoteCigar commented Aug 25, 2026 •

Copy link
Copy Markdown

At that point, I would think they would have just set themselves to whatever they want anyway.

Issue is that they can fill the lobby with computer slots, click random and then see how the lobby would turn out before setting everything back to "normal".

Anyone who joins the lobby afterwards is none the wiser but the host has the advantage of knowing this info.

in that case the random increment is progressed or should progress no? that way the host doesn't have information on the outcome.

Announces each randomize to the whole lobby with a roll counter so re-rolling is visible to everyone present; the assignment itself keeps drawing from the clock-seeded CRT RNG, independent of the server-minted lobby seed that match start uses. Also clamps the start-spot tables to MAX_SLOTS, picks colors uniformly from the untaken set, null-guards the button lookups for older .wnd files, guards the auto-ready countdown reset like the other host updates, and adds the license headers and change tags.
The button text falls back to an English default when GUI:Randomize is missing from the text table, so the layout no longer depends on a .csf update.
…changed

Review follow-up. Online, the lobby service owns the slots, so the roll is computed on a scratch copy of the game slots, only the slots the roll changed are sent (with the occupant's user id so the service can skip a slot that changed hands, and without the team field the roll never touches), and the announcement waits for the service to accept the update; on failure the local slots are re-synced from the lobby. Observer slots are left alone (match start resolves them), an unknown map hands out no start spots, the roll draws from a private mt19937 instead of reseeding the CRT RNG, locked generals are filtered with the same test the faction combo uses, a rolled host faction is not persisted as the preferred one, the button lookups no longer assert on older layouts, and the announcements follow the Topic: message style.
… the host

Lab run: the button was disabled for the duration of the request but only re-enabled on failure, so a lobby allowed exactly one roll. It now returns to whatever state it had when the roll started, which also keeps it disabled for a guest or a stats match. The host's lobby showed a remote player's rolled colour as ???, because a slot whose colour combo is disabled is never repopulated and the new colour was missing from the stale list; the selection now rebuilds the list once and looks again. A rolled colour is no longer persisted as the host's preferred colour either, which already applied to the faction.
The lobby stored whatever the local slot happened to hold when the player left or started, so a slot the host had rolled or moved became that player's remembered preference, on guests as well as the host. The earlier guard could not work: it was cleared from the combo callback, and the service push that delivers a roll fires those callbacks exactly like a click. The repaint driven by a push is now marked as such, and only a pick made here marks the slot as chosen; nothing else is persisted.
…s apart

Pass the change list by reference, pick the first start spot directly
since nothing is taken yet, reset the accepted flags in the LAN caller
rather than inside the roll, and drop the re-pull on a failed online
roll since the scratch copy was already restored. A chosen colour no
longer makes a rolled faction count as a choice, and vice versa.
@bill-rich

Copy link
Copy Markdown
Author

At that point, I would think they would have just set themselves to whatever they want anyway.

Issue is that they can fill the lobby with computer slots, click random and then see how the lobby would turn out before setting everything back to "normal".
Anyone who joins the lobby afterwards is none the wiser but the host has the advantage of knowing this info.

in that case the random increment is progressed or should progress no? that way the host doesn't have information on the outcome.

That is how it works, and the update I'm pushing makes it explicit. There are two separate draws:

  1. The button resolves the lobby's Random slots with its own std::mt19937, seeded from random_device and the clock. It only rewrites the slot settings everyone can already see in the lobby.
  2. Match start reseeds the game RNG from the lobby seed the service mints (setSeed(lobby.rng_seed) in NGMPGame.cpp). The button never touches or reads that.

So filling the room with AI, pressing Randomize and setting things back teaches the host nothing about what a real random start would produce. What they get is the same thing they could get today by starting and abandoning a match, which is the in-and-out this button exists to remove.

To make re-rolling visible, every press is now announced to the whole lobby as a system line, "Randomize: the host resolved the random factions, colors and start positions (roll N)". Anyone present sees the count climb. Late joiners see the current slots like any other host change; if you want the roll count visible to them too I can keep it in the lobby state so it shows on join.

Online the roll is computed on a scratch copy and sent as one host action, so the service stays authoritative; the host's own client never applies it locally.

GeneralsOnlineDevelopmentTeam/Services#82 Is required before the new changes will work.

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