Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ICmpUnitMotion.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 "ICmpUnitMotion.h"
21 
24 
25 BEGIN_INTERFACE_WRAPPER(UnitMotion)
26 DEFINE_INTERFACE_METHOD_4("MoveToPointRange", bool, ICmpUnitMotion, MoveToPointRange, entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t)
27 DEFINE_INTERFACE_METHOD_4("IsInPointRange", bool, ICmpUnitMotion, IsInPointRange, entity_pos_t, entity_pos_t, entity_pos_t, entity_pos_t)
28 DEFINE_INTERFACE_METHOD_3("IsInTargetRange", bool, ICmpUnitMotion, IsInTargetRange, entity_id_t, entity_pos_t, entity_pos_t)
29 DEFINE_INTERFACE_METHOD_3("MoveToTargetRange", bool, ICmpUnitMotion, MoveToTargetRange, entity_id_t, entity_pos_t, entity_pos_t)
30 DEFINE_INTERFACE_METHOD_3("MoveToFormationOffset", void, ICmpUnitMotion, MoveToFormationOffset, entity_id_t, entity_pos_t, entity_pos_t)
31 DEFINE_INTERFACE_METHOD_2("FaceTowardsPoint", void, ICmpUnitMotion, FaceTowardsPoint, entity_pos_t, entity_pos_t)
32 DEFINE_INTERFACE_METHOD_0("StopMoving", void, ICmpUnitMotion, StopMoving)
33 DEFINE_INTERFACE_METHOD_0("GetCurrentSpeed", fixed, ICmpUnitMotion, GetCurrentSpeed)
34 DEFINE_INTERFACE_METHOD_1("SetSpeed", void, ICmpUnitMotion, SetSpeed, fixed)
35 DEFINE_INTERFACE_METHOD_0("IsMoving", bool, ICmpUnitMotion, IsMoving)
36 DEFINE_INTERFACE_METHOD_0("GetWalkSpeed", fixed, ICmpUnitMotion, GetWalkSpeed)
37 DEFINE_INTERFACE_METHOD_0("GetRunSpeed", fixed, ICmpUnitMotion, GetRunSpeed)
38 DEFINE_INTERFACE_METHOD_1("SetFacePointAfterMove", void, ICmpUnitMotion, SetFacePointAfterMove, bool)
39 DEFINE_INTERFACE_METHOD_1("SetUnitRadius", void, ICmpUnitMotion, SetUnitRadius, fixed)
40 DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpUnitMotion, SetDebugOverlay, bool)
41 END_INTERFACE_WRAPPER(UnitMotion)
42 
43 class CCmpUnitMotionScripted : public ICmpUnitMotion
44 {
45 public:
46  DEFAULT_SCRIPT_WRAPPER(UnitMotionScripted)
47 
48  virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)
49  {
50  return m_Script.Call<bool>("MoveToPointRange", x, z, minRange, maxRange);
51  }
52 
53  virtual bool IsInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)
54  {
55  return m_Script.Call<bool>("IsInPointRange", x, z, minRange, maxRange);
56  }
57 
58  virtual bool IsInTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
59  {
60  return m_Script.Call<bool>("IsInTargetRange", target, minRange, maxRange);
61  }
62 
63  virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
64  {
65  return m_Script.Call<bool>("MoveToTargetRange", target, minRange, maxRange);
66  }
67 
68  virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z)
69  {
70  m_Script.CallVoid("MoveToFormationOffset", target, x, z);
71  }
72 
73  virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z)
74  {
75  m_Script.CallVoid("FaceTowardsPoint", x, z);
76  }
77 
78  virtual void StopMoving()
79  {
80  m_Script.CallVoid("StopMoving");
81  }
82 
83  virtual fixed GetCurrentSpeed()
84  {
85  return m_Script.Call<fixed>("GetCurrentSpeed");
86  }
87 
88  virtual void SetSpeed(fixed speed)
89  {
90  m_Script.CallVoid("SetSpeed", speed);
91  }
92 
93  virtual bool IsMoving()
94  {
95  return m_Script.Call<bool>("IsMoving");
96  }
97 
98  virtual fixed GetWalkSpeed()
99  {
100  return m_Script.Call<fixed>("GetWalkSpeed");
101  }
102 
103  virtual fixed GetRunSpeed()
104  {
105  return m_Script.Call<fixed>("GetRunSpeed");
106  }
107 
108  virtual void SetFacePointAfterMove(bool facePointAfterMove)
109  {
110  m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
111  }
112 
114  {
115  return m_Script.Call<ICmpPathfinder::pass_class_t>("GetPassabilityClass");
116  }
117 
118  virtual void SetUnitRadius(fixed radius)
119  {
120  m_Script.CallVoid("SetUnitRadius", radius);
121  }
122 
123  virtual void SetDebugOverlay(bool enabled)
124  {
125  m_Script.CallVoid("SetDebugOverlay", enabled);
126  }
127 
128 };
129 
130 REGISTER_COMPONENT_SCRIPT_WRAPPER(UnitMotionScripted)
A simple fixed-point number class.
Definition: Fixed.h:115
virtual void SetFacePointAfterMove(bool facePointAfterMove)
Set whether the unit will turn to face the target point after finishing moving.
virtual ICmpPathfinder::pass_class_t GetPassabilityClass()
Get the unit&#39;s passability class.
#define DEFINE_INTERFACE_METHOD_3(scriptname, rettype, classname, methodname, arg1, arg2, arg3)
virtual fixed GetCurrentSpeed()
Get the current movement speed.
#define DEFINE_INTERFACE_METHOD_2(scriptname, rettype, classname, methodname, arg1, arg2)
#define END_INTERFACE_WRAPPER(iname)
virtual void StopMoving()
Stop moving immediately.
virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z)
Join a formation, and move towards a given offset relative to the formation controller entity...
virtual void SetDebugOverlay(bool enabled)
Toggle the rendering of debug info.
virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z)
Turn to look towards the given point.
#define DEFINE_INTERFACE_METHOD_1(scriptname, rettype, classname, methodname, arg1)
virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
Attempt to walk into range of a given target entity, or as close as possible.
virtual fixed GetRunSpeed()
Get the default speed that this unit will have when running, in metres per second.
virtual void SetSpeed(fixed speed)
Set the current movement speed.
Motion interface for entities with complex movement capabilities.
#define DEFINE_INTERFACE_METHOD_4(scriptname, rettype, classname, methodname, arg1, arg2, arg3, arg4)
#define DEFINE_INTERFACE_METHOD_0(scriptname, rettype, classname, methodname)
#define DEFAULT_SCRIPT_WRAPPER(cname)
Definition: Component.h:48
virtual fixed GetWalkSpeed()
Get the default speed that this unit will have when walking, in metres per second.
virtual bool IsInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)
Determine wether the givven point is within the given range, using the same measurement as MoveToPoin...
virtual bool IsInTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
Determine whether the target is within the given range, using the same measurement as MoveToTargetRan...
virtual bool IsMoving()
Get whether the unit is moving.
#define BEGIN_INTERFACE_WRAPPER(iname)
#define REGISTER_COMPONENT_SCRIPT_WRAPPER(cname)
Definition: Component.h:37
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
virtual void SetUnitRadius(fixed radius)
Override the default obstruction radius, used for planning paths and checking for collisions...