Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpObstruction.cpp
Show First 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | return | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<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'>" | "<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'>" | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<element name='BlockConstruction' a:help='Whether players should be unable to begin constructing buildings placed on top of this entity'>" | "<element name='BlockConstruction' a:help='Whether players should be unable to begin constructing buildings placed on top of this entity'>" | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<element name='DeleteUponConstruction' a:help='Whether this entity should be deleted when construction on a buildings placed on top of this entity is started.'>" | |||||
"<data type='boolean'/>" | |||||
"</element>" | |||||
"<element name='DisableBlockMovement' a:help='If true, BlockMovement will be overridden and treated as false. (This is a special case to handle foundations)'>" | "<element name='DisableBlockMovement' a:help='If true, BlockMovement will be overridden and treated as false. (This is a special case to handle foundations)'>" | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<element name='DisableBlockPathfinding' a:help='If true, BlockPathfinding will be overridden and treated as false. (This is a special case to handle foundations)'>" | "<element name='DisableBlockPathfinding' a:help='If true, BlockPathfinding will be overridden and treated as false. (This is a special case to handle foundations)'>" | ||||
"<data type='boolean'/>" | "<data type='boolean'/>" | ||||
"</element>" | "</element>" | ||||
"<optional>" | "<optional>" | ||||
"<element name='ControlPersist' a:help='If present, the control group of this entity will be given to entities that are colliding with it.'>" | "<element name='ControlPersist' a:help='If present, the control group of this entity will be given to entities that are colliding with it.'>" | ||||
Show All 11 Lines | virtual void Init(const CParamNode& paramNode) | ||||
if (paramNode.GetChild("BlockMovement").ToBool()) | if (paramNode.GetChild("BlockMovement").ToBool()) | ||||
m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_MOVEMENT; | m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_MOVEMENT; | ||||
if (paramNode.GetChild("BlockPathfinding").ToBool()) | if (paramNode.GetChild("BlockPathfinding").ToBool()) | ||||
m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_PATHFINDING; | m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_PATHFINDING; | ||||
if (paramNode.GetChild("BlockFoundation").ToBool()) | if (paramNode.GetChild("BlockFoundation").ToBool()) | ||||
m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_FOUNDATION; | m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_FOUNDATION; | ||||
if (paramNode.GetChild("BlockConstruction").ToBool()) | if (paramNode.GetChild("BlockConstruction").ToBool()) | ||||
m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_CONSTRUCTION; | m_TemplateFlags |= ICmpObstructionManager::FLAG_BLOCK_CONSTRUCTION; | ||||
if (paramNode.GetChild("DeleteUponConstruction").ToBool()) | |||||
m_TemplateFlags |= ICmpObstructionManager::FLAG_DELETE_UPON_CONSTRUCTION; | |||||
m_Flags = m_TemplateFlags; | m_Flags = m_TemplateFlags; | ||||
if (paramNode.GetChild("DisableBlockMovement").ToBool()) | if (paramNode.GetChild("DisableBlockMovement").ToBool()) | ||||
m_Flags &= (flags_t)(~ICmpObstructionManager::FLAG_BLOCK_MOVEMENT); | m_Flags &= (flags_t)(~ICmpObstructionManager::FLAG_BLOCK_MOVEMENT); | ||||
if (paramNode.GetChild("DisableBlockPathfinding").ToBool()) | if (paramNode.GetChild("DisableBlockPathfinding").ToBool()) | ||||
m_Flags &= (flags_t)(~ICmpObstructionManager::FLAG_BLOCK_PATHFINDING); | m_Flags &= (flags_t)(~ICmpObstructionManager::FLAG_BLOCK_PATHFINDING); | ||||
if (paramNode.GetChild("Unit").IsOk()) | if (paramNode.GetChild("Unit").IsOk()) | ||||
▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | SkipTagRequireControlGroupsAndFlagObstructionFilter filter(m_Tag, m_ControlGroup, m_ControlGroup2, | ||||
ICmpObstructionManager::FLAG_BLOCK_FOUNDATION); | ICmpObstructionManager::FLAG_BLOCK_FOUNDATION); | ||||
if (m_Type == UNIT) | if (m_Type == UNIT) | ||||
return !cmpObstructionManager->TestUnitShape(filter, pos.X, pos.Y, m_Clearance, NULL); | return !cmpObstructionManager->TestUnitShape(filter, pos.X, pos.Y, m_Clearance, NULL); | ||||
else | else | ||||
return !cmpObstructionManager->TestStaticShape(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, NULL ); | return !cmpObstructionManager->TestStaticShape(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, NULL ); | ||||
} | } | ||||
virtual std::vector<entity_id_t> GetUnitCollisions() const | virtual std::vector<entity_id_t> GetEntitiesByFlags(flags_t flags) const | ||||
{ | { | ||||
std::vector<entity_id_t> ret; | std::vector<entity_id_t> ret; | ||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | ||||
if (!cmpObstructionManager) | if (!cmpObstructionManager) | ||||
return ret; // error | return ret; // error | ||||
// There are four 'block' flags: construction, foundation, movement, | |||||
// and pathfinding. Structures have all of these flags, while most units | |||||
// block only movement and construction. | |||||
flags_t flags = ICmpObstructionManager::FLAG_BLOCK_CONSTRUCTION; | |||||
// Ignore collisions within the same control group, or with other shapes that don't match the filter. | // Ignore collisions within the same control group, or with other shapes that don't match the filter. | ||||
// Note that, since the control group for each entity defaults to the entity's ID, this is typically | // Note that, since the control group for each entity defaults to the entity's ID, this is typically | ||||
// equivalent to only ignoring the entity's own shape and other shapes that don't match the filter. | // equivalent to only ignoring the entity's own shape and other shapes that don't match the filter. | ||||
SkipControlGroupsRequireFlagObstructionFilter filter(false, m_ControlGroup, m_ControlGroup2, flags); | SkipControlGroupsRequireFlagObstructionFilter filter(false, m_ControlGroup, m_ControlGroup2, flags); | ||||
ICmpObstructionManager::ObstructionSquare square; | ICmpObstructionManager::ObstructionSquare square; | ||||
if (!GetObstructionSquare(square)) | if (!GetObstructionSquare(square)) | ||||
return ret; // error | return ret; // error | ||||
cmpObstructionManager->GetUnitsOnObstruction(square, ret, filter); | cmpObstructionManager->GetUnitsOnObstruction(square, ret, filter, false); | ||||
cmpObstructionManager->GetStaticObstructionsOnObstruction(square, ret, filter); | |||||
return ret; | return ret; | ||||
} | } | ||||
virtual std::vector<entity_id_t> GetEntityCollisions() const | virtual std::vector<entity_id_t> GetEntitiesBlockingConstruction() const | ||||
{ | { | ||||
std::vector<entity_id_t> ret; | return GetEntitiesByFlags(ICmpObstructionManager::FLAG_BLOCK_CONSTRUCTION); | ||||
} | |||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | |||||
if (!cmpObstructionManager) | |||||
return ret; // error | |||||
// Ignore collisions within the same control group. | |||||
SkipControlGroupsRequireFlagObstructionFilter filter(true, m_ControlGroup, m_ControlGroup2, 0); | |||||
ICmpObstructionManager::ObstructionSquare square; | |||||
if (!GetObstructionSquare(square)) | |||||
return ret; // error | |||||
cmpObstructionManager->GetUnitsOnObstruction(square, ret, filter, false); | |||||
cmpObstructionManager->GetStaticObstructionsOnObstruction(square, ret, filter); | |||||
return ret; | virtual std::vector<entity_id_t> GetEntitiesDeletedUponConstruction() const | ||||
{ | |||||
return GetEntitiesByFlags(ICmpObstructionManager::FLAG_DELETE_UPON_CONSTRUCTION); | |||||
} | } | ||||
virtual void SetMovingFlag(bool enabled) | virtual void SetMovingFlag(bool enabled) | ||||
{ | { | ||||
m_Moving = enabled; | m_Moving = enabled; | ||||
if (m_Tag.valid() && m_Type == UNIT) | if (m_Tag.valid() && m_Type == UNIT) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator