Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CCmpTerritoryInfluence.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 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 
21 #include "ICmpTerritoryInfluence.h"
22 
26 
28 {
29 public:
30  static void ClassInit(CComponentManager& UNUSED(componentManager))
31  {
32  }
33 
34  DEFAULT_COMPONENT_ALLOCATOR(TerritoryInfluence)
35 
37  bool m_Root;
40 
41  static std::string GetSchema()
42  {
43  return
44  "<optional>"
45  "<element name='OverrideCost'>"
46  "<data type='nonNegativeInteger'>"
47  "<param name='maxInclusive'>255</param>"
48  "</data>"
49  "</element>"
50  "</optional>"
51  "<element name='Root'>"
52  "<data type='boolean'/>"
53  "</element>"
54  "<element name='Weight'>"
55  "<data type='nonNegativeInteger'/>"
56  "</element>"
57  "<element name='Radius'>"
58  "<data type='nonNegativeInteger'/>"
59  "</element>";
60  }
61 
62  virtual void Init(const CParamNode& paramNode)
63  {
64  if (paramNode.GetChild("OverrideCost").IsOk())
65  m_Cost = paramNode.GetChild("OverrideCost").ToInt();
66  else
67  m_Cost = -1;
68 
69  m_Root = paramNode.GetChild("Root").ToBool();
70  m_Weight = paramNode.GetChild("Weight").ToInt();
71  m_Radius = paramNode.GetChild("Radius").ToInt();
72  }
73 
74  virtual void Deinit()
75  {
76  }
77 
78  virtual void Serialize(ISerializer& UNUSED(serialize))
79  {
80  }
81 
82  virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize))
83  {
84  Init(paramNode);
85  }
86 
87  virtual i32 GetCost()
88  {
89  return m_Cost;
90  }
91 
92  virtual bool IsRoot()
93  {
94  return m_Root;
95  }
96 
97  virtual u32 GetWeight()
98  {
99  return m_Weight;
100  }
101 
102  virtual u32 GetRadius()
103  {
104  u32 newRadius = m_Radius;
105 
106  CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle());
107  if (cmpOwnership && cmpOwnership->GetOwner() != INVALID_PLAYER)
108  {
109  CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity());
110  entity_id_t playerEnt = cmpPlayerManager->GetPlayerByID(cmpOwnership->GetOwner());
111 
112  if (playerEnt != INVALID_ENTITY)
113  {
114  CmpPtr<ICmpTechnologyManager> cmpTechnologyManager(GetSimContext(), playerEnt);
115  if (cmpTechnologyManager)
116  newRadius = cmpTechnologyManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId());
117  }
118  }
119 
120  return newRadius;
121  }
122 };
123 
124 REGISTER_COMPONENT_TYPE(TerritoryInfluence)
An entity initialisation parameter node.
Definition: ParamNode.h:112
#define REGISTER_COMPONENT_TYPE(cname)
Definition: Component.h:30
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
bool ToBool() const
Parses the content of this node as a boolean (&quot;true&quot; == true, anything else == false) ...
Definition: ParamNode.cpp:236
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
Definition: ParamNode.cpp:193
#define i32
Definition: types.h:36
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
int ToInt() const
Parses the content of this node as an integer.
Definition: ParamNode.cpp:213
CEntityHandle GetEntityHandle() const
Definition: IComponent.h:45
virtual void Serialize(ISerializer &serialize)
virtual void Deserialize(const CParamNode &paramNode, IDeserializer &deserialize)
virtual i32 GetCost()
Returns either -1 to indicate no special terrain cost, or a value in [0, 255] to indicate overriding ...
entity_id_t GetEntityId() const
Definition: IComponent.h:48
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Definition: ParamNode.cpp:185
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity)=0
virtual entity_id_t GetPlayerByID(int32_t id)=0
virtual player_id_t GetOwner()=0
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
Definition: Component.h:44
const CSimContext & GetSimContext() const
Definition: IComponent.h:52
A simplified syntax for accessing entity components.
Definition: CmpPtr.h:55
virtual void Init(const CParamNode &paramNode)
static void ClassInit(CComponentManager &componentManager)
CEntityHandle GetSystemEntity() const
Definition: IComponent.h:50
#define u32
Definition: types.h:41
const entity_id_t INVALID_ENTITY
Invalid entity ID.
Definition: Entity.h:36
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
static const player_id_t INVALID_PLAYER
Definition: Player.h:26
static std::string GetSchema()
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34