Pyrogenesis  trunk
ICmpObstruction.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 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_ICMPOBSTRUCTION
19 #define INCLUDED_ICMPOBSTRUCTION
20 
22 
24 
25 /**
26  * Flags an entity as obstructing movement for other units,
27  * and handles the processing of collision queries.
28  */
30 {
31 public:
32 
39  };
40 
45  };
46 
48 
49  /**
50  * Gets the square corresponding to this obstruction shape.
51  * @return true and updates @p out on success;
52  * false on failure (e.g. object not in the world).
53  */
55 
56  /**
57  * Same as the method above, but returns an obstruction shape for the previous turn
58  */
60 
61  /**
62  * @return the size of the obstruction (either the clearance or a circumscribed circle).
63  */
64  virtual entity_pos_t GetSize() const = 0;
65 
66  /**
67  * @return the size of the static obstruction or (0,0) for a unit shape.
68  */
69  virtual CFixedVector2D GetStaticSize() const = 0;
70 
71  virtual EObstructionType GetObstructionType() const = 0;
72 
73  virtual void SetUnitClearance(const entity_pos_t& clearance) = 0;
74 
75  virtual bool IsControlPersistent() const = 0;
76 
77  /**
78  * Test whether the front of the obstruction square is in the water and the back is on the shore.
79  */
80  virtual bool CheckShorePlacement() const = 0;
81 
82  /**
83  * Test whether this entity is colliding with any obstruction that are set to
84  * block the creation of foundations.
85  * @param ignoredEntities List of entities to ignore during the test.
86  * @return FOUNDATION_CHECK_SUCCESS if check passes, else an EFoundationCheck
87  * value describing the type of failure.
88  */
89  virtual EFoundationCheck CheckFoundation(const std::string& className) const = 0;
90  virtual EFoundationCheck CheckFoundation(const std::string& className, bool onlyCenterPoint) const = 0;
91 
92  /**
93  * CheckFoundation wrapper for script calls, to return friendly strings instead of an EFoundationCheck.
94  * @return "success" if check passes, else a string describing the type of failure.
95  */
96  virtual std::string CheckFoundation_wrapper(const std::string& className, bool onlyCenterPoint) const;
97 
98  /**
99  * Test whether this entity is colliding with any obstructions that share its
100  * control groups and block the creation of foundations.
101  * @return true if foundation is valid (not obstructed)
102  */
103  virtual bool CheckDuplicateFoundation() const = 0;
104 
105  /**
106  * Returns a list of entities that have an obstruction matching the given flag and intersect the current obstruction.
107  * @return vector of blocking entities
108  */
109  virtual std::vector<entity_id_t> GetEntitiesByFlags(ICmpObstructionManager::flags_t flags) const = 0;
110 
111  /**
112  * Returns a list of entities that are blocking movement.
113  * @return vector of blocking entities
114  */
115  virtual std::vector<entity_id_t> GetEntitiesBlockingMovement() const = 0;
116 
117  /**
118  * Returns a list of entities that are blocking construction of a foundation.
119  * @return vector of blocking entities
120  */
121  virtual std::vector<entity_id_t> GetEntitiesBlockingConstruction() const = 0;
122 
123  /**
124  * Returns a list of entities that shall be deleted when a construction on this obstruction starts,
125  * for example sheep carcasses.
126  */
127  virtual std::vector<entity_id_t> GetEntitiesDeletedUponConstruction() const = 0;
128 
129  /**
130  * Detects collisions between foundation-blocking entities and
131  * tries to fix them by setting control groups, if appropriate.
132  */
133  virtual void ResolveFoundationCollisions() const = 0;
134 
135  virtual void SetActive(bool active) = 0;
136 
137  virtual void SetMovingFlag(bool enabled) = 0;
138 
139  virtual void SetDisableBlockMovementPathfinding(bool movementDisabled, bool pathfindingDisabled, int32_t shape) = 0;
140 
141  /**
142  * @param templateOnly - whether to return the raw template value or the current value.
143  */
144  virtual bool GetBlockMovementFlag(bool templateOnly) const = 0;
145 
146  /**
147  * Change the control group that the entity belongs to.
148  * Control groups are used to let units ignore collisions with other units from
149  * the same group. Default is the entity's own ID.
150  */
151  virtual void SetControlGroup(entity_id_t group) = 0;
152 
153  /// See SetControlGroup.
154  virtual entity_id_t GetControlGroup() const = 0;
155 
156  virtual void SetControlGroup2(entity_id_t group2) = 0;
157  virtual entity_id_t GetControlGroup2() const = 0;
158 
159  DECLARE_INTERFACE_TYPE(Obstruction)
160 };
161 
162 #endif // INCLUDED_ICMPOBSTRUCTION
Definition: IComponent.h:32
A simple fixed-point number class.
Definition: Fixed.h:119
Definition: FixedVector2D.h:24
Definition: ICmpObstruction.h:44
virtual void ResolveFoundationCollisions() const =0
Detects collisions between foundation-blocking entities and tries to fix them by setting control grou...
virtual void SetControlGroup2(entity_id_t group2)=0
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:421
Definition: ICmpObstruction.h:42
virtual std::string CheckFoundation_wrapper(const std::string &className, bool onlyCenterPoint) const
CheckFoundation wrapper for script calls, to return friendly strings instead of an EFoundationCheck...
Definition: ICmpObstruction.cpp:26
EFoundationCheck
Definition: ICmpObstruction.h:33
virtual void SetDisableBlockMovementPathfinding(bool movementDisabled, bool pathfindingDisabled, int32_t shape)=0
Flags an entity as obstructing movement for other units, and handles the processing of collision quer...
Definition: ICmpObstruction.h:29
virtual bool GetBlockMovementFlag(bool templateOnly) const =0
virtual void SetMovingFlag(bool enabled)=0
virtual EObstructionType GetObstructionType() const =0
virtual ICmpObstructionManager::tag_t GetObstruction() const =0
virtual std::vector< entity_id_t > GetEntitiesByFlags(ICmpObstructionManager::flags_t flags) const =0
Returns a list of entities that have an obstruction matching the given flag and intersect the current...
u8 flags_t
Bitmask of EFlag values.
Definition: ICmpObstructionManager.h:102
virtual CFixedVector2D GetStaticSize() const =0
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
virtual bool GetPreviousObstructionSquare(ICmpObstructionManager::ObstructionSquare &out) const =0
Same as the method above, but returns an obstruction shape for the previous turn. ...
virtual void SetActive(bool active)=0
Definition: ICmpObstruction.h:34
virtual entity_id_t GetControlGroup2() const =0
virtual entity_id_t GetControlGroup() const =0
See SetControlGroup.
virtual bool CheckShorePlacement() const =0
Test whether the front of the obstruction square is in the water and the back is on the shore...
EObstructionType
Definition: ICmpObstruction.h:41
virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare &out) const =0
Gets the square corresponding to this obstruction shape.
virtual std::vector< entity_id_t > GetEntitiesBlockingMovement() const =0
Returns a list of entities that are blocking movement.
virtual EFoundationCheck CheckFoundation(const std::string &className) const =0
Test whether this entity is colliding with any obstruction that are set to block the creation of foun...
virtual bool CheckDuplicateFoundation() const =0
Test whether this entity is colliding with any obstructions that share its control groups and block t...
Definition: ICmpObstruction.h:35
virtual std::vector< entity_id_t > GetEntitiesDeletedUponConstruction() const =0
Returns a list of entities that shall be deleted when a construction on this obstruction starts...
virtual std::vector< entity_id_t > GetEntitiesBlockingConstruction() const =0
Returns a list of entities that are blocking construction of a foundation.
virtual void SetUnitClearance(const entity_pos_t &clearance)=0
virtual entity_pos_t GetSize() const =0
virtual void SetControlGroup(entity_id_t group)=0
Change the control group that the entity belongs to.
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
virtual bool IsControlPersistent() const =0
Standard representation for all types of shapes, for use with geometry processing code...
Definition: ICmpObstructionManager.h:66
External identifiers for shapes.
Definition: ICmpObstructionManager.h:77
Definition: ICmpObstruction.h:43