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
30 static void ClassInit(CComponentManager
& UNUSED(componentManager
))
34 DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence
)
40 static std::string
GetSchema()
43 "<element name='Root'>"
44 "<data type='boolean'/>"
46 "<element name='Weight'>"
47 "<data type='nonNegativeInteger'>"
48 "<param name='maxInclusive'>65535</param>" // Max u16 value
51 "<element name='Radius'>"
52 "<data type='nonNegativeInteger'/>"
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
76 bool IsRoot() const override
78 CmpPtr
<ICmpValueModificationManager
> cmpValueModificationManager(GetSystemEntity());
79 if (!cmpValueModificationManager
)
82 return cmpValueModificationManager
->ApplyModifications(L
"TerritoryInfluence/Root", m_Root
, GetEntityId());
85 u16
GetWeight() const override
87 CmpPtr
<ICmpValueModificationManager
> cmpValueModificationManager(GetSystemEntity());
88 if (!cmpValueModificationManager
)
91 return cmpValueModificationManager
->ApplyModifications(L
"TerritoryInfluence/Weight", m_Weight
, GetEntityId());
94 u32
GetRadius() const override
96 CmpPtr
<ICmpValueModificationManager
> cmpValueModificationManager(GetSystemEntity());
97 if (!cmpValueModificationManager
)
100 u32 newRadius
= cmpValueModificationManager
->ApplyModifications(L
"TerritoryInfluence/Radius", m_Radius
, GetEntityId());
105 REGISTER_COMPONENT_TYPE(TerritoryInfluence
)