Ticket #3334: t3334_precise_territory_radius_v3.patch
File t3334_precise_territory_radius_v3.patch, 4.0 KB (added by , 9 years ago) |
---|
-
source/simulation2/components/CCmpTerritoryInfluence.cpp
18 18 #include "precompiled.h" 19 19 20 20 #include "simulation2/system/Component.h" 21 21 #include "ICmpTerritoryInfluence.h" 22 22 23 #include "ps/CLogger.h" 23 24 #include "simulation2/components/ICmpOwnership.h" 24 25 #include "simulation2/components/ICmpPlayerManager.h" 25 26 #include "simulation2/components/ICmpValueModificationManager.h" 26 27 27 28 class CCmpTerritoryInfluence : public ICmpTerritoryInfluence … … public: 33 34 34 35 DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence) 35 36 36 37 bool m_Root; 37 38 u16 m_Weight; 38 u 32m_Radius;39 u16 m_Radius; 39 40 40 41 static std::string GetSchema() 41 42 { 42 43 return 43 44 "<element name='Root'>" … … public: 47 48 "<data type='nonNegativeInteger'>" 48 49 "<param name='maxInclusive'>65535</param>" // Max u16 value 49 50 "</data>" 50 51 "</element>" 51 52 "<element name='Radius'>" 52 "<data type='nonNegativeInteger'/>" 53 "<data type='nonNegativeInteger'>" 54 "<param name='maxInclusive'>65535</param>" // Max u16 value 55 "</data>" 53 56 "</element>"; 54 57 } 55 58 56 59 virtual void Init(const CParamNode& paramNode) 57 60 { 58 61 m_Root = paramNode.GetChild("Root").ToBool(); 59 62 m_Weight = (u16)paramNode.GetChild("Weight").ToInt(); 60 m_Radius = paramNode.GetChild("Radius").ToInt();63 m_Radius = (u16)paramNode.GetChild("Radius").ToInt(); 61 64 } 62 65 63 66 virtual void Deinit() 64 67 { 65 68 } … … public: 81 84 virtual u16 GetWeight() 82 85 { 83 86 return m_Weight; 84 87 } 85 88 86 virtual u 32GetRadius()89 virtual u16 GetRadius() 87 90 { 88 91 CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity()); 89 92 if (!cmpValueModificationManager) 90 93 return m_Radius; 91 94 92 95 u32 newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); 93 return newRadius; 96 97 // should be < 1000 98 if (newRadius > std::numeric_limits<u16>::max()) 99 { 100 newRadius = std::numeric_limits<u16>::max(); 101 LOGWARNING("Territory radius overflow for entity ID %d", GetEntityId()); 102 } 103 104 return (u16) newRadius; 94 105 } 95 106 }; 96 107 97 108 REGISTER_COMPONENT_TYPE(TerritoryInfluence) -
source/simulation2/components/CCmpTerritoryManager.cpp
void CCmpTerritoryManager::CalculateTerr 438 438 { 439 439 CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), ent); 440 440 if (!cmpPosition || !cmpPosition->IsInWorld()) 441 441 continue; 442 442 443 // Multiply with 2^8 to improve precision 443 444 CmpPtr<ICmpTerritoryInfluence> cmpTerritoryInfluence(GetSimContext(), ent); 444 445 u32 weight = cmpTerritoryInfluence->GetWeight(); 445 u32 radius = cmpTerritoryInfluence->GetRadius() / (Pathfinding::NAVCELL_SIZE * NAVCELLS_PER_TERRITORY_TILE).ToInt_RoundToNegInfinity(); 446 u32 radius = ((u32) cmpTerritoryInfluence->GetRadius() << 8) / (Pathfinding::NAVCELL_SIZE * NAVCELLS_PER_TERRITORY_TILE).ToInt_RoundToNegInfinity(); 447 446 448 if (weight == 0 || radius == 0) 447 449 continue; 448 u32 falloff = weight / radius; 450 451 u32 falloff = (weight << 8) / radius; 449 452 450 453 CFixedVector2D pos = cmpPosition->GetPosition2D(); 451 454 u16 i, j; 452 455 NearestTerritoryTile(pos.X, pos.Y, i, j, tilesW, tilesH); 453 456 -
source/simulation2/components/ICmpTerritoryInfluence.h
class ICmpTerritoryInfluence : public IC 25 25 public: 26 26 virtual bool IsRoot() = 0; 27 27 28 28 virtual u16 GetWeight() = 0; 29 29 30 virtual u 32GetRadius() = 0;30 virtual u16 GetRadius() = 0; 31 31 32 32 DECLARE_INTERFACE_TYPE(TerritoryInfluence) 33 33 }; 34 34 35 35 #endif // INCLUDED_ICMPTERRITORYINFLUENCE