Fix GetTerritoryPercentage when changing number of players
Check for player being out of bounds after m_TerritoryCellCounts may be recomputed. Differential Revision: https://code.wildfiregames.com/D2046 Reviewed by: @Stan This was SVN commit r23510.
This commit is contained in:
parent
b4da3388ec
commit
0b8aa7eb5a
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2019 Wildfire Games.
|
/* Copyright (C) 2020 Wildfire Games.
|
||||||
* This file is part of 0 A.D.
|
* This file is part of 0 A.D.
|
||||||
*
|
*
|
||||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||||
@ -581,12 +581,13 @@ std::vector<STerritoryBoundary> CCmpTerritoryManager::ComputeBoundaries()
|
|||||||
|
|
||||||
u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player)
|
u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player)
|
||||||
{
|
{
|
||||||
if (player <= 0 || (size_t)player > m_TerritoryCellCounts.size())
|
if (player <= 0 || static_cast<size_t>(player) >= m_TerritoryCellCounts.size())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CalculateTerritories();
|
CalculateTerritories();
|
||||||
|
|
||||||
if (m_TerritoryTotalPassableCellCount == 0)
|
// Territories may have been recalculated, check whether player is still there.
|
||||||
|
if (m_TerritoryTotalPassableCellCount == 0 || static_cast<size_t>(player) >= m_TerritoryCellCounts.size())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount;
|
u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user