CCopyEntity *EntityManager::CreateEntity( CCopyEntityDesc& rCopyEntityDesc ) { if( !rCopyEntityDesc.pBaseEntityHandle ) return NULL; BaseEntityHandle& rBaseEntityHandle = *(rCopyEntityDesc.pBaseEntityHandle); // LOG_PRINT( "creating a copy entity of " + string(rBaseEntityHandle.GetBaseEntityName()) ); BaseEntity *pBaseEntity = GetBaseEntity( rBaseEntityHandle ); if( !pBaseEntity ) return NULL; BaseEntity& rBaseEntity = *(pBaseEntity); // LOG_PRINT( "checking the initial position of " + rBaseEntity.GetNameString() ); // determine the entity group id // priority (higher to lower): // (id set to copy entity desc) -> (id set to base entity) int entity_group_id = ENTITY_GROUP_INVALID_ID; if( rCopyEntityDesc.sGroupID != ENTITY_GROUP_INVALID_ID ) { entity_group_id = rCopyEntityDesc.sGroupID; } else { // try the group of base entity entity_group_id = rBaseEntity.GetEntityGroupID(); } if( false ) // if( !rBaseEntity.m_bNoClip ) // && rCopyEntityDesc.DontCreateIfOverlapIsDetected ) { // check for overlaps with other entities // to see if the new entity is in a valid position // if( rCopyEnt.bvType == BVTYPE_AABB || rCopyEnt.bvType == BVTYPE_DOT ) // { STrace tr; tr.sTraceType = TRACETYPE_IGNORE_NOCLIP_ENTITIES; tr.vEnd = rCopyEntityDesc.WorldPose.vPosition; tr.bvType = rBaseEntity.m_BoundingVolumeType; tr.aabb = rBaseEntity.m_aabb; tr.GroupIndex = entity_group_id; if( rBaseEntity.m_bNoClipAgainstMap ) tr.sTraceType |= TRACETYPE_IGNORE_MAP; m_pStage->CheckPosition( tr ); if(tr.in_solid) { LOG_PRINT( " - cannot create a copy entity due to overlaps: " + string(rBaseEntityHandle.GetBaseEntityName()) ); return NULL; // specified position is invalid - cannot create entity } // } } // LOG_PRINT( "the copy entity of " + rBaseEntity.GetNameString() + " is in a valid position" ); // create an entity shared_ptr<CCopyEntity> pNewEntitySharedPtr = m_pEntityFactory->CreateEntity( rCopyEntityDesc.TypeID ); if( !pNewEntitySharedPtr ) { /// too many entities or no entity is defined for rCopyEntityDesc.TypeID LOG_PRINT_ERROR( " - cannot create a copy entity of '" + string(rBaseEntityHandle.GetBaseEntityName()) + "'" ); return NULL; } CCopyEntity *pNewCopyEnt = pNewEntitySharedPtr.get(); pNewCopyEnt->m_TypeID = rCopyEntityDesc.TypeID; // copy parameter values from base entity (entity attributes set) SetBasicEntityAttributes( pNewCopyEnt, rBaseEntity ); // copy parameter values from entity desc pNewCopyEnt->SetName( rCopyEntityDesc.strName ); pNewCopyEnt->SetWorldPose( rCopyEntityDesc.WorldPose ); pNewCopyEnt->Velocity() = rCopyEntityDesc.vVelocity; pNewCopyEnt->fSpeed = rCopyEntityDesc.fSpeed; pNewCopyEnt->m_MeshHandle = rCopyEntityDesc.MeshObjectHandle; pNewCopyEnt->f1 = rCopyEntityDesc.f1; pNewCopyEnt->f2 = rCopyEntityDesc.f2; pNewCopyEnt->f3 = rCopyEntityDesc.f3; pNewCopyEnt->f4 = rCopyEntityDesc.f4; pNewCopyEnt->f5 = 0.0f; pNewCopyEnt->s1 = rCopyEntityDesc.s1; pNewCopyEnt->v1 = rCopyEntityDesc.v1; pNewCopyEnt->v2 = rCopyEntityDesc.v2; pNewCopyEnt->iExtraDataIndex = rCopyEntityDesc.iExtraDataIndex; pNewCopyEnt->pUserData = rCopyEntityDesc.pUserData; pNewCopyEnt->sState = 0; pNewCopyEnt->bInSolid = false; pNewCopyEnt->GroupIndex = entity_group_id; // pNewCopyEnt->GroupIndex = rCopyEntityDesc.sGroupID; pNewCopyEnt->touch_plane.dist = 0; pNewCopyEnt->touch_plane.normal = Vector3(0,0,0); InitEntity( pNewEntitySharedPtr, rCopyEntityDesc.pParent, pBaseEntity, rCopyEntityDesc.pPhysActorDesc ); pNewCopyEnt->Init( rCopyEntityDesc ); LOG_PRINT_VERBOSE( " - created a copy entity of " + rBaseEntity.GetNameString() ); return pNewCopyEnt; }