Fix a special situation where map control percentage wasn't computed properly.

Also improve the code and fix a typo.

Based on patch by s0600204, fixes #3378.

This was SVN commit r16941.
This commit is contained in:
Itms
2015-08-27 16:26:32 +00:00
parent e3208c8784
commit d129ae3cd8
@@ -389,7 +389,7 @@ void CCmpTerritoryManager::CalculateTerritories()
// Reset territory counts for all players
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
if (cmpPlayerManager && cmpPlayerManager->GetNumPlayers() != m_TerritoryCellCounts.size())
if (cmpPlayerManager && (size_t)cmpPlayerManager->GetNumPlayers() != m_TerritoryCellCounts.size())
m_TerritoryCellCounts.resize(cmpPlayerManager->GetNumPlayers());
for (u16& count : m_TerritoryCellCounts)
count = 0;
@@ -532,9 +532,12 @@ std::vector<STerritoryBoundary> CCmpTerritoryManager::ComputeBoundaries()
u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player)
{
if (player <= 0 && (size_t)player > m_TerritoryCellCounts.size())
if (player <= 0 || (size_t)player > m_TerritoryCellCounts.size())
return 0;
if (m_TerritoryTotalPassableCellCount == 0)
CalculateTerritories();
ENSURE(m_TerritoryTotalPassableCellCount > 0);
u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount;
ENSURE(percentage <= 100);