2012-02-08 03:46:15 +01:00
/* Copyright (C) 2012 Wildfire Games.
2010-01-29 22:13:18 +01:00
* This file is part of 0 A . D .
*
* 0 A . D . is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 2 of the License , or
* ( at your option ) any later version .
*
* 0 A . D . is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with 0 A . D . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "precompiled.h"
# include "simulation2/system/Component.h"
# include "ICmpObstruction.h"
2012-05-05 21:22:22 +02:00
# include "ps/CLogger.h"
# include "simulation2/MessageTypes.h"
2011-08-06 10:11:05 +02:00
# include "simulation2/components/ICmpObstructionManager.h"
# include "simulation2/components/ICmpPosition.h"
2010-01-29 22:13:18 +01:00
/**
* Obstruction implementation . This keeps the ICmpPathfinder ' s model of the world updated when the
* entities move and die , with shapes derived from ICmpFootprint .
*/
class CCmpObstruction : public ICmpObstruction
{
public :
static void ClassInit ( CComponentManager & componentManager )
{
componentManager . SubscribeToMessageType ( MT_PositionChanged ) ;
componentManager . SubscribeToMessageType ( MT_Destroy ) ;
}
DEFAULT_COMPONENT_ALLOCATOR ( Obstruction )
2011-08-16 13:18:32 +02:00
typedef ICmpObstructionManager : : tag_t tag_t ;
typedef ICmpObstructionManager : : flags_t flags_t ;
2010-04-30 01:36:05 +02:00
// Template state:
enum {
STATIC ,
UNIT
} m_Type ;
2012-05-05 21:22:22 +02:00
2010-04-30 01:36:05 +02:00
entity_pos_t m_Size0 ; // radius or width
entity_pos_t m_Size1 ; // radius or depth
2011-08-16 13:18:32 +02:00
flags_t m_TemplateFlags ;
2010-03-18 00:13:21 +01:00
2010-04-30 01:36:05 +02:00
// Dynamic state:
2012-05-06 01:10:25 +02:00
/// Whether the obstruction is actively obstructing or just an inactive placeholder.
bool m_Active ;
/// Whether the entity associated with this obstruction is currently moving. Only applicable for
/// UNIT-type obstructions.
2010-04-30 01:36:05 +02:00
bool m_Moving ;
2012-05-05 21:22:22 +02:00
/**
2012-05-06 01:10:25 +02:00
* Primary control group identifier . Indicates to which control group this entity ' s shape belongs .
* Typically used in combination with obstruction test filters to have member shapes ignore each
* other during obstruction tests . Defaults to the entity ' s ID . Must never be set to INVALID_ENTITY .
2012-05-05 21:22:22 +02:00
*/
2010-09-03 11:55:14 +02:00
entity_id_t m_ControlGroup ;
2012-05-06 01:10:25 +02:00
/**
* Optional secondary control group identifier . Similar to m_ControlGroup ; if set to a valid value ,
* then this field identifies an additional , secondary control group to which this entity ' s shape
* belongs . Set to INVALID_ENTITY to not assign any secondary group . Defaults to INVALID_ENTITY .
*
* These are only necessary in case it is not sufficient for an entity to belong to only one control
* group . Otherwise , they can be ignored .
*/
2012-05-05 21:22:22 +02:00
entity_id_t m_ControlGroup2 ;
2012-05-06 01:10:25 +02:00
/// Identifier of this entity's obstruction shape, as registered in the obstruction manager. Contains
/// structure, but should be treated as opaque here.
2011-08-16 13:18:32 +02:00
tag_t m_Tag ;
2012-05-06 01:10:25 +02:00
2012-05-05 21:22:22 +02:00
/// Set of flags affecting the behaviour of this entity's obstruction shape.
2011-08-16 13:18:32 +02:00
flags_t m_Flags ;
2010-03-18 00:13:21 +01:00
2010-04-09 21:02:39 +02:00
static std : : string GetSchema ( )
{
return
2010-04-23 18:09:03 +02:00
" <a:example/> "
2011-02-10 17:06:28 +01:00
" <a:help>Causes this entity to obstruct the motion of other units.</a:help> "
2010-04-30 01:36:05 +02:00
" <choice> "
" <element name='Static'> "
" <attribute name='width'> "
" <ref name='positiveDecimal'/> "
" </attribute> "
" <attribute name='depth'> "
" <ref name='positiveDecimal'/> "
" </attribute> "
" </element> "
" <element name='Unit'> "
" <attribute name='radius'> "
" <ref name='positiveDecimal'/> "
" </attribute> "
" </element> "
" </choice> "
2011-02-10 17:06:28 +01:00
" <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'> "
" <data type='boolean'/> "
" </element> "
" <element name='BlockMovement' a:help='Whether units should be allowed to walk through this entity'> "
" <data type='boolean'/> "
" </element> "
" <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'> "
" <data type='boolean'/> "
" </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'> "
" <data type='boolean'/> "
" </element> "
" <element name='BlockConstruction' a:help='Whether players should be unable to begin constructing buildings placed on top of this entity'> "
" <data type='boolean'/> "
2011-02-24 22:49:24 +01:00
" </element> "
" <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'/> "
" </element> "
" <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'/> "
2011-02-10 17:06:28 +01:00
" </element> " ;
2010-04-09 21:02:39 +02:00
}
2010-04-23 18:09:03 +02:00
2011-01-16 15:08:38 +01:00
virtual void Init ( const CParamNode & paramNode )
2010-01-29 22:13:18 +01:00
{
2010-04-30 01:36:05 +02:00
if ( paramNode . GetChild ( " Unit " ) . IsOk ( ) )
{
m_Type = UNIT ;
m_Size0 = m_Size1 = paramNode . GetChild ( " Unit " ) . GetChild ( " @radius " ) . ToFixed ( ) ;
}
else
{
m_Type = STATIC ;
m_Size0 = paramNode . GetChild ( " Static " ) . GetChild ( " @width " ) . ToFixed ( ) ;
m_Size1 = paramNode . GetChild ( " Static " ) . GetChild ( " @depth " ) . ToFixed ( ) ;
}
2011-02-24 22:49:24 +01:00
m_TemplateFlags = 0 ;
2011-02-10 17:06:28 +01:00
if ( paramNode . GetChild ( " BlockMovement " ) . ToBool ( ) )
2011-02-24 22:49:24 +01:00
m_TemplateFlags | = ICmpObstructionManager : : FLAG_BLOCK_MOVEMENT ;
2011-02-10 17:06:28 +01:00
if ( paramNode . GetChild ( " BlockPathfinding " ) . ToBool ( ) )
2011-02-24 22:49:24 +01:00
m_TemplateFlags | = ICmpObstructionManager : : FLAG_BLOCK_PATHFINDING ;
2011-02-10 17:06:28 +01:00
if ( paramNode . GetChild ( " BlockFoundation " ) . ToBool ( ) )
2011-02-24 22:49:24 +01:00
m_TemplateFlags | = ICmpObstructionManager : : FLAG_BLOCK_FOUNDATION ;
2011-02-10 17:06:28 +01:00
if ( paramNode . GetChild ( " BlockConstruction " ) . ToBool ( ) )
2011-02-24 22:49:24 +01:00
m_TemplateFlags | = ICmpObstructionManager : : FLAG_BLOCK_CONSTRUCTION ;
m_Flags = m_TemplateFlags ;
if ( paramNode . GetChild ( " DisableBlockMovement " ) . ToBool ( ) )
2011-08-16 13:18:32 +02:00
m_Flags & = ( flags_t ) ( ~ ICmpObstructionManager : : FLAG_BLOCK_MOVEMENT ) ;
2011-02-24 22:49:24 +01:00
if ( paramNode . GetChild ( " DisableBlockPathfinding " ) . ToBool ( ) )
2011-08-16 13:18:32 +02:00
m_Flags & = ( flags_t ) ( ~ ICmpObstructionManager : : FLAG_BLOCK_PATHFINDING ) ;
2011-02-10 17:06:28 +01:00
m_Active = paramNode . GetChild ( " Active " ) . ToBool ( ) ;
2010-03-18 00:13:21 +01:00
2011-08-16 13:18:32 +02:00
m_Tag = tag_t ( ) ;
2010-04-30 01:36:05 +02:00
m_Moving = false ;
2010-09-03 11:55:14 +02:00
m_ControlGroup = GetEntityId ( ) ;
2012-05-05 21:22:22 +02:00
m_ControlGroup2 = INVALID_ENTITY ;
2010-01-29 22:13:18 +01:00
}
2011-01-16 15:08:38 +01:00
virtual void Deinit ( )
2010-01-29 22:13:18 +01:00
{
}
2010-10-23 21:59:40 +02:00
template < typename S >
void SerializeCommon ( S & serialize )
2010-01-29 22:13:18 +01:00
{
2011-02-10 17:06:28 +01:00
serialize . Bool ( " active " , m_Active ) ;
2010-10-23 21:59:40 +02:00
serialize . Bool ( " moving " , m_Moving ) ;
serialize . NumberU32_Unbounded ( " control group " , m_ControlGroup ) ;
2012-05-05 21:22:22 +02:00
serialize . NumberU32_Unbounded ( " control group 2 " , m_ControlGroup2 ) ;
2010-10-23 21:59:40 +02:00
serialize . NumberU32_Unbounded ( " tag " , m_Tag . n ) ;
2011-02-24 22:49:24 +01:00
serialize . NumberU8_Unbounded ( " flags " , m_Flags ) ;
2010-01-29 22:13:18 +01:00
}
2010-10-23 21:59:40 +02:00
virtual void Serialize ( ISerializer & serialize )
{
SerializeCommon ( serialize ) ;
}
2011-01-16 15:08:38 +01:00
virtual void Deserialize ( const CParamNode & paramNode , IDeserializer & deserialize )
2010-01-29 22:13:18 +01:00
{
2011-01-16 15:08:38 +01:00
Init ( paramNode ) ;
2010-01-29 22:13:18 +01:00
2010-10-23 21:59:40 +02:00
SerializeCommon ( deserialize ) ;
2010-01-29 22:13:18 +01:00
}
2011-01-16 15:08:38 +01:00
virtual void HandleMessage ( const CMessage & msg , bool UNUSED ( global ) )
2010-01-29 22:13:18 +01:00
{
switch ( msg . GetType ( ) )
{
case MT_PositionChanged :
{
2010-03-18 00:13:21 +01:00
if ( ! m_Active )
break ;
2010-01-29 22:13:18 +01:00
const CMessagePositionChanged & data = static_cast < const CMessagePositionChanged & > ( msg ) ;
2010-07-04 19:19:38 +02:00
if ( ! data . inWorld & & ! m_Tag . valid ( ) )
2010-03-18 00:13:21 +01:00
break ; // nothing needs to change
2010-01-29 22:13:18 +01:00
2011-01-16 15:08:38 +01:00
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpObstructionManager )
2011-02-10 17:06:28 +01:00
break ; // error
2010-01-29 22:13:18 +01:00
2010-07-04 19:19:38 +02:00
if ( data . inWorld & & m_Tag . valid ( ) )
2010-01-29 22:13:18 +01:00
{
2010-03-18 00:13:21 +01:00
cmpObstructionManager - > MoveShape ( m_Tag , data . x , data . z , data . a ) ;
2010-01-29 22:13:18 +01:00
}
2010-07-04 19:19:38 +02:00
else if ( data . inWorld & & ! m_Tag . valid ( ) )
2010-01-29 22:13:18 +01:00
{
// Need to create a new pathfinder shape:
2010-04-30 01:36:05 +02:00
if ( m_Type = = STATIC )
2011-02-10 17:06:28 +01:00
m_Tag = cmpObstructionManager - > AddStaticShape ( GetEntityId ( ) ,
2012-05-05 21:22:22 +02:00
data . x , data . z , data . a , m_Size0 , m_Size1 , m_Flags , m_ControlGroup , m_ControlGroup2 ) ;
2010-01-29 22:13:18 +01:00
else
2011-02-10 17:06:28 +01:00
m_Tag = cmpObstructionManager - > AddUnitShape ( GetEntityId ( ) ,
2011-08-16 13:18:32 +02:00
data . x , data . z , m_Size0 , ( flags_t ) ( m_Flags | ( m_Moving ? ICmpObstructionManager : : FLAG_MOVING : 0 ) ) , m_ControlGroup ) ;
2010-01-29 22:13:18 +01:00
}
2010-07-04 19:19:38 +02:00
else if ( ! data . inWorld & & m_Tag . valid ( ) )
2010-01-29 22:13:18 +01:00
{
2010-03-18 00:13:21 +01:00
cmpObstructionManager - > RemoveShape ( m_Tag ) ;
2011-08-16 13:18:32 +02:00
m_Tag = tag_t ( ) ;
2010-01-29 22:13:18 +01:00
}
break ;
}
case MT_Destroy :
{
2010-07-04 19:19:38 +02:00
if ( m_Tag . valid ( ) )
2010-01-29 22:13:18 +01:00
{
2011-01-16 15:08:38 +01:00
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpObstructionManager )
2011-02-10 17:06:28 +01:00
break ; // error
2010-01-29 22:13:18 +01:00
2010-03-18 00:13:21 +01:00
cmpObstructionManager - > RemoveShape ( m_Tag ) ;
2011-08-16 13:18:32 +02:00
m_Tag = tag_t ( ) ;
2010-01-29 22:13:18 +01:00
}
break ;
}
}
}
2010-03-18 00:13:21 +01:00
2011-02-10 17:06:28 +01:00
virtual void SetActive ( bool active )
{
if ( active & & ! m_Active )
{
m_Active = true ;
// Construct the obstruction shape
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpObstructionManager )
2011-02-10 17:06:28 +01:00
return ; // error
CmpPtr < ICmpPosition > cmpPosition ( GetSimContext ( ) , GetEntityId ( ) ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpPosition )
2011-02-10 17:06:28 +01:00
return ; // error
if ( ! cmpPosition - > IsInWorld ( ) )
return ; // don't need an obstruction
2012-05-05 21:22:22 +02:00
// TODO: code duplication from message handlers
2011-02-10 17:06:28 +01:00
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
if ( m_Type = = STATIC )
m_Tag = cmpObstructionManager - > AddStaticShape ( GetEntityId ( ) ,
2012-05-05 21:22:22 +02:00
pos . X , pos . Y , cmpPosition - > GetRotation ( ) . Y , m_Size0 , m_Size1 , m_Flags , m_ControlGroup , m_ControlGroup2 ) ;
2011-02-10 17:06:28 +01:00
else
m_Tag = cmpObstructionManager - > AddUnitShape ( GetEntityId ( ) ,
2011-08-16 13:18:32 +02:00
pos . X , pos . Y , m_Size0 , ( flags_t ) ( m_Flags | ( m_Moving ? ICmpObstructionManager : : FLAG_MOVING : 0 ) ) , m_ControlGroup ) ;
2011-02-10 17:06:28 +01:00
}
else if ( ! active & & m_Active )
{
m_Active = false ;
// Delete the obstruction shape
2012-05-05 21:22:22 +02:00
// TODO: code duplication from message handlers
2011-02-10 17:06:28 +01:00
if ( m_Tag . valid ( ) )
{
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpObstructionManager )
2011-02-10 17:06:28 +01:00
return ; // error
cmpObstructionManager - > RemoveShape ( m_Tag ) ;
2011-08-16 13:18:32 +02:00
m_Tag = tag_t ( ) ;
2011-02-10 17:06:28 +01:00
}
}
// else we didn't change the active status
}
2011-02-24 22:49:24 +01:00
virtual void SetDisableBlockMovementPathfinding ( bool disabled )
{
if ( disabled )
{
// Remove the blocking flags
2011-08-16 13:18:32 +02:00
m_Flags & = ( flags_t ) ( ~ ICmpObstructionManager : : FLAG_BLOCK_MOVEMENT ) ;
m_Flags & = ( flags_t ) ( ~ ICmpObstructionManager : : FLAG_BLOCK_PATHFINDING ) ;
2011-02-24 22:49:24 +01:00
}
else
{
// Add the blocking flags if the template had enabled them
2011-08-16 13:18:32 +02:00
m_Flags = ( flags_t ) ( m_Flags | ( m_TemplateFlags & ICmpObstructionManager : : FLAG_BLOCK_MOVEMENT ) ) ;
m_Flags = ( flags_t ) ( m_Flags | ( m_TemplateFlags & ICmpObstructionManager : : FLAG_BLOCK_PATHFINDING ) ) ;
2011-02-24 22:49:24 +01:00
}
// Reset the shape with the new flags (kind of inefficiently - we
// should have a ICmpObstructionManager::SetFlags function or something)
if ( m_Active )
{
SetActive ( false ) ;
SetActive ( true ) ;
}
}
2011-05-13 22:32:41 +02:00
virtual bool GetBlockMovementFlag ( )
{
return ( m_TemplateFlags & ICmpObstructionManager : : FLAG_BLOCK_MOVEMENT ) ! = 0 ;
}
2010-04-30 01:36:05 +02:00
virtual ICmpObstructionManager : : tag_t GetObstruction ( )
2010-03-18 00:13:21 +01:00
{
2010-04-30 01:36:05 +02:00
return m_Tag ;
}
2010-03-18 00:13:21 +01:00
2011-02-10 17:06:28 +01:00
virtual bool GetObstructionSquare ( ICmpObstructionManager : : ObstructionSquare & out )
{
CmpPtr < ICmpPosition > cmpPosition ( GetSimContext ( ) , GetEntityId ( ) ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpPosition )
2011-02-10 17:06:28 +01:00
return false ; // error
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpObstructionManager )
2011-02-10 17:06:28 +01:00
return false ; // error
if ( ! cmpPosition - > IsInWorld ( ) )
return false ; // no obstruction square
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
if ( m_Type = = STATIC )
out = cmpObstructionManager - > GetStaticShapeObstruction ( pos . X , pos . Y , cmpPosition - > GetRotation ( ) . Y , m_Size0 , m_Size1 ) ;
else
out = cmpObstructionManager - > GetUnitShapeObstruction ( pos . X , pos . Y , m_Size0 ) ;
return true ;
}
2010-04-30 01:36:05 +02:00
virtual entity_pos_t GetUnitRadius ( )
{
if ( m_Type = = UNIT )
return m_Size0 ;
else
return entity_pos_t : : Zero ( ) ;
}
2011-08-06 10:11:05 +02:00
virtual bool CheckFoundation ( std : : string className )
2011-02-10 17:06:28 +01:00
{
CmpPtr < ICmpPosition > cmpPosition ( GetSimContext ( ) , GetEntityId ( ) ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpPosition )
2011-02-10 17:06:28 +01:00
return false ; // error
if ( ! cmpPosition - > IsInWorld ( ) )
return false ; // no obstruction
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
2011-08-06 10:11:05 +02:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpPathfinder )
2011-02-10 17:06:28 +01:00
return false ; // error
2012-05-05 21:22:22 +02:00
// required precondition to use SkipControlGroupsRequireFlagObstructionFilter
if ( m_ControlGroup = = INVALID_ENTITY )
{
LOGERROR ( L " [CmpObstruction] Cannot test for foundation obstructions; primary control group must be valid " ) ;
return false ;
}
2011-08-06 10:11:05 +02:00
// Get passability class
ICmpPathfinder : : pass_class_t passClass = cmpPathfinder - > GetPassabilityClass ( className ) ;
2012-05-05 21:22:22 +02:00
// Ignore collisions within the same control group, or with other non-foundation-blocking shapes.
// 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 non-foundation-blocking shapes.
SkipControlGroupsRequireFlagObstructionFilter filter ( m_ControlGroup , m_ControlGroup2 ,
ICmpObstructionManager : : FLAG_BLOCK_FOUNDATION ) ;
2011-02-10 17:06:28 +01:00
if ( m_Type = = STATIC )
2011-08-06 10:11:05 +02:00
return cmpPathfinder - > CheckBuildingPlacement ( filter , pos . X , pos . Y , cmpPosition - > GetRotation ( ) . Y , m_Size0 , m_Size1 , GetEntityId ( ) , passClass ) ;
2011-02-10 17:06:28 +01:00
else
2011-08-06 10:11:05 +02:00
return cmpPathfinder - > CheckUnitPlacement ( filter , pos . X , pos . Y , m_Size0 , passClass ) ;
2011-02-10 17:06:28 +01:00
}
virtual std : : vector < entity_id_t > GetConstructionCollisions ( )
2010-04-30 01:36:05 +02:00
{
2011-02-10 17:06:28 +01:00
std : : vector < entity_id_t > ret ;
2010-05-01 11:48:39 +02:00
CmpPtr < ICmpPosition > cmpPosition ( GetSimContext ( ) , GetEntityId ( ) ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpPosition )
2011-02-10 17:06:28 +01:00
return ret ; // error
if ( ! cmpPosition - > IsInWorld ( ) )
return ret ; // no obstruction
2010-03-18 00:13:21 +01:00
2010-07-29 22:39:23 +02:00
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
2010-03-18 00:13:21 +01:00
2010-05-01 11:48:39 +02:00
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( ! cmpObstructionManager )
2011-02-10 17:06:28 +01:00
return ret ; // error
2010-03-18 00:13:21 +01:00
2012-05-05 21:22:22 +02:00
// required precondition to use SkipControlGroupsRequireFlagObstructionFilter
if ( m_ControlGroup = = INVALID_ENTITY )
{
LOGERROR ( L " [CmpObstruction] Cannot test for construction obstructions; primary control group must be valid " ) ;
return ret ;
}
// Ignore collisions within the same control group, or with other non-construction-blocking shapes.
// 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 non-construction-blocking shapes.
SkipControlGroupsRequireFlagObstructionFilter filter ( m_ControlGroup , m_ControlGroup2 ,
ICmpObstructionManager : : FLAG_BLOCK_CONSTRUCTION ) ;
2010-03-18 00:13:21 +01:00
2010-04-30 01:36:05 +02:00
if ( m_Type = = STATIC )
2011-02-10 17:06:28 +01:00
cmpObstructionManager - > TestStaticShape ( filter , pos . X , pos . Y , cmpPosition - > GetRotation ( ) . Y , m_Size0 , m_Size1 , & ret ) ;
2010-03-18 00:13:21 +01:00
else
2011-02-10 17:06:28 +01:00
cmpObstructionManager - > TestUnitShape ( filter , pos . X , pos . Y , m_Size0 , & ret ) ;
return ret ;
2010-03-18 00:13:21 +01:00
}
2010-09-03 11:55:14 +02:00
virtual void SetMovingFlag ( bool enabled )
{
m_Moving = enabled ;
if ( m_Tag . valid ( ) & & m_Type = = UNIT )
{
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( cmpObstructionManager )
2010-09-03 11:55:14 +02:00
cmpObstructionManager - > SetUnitMovingFlag ( m_Tag , m_Moving ) ;
}
}
virtual void SetControlGroup ( entity_id_t group )
{
m_ControlGroup = group ;
2012-05-05 21:22:22 +02:00
UpdateControlGroups ( ) ;
}
2010-09-03 11:55:14 +02:00
2012-05-05 21:22:22 +02:00
virtual void SetControlGroup2 ( entity_id_t group2 )
{
m_ControlGroup2 = group2 ;
UpdateControlGroups ( ) ;
}
virtual entity_id_t GetControlGroup ( )
{
return m_ControlGroup ;
}
virtual entity_id_t GetControlGroup2 ( )
{
return m_ControlGroup2 ;
}
void UpdateControlGroups ( )
{
if ( m_Tag . valid ( ) )
2010-09-03 11:55:14 +02:00
{
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
2012-02-08 03:46:15 +01:00
if ( cmpObstructionManager )
2012-05-05 21:22:22 +02:00
{
if ( m_Type = = UNIT )
{
cmpObstructionManager - > SetUnitControlGroup ( m_Tag , m_ControlGroup ) ;
}
else if ( m_Type = = STATIC )
{
cmpObstructionManager - > SetStaticControlGroup ( m_Tag , m_ControlGroup , m_ControlGroup2 ) ;
}
}
2010-09-03 11:55:14 +02:00
}
}
2010-01-29 22:13:18 +01:00
} ;
REGISTER_COMPONENT_TYPE ( Obstruction )