Ticket #3321: 1_TerritoryManager.patch
File 1_TerritoryManager.patch, 3.1 KB (added by , 9 years ago) |
---|
-
source/simulation2/components/CCmpTerritoryManager.cpp
86 86 // processed flag in bit 7 (TERRITORY_PROCESSED_MASK) 87 87 Grid<u8>* m_Territories; 88 88 89 // idx 0 : total passible territory cells 90 // idx n>0 : player territory counts 91 std::vector<u16> m_TerritoryCounts; 92 89 93 // Saves the cost per tile (to stop territory on impassable tiles) 90 94 Grid<u8>* m_CostGrid; 91 95 … … 260 264 261 265 void CalculateTerritories(); 262 266 267 u8 GetTerritoryPercentage(player_id_t player); 268 263 269 std::vector<STerritoryBoundary> ComputeBoundaries(); 264 270 265 271 void UpdateBoundaryLines(); … … 498 504 m_Territories->set(nx, nz, owner | TERRITORY_CONNECTED_MASK); 499 505 ); 500 506 } 507 508 m_TerritoryCounts.clear(); 509 m_TerritoryCounts.resize(9, 0); 510 for (u16 w = 0; w < tilesW; ++w) 511 { 512 for (u16 h = 0; h < tilesH; ++h) 513 { 514 if (m_CostGrid->get(w,h) >= m_ImpassableCost) 515 continue; 516 ++m_TerritoryCounts[0]; 517 518 player_id_t owner = m_Territories->get(w,h) & TERRITORY_PLAYER_MASK; 519 if (owner > 0) // gaia is owner 0 520 ++m_TerritoryCounts[owner]; 521 } 522 } 501 523 } 502 524 503 525 std::vector<STerritoryBoundary> CCmpTerritoryManager::ComputeBoundaries() … … 510 532 return CTerritoryBoundaryCalculator::ComputeBoundaries(m_Territories); 511 533 } 512 534 535 u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player) 536 { 537 float result = (float)m_TerritoryCounts[player] / m_TerritoryCounts[0]; 538 return (u8)floor(result * 100); 539 } 540 513 541 void CCmpTerritoryManager::UpdateBoundaryLines() 514 542 { 515 543 PROFILE("update boundary lines"); -
source/simulation2/components/ICmpTerritoryManager.cpp
26 26 DEFINE_INTERFACE_METHOD_3("GetNeighbours", std::vector<u32>, ICmpTerritoryManager, GetNeighbours, entity_pos_t, entity_pos_t, bool) 27 27 DEFINE_INTERFACE_METHOD_2("IsConnected", bool, ICmpTerritoryManager, IsConnected, entity_pos_t, entity_pos_t) 28 28 DEFINE_INTERFACE_METHOD_2("SetTerritoryBlinking", void, ICmpTerritoryManager, SetTerritoryBlinking, entity_pos_t, entity_pos_t) 29 DEFINE_INTERFACE_METHOD_1("GetTerritoryPercentage", u8, ICmpTerritoryManager, GetTerritoryPercentage, player_id_t) 29 30 END_INTERFACE_WRAPPER(TerritoryManager) -
source/simulation2/components/ICmpTerritoryManager.h
72 72 */ 73 73 virtual void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z) = 0; 74 74 75 /** 76 * Once finished, this should return the percentage of the world covered by a given 77 * player's territory 78 */ 79 virtual u8 GetTerritoryPercentage(player_id_t player) = 0; 80 75 81 DECLARE_INTERFACE_TYPE(TerritoryManager) 76 82 }; 77 83