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