Ticket #3476: t3476_dont_even_look_at_it_wip.patch

File t3476_dont_even_look_at_it_wip.patch, 11.3 KB (added by elexis, 8 years ago)

completely broken WIP from 2015_04_10, in case it helps anyone.

  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    18921892        var mapSize = Engine.GetGUIObjectByName("mapSize").list_data[selectedMapSize];
    18931893    else
    18941894        var mapSize = "Default";
     1895   
     1896    var victoryCondition = Engine.GetGUIObjectByName("victoryCondition").list[selectedVictoryCondition];
    18951897
    1896     var victoryCondition = Engine.GetGUIObjectByName("victoryCondition").list[selectedVictoryCondition];
     1898   
     1899    /*var object = g_GameAttributes.settings.PlayerData;
     1900    var output = 'PlayerData:\n';
     1901    for (var player in object) {
     1902        output += "player" + player + ":\n";
     1903        for (var property in object[player]) {
     1904            output += "\t" + property + ': ' + object[player][property]+'\n';
     1905        }
     1906    }
     1907    error(output);
     1908   
     1909    return;
     1910    var object = g_PlayerAssignments;
     1911    var output = 'PlayerAssignments:\n';
     1912    for (var guid in object) {
     1913        output += "guid" + guid + "\n";
     1914        for (var property in object[guid]) {
     1915            output += "\t" + property + ': ' + object[guid][property]+'\n';
     1916        }
     1917    }
     1918    error(output);
     1919    return;
     1920   
     1921    */
     1922
     1923    // DEPRECATED
     1924    // nbp = client count
     1925    // tnbp = slots available
    18971926    var numberOfPlayers = Object.keys(g_PlayerAssignments).length;
    18981927    var players = [ assignment.name for each (assignment in g_PlayerAssignments) ].join(", ");
    1899 
    19001928    var nbp = numberOfPlayers ? numberOfPlayers : 1;
    19011929    var tnbp = g_GameAttributes.settings.PlayerData.length;
     1930    var players = [ assignment.name for each (assignment in g_PlayerAssignments) ].join(", ");
    19021931
     1932    // new
     1933    var teams = getTeams(g_PlayerAssignments, g_GameAttributes.settings.PlayerData);
     1934    var maxPlayers = g_GameAttributes.settings.PlayerData.length;
     1935    var playerCount = 0;
     1936    for(var i in g_PlayerAssignments)
     1937    {
     1938        if (g_PlayerAssignments[i]["player"] != -1)
     1939            playerCount += 1;
     1940    }
     1941
     1942    // The player names are saved in the assignments
     1943    // The team settings are saved in g_GameAttributes.settings.PlayerData
     1944
     1945    error("Sending stanza");
     1946   
    19031947    var gameData = {
    19041948        "name":g_ServerName,
    19051949        "mapName":g_GameAttributes.map,
     
    19071951        "mapSize":mapSize,
    19081952        "mapType":g_GameAttributes.mapType,
    19091953        "victoryCondition":victoryCondition,
    1910         "nbp":nbp,
     1954       
     1955        // those 3 deprecated
     1956        "nbp":playerCount,
    19111957        "tnbp":tnbp,
    1912         "players":players
     1958        "players":players,
     1959
     1960        "playerCount":playerCount,
     1961        "maxPlayers":maxPlayers,
     1962        "teams":JSON.stringify(teams),
     1963        // save turnnumber, so that we can compute lag time with real time - ingame time - pause time
     1964        "pausedTime":0,
     1965        "turn":0 // get m_CurrentTurn
    19131966    };
    19141967    Engine.SendRegisterGame(gameData);
    19151968}
    19161969
     1970function getTeams(g_PlayerAssignments, playerData)
     1971{
     1972    var teams = {};
     1973    for(var i in playerData)
     1974    {
     1975        var team = playerData[i]["Team"] + 1;
     1976        var ai = playerData[i]["AI"];
     1977       
     1978        // get player name
     1979        var add = false;
     1980        var name = "(unassigned)";
     1981        if (ai != "")
     1982        {
     1983            name = ai + " AI";
     1984            add = true;
     1985        } else {
     1986            for(var j in g_PlayerAssignments)
     1987            {
     1988                if (g_PlayerAssignments[j]["player"] == parseInt(i) + 1) {
     1989                    name = g_PlayerAssignments[j]["name"];
     1990                    add = true;
     1991                }
     1992            }
     1993        }
     1994
     1995        if (add) {
     1996            if (!teams.hasOwnProperty(team)) {
     1997                teams[team] = [];
     1998            }
     1999            teams[team].push(name);
     2000        }
     2001    }
     2002   
     2003    // add observers
     2004    teams[-1] = [];
     2005    for(var i in g_PlayerAssignments)
     2006    {
     2007        if (g_PlayerAssignments[i]["player"] == -1)
     2008            teams["-1"].push(g_PlayerAssignments[i]["name"]);
     2009    }
     2010   
     2011    return teams;
     2012}
     2013
    19172014function getVictoryConditions()
    19182015{
    19192016    var r = {};
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    113113    // We assume index 0 means display all for any given filter.
    114114    if (mapSizeFilter.selected != 0 && game.mapSize != mapSizeFilter.list_data[mapSizeFilter.selected])
    115115        return true;
    116     if (playersNumberFilter.selected != 0 && game.tnbp != playersNumberFilter.list_data[playersNumberFilter.selected])
     116    if (playersNumberFilter.selected != 0 && game.maxPlayers != playersNumberFilter.list_data[playersNumberFilter.selected])
    117117        return true;
    118118    if (mapTypeFilter.selected != 0 && game.mapType != mapTypeFilter.list_data[mapTypeFilter.selected])
    119119        return true;
    120     if (!showFullFilter.checked && game.tnbp <= game.nbp)
     120    if (!showFullFilter.checked && game.playerCount >= game.maxPlayers)
    121121        return true;
    122122
    123123    return false;
     
    361361    // Store the game whole game list data so that we can access it later
    362362    // to update the game info panel.
    363363    g_GameList = gameList;
    364 
     364   
    365365    // Sort the list of games to that games 'waiting' are displayed at the top, followed by 'init', followed by 'running'.
    366366    var gameStatuses = ['waiting', 'init', 'running'];
    367367    g_GameList.sort(function (a,b) {
     
    406406            list_mapSize.push(translatedMapSize(g.mapSize));
    407407            let idx = g_mapTypes.indexOf(g.mapType);
    408408            list_mapType.push(idx != -1 ? g_mapTypesText[idx] : "");
    409             list_nPlayers.push(g.nbp + "/" +g.tnbp);
     409            list_nPlayers.push(g.playerCount + "/" +g.maxPlayers);
    410410            list.push(g.name);
    411411            list_data.push(c);
    412412        }
     
    528528
    529529    // Display the map name, number of players, the names of the players, the map size and the map type.
    530530    Engine.GetGUIObjectByName("sgMapName").caption = translate(g_GameList[g].niceMapName);
    531     Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].nbp + "/" + g_GameList[g].tnbp;
    532     Engine.GetGUIObjectByName("sgPlayersNames").caption = g_GameList[g].players;
     531    Engine.GetGUIObjectByName("sgNbPlayers").caption = g_GameList[g].playerCount + "/" + g_GameList[g].maxPlayers;
     532    Engine.GetGUIObjectByName("sgPlayersNames").caption = getGameText(g_GameList[g]);
    533533    Engine.GetGUIObjectByName("sgMapSize").caption = translatedMapSize(g_GameList[g].mapSize);
    534534    let idx = g_mapTypes.indexOf(g_GameList[g].mapType);
    535535    Engine.GetGUIObjectByName("sgMapType").caption = idx != -1 ? g_mapTypesText[idx] : "";
     
    550550    Engine.GetGUIObjectByName("sgMapPreview").sprite = "cropped:(0.7812,0.5859)session/icons/mappreview/" + mapPreview;
    551551}
    552552
     553function getGameText(game)
     554{
     555    var teams = JSON.parse(game["teams"]);
     556   
     557    // find out if free for all
     558    var freeForAll = true;
     559    for (var team=1; team<=4; team++)           
     560    {
     561        if (teams.hasOwnProperty(team) && teams[team].length > 0) {
     562            freeForAll = false;
     563            break;
     564        }
     565    }
     566   
     567    // assemble text
     568    var text = "";
     569    var printOrder = [1,2,3,4,0,-1];
     570    for(var p in printOrder)
     571    {
     572   
     573        var team = printOrder[p];
     574        if (!teams.hasOwnProperty(team) || teams[team].length == 0) {
     575            continue;
     576        }
     577       
     578        var names = teams[team].join(", ");
     579       
     580        if (team > 0)
     581            text += "Team: " +  team + ": " + names + "\n";
     582        else if (team == -1)
     583            text += "Observer: " + names + "\n";
     584        else if (team == 0)
     585        {
     586            if (freeForAll)
     587                text += names + "\n";
     588            else
     589                text += "No Team: " + names + "\n";
     590        }
     591    }
     592   
     593    if (game["state"] == "running")
     594    {
     595        text += "Started: \n";
     596        text += "Time: \n";
     597        text += "Lag: \n"; // show period spend lagging
     598    }
     599
     600    return text;
     601}
     602
     603
    553604/**
    554605 * Start the joining process on the currectly selected game.
    555606 */
     
    599650
    600651function onTick()
    601652{
     653
    602654    updateTimers();
    603655    checkSpamMonitor();
    604656
     
    839891        updateSpamMonitor(msg.from);
    840892    if (isSpam(msg.text, msg.from))
    841893        return;
    842 
     894   
    843895    // Format Text
    844896    var formatted = ircFormat(msg.text, msg.from, msg.color, msg.key, msg.datetime);
    845897
  • source/gui/scripting/ScriptFunctions.cpp

     
    420420    return ps_generate_guid().FromUTF8();
    421421}
    422422
     423u32 getCurrentTurn(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
     424{
     425    return g_Game->GetTurnManager()->m_CurrentTurn;
     426}
     427
    423428void RestartInAtlas(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
    424429{
    425430    restart_mainloop_in_atlas();
     
    969974    scriptInterface.RegisterFunction<void, int, &SetPlayerID>("SetPlayerID");
    970975    scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
    971976    scriptInterface.RegisterFunction<std::wstring, &GetMatchID>("GetMatchID");
     977    scriptInterface.RegisterFunction<u32, &GetCurrentTurn>("GetCurrentTurn");
    972978    scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
    973979    scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
    974980    scriptInterface.RegisterFunction<bool, &IsAtlasRunning>("IsAtlasRunning");
  • source/lobby/XmppClient.cpp

     
    373373        std::wstring value;
    374374        scriptInterface.GetProperty(data, properties[i].c_str(), value);
    375375        game->addAttribute(properties[i], utf8_from_wstring(value));
     376
     377        //debug_printf("ADDING %s = %s\n", properties[i].c_str(), value.c_str());
    376378    }
    377379
    378380    // Push the stanza onto the IQ
     
    528530        JS::RootedValue game(cx);
    529531        scriptInterface.Eval("({})", &game);
    530532
    531         const char* stats[] = { "name", "ip", "state", "nbp", "tnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };
     533        const char* stats[] = { "name", "ip", "state", "nbp", "tnbp", "playerCount", "maxPlayers", "teams", "pausedTime", "turn", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };
    532534        for (size_t i = 0; i < ARRAY_SIZE(stats); ++i)
    533535            scriptInterface.SetProperty(game, stats[i], wstring_from_utf8((*it)->findAttribute(stats[i]).to_string()));
    534536
  • source/tools/XpartaMuPP/XpartaMuPP.py

     
    2020import logging, time, traceback
    2121from optparse import OptionParser
    2222
    23 import sleekxmpp
     23import sleekxmpp,sys
    2424from sleekxmpp.stanza import Iq
    2525from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin, ET
    2626from sleekxmpp.xmlstream.handler import Callback
     
    281281    """
    282282      Add a game
    283283    """
     284    # DEPRECATED
    284285    data['players-init'] = data['players']
    285286    data['nbp-init'] = data['nbp']
     287   
     288    data['playerCount-init'] = data['playerCount']
     289    data['teams-init'] = data['teams']
     290   
     291    # save when the game started so that we can compute lag time
     292    data['game-started'] = time.time()
     293
    286294    data['state'] = 'init'
    287295    self.gameList[str(JID)] = data
    288296  def removeGame(self, JID):
     
    301309    """
    302310    JID = str(JID)
    303311    if JID in self.gameList:
     312      self.gameList[JID]['nbp'] = data['nbp']
    304313      if self.gameList[JID]['nbp-init'] > data['nbp']:
    305314        logging.debug("change game (%s) state from %s to %s", JID, self.gameList[JID]['state'], 'waiting')
    306         self.gameList[JID]['nbp'] = data['nbp']
    307315        self.gameList[JID]['state'] = 'waiting'
    308316      else:
    309317        logging.debug("change game (%s) state from %s to %s", JID, self.gameList[JID]['state'], 'running')