Ticket #2587: team_exploration.patch
File team_exploration.patch, 9.1 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/gui/summary/summary.js
787 787 sumVegetarianRatio(); 788 788 sumFeminisation(); 789 789 sumKillDeathRatio(); 790 // TODO: probably change from simple sum to union from range manager 791 panels.miscelanous.counters.mapExploration.teamsScores[playerState.team] += playerState.statistics.percentMapExplored; 790 panels.miscelanous.counters.mapExploration.teamsScores[playerState.team] = playerState.statistics.teamPercentMapExplored; 792 791 panels.miscelanous.counters.mapExploration.teamsScoresCaption[playerState.team] = panels.miscelanous.counters.mapExploration.teamsScores[playerState.team] + "%"; 793 792 } 794 793 -
binaries/data/mods/public/simulation/components/AIInterface.js
40 40 var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 41 41 42 42 // Return the same game state as the GUI uses 43 var state = cmpGuiInterface.Get ExtendedSimulationState(-1);43 var state = cmpGuiInterface.GetSimulationState(-1); 44 44 45 45 // Add some extra AI-specific data 46 46 // add custom events and reset them for the next turn -
binaries/data/mods/public/simulation/components/GuiInterface.js
119 119 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 120 120 ret.timeElapsed = cmpTimer.GetTime(); 121 121 122 // and the game type122 // Add the game type 123 123 var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 124 124 ret.gameType = cmpEndGameManager.GetGameType(); 125 125 126 // Add bartering prices 127 var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter); 128 ret.barterPrices = cmpBarter.GetPrices(); 129 126 130 return ret; 127 131 }; 128 132 133 /** 134 * Returns global information about the current game state, plus statistics. 135 * This is used by the GUI at the end of a game, in the summary screen. 136 * Note: Amongst statistics, the team exploration map percentage is computed from 137 * scratch, so the extended simulation state should not be requested too often. 138 */ 129 139 GuiInterface.prototype.GetExtendedSimulationState = function(player) 130 140 { 131 141 // Get basic simulation info … … 141 151 ret.players[i].statistics = cmpPlayerStatisticsTracker.GetStatistics(); 142 152 } 143 153 144 // Add bartering prices145 var cmpBarter = Engine.QueryInterface(SYSTEM_ENTITY, IID_Barter);146 ret.barterPrices = cmpBarter.GetPrices();147 148 154 return ret; 149 155 }; 150 156 -
binaries/data/mods/public/simulation/components/StatisticsTracker.js
142 142 "tributesReceived": this.tributesReceived, 143 143 "tradeIncome": this.tradeIncome, 144 144 "treasuresCollected": this.treasuresCollected, 145 "percentMapExplored": this.GetPercentMapExplored() 145 "percentMapExplored": this.GetPercentMapExplored(), 146 "teamPercentMapExplored": this.GetTeamPercentMapExplored() 146 147 }; 147 148 }; 148 149 … … 336 337 return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); 337 338 }; 338 339 340 /** 341 * Note: cmpRangeManager.GetUnionPercentMapExplored computes statistics from scratch! 342 * As a consequence, this function should not be called too often. 343 */ 344 StatisticsTracker.prototype.GetTeamPercentMapExplored = function() 345 { 346 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 347 348 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 349 var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); 350 351 if (!cmpPlayer) 352 return 0; 353 354 var team = cmpPlayer.GetTeam(); 355 // If teams are not locked, this statistic won't be displayed, so don't bother computing 356 if (team == -1 || !cmpPlayer.GetLockTeams()) 357 return cmpRangeManager.GetPercentMapExplored(cmpPlayer.GetPlayerID()); 358 359 var teamPlayers = []; 360 for (var i = 1; i < cmpPlayerManager.GetNumPlayers(); ++i) 361 { 362 let cmpOtherPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i), IID_Player); 363 if (cmpOtherPlayer && cmpOtherPlayer.GetTeam() == team) 364 teamPlayers.push(i); 365 } 366 367 return cmpRangeManager.GetUnionPercentMapExplored(teamPlayers); 368 }; 369 339 370 Engine.RegisterComponentType(IID_StatisticsTracker, "StatisticsTracker", StatisticsTracker); -
binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
117 117 }, 118 118 "treasuresCollected": 0, 119 119 "percentMapExplored": 10, 120 "teamPercentMapExplored": 10 120 121 }; 121 122 }, 122 123 IncreaseTrainedUnitsCounter: function() { return 1; }, … … 180 181 }, 181 182 "treasuresCollected": 0, 182 183 "percentMapExplored": 10, 184 "teamPercentMapExplored": 10 183 185 }; 184 186 }, 185 187 IncreaseTrainedUnitsCounter: function() { return 1; }, … … 254 256 circularMap: false, 255 257 timeElapsed: 0, 256 258 gameType: "conquest", 259 barterPrices: {buy: {food: 150}, sell: {food: 25}} 257 260 }); 258 261 259 262 TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), { … … 301 304 }, 302 305 treasuresCollected: 0, 303 306 percentMapExplored: 10, 307 teamPercentMapExplored: 10 304 308 }, 305 309 }, 306 310 { … … 346 350 }, 347 351 treasuresCollected: 0, 348 352 percentMapExplored: 10, 353 teamPercentMapExplored: 10 349 354 }, 350 355 } 351 356 ], -
source/simulation2/components/CCmpRangeManager.cpp
656 656 { 657 657 for (i32 i = 0; i < m_TerrainVerticesPerSide; i++) 658 658 { 659 if ( !LosIsOffWorld(i, j))660 {661 for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) 662 m_ExploredVertices.at(k) += ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*(k-1)))) > 0);663 }659 if (LosIsOffWorld(i, j)) 660 continue; 661 662 for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) 663 m_ExploredVertices.at(k) += ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*(k-1)))) > 0); 664 664 } 665 665 } 666 666 } … … 2048 2048 { 2049 2049 return m_ExploredVertices.at((u8)player) * 100 / m_TotalInworldVertices; 2050 2050 } 2051 2052 virtual u8 GetUnionPercentMapExplored(std::vector<player_id_t> players) 2053 { 2054 u32 exploredVertices = 0; 2055 std::vector<player_id_t>::iterator playerIt; 2056 2057 for (i32 j = 0; j < m_TerrainVerticesPerSide; j++) 2058 { 2059 for (i32 i = 0; i < m_TerrainVerticesPerSide; i++) 2060 { 2061 if (LosIsOffWorld(i, j)) 2062 continue; 2063 2064 for (playerIt = players.begin(); playerIt != players.end(); ++playerIt) 2065 { 2066 if ((m_LosState[j*m_TerrainVerticesPerSide + i] & (LOS_EXPLORED << (2*((*playerIt)-1)))) == 0) 2067 continue; 2068 2069 exploredVertices += 1; 2070 break; 2071 } 2072 } 2073 } 2074 2075 return exploredVertices * 100 / m_TotalInworldVertices; 2076 } 2051 2077 }; 2052 2078 2053 2079 REGISTER_COMPONENT_TYPE(RangeManager) -
source/simulation2/components/ICmpRangeManager.cpp
56 56 DEFINE_INTERFACE_METHOD_0("GetLosCircular", bool, ICmpRangeManager, GetLosCircular) 57 57 DEFINE_INTERFACE_METHOD_2("SetSharedLos", void, ICmpRangeManager, SetSharedLos, player_id_t, std::vector<player_id_t>) 58 58 DEFINE_INTERFACE_METHOD_1("GetPercentMapExplored", u8, ICmpRangeManager, GetPercentMapExplored, player_id_t) 59 DEFINE_INTERFACE_METHOD_1("GetUnionPercentMapExplored", u8, ICmpRangeManager, GetUnionPercentMapExplored, std::vector<player_id_t>) 59 60 END_INTERFACE_WRAPPER(RangeManager) -
source/simulation2/components/ICmpRangeManager.h
380 380 */ 381 381 virtual u8 GetPercentMapExplored(player_id_t player) = 0; 382 382 383 /** 384 * Get percent map explored statistics for specified set of players. 385 * Note: this function computes statistics from scratch and should not be called too often. 386 */ 387 virtual u8 GetUnionPercentMapExplored(std::vector<player_id_t> players) = 0; 383 388 389 384 390 /** 385 391 * Perform some internal consistency checks for testing/debugging. 386 392 */