Fixes macOS warnings after adding final keyword to simulation classes in rP26537.
[0ad.git] / source / simulation2 / components / CCmpTerritoryInfluence.cpp
blobd6228d40ba3bf4f11b1ef67a58c40c56100c82aa
1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #include "precompiled.h"
20 #include "simulation2/system/Component.h"
21 #include "ICmpTerritoryInfluence.h"
23 #include "simulation2/components/ICmpOwnership.h"
24 #include "simulation2/components/ICmpPlayerManager.h"
25 #include "simulation2/components/ICmpValueModificationManager.h"
27 class CCmpTerritoryInfluence final : public ICmpTerritoryInfluence
29 public:
30 static void ClassInit(CComponentManager& UNUSED(componentManager))
34 DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence)
36 bool m_Root;
37 u16 m_Weight;
38 u32 m_Radius;
40 static std::string GetSchema()
42 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 u16 value
49 "</data>"
50 "</element>"
51 "<element name='Radius'>"
52 "<data type='nonNegativeInteger'/>"
53 "</element>";
56 void Init(const CParamNode& paramNode) override
58 m_Root = paramNode.GetChild("Root").ToBool();
59 m_Weight = (u16)paramNode.GetChild("Weight").ToInt();
60 m_Radius = paramNode.GetChild("Radius").ToInt();
63 void Deinit() override
67 void Serialize(ISerializer& UNUSED(serialize)) override
71 void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) override
73 Init(paramNode);
76 bool IsRoot() const override
78 CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
79 if (!cmpValueModificationManager)
80 return m_Root;
82 return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Root", m_Root, GetEntityId());
85 u16 GetWeight() const override
87 CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
88 if (!cmpValueModificationManager)
89 return m_Weight;
91 return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Weight", m_Weight, GetEntityId());
94 u32 GetRadius() const override
96 CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
97 if (!cmpValueModificationManager)
98 return m_Radius;
100 u32 newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId());
101 return newRadius;
105 REGISTER_COMPONENT_TYPE(TerritoryInfluence)