Ticket #3016: api_fix.patch

File api_fix.patch, 3.5 KB (added by Itms, 9 years ago)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    128128    var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter);
    129129    ret.barterPrices = cmpBarter.GetPrices();
    130130
     131    // Add basic statistics to each player
     132    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     133    var n = cmpPlayerMan.GetNumPlayers();
     134    for (var i = 0; i < n; ++i)
     135    {
     136        var playerEnt = cmpPlayerMan.GetPlayerByID(i);
     137        var cmpPlayerStatisticsTracker = Engine.QueryInterface(playerEnt, IID_StatisticsTracker);
     138        if (cmpPlayerStatisticsTracker)
     139            ret.players[i].statistics = cmpPlayerStatisticsTracker.GetBasicStatistics();
     140    }
     141
    131142    return ret;
    132143};
    133144
  • binaries/data/mods/public/simulation/components/StatisticsTracker.js

     
    121121    this.treasuresCollected = 0;
    122122};
    123123
     124/**
     125 * Returns a subset of statistics that will be added to the simulation state,
     126 * thus called each turn. Basic statistics should not contain data that would
     127 * be expensive to compute.
     128 *
     129 * Note: as of now, nothing in the game needs that, but some AIs developed by
     130 * modders need it in the API.
     131 */
     132StatisticsTracker.prototype.GetBasicStatistics = function()
     133{
     134    return {
     135        "resourcesGathered": this.resourcesGathered,
     136        "percentMapExplored": this.GetPercentMapExplored()
     137    };
     138};
     139
    124140StatisticsTracker.prototype.GetStatistics = function()
    125141{
    126142    return {
  • binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js

     
    101101});
    102102
    103103AddMock(100, IID_StatisticsTracker, {
     104    GetBasicStatistics: function() {
     105        return {
     106            "resourcesGathered": {
     107                "food": 100,   
     108                "wood": 0, 
     109                "metal": 0,
     110                "stone": 0,
     111                "vegetarianFood": 0,
     112            },
     113            "percentMapExplored": 10
     114        };
     115    },
    104116    GetStatistics: function() {
    105117        return {
    106118            "unitsTrained": 10,
     
    165177});
    166178
    167179AddMock(101, IID_StatisticsTracker, {
     180    GetBasicStatistics: function() {
     181        return {
     182            "resourcesGathered": {
     183                "food": 100,   
     184                "wood": 0, 
     185                "metal": 0,
     186                "stone": 0,
     187                "vegetarianFood": 0,
     188            },
     189            "percentMapExplored": 10
     190        };
     191    },
    168192    GetStatistics: function() {
    169193        return {
    170194            "unitsTrained": 10,
     
    222246            researchedTechs: {},
    223247            classCounts: {},
    224248            typeCountsByClass: {},
     249            statistics: {
     250                resourcesGathered: {
     251                    food: 100,
     252                    wood: 0,
     253                    metal: 0,
     254                    stone: 0,
     255                    vegetarianFood: 0,
     256                },
     257                percentMapExplored: 10
     258            },
    225259        },
    226260        {
    227261            name: "Player 2",
     
    251285            researchedTechs: {},
    252286            classCounts: {},
    253287            typeCountsByClass: {},
     288            statistics: {
     289                resourcesGathered: {
     290                    food: 100,
     291                    wood: 0,
     292                    metal: 0,
     293                    stone: 0,
     294                    vegetarianFood: 0,
     295                },
     296                percentMapExplored: 10
     297            },
    254298        }
    255299    ],
    256300    circularMap: false,