mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-23 14:54:10 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user