Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "precompiled.h" 19 : 20 : #include "ICmpTerritoryInfluence.h" 21 : 22 : #include "simulation2/components/ICmpValueModificationManager.h" 23 : #include "simulation2/system/Component.h" 24 : 25 : #include <string> 26 : 27 0 : class CCmpTerritoryInfluence final : public ICmpTerritoryInfluence 28 : { 29 : public: 30 : static void ClassInit(CComponentManager&) 31 : { 32 : } 33 : 34 0 : DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence) 35 : 36 : bool m_Root; 37 : std::uint16_t m_Weight; 38 : std::uint32_t m_Radius; 39 : 40 137 : static std::string GetSchema() 41 : { 42 137 : return 43 : "<element name='Root'>" 44 : "<data type='boolean'/>" 45 : "</element>" 46 : "<element name='Weight'>" 47 : "<data type='nonNegativeInteger'>" 48 : "<param name='maxInclusive'>65535</param>" // Max std::uint16_t value 49 : "</data>" 50 : "</element>" 51 : "<element name='Radius'>" 52 : "<data type='nonNegativeInteger'/>" 53 137 : "</element>"; 54 : } 55 : 56 0 : void Init(const CParamNode& paramNode) override 57 : { 58 0 : m_Root = paramNode.GetChild("Root").ToBool(); 59 0 : m_Weight = static_cast<std::uint16_t>(paramNode.GetChild("Weight").ToInt()); 60 0 : m_Radius = paramNode.GetChild("Radius").ToInt(); 61 0 : } 62 : 63 0 : void Deinit() override 64 : { 65 0 : } 66 : 67 0 : void Serialize(ISerializer&) override 68 : { 69 0 : } 70 : 71 0 : void Deserialize(const CParamNode& paramNode, IDeserializer&) override 72 : { 73 0 : Init(paramNode); 74 0 : } 75 : 76 0 : bool IsRoot() const override 77 : { 78 0 : CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity()); 79 0 : if (!cmpValueModificationManager) 80 0 : return m_Root; 81 : 82 0 : return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Root", m_Root, GetEntityId()); 83 : } 84 : 85 0 : std::uint16_t GetWeight() const override 86 : { 87 0 : CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity()); 88 0 : if (!cmpValueModificationManager) 89 0 : return m_Weight; 90 : 91 0 : return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Weight", m_Weight, GetEntityId()); 92 : } 93 : 94 0 : std::uint32_t GetRadius() const override 95 : { 96 0 : CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity()); 97 0 : if (!cmpValueModificationManager) 98 0 : return m_Radius; 99 : 100 0 : std::uint32_t newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); 101 0 : return newRadius; 102 : } 103 : }; 104 : 105 274 : REGISTER_COMPONENT_TYPE(TerritoryInfluence)