Ticket #1054: Patch1054.patch

File Patch1054.patch, 2.3 KB (added by Matt Doerksen, 12 years ago)
  • gamesetup.js

     
    1111// Max number of players for any map
    1212const MAX_PLAYERS = 8;
    1313
     14// Must have at least 2 humans for a network game
     15const MIN_HUMANS_NETWORK = 2;
     16
    1417////////////////////////////////////////////////////////////////////////////////////////////////
    1518
    1619// Is this is a networked game, or offline
     
    692695    updateGameAttributes();
    693696}
    694697
     698function validateNetworkPlayerAssignment()
     699{
     700    if ( !g_IsNetworked )
     701        return false;   // why are you trying to validate a single player game using this?
     702       
     703    g_IsInGuiUpdate = true;
     704
     705    var hostNameList = [];
     706    var hostGuidList = [];
     707    var assignments = [];
     708    var aiAssignments = {};
     709
     710    for (var guid in g_PlayerAssignments)
     711    {
     712        var name = g_PlayerAssignments[guid].name;
     713        var hostID = hostNameList.length;
     714        var player = g_PlayerAssignments[guid].player;
     715
     716        hostNameList.push(name);
     717        hostGuidList.push(guid);
     718        assignments[player] = hostID;
     719    }
     720   
     721    var humanCount = 0;
     722    var playerCount = g_GameAttributes.settings.PlayerData.length;
     723
     724    for (var i = 0; i < MAX_PLAYERS; ++i)
     725    {
     726        let playerSlot = i;
     727        let playerID = i+1; // we don't show Gaia, so first slot is ID 1
     728
     729        var selection = assignments[playerID];
     730
     731        // Look for valid player slots
     732        if (playerSlot < playerCount)
     733        {
     734            // human?
     735            if (selection !== undefined)
     736            {
     737                humanCount++;
     738            }
     739        }
     740        else
     741        {
     742            break;
     743        }
     744    }
     745
     746    g_IsInGuiUpdate = false;
     747   
     748    // if there are enough humans, who cares about bots?
     749    if ( humanCount < MIN_HUMANS_NETWORK )
     750    {
     751        return false;
     752    }
     753   
     754    return true;    // valid game
     755}
     756
    695757function launchGame()
    696758{
    697759    if (g_IsNetworked && !g_IsController)
     
    708770
    709771    if (g_IsNetworked)
    710772    {
    711         Engine.SetNetworkGameAttributes(g_GameAttributes);
    712         Engine.StartNetworkGame();
     773        if ( validateNetworkPlayerAssignment() )
     774        {
     775            Engine.SetNetworkGameAttributes(g_GameAttributes);
     776            Engine.StartNetworkGame();
     777        }
     778        else
     779        {
     780            // TODO: how to show dialog box to user saying they need more people before they start?
     781            error("You must have at least 2 humans to start a network game.");
     782        }
    713783    }
    714784    else
    715785    {
     
    12421312        }
    12431313    }
    12441314    return false;
    1245 }
     1315}
     1316 No newline at end of file