Skip to content

Commit

Permalink
Expose player ratings and divisions to the session
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed Nov 30, 2024
1 parent 0971d51 commit c397db6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
45 changes: 44 additions & 1 deletion lua/ui/lobby/autolobby/AutolobbyController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,44 @@ AutolobbyCommunications = Class(MohoLobbyMethods, AutolobbyServerCommunicationsC
return 'Ready'
end,

---@param self UIAutolobbyCommunications
---@param playerOptions UIAutolobbyPlayer[]
---@return table<string, number>
CreateRatingsTable = function(self, playerOptions)
---@type table<string, number>
local allRatings = {}

for slot, options in pairs(playerOptions) do
if options.Human and options.PL then
allRatings[options.PlayerName] = options.PL
end
end

return allRatings
end,

---@param self UIAutolobbyCommunications
---@param playerOptions UIAutolobbyPlayer[]
---@return table<string, string>
CreateDivisionsTable = function(self, playerOptions)
---@type table<string, string>
local allDivisions = {}

for slot, options in pairs(playerOptions) do
if options.Human and options.PL then
if options.DIV ~= "unlisted" then
local division = options.DIV
if options.SUBDIV and options.SUBDIV ~="" then
division = division .. ' ' .. options.SUBDIV
end
allDivisions[options.PlayerName]= division
end
end
end

return allDivisions
end,

--- Verifies whether we can launch the game.
---@param self UIAutolobbyCommunications
---@param peerStatus UIAutolobbyStatus
Expand Down Expand Up @@ -488,6 +526,11 @@ AutolobbyCommunications = Class(MohoLobbyMethods, AutolobbyServerCommunicationsC
self:SendPlayerOptionToServer(ownerId, 'Faction', playerOptions.Faction)
end

-- tuck them into the game options. By all means a hack, but
-- this way they are available in both the sim and the UI
self.GameOptions.Ratings = self:CreateRatingsTable(self.PlayerOptions)
self.GameOptions.Divisions = self:CreateDivisionsTable(self.PlayerOptions)

-- create game configuration
local gameConfiguration = {
GameMods = self.GameMods,
Expand All @@ -496,7 +539,7 @@ AutolobbyCommunications = Class(MohoLobbyMethods, AutolobbyServerCommunicationsC
Observers = {},
}

-- send it to all players and tell them to launch
-- send it to all players and tell them to launch with the configuration
self:BroadcastData({ Type = "Launch", GameConfig = gameConfiguration })
self:LaunchGame(gameConfiguration)
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/LaunchFAInstances.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if ($players -eq 1) {
$hostLogFile = "host_dev_1.log"
$hostFaction = $factions | Get-Random
$hostTeamArgument = Get-TeamArgument -instanceNumber 0
$hostArguments = "/log $hostLogFile /showlog /hostgame $hostProtocol $port $hostPlayerName $gameName $map /startspot 1 /players $players /$hostFaction $hostTeamArgument $baseArguments"
$hostArguments = "/log $hostLogFile /showlog /hostgame $hostProtocol $port $hostPlayerName $gameName $map /startspot 1 /players $players /$hostFaction $hostTeamArgument $baseArguments /division HostDivision /subdivision 1"

# Launch host game instance
Launch-GameInstance -instanceNumber 1 -xPos 0 -yPos 0 -arguments $hostArguments
Expand All @@ -107,7 +107,7 @@ if ($players -eq 1) {
$clientPlayerName = "ClientPlayer_$($i + 1)"
$clientFaction = $factions | Get-Random
$clientTeamArgument = Get-TeamArgument -instanceNumber $i
$clientArguments = "/log $clientLogFile /joingame $hostProtocol localhost:$port $clientPlayerName /startspot $($i + 1) /players $players /$clientFaction $clientTeamArgument $baseArguments"
$clientArguments = "/log $clientLogFile /joingame $hostProtocol localhost:$port $clientPlayerName /startspot $($i + 1) /players $players /$clientFaction $clientTeamArgument $baseArguments /division Diamond /subdivision $($i + 1)"

Launch-GameInstance -instanceNumber ($i + 1) -xPos $xPos -yPos $yPos -arguments $clientArguments
}
Expand Down

0 comments on commit c397db6

Please sign in to comment.