Ticket #3016: api_fix.patch
File api_fix.patch, 3.5 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GuiInterface.js
128 128 var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter); 129 129 ret.barterPrices = cmpBarter.GetPrices(); 130 130 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 131 142 return ret; 132 143 }; 133 144 -
binaries/data/mods/public/simulation/components/StatisticsTracker.js
121 121 this.treasuresCollected = 0; 122 122 }; 123 123 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 */ 132 StatisticsTracker.prototype.GetBasicStatistics = function() 133 { 134 return { 135 "resourcesGathered": this.resourcesGathered, 136 "percentMapExplored": this.GetPercentMapExplored() 137 }; 138 }; 139 124 140 StatisticsTracker.prototype.GetStatistics = function() 125 141 { 126 142 return { -
binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
101 101 }); 102 102 103 103 AddMock(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 }, 104 116 GetStatistics: function() { 105 117 return { 106 118 "unitsTrained": 10, … … 165 177 }); 166 178 167 179 AddMock(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 }, 168 192 GetStatistics: function() { 169 193 return { 170 194 "unitsTrained": 10, … … 222 246 researchedTechs: {}, 223 247 classCounts: {}, 224 248 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 }, 225 259 }, 226 260 { 227 261 name: "Player 2", … … 251 285 researchedTechs: {}, 252 286 classCounts: {}, 253 287 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 }, 254 298 } 255 299 ], 256 300 circularMap: false,