Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpTerritoryManager.cpp
/* 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 | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 566 Lines • ▼ Show 20 Lines | std::vector<STerritoryBoundary> CCmpTerritoryManager::ComputeBoundaries() | ||||
CalculateTerritories(); | CalculateTerritories(); | ||||
ENSURE(m_Territories); | ENSURE(m_Territories); | ||||
return CTerritoryBoundaryCalculator::ComputeBoundaries(m_Territories); | return CTerritoryBoundaryCalculator::ComputeBoundaries(m_Territories); | ||||
} | } | ||||
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()) | ||||
Silier: we probably should check against number of players in game and if it is not out of scope then… | |||||
Not Done Inline ActionsThere is a flag for whether the territories are dirty. Maybe we should use that? Stan: There is a flag for whether the territories are dirty. Maybe we should use that? | |||||
Done Inline Actionswell actually no, CalculateTerritories has early return if m_Territories exists, so it recomputes only if really needed. Silier: well actually no, CalculateTerritories has early return if m_Territories exists, so it… | |||||
return 0; | return 0; | ||||
CalculateTerritories(); | CalculateTerritories(); | ||||
if (m_TerritoryTotalPassableCellCount == 0) | // Territories may be recalculated, check player is still there. | ||||
StanUnsubmitted Not Done Inline Actions// Territories may have been recalculated, check whether player is still there. ? Stan: // 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; | ||||
Not Done Inline Actionsstatic_cast Stan: static_cast | |||||
u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount; | u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount; | ||||
ENSURE(percentage <= 100); | ENSURE(percentage <= 100); | ||||
return percentage; | return percentage; | ||||
} | } | ||||
void CCmpTerritoryManager::UpdateBoundaryLines() | void CCmpTerritoryManager::UpdateBoundaryLines() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 261 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
we probably should check against number of players in game and if it is not out of scope then let to recompute territories