Beispiel #1
0
int CheckBaseHandle(CBaseHandle &hndl)
{
	if (!hndl.IsValid())
	{
		return -1;
	}

	int index = hndl.GetEntryIndex();

	edict_t *pStoredEdict;

	pStoredEdict = engine->PEntityOfEntIndex(index);

	if (pStoredEdict == NULL)
	{
		return -1;
	}

	IServerEntity *pSE = pStoredEdict->GetIServerEntity();

	if (pSE == NULL)
	{
		return -1;
	}

	if (pSE->GetRefEHandle() != hndl)
	{
		return -1;
	}

	return index;
}
Beispiel #2
0
bool CTeamControlPointRound :: isPointInRound ( edict_t *point_pent )
{
	edict_t *pPoint;
	extern ConVar rcbot_const_point_offset;

	for ( int i = 0; i < m_ControlPoints.Size(); i ++ )
	{
		CBaseHandle *hndl;

		hndl = (CBaseHandle *)&(m_ControlPoints[i]); 

		if ( hndl )
		{ 
			pPoint = INDEXENT(hndl->GetEntryIndex());

			CBaseEntity *pent = pPoint->GetUnknown()->GetBaseEntity();

			if ( point_pent->GetUnknown()->GetBaseEntity() == pent )
				return true;

			//CTeamControlPoint *point = (CTeamControlPoint*)((unsigned long)pent + rcbot_const_point_offset.GetInt() );

			//if ( point )
			//{
			//	if ( point->m_iIndex == iIndex )
			//		return true;
			//}
		}
	}

	return false;
}
IPhysicsVehicleController *GetLuaVehicle(ILuaInterface *gLua)
{
	gLua->CheckType(1, GLua::TYPE_ENTITY);

	CBaseHandle *handle = (CBaseHandle*)gLua->GetUserData(1);
	CBaseEntity *entity = GetBaseEntity(handle->GetEntryIndex());

	if(!entity)
	{
		gLua->Error("[gm_pimpmyride] NO ENTITY!");
		return NULL;
	}

	IServerVehicle *vehicle = entity->GetServerVehicle();

	if(!vehicle)
	{
		gLua->Error("[gm_pimpmyride] NO VEHICLE!");
		return NULL;
	}

	IPhysicsVehicleController *controller = vehicle->GetVehicleController();

	if(!controller)
	{
		gLua->Error("[gm_pimpmyride] NO PHYSICS CONTROLLER!");
		return NULL;
	}

	return controller;
}
Beispiel #4
0
int PyHandle::Cmp( bp::object other )
{
	// The thing to which we compare is NULL
	PyObject *pPyObject = other.ptr();
	if( pPyObject == Py_None ) {
		return Get() != NULL;
	}

	// We are NULL
	if( Get() == NULL )
	{
		return pPyObject != NULL;
	}

	// Check if it is directly a pointer to an entity
#ifdef CLIENT_DLL
	if( PyObject_IsInstance(pPyObject, bp::object(_entities.attr("C_BaseEntity")).ptr()) )
#else
	if( PyObject_IsInstance(pPyObject, bp::object(_entities.attr("CBaseEntity")).ptr()) )
#endif // CLIENT_DLL
	{
		CBaseEntity *pSelf = Get();
		CBaseEntity *pOther = boost::python::extract< CBaseEntity * >(other);
		if( pOther == pSelf )
		{
			return 0;
		}
		else if( pOther->entindex() > pSelf->entindex() )
		{
			return 1;
		}
		else
		{
			return -1;
		}
	}

	try
	{
		// Must be a handle
		CBaseHandle *pHandle = bp::extract< CBaseHandle * >( other );
		if( pHandle )
		{
			if( pHandle->ToInt() == ToInt() )
				return 0;
			else if( pHandle->GetEntryIndex() > GetEntryIndex() )
				return 1;
			else
				return -1;
		}
	}
	catch( bp::error_already_set & )
	{
		// Not a handle, just clear error and return -1
		PyErr_Clear();	
	}

	return -1;
}
//-----------------------------------------------------------------------------
// After we built the touch list, deal with all the impacts...
//-----------------------------------------------------------------------------
void CMoveHelperServer::ProcessImpacts( void )
{
	Assert( m_pHostPlayer );

	// Relink in order to build absorigin and absmin/max to reflect any changes
	//  from prediction.  Relink will early out on SOLID_NOT
	engine->RelinkEntity( m_pHostPlayer->pev, true );

	// Don't bother if the player ain't solid
	if ( m_pHostPlayer->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
	{
		return;
	}

	// Save off the velocity, cause we need to temporarily reset it
	Vector vel = m_pHostPlayer->GetAbsVelocity();

	// Touch other objects that were intersected during the movement.
	for (int i = 0 ; i < m_TouchList.Size(); i++)
	{
		CBaseHandle entindex = m_TouchList[i].trace.m_pEnt->GetRefEHandle();

		// We should have culled negative indices by now
		Assert( entindex.IsValid() );

		edict_t* ent = GetEdict( entindex );
		if (!ent)
			continue;

		// Run the impact function as if we had run it during movement.
		CBaseEntity *entity = GetContainingEntity( ent );
		if ( !entity )
			continue;

		Assert( entity != m_pHostPlayer );
		// Don't ever collide with self!!!!
		if ( entity == m_pHostPlayer )
			continue;

		// Reconstruct trace results.
		m_TouchList[i].trace.m_pEnt = CBaseEntity::Instance( ent );

		// Use the velocity we had when we collided, so boxes will move, etc.
		m_pHostPlayer->SetAbsVelocity( m_TouchList[i].deltavelocity );
		
		entity->PhysicsImpact( m_pHostPlayer, m_TouchList[i].trace );
	}

	// Restore the velocity
	m_pHostPlayer->SetAbsVelocity( vel );

	// So no stuff is ever left over, sigh...
	ResetTouchList();
}
Beispiel #6
0
//-----------------------------------------------------------------------------
// Returns an index from the given BaseHandle instance.
//-----------------------------------------------------------------------------
bool IndexFromBaseHandle( CBaseHandle hBaseHandle, unsigned int& output )
{
    if (!hBaseHandle.IsValid() || !hBaseHandle.ToInt())
        return false;

    int iEntityIndex = hBaseHandle.GetEntryIndex();
    if (iEntityIndex == INVALID_ENTITY_INDEX)
        return false;

    output = iEntityIndex;
    return true;
}
//-----------------------------------------------------------------------------
// Returns an IntHandle from the given BaseHandle instance.
//-----------------------------------------------------------------------------
bool IntHandleFromBaseHandle( CBaseHandle hBaseHandle, unsigned int& output )
{
	if (!hBaseHandle.IsValid())
		return false;

	unsigned int iEntityHandle = hBaseHandle.ToInt();
	if (!iEntityHandle)
		return false;

	output = iEntityHandle;
	return true;
}
void SendProxy_EHandleToInt( const SendProp *pProp, const void *pStruct, const void *pVarData, DVariant *pOut, int iElement, int objectID)
{
	CBaseHandle *pHandle = (CBaseHandle*)pVarData;

	if ( pHandle && pHandle->Get() )
	{
		int iSerialNum = pHandle->GetSerialNumber() & (1 << NUM_NETWORKED_EHANDLE_SERIAL_NUMBER_BITS) - 1;
		pOut->m_Int = pHandle->GetEntryIndex() | (iSerialNum << MAX_EDICT_BITS);
	}
	else
	{
		pOut->m_Int = INVALID_NETWORKED_EHANDLE_VALUE;
	}
}
Beispiel #9
0
void RecvProxy_IntToEHandle( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
	CBaseHandle *pEHandle = (CBaseHandle*)pOut;
	
	if ( pData->m_Value.m_Int == INVALID_NETWORKED_EHANDLE_VALUE )
	{
		*pEHandle = INVALID_EHANDLE_INDEX;
	}
	else
	{
		int iEntity = pData->m_Value.m_Int & ((1 << MAX_EDICT_BITS) - 1);
		int iSerialNum = pData->m_Value.m_Int >> MAX_EDICT_BITS;
		
		pEHandle->Init( iEntity, iSerialNum );
	}
}
void CClientEntityList::OnAddEntity( IHandleEntity *pEnt, CBaseHandle handle )
{
	int entnum = handle.GetEntryIndex();
	EntityCacheInfo_t *pCache = &m_EntityCacheInfo[entnum];

	if ( entnum >= 0 && entnum < MAX_EDICTS )
	{
		// Update our counters.
		m_iNumServerEnts++;
		if ( entnum > m_iMaxUsedServerIndex )
		{
			m_iMaxUsedServerIndex = entnum;
		}


		// Cache its networkable pointer.
		Assert( dynamic_cast< IClientUnknown* >( pEnt ) );
		Assert( ((IClientUnknown*)pEnt)->GetClientNetworkable() ); // Server entities should all be networkable.
		pCache->m_pNetworkable = ((IClientUnknown*)pEnt)->GetClientNetworkable();
	}

	// Store it in a special list for fast iteration if it's a C_BaseEntity.
	IClientUnknown *pUnknown = (IClientUnknown*)pEnt;
	C_BaseEntity *pBaseEntity = pUnknown->GetBaseEntity();
	if ( pBaseEntity )
	{
		pCache->m_BaseEntitiesIndex = m_BaseEntities.AddToTail( pBaseEntity );
	}
	else
	{
		pCache->m_BaseEntitiesIndex = m_BaseEntities.InvalidIndex();
	}
}
Beispiel #11
0
void CHalfLife2::SetHandleEntity(CBaseHandle &hndl, edict_t *pEnt)
{
	IServerEntity *pEntOther = pEnt->GetIServerEntity();

	if (pEntOther == NULL)
	{
		return;
	}

	hndl.Set(pEntOther);
}
Beispiel #12
0
void GetResourceEntity()
{
	g_ResourceEntity.Term();
	
#if SOURCE_ENGINE >= SE_ORANGEBOX
	const char *classname = g_pGameConf->GetKeyValue("ResourceEntityClassname");
	if (classname != NULL)
	{
		for (CBaseEntity *pEntity = (CBaseEntity *)servertools->FirstEntity(); pEntity; pEntity = (CBaseEntity *)servertools->NextEntity(pEntity))
		{
			if (!strcmp(gamehelpers->GetEntityClassname(pEntity), classname))
			{
				g_ResourceEntity = ((IHandleEntity *)pEntity)->GetRefEHandle();
				break;
			}
		}
	}
	else
#endif
	{
		int edictCount = gpGlobals->maxEntities;

		for (int i=0; i<edictCount; i++)
		{
			edict_t *pEdict = PEntityOfEntIndex(i);
			if (!pEdict || pEdict->IsFree())
			{
				continue;
			}
			if (!pEdict->GetNetworkable())
			{
				continue;
			}

			IHandleEntity *pHandleEnt = pEdict->GetNetworkable()->GetEntityHandle();
			if (!pHandleEnt)
			{
				continue;
			}

			ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
			if (FindNestedDataTable(pClass->m_pTable, "DT_PlayerResource"))
			{
				g_ResourceEntity = pHandleEnt->GetRefEHandle();
				break;
			}
		}
	}
}
Beispiel #13
0
cell_t CHalfLife2::EntityToBCompatRef(CBaseEntity *pEntity)
{
	if (pEntity == NULL)
	{
		return INVALID_EHANDLE_INDEX;
	}

	IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
	CBaseHandle hndl = pUnknown->GetRefEHandle();

	if (hndl == INVALID_EHANDLE_INDEX)
	{
		return INVALID_EHANDLE_INDEX;
	}
	
	if (hndl.GetEntryIndex() >= MAX_EDICTS)
	{
		return (hndl.ToInt() | (1<<31));
	}
	else
	{
		return hndl.GetEntryIndex();
	}
}
Beispiel #14
0
//-----------------------------------------------------------------------------
// Returns an index from the given IntHandle.
//-----------------------------------------------------------------------------
bool IndexFromIntHandle( unsigned int iEntityHandle, unsigned int& output )
{
    if (iEntityHandle == (int) INVALID_EHANDLE_INDEX)
        return false;

    CBaseHandle hBaseHandle(iEntityHandle);
    unsigned int iEntityIndex;
    if (!IndexFromBaseHandle(hBaseHandle, iEntityIndex))
        return false;

    edict_t* pEdict;
    if (!EdictFromIndex(iEntityIndex, pEdict))
        return false;

    CBaseHandle hTestHandle;
    if (!BaseHandleFromEdict(pEdict, hTestHandle))
        return false;

    if (!hTestHandle.IsValid() || hBaseHandle.GetSerialNumber() != hTestHandle.GetSerialNumber())
        return false;

    output = iEntityIndex;
    return true;
}
Beispiel #15
0
void CGlobalEntityList::OnAddEntity( IHandleEntity *pEnt, CBaseHandle handle )
{
	int i = handle.GetEntryIndex();

	// record current list details
	m_iNumEnts++;
	if ( i > m_iHighestEnt )
		m_iHighestEnt = i;

	// If it's a CBaseEntity, notify the listeners.
	CBaseEntity *pBaseEnt = static_cast<IServerUnknown*>(pEnt)->GetBaseEntity();
	if ( pBaseEnt->edict() )
		m_iNumEdicts++;
	
	// NOTE: Must be a CBaseEntity on server
	Assert( pBaseEnt );
	//DevMsg(2,"Created %s\n", pBaseEnt->GetClassname() );
	for ( i = m_entityListeners.Count()-1; i >= 0; i-- )
	{
		m_entityListeners[i]->OnEntityCreated( pBaseEnt );
	}
}
void CClientEntityList::OnRemoveEntity( IHandleEntity *pEnt, CBaseHandle handle )
{
	int entnum = handle.GetEntryIndex();
	EntityCacheInfo_t *pCache = &m_EntityCacheInfo[entnum];

	if ( entnum >= 0 && entnum < MAX_EDICTS )
	{
		// This is a networkable ent. Clear out our cache info for it.
		pCache->m_pNetworkable = NULL;
		m_iNumServerEnts--;

		if ( entnum >= m_iMaxUsedServerIndex )
		{
			RecomputeHighestEntityUsed();
		}
	}

	if ( pCache->m_BaseEntitiesIndex != m_BaseEntities.InvalidIndex() )
		m_BaseEntities.Remove( pCache->m_BaseEntitiesIndex );

	pCache->m_BaseEntitiesIndex = m_BaseEntities.InvalidIndex();
}
IServerEntity *CServerTools::GetIServerEntity( IClientEntity *pClientEntity )
{
	if ( pClientEntity == NULL )
		return NULL;

	CBaseHandle ehandle = pClientEntity->GetRefEHandle();
	if ( ehandle.GetEntryIndex() >= MAX_EDICTS )
		return NULL; // the first MAX_EDICTS entities are networked, the rest are client or server only

#if 0
	// this fails, since the server entities have extra bits in their serial numbers,
	// since 20 bits are reserved for serial numbers, except for networked entities, which are restricted to 10

	// Brian believes that everything should just restrict itself to 10 to make things simpler,
	// so if/when he changes NUM_SERIAL_NUM_BITS to 10, we can switch back to this simpler code

	IServerNetworkable *pNet = gEntList.GetServerNetworkable( ehandle );
	if ( pNet == NULL )
		return NULL;

	CBaseEntity *pServerEnt = pNet->GetBaseEntity();
	return pServerEnt;
#else
	IHandleEntity *pEnt = gEntList.LookupEntityByNetworkIndex( ehandle.GetEntryIndex() );
	if ( pEnt == NULL )
		return NULL;

	CBaseHandle h = gEntList.GetNetworkableHandle( ehandle.GetEntryIndex() );
	const int mask = ( 1 << NUM_NETWORKED_EHANDLE_SERIAL_NUMBER_BITS ) - 1;
	if ( !h.IsValid() || ( ( h.GetSerialNumber() & mask ) != ( ehandle.GetSerialNumber() & mask ) ) )
		return NULL;

	IServerUnknown *pUnk = static_cast< IServerUnknown* >( pEnt );
	return pUnk->GetBaseEntity();
#endif
}
Beispiel #18
0
void CGameEngine::addEntity(boost::shared_ptr<IEntity> entity, const CBaseHandle& handle)
{
	assert(handle.isValid());
	m_level->addEntity(entity,handle);
}
LUA_API void lua_pushweapon (lua_State *L, lua_CBaseCombatWeapon *pWeapon) {
  CBaseHandle *hWeapon = (CBaseHandle *)lua_newuserdata(L, sizeof(CBaseHandle));
  hWeapon->Set((CBaseEntity *)pWeapon);
  luaL_getmetatable(L, "CBaseCombatWeapon");
  lua_setmetatable(L, -2);
}
LUA_API lua_CBaseCombatWeapon *lua_toweapon (lua_State *L, int idx) {
  CBaseHandle *hWeapon = dynamic_cast<CBaseHandle *>((CBaseHandle *)lua_touserdata(L, idx));
  if (hWeapon == NULL)
    return NULL;
  return dynamic_cast<lua_CBaseCombatWeapon *>(hWeapon->Get());
}
Beispiel #21
0
cell_t CHalfLife2::EntityToReference(CBaseEntity *pEntity)
{
	IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
	CBaseHandle hndl = pUnknown->GetRefEHandle();
	return (hndl.ToInt() | (1<<31));
}
void CBaseEntityList::RemoveEntity( CBaseHandle handle )
{
	RemoveEntityAtSlot( handle.GetEntryIndex() );
}
bool CStaticPropMgr::IsStaticProp( CBaseHandle handle ) const
{
	return (handle.ToInt() & STATICPROP_EHANDLE_MASK) != 0;
}
int CStaticProp::DrawModel( int flags )
{
#ifndef SWDS
	VPROF_BUDGET( "CStaticProp::DrawModel", VPROF_BUDGETGROUP_STATICPROP_RENDERING );

	if( !r_drawstaticprops.GetBool() )
	{
		return 0;
	}

#ifdef _DEBUG
	if (r_DrawSpecificStaticProp.GetInt() >= 0)
	{
		if ( (m_EntHandle.ToInt() & (~STATICPROP_EHANDLE_MASK) ) != r_DrawSpecificStaticProp.GetInt())
			return 0;
	}
#endif

	if ((m_Alpha == 0) || (!m_pModel))
		return 0;

	if( r_colorstaticprops.GetBool() )
	{
		Vector color;
		RandomColorFromModeInstanceHandle( m_ModelInstance, color );
		VectorCopy( color.Base(), r_colormod );
	}

	modelrender->UseLightcache( &m_LightCacheHandle );

#ifdef _DEBUG
	studiohdr_t *pStudioHdr = modelinfo->GetStudiomodel( m_pModel );
	Assert( pStudioHdr );
	if( !( pStudioHdr->flags & STUDIOHDR_FLAGS_STATIC_PROP ) )
	{
		return 0;
	}
#endif

	flags |= STUDIO_STATIC_LIGHTING;
#if 0
	Vector mins;
	Vector maxs;
	VectorAdd( m_RenderBBoxMin, m_Origin, mins );
	VectorAdd( m_RenderBBoxMax, m_Origin, maxs );
#endif	
	int drawn = modelrender->DrawModel( 
		flags, 
		this,
		m_ModelInstance,
		-1,		// no entity index
		m_pModel,
		m_Origin,
		m_Angles,
		0,		// sequence
		m_Skin,	// skin
		0,		// body
		0,		// hitboxset
#if 1
		NULL, NULL,
#else
		&mins, &maxs,
#endif
		&m_ModelToWorld
		);

	modelrender->UseLightcache();

	if ( vcollide_wireframe.GetBool() )
	{
		if ( m_pModel && m_nSolidType == SOLID_VPHYSICS )
		{
			// This works because VCollideForModel only uses modelindex for mod_brush
			// and props are always mod_Studio.
			vcollide_t * pCollide = CM_VCollideForModel( -1, m_pModel ); 
			if ( pCollide && pCollide->solidCount == 1 )
			{
				static color32 debugColor = {0,255,255,0};
				DebugDrawPhysCollide( pCollide->solids[0], NULL, m_ModelToWorld, debugColor );
			}
		}
	}

	return drawn;
#else
	return 0;
#endif
}