Ticket #3321: 1_TerritoryManager-v4.patch
File 1_TerritoryManager-v4.patch, 4.0 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 std::vector<u16> m_TerritoryCellCounts; 90 u16 m_TerritoryTotalPassableCellCount; 91 89 92 // Saves the cost per tile (to stop territory on impassable tiles) 90 93 Grid<u8>* m_CostGrid; 91 94 … … 123 126 124 127 m_AnimTime = 0.0; 125 128 129 m_TerritoryTotalPassableCellCount = 0; 130 126 131 // Register Relax NG validator 127 132 CXeromyces::AddValidator(g_VFS, "territorymanager", "simulation/data/territorymanager.rng"); 128 133 … … 260 265 261 266 void CalculateTerritories(); 262 267 268 u8 GetTerritoryPercentage(player_id_t player); 269 263 270 std::vector<STerritoryBoundary> ComputeBoundaries(); 264 271 265 272 void UpdateBoundaryLines(); … … 337 344 int tilesH = passGrid.m_H / NAVCELLS_PER_TERRITORY_TILE; 338 345 339 346 m_CostGrid = new Grid<u8>(tilesW, tilesH); 347 m_TerritoryTotalPassableCellCount = 0; 340 348 341 349 for (int i = 0; i < tilesW; ++i) 342 350 { … … 353 361 else if (c & passClassUnrestricted) 354 362 m_CostGrid->set(i, j, 255); // off the world; use maximum cost 355 363 else 364 { 356 365 m_CostGrid->set(i, j, 1); 366 ++m_TerritoryTotalPassableCellCount; 367 } 357 368 } 358 369 } 359 370 } … … 376 387 377 388 m_Territories = new Grid<u8>(tilesW, tilesH); 378 389 390 CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); 391 m_TerritoryCellCounts.clear(); 392 m_TerritoryCellCounts.resize(cmpPlayerManager->GetNumPlayers(), 0); 393 379 394 // Find all territory influence entities 380 395 CComponentManager::InterfaceList influences = GetSimContext().GetComponentManager().GetEntitiesWithInterface(IID_TerritoryInfluence); 381 396 … … 496 511 if (m_Territories->get(nx, nz) != owner) 497 512 continue; 498 513 m_Territories->set(nx, nz, owner | TERRITORY_CONNECTED_MASK); 514 if (m_CostGrid->get(nx, nz) < m_ImpassableCost) 515 ++m_TerritoryCellCounts[owner]; 499 516 ); 500 517 } 501 518 } … … 510 527 return CTerritoryBoundaryCalculator::ComputeBoundaries(m_Territories); 511 528 } 512 529 530 u8 CCmpTerritoryManager::GetTerritoryPercentage(player_id_t player) 531 { 532 if (player <= 0 && (u8)player > m_TerritoryCellCounts.size()) 533 return 0; 534 535 ENSURE(m_TerritoryTotalPassableCellCount > 0); 536 u8 percentage = (m_TerritoryCellCounts[player] * 100) / m_TerritoryTotalPassableCellCount; 537 ENSURE(percentage <= 100); 538 return percentage; 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 * Returns the percentage of the world controlled by a given player as defined by 77 * the number of territory cells the given player owns 78 */ 79 virtual u8 GetTerritoryPercentage(player_id_t player) = 0; 80 75 81 DECLARE_INTERFACE_TYPE(TerritoryManager) 76 82 }; 77 83