Line data Source code
1 : /* Copyright (C) 2022 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 "simulation2/system/Component.h"
21 : #include "ICmpTerritoryInfluence.h"
22 :
23 : #include "simulation2/components/ICmpOwnership.h"
24 : #include "simulation2/components/ICmpPlayerManager.h"
25 : #include "simulation2/components/ICmpValueModificationManager.h"
26 :
27 0 : class CCmpTerritoryInfluence final : public ICmpTerritoryInfluence
28 : {
29 : public:
30 116 : static void ClassInit(CComponentManager& UNUSED(componentManager))
31 : {
32 116 : }
33 :
34 0 : DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence)
35 :
36 : bool m_Root;
37 : u16 m_Weight;
38 : u32 m_Radius;
39 :
40 116 : static std::string GetSchema()
41 : {
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 116 : "</element>";
54 : }
55 :
56 0 : void Init(const CParamNode& paramNode) override
57 : {
58 0 : m_Root = paramNode.GetChild("Root").ToBool();
59 0 : m_Weight = (u16)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& UNUSED(serialize)) override
68 : {
69 0 : }
70 :
71 0 : void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) 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 : u16 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 : u32 GetRadius() const override
95 : {
96 0 : CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
97 0 : if (!cmpValueModificationManager)
98 0 : return m_Radius;
99 :
100 0 : u32 newRadius = cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId());
101 0 : return newRadius;
102 : }
103 : };
104 :
105 119 : REGISTER_COMPONENT_TYPE(TerritoryInfluence)
|