Pyrogenesis  trunk
ICmpUnitMotion.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 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 #ifndef INCLUDED_ICMPUNITMOTION
19 #define INCLUDED_ICMPUNITMOTION
20 
22 
23 #include "simulation2/components/ICmpPathfinder.h" // for pass_class_t
24 #include "simulation2/components/ICmpPosition.h" // for entity_pos_t
25 
26 /**
27  * Motion interface for entities with complex movement capabilities.
28  * (Simpler motion is handled by ICmpMotion instead.)
29  *
30  * It should eventually support different movement speeds, moving to areas
31  * instead of points, moving as part of a group, moving as part of a formation,
32  * etc.
33  */
34 class ICmpUnitMotion : public IComponent
35 {
36 public:
37 
38  /**
39  * Attempt to walk into range of a to a given point, or as close as possible.
40  * The range is measured from the center of the unit.
41  * If the unit is already in range, or cannot move anywhere at all, or if there is
42  * some other error, then returns false.
43  * Otherwise, returns true and sends a MotionChanged message after starting to move,
44  * and sends another MotionChanged after finishing moving.
45  * If maxRange is negative, then the maximum range is treated as infinity.
46  */
47  virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) = 0;
48 
49  /**
50  * Determine wether the givven point is within the given range, using the same measurement
51  * as MoveToPointRange.
52  */
53  virtual bool IsInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) const = 0;
54 
55  /**
56  * Determine whether the target is within the given range, using the same measurement
57  * as MoveToTargetRange.
58  */
59  virtual bool IsInTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) const = 0;
60 
61  /**
62  * Attempt to walk into range of a given target entity, or as close as possible.
63  * The range is measured between approximately the edges of the unit and the target, so that
64  * maxRange=0 is not unreachably close to the target.
65  * If the unit is already in range, or cannot move anywhere at all, or if there is
66  * some other error, then returns false.
67  * Otherwise, returns true and sends a MotionChanged message after starting to move,
68  * and sends another MotionChanged after finishing moving.
69  * If maxRange is negative, then the maximum range is treated as infinity.
70  */
71  virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) = 0;
72 
73  /**
74  * Join a formation, and move towards a given offset relative to the formation controller entity.
75  * Continues following the formation until given a different command.
76  */
77  virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z) = 0;
78 
79  /**
80  * Turn to look towards the given point.
81  */
82  virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) = 0;
83 
84  /**
85  * Stop moving immediately.
86  */
87  virtual void StopMoving() = 0;
88 
89  /**
90  * Get the current movement speed.
91  */
92  virtual fixed GetCurrentSpeed() const = 0;
93 
94  /**
95  * Set the current movement speed.
96  */
97  virtual void SetSpeed(fixed speed) = 0;
98 
99  /**
100  * Get whether the unit is moving.
101  */
102  virtual bool IsMoving() const = 0;
103 
104  /**
105  * Get the default speed that this unit will have when walking, in metres per second.
106  */
107  virtual fixed GetWalkSpeed() const = 0;
108 
109  /**
110  * Get the default speed that this unit will have when running, in metres per second.
111  */
112  virtual fixed GetRunSpeed() const = 0;
113 
114  /**
115  * Set whether the unit will turn to face the target point after finishing moving.
116  */
117  virtual void SetFacePointAfterMove(bool facePointAfterMove) = 0;
118 
119  /**
120  * Get the unit's passability class.
121  */
122  virtual pass_class_t GetPassabilityClass() const = 0;
123 
124  /**
125  * Get the passability class name (as defined in pathfinder.xml)
126  */
127  virtual std::string GetPassabilityClassName() const = 0;
128 
129  /**
130  * Get the unit clearance (used by the Obstruction component)
131  */
132  virtual entity_pos_t GetUnitClearance() const = 0;
133 
134  /**
135  * Toggle the rendering of debug info.
136  */
137  virtual void SetDebugOverlay(bool enabled) = 0;
138 
139  DECLARE_INTERFACE_TYPE(UnitMotion)
140 };
141 
142 #endif // INCLUDED_ICMPUNITMOTION
Definition: IComponent.h:33
A simple fixed-point number class.
Definition: Fixed.h:115
virtual void StopMoving()=0
Stop moving immediately.
u16 pass_class_t
Definition: Pathfinding.h:29
virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)=0
Attempt to walk into range of a given target entity, or as close as possible.
virtual fixed GetWalkSpeed() const =0
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) const =0
Determine wether the givven point is within the given range, using the same measurement as MoveToPoin...
virtual bool IsMoving() const =0
Get whether the unit is moving.
virtual void SetFacePointAfterMove(bool facePointAfterMove)=0
Set whether the unit will turn to face the target point after finishing moving.
virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)=0
Attempt to walk into range of a to a given point, or as close as possible.
virtual pass_class_t GetPassabilityClass() const =0
Get the unit&#39;s passability class.
virtual fixed GetRunSpeed() const =0
Get the default speed that this unit will have when running, in metres per second.
Motion interface for entities with complex movement capabilities.
Definition: ICmpUnitMotion.h:34
virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z)=0
Join a formation, and move towards a given offset relative to the formation controller entity...
virtual std::string GetPassabilityClassName() const =0
Get the passability class name (as defined in pathfinder.xml)
virtual void SetSpeed(fixed speed)=0
Set the current movement speed.
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
virtual entity_pos_t GetUnitClearance() const =0
Get the unit clearance (used by the Obstruction component)
virtual void SetDebugOverlay(bool enabled)=0
Toggle the rendering of debug info.
virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z)=0
Turn to look towards the given point.
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
virtual bool IsInTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) const =0
Determine whether the target is within the given range, using the same measurement as MoveToTargetRan...
virtual fixed GetCurrentSpeed() const =0
Get the current movement speed.