18 #include "precompiled.h"
29 #define MAX(x,y) x>y ? x : y
30 #define MIN(x,y) x>y ? y : x
111 "<a:help>Causes this entity to obstruct the motion of other units.</a:help>"
113 "<element name='Static'>"
114 "<attribute name='width'>"
115 "<ref name='positiveDecimal'/>"
117 "<attribute name='depth'>"
118 "<ref name='positiveDecimal'/>"
121 "<element name='Unit'>"
122 "<attribute name='radius'>"
123 "<ref name='positiveDecimal'/>"
126 "<element name='Obstructions'>"
131 "<attribute name='x'>"
132 "<data type='decimal'/>"
136 "<attribute name='z'>"
137 "<data type='decimal'/>"
140 "<attribute name='width'>"
141 "<ref name='positiveDecimal'/>"
143 "<attribute name='depth'>"
144 "<ref name='positiveDecimal'/>"
150 "<element name='Active' a:help='If false, this entity will be ignored in collision tests by other units but can still perform its own collision tests'>"
151 "<data type='boolean'/>"
153 "<element name='BlockMovement' a:help='Whether units should be allowed to walk through this entity'>"
154 "<data type='boolean'/>"
156 "<element name='BlockPathfinding' a:help='Whether the long-distance pathfinder should avoid paths through this entity. This should only be set for large stationary obstructions'>"
157 "<data type='boolean'/>"
159 "<element name='BlockFoundation' a:help='Whether players should be unable to place building foundations on top of this entity. If true, BlockConstruction should be true too'>"
160 "<data type='boolean'/>"
162 "<element name='BlockConstruction' a:help='Whether players should be unable to begin constructing buildings placed on top of this entity'>"
163 "<data type='boolean'/>"
165 "<element name='DisableBlockMovement' a:help='If true, BlockMovement will be overridden and treated as false. (This is a special case to handle foundations)'>"
166 "<data type='boolean'/>"
168 "<element name='DisableBlockPathfinding' a:help='If true, BlockPathfinding will be overridden and treated as false. (This is a special case to handle foundations)'>"
169 "<data type='boolean'/>"
172 "<element name='ControlPersist' a:help='If present, the control group of this entity will be given to entities that are colliding with it.'>"
213 for(CParamNode::ChildrenMap::const_iterator it = clusterMap.begin(); it != clusterMap.end(); ++it)
216 b.
size0 = it->second.GetChild(
"@width").ToFixed();
217 b.
size1 = it->second.GetChild(
"@depth").ToFixed();
218 b.
dx = it->second.GetChild(
"@x").ToFixed();
219 b.
dz = it->second.GetChild(
"@z").ToFixed();
252 serialize.NumberU32_Unbounded(
"tag", value.
n);
263 serialize.NumberU32_Unbounded(
"tag",
m_Tag.
n);
264 serialize.NumberU8_Unbounded(
"flags",
m_Flags);
296 if (!cmpObstructionManager)
305 for (
size_t i = 0; i <
m_Shapes.size(); ++i)
340 if (!cmpObstructionManager)
362 if (!cmpObstructionManager)
393 if (!cmpObstructionManager)
417 if (movementDisabled)
421 if (pathfindingDisabled)
452 if (!cmpObstructionManager)
504 LOGERROR(L
"[CmpObstruction] Cannot test for foundation obstructions; primary control group must be valid");
535 if (!cmpObstructionManager)
541 LOGERROR(L
"[CmpObstruction] Cannot test for foundation obstructions; primary control group must be valid");
557 std::vector<entity_id_t> ret;
569 if (!cmpObstructionManager)
575 LOGERROR(L
"[CmpObstruction] Cannot test for unit or structure obstructions; primary control group must be valid");
580 bool invertMatch =
false;
587 if (checkStructures && checkUnits)
590 else if (checkStructures)
624 if (cmpObstructionManager)
656 if (cmpObstructionManager)
684 if (!cmpObstructionManager)
702 std::vector<entity_id_t> collisions;
705 std::vector<entity_id_t> persistentEnts, normalEnts;
712 for (std::vector<entity_id_t>::iterator it = collisions.begin(); it != collisions.end(); ++it)
720 normalEnts.push_back(ent);
726 if (persistentEnts.empty())
730 for (std::vector<entity_id_t>::iterator it = normalEnts.begin(); it != normalEnts.end(); ++it)
735 for (std::vector<entity_id_t>::iterator it = persistentEnts.begin(); it != persistentEnts.end(); ++it)
754 if (!cmpObstructionManager)
768 for (
size_t i = 0; i <
m_Shapes.size(); ++i)
780 if (!cmpObstructionManager)
An entity initialisation parameter node.
virtual pass_class_t GetPassabilityClass(const std::string &name)=0
Get the tag for a given passability class name.
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
virtual bool TestStaticShape(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, std::vector< entity_id_t > *out)=0
Collision test a static square shape against the current set of shapes.
virtual ICmpObstructionManager::tag_t GetObstruction()
A simple fixed-point number class.
Obstruction test filter that will test only against shapes that:
void SerializeCommon(S &serialize)
virtual void SetControlGroup(entity_id_t group)
Change the control group that the entity belongs to.
Obstruction test filter that will test only against shapes that:
bool m_Moving
Whether the entity associated with this obstruction is currently moving.
#define REGISTER_COMPONENT_TYPE(cname)
Helper templates for serializing/deserializing common objects.
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
virtual EFoundationCheck CheckFoundation(std::string className, bool onlyCenterPoint)
virtual void SetUnitControlGroup(tag_t tag, entity_id_t group)=0
Set the control group of a unit shape.
bool ToBool() const
Parses the content of this node as a boolean ("true" == true, anything else == false) ...
entity_id_t m_ControlGroup2
Optional secondary control group identifier.
virtual tag_t AddStaticShape(entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h, flags_t flags, entity_id_t group, entity_id_t group2=INVALID_ENTITY)=0
Register a static shape.
virtual ObstructionSquare GetStaticShapeObstruction(entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h)=0
virtual bool TestUnitShape(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, std::vector< entity_id_t > *out)=0
Collision test a unit shape against the current set of registered shapes, and optionally writes a lis...
virtual void SetMovingFlag(bool enabled)
virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass)=0
Check whether a building placed here is valid and doesn't hit any obstructions or impassable terrain...
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
virtual void SetControlGroup2(entity_id_t group2)=0
Serialization interface; see serialization overview.
std::vector< Shape > m_Shapes
static void out(const wchar_t *fmt,...)
virtual entity_pos_t GetUnitRadius()
virtual CFixedVector3D GetRotation()=0
Returns the current rotation (relative to the upwards axis), as Euler angles with X=pitch...
virtual void SetDisableBlockMovementPathfinding(bool movementDisabled, bool pathfindingDisabled, int32_t shape)
virtual void Init(const CParamNode ¶mNode)
void UpdateControlGroups()
const ChildrenMap & GetChildren() const
Returns the names/nodes of the children of this node, ordered by name.
virtual std::vector< entity_id_t > GetEntityCollisions(bool checkStructures, bool checkUnits)
Returns a list of entities that are colliding with this entity, filtered depending on type of entitie...
virtual bool IsControlPersistent()=0
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)
virtual bool IsInWorld()=0
Returns true if the entity currently exists at a defined position in the world.
void ResolveFoundationCollisions()
Detects collisions between foundation-blocking entities and tries to fix them by setting control grou...
Obstruction implementation.
virtual void HandleMessage(const CMessage &msg, bool global)
Flags an entity as obstructing movement for other units, and handles the processing of collision quer...
CEntityHandle GetEntityHandle() const
ICmpObstructionManager::tag_t tag_t
fixed ToFixed() const
Parses the content of this node as a fixed-point number.
entity_id_t GetEntityId() const
virtual int GetType() const =0
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...
virtual entity_id_t GetControlGroup()
See SetControlGroup.
virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass)=0
Check whether a unit placed here is valid and doesn't hit any obstructions or impassable terrain...
tag_t m_Tag
Identifier of this entity's obstruction shape, as registered in the obstruction manager.
virtual void SetUnitMovingFlag(tag_t tag, bool moving)=0
Set whether a unit shape is moving or stationary.
static void ClassInit(CComponentManager &componentManager)
virtual entity_id_t GetControlGroup2()
virtual entity_id_t GetControlGroup2()=0
virtual void SetStaticControlGroup(tag_t tag, entity_id_t group, entity_id_t group2)=0
Sets the control group of a static shape.
CFixed Multiply(CFixed n) const
Multiply by a CFixed.
bool m_Active
Whether the obstruction is actively obstructing or just an inactive placeholder.
virtual bool CheckDuplicateFoundation()
Test whether this entity is colliding with any obstructions that share its control groups and block t...
virtual void SetActive(bool active)
virtual CFixedVector2D GetPosition2D()=0
Returns the current x,z position (no interpolation).
virtual bool IsControlPersistent()
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
const CSimContext & GetSimContext() const
virtual void SetControlGroup2(entity_id_t group2)
static std::string GetSchema()
virtual bool GetBlockMovementFlag()
virtual EFoundationCheck CheckFoundation(std::string className)
Test whether this entity is colliding with any obstruction that are set to block the creation of foun...
A simplified syntax for accessing entity components.
ICmpObstructionManager::flags_t flags_t
CEntityHandle GetSystemEntity() const
static CFixed FromInt(int n)
virtual ObstructionSquare GetUnitShapeObstruction(entity_pos_t x, entity_pos_t z, entity_pos_t r)=0
void AddClusterShapes(entity_pos_t x, entity_pos_t z, entity_angle_t a)
void RemoveClusterShapes()
flags_t m_Flags
Set of flags affecting the behaviour of this entity's obstruction shape.
enum CCmpObstruction::@52 m_Type
void operator()(S &serialize, const char *name, tag_t &value)
void sincos_approx(CFixed_15_16 a, CFixed_15_16 &sin_out, CFixed_15_16 &cos_out)
Compute sin(a) and cos(a).
virtual entity_id_t GetControlGroup()=0
See SetControlGroup.
virtual void RemoveShape(tag_t tag)=0
Remove an existing shape.
virtual void Serialize(ISerializer &serialize)
const entity_id_t INVALID_ENTITY
Invalid entity ID.
virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare &out)
Gets the square corresponding to this obstruction shape.
virtual void SetControlGroup(entity_id_t group)=0
Change the control group that the entity belongs to.
u32 entity_id_t
Entity ID type.
std::vector< tag_t > m_ClusterTags
std::map< std::string, CParamNode > ChildrenMap
virtual void MoveShape(tag_t tag, entity_pos_t x, entity_pos_t z, entity_angle_t a)=0
Adjust the position and angle of an existing shape.
Standard representation for all types of shapes, for use with geometry processing code...
Obstruction manager: provides efficient spatial queries over objects in the world.
entity_id_t m_ControlGroup
Primary control group identifier.
bool m_ControlPersist
Whether an obstruction's control group should be kept consistent and used to set control groups for e...
Deserialization interface; see serialization overview.
External identifiers for shapes.
virtual tag_t AddUnitShape(entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_angle_t r, flags_t flags, entity_id_t group)=0
Register a unit shape.