Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

774 lines
22 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "saverestore.h"
#include "client.h"
#include "decals.h"
#include "gamerules.h"
#include "game.h"
void EntvarsKeyvalue( entvars_t *pev, KeyValueData *pkvd );
extern "C" void PM_Move ( struct playermove_s *ppmove, int server );
extern "C" void PM_Init ( struct playermove_s *ppmove );
extern "C" char PM_FindTextureType( char *name );
extern Vector VecBModelOrigin( entvars_t* pevBModel );
8 years ago
extern DLL_GLOBAL Vector g_vecAttackDir;
extern DLL_GLOBAL int g_iSkillLevel;
9 years ago
8 years ago
static DLL_FUNCTIONS gFunctionTable =
9 years ago
{
GameDLLInit, //pfnGameInit
DispatchSpawn, //pfnSpawn
DispatchThink, //pfnThink
DispatchUse, //pfnUse
DispatchTouch, //pfnTouch
DispatchBlocked, //pfnBlocked
DispatchKeyValue, //pfnKeyValue
DispatchSave, //pfnSave
DispatchRestore, //pfnRestore
DispatchObjectCollsionBox, //pfnAbsBox
SaveWriteFields, //pfnSaveWriteFields
SaveReadFields, //pfnSaveReadFields
SaveGlobalState, //pfnSaveGlobalState
RestoreGlobalState, //pfnRestoreGlobalState
ResetGlobalState, //pfnResetGlobalState
ClientConnect, //pfnClientConnect
ClientDisconnect, //pfnClientDisconnect
ClientKill, //pfnClientKill
ClientPutInServer, //pfnClientPutInServer
ClientCommand, //pfnClientCommand
ClientUserInfoChanged, //pfnClientUserInfoChanged
ServerActivate, //pfnServerActivate
ServerDeactivate, //pfnServerDeactivate
PlayerPreThink, //pfnPlayerPreThink
PlayerPostThink, //pfnPlayerPostThink
StartFrame, //pfnStartFrame
ParmsNewLevel, //pfnParmsNewLevel
ParmsChangeLevel, //pfnParmsChangeLevel
GetGameDescription, //pfnGetGameDescription Returns string describing current .dll game.
PlayerCustomization, //pfnPlayerCustomization Notifies .dll of new customization for player.
SpectatorConnect, //pfnSpectatorConnect Called when spectator joins server
SpectatorDisconnect, //pfnSpectatorDisconnect Called when spectator leaves the server
SpectatorThink, //pfnSpectatorThink Called when spectator sends a command packet (usercmd_t)
Sys_Error, //pfnSys_Error Called when engine has encountered an error
PM_Move, //pfnPM_Move
PM_Init, //pfnPM_Init Server version of player movement initialization
PM_FindTextureType, //pfnPM_FindTextureType
8 years ago
9 years ago
SetupVisibility, //pfnSetupVisibility Set up PVS and PAS for networking for this client
UpdateClientData, //pfnUpdateClientData Set up data sent only to specific client
AddToFullPack, //pfnAddToFullPack
CreateBaseline, //pfnCreateBaseline Tweak entity baseline for network encoding, allows setup of player baselines, too.
RegisterEncoders, //pfnRegisterEncoders Callbacks for network encoding
GetWeaponData, //pfnGetWeaponData
CmdStart, //pfnCmdStart
CmdEnd, //pfnCmdEnd
ConnectionlessPacket, //pfnConnectionlessPacket
GetHullBounds, //pfnGetHullBounds
CreateInstancedBaselines, //pfnCreateInstancedBaselines
InconsistentFile, //pfnInconsistentFile
AllowLagCompensation, //pfnAllowLagCompensation
};
static void SetObjectCollisionBox( entvars_t *pev );
#ifndef _WIN32
extern "C" {
#endif
int GetEntityAPI( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion )
{
8 years ago
if( !pFunctionTable || interfaceVersion != INTERFACE_VERSION )
9 years ago
{
return FALSE;
}
8 years ago
memcpy( pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS) );
9 years ago
return TRUE;
}
int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion )
{
8 years ago
if( !pFunctionTable || *interfaceVersion != INTERFACE_VERSION )
9 years ago
{
// Tell engine what version we had, so it can figure out who is out of date.
*interfaceVersion = INTERFACE_VERSION;
return FALSE;
}
8 years ago
memcpy( pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS) );
9 years ago
return TRUE;
}
#ifndef _WIN32
}
#endif
int DispatchSpawn( edict_t *pent )
{
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
9 years ago
8 years ago
if( pEntity )
9 years ago
{
//
// The Gate:
//
// Prevent level shutting down due to engine limitation.
//
if( FStrEq( STRING( gpGlobals->mapname ), "gate18" ) )
{
if( FStringNull( pEntity->pev->targetname ) )
{
if( FClassnameIs( pEntity->pev, "monster_furniture" ) )
return 0;
}
}
9 years ago
// Initialize these or entities who don't link to the world won't have anything in here
8 years ago
pEntity->pev->absmin = pEntity->pev->origin - Vector( 1, 1, 1 );
pEntity->pev->absmax = pEntity->pev->origin + Vector( 1, 1, 1 );
9 years ago
pEntity->Spawn();
// Try to get the pointer again, in case the spawn function deleted the entity.
// UNDONE: Spawn() should really return a code to ask that the entity be deleted, but
// that would touch too much code for me to do that right now.
8 years ago
pEntity = (CBaseEntity *)GET_PRIVATE( pent );
9 years ago
8 years ago
if( pEntity )
9 years ago
{
8 years ago
if( g_pGameRules && !g_pGameRules->IsAllowedToSpawn( pEntity ) )
9 years ago
return -1; // return that this entity should be deleted
8 years ago
if( pEntity->pev->flags & FL_KILLME )
9 years ago
return -1;
}
// Handle global stuff here
8 years ago
if( pEntity && pEntity->pev->globalname )
9 years ago
{
const globalentity_t *pGlobal = gGlobalState.EntityFromTable( pEntity->pev->globalname );
8 years ago
if( pGlobal )
9 years ago
{
// Already dead? delete
8 years ago
if( pGlobal->state == GLOBAL_DEAD )
9 years ago
return -1;
8 years ago
else if( !FStrEq( STRING( gpGlobals->mapname ), pGlobal->levelName ) )
9 years ago
pEntity->MakeDormant(); // Hasn't been moved to this level yet, wait but stay alive
// In this level & not dead, continue on as normal
}
else
{
// Spawned entities default to 'On'
gGlobalState.EntityAdd( pEntity->pev->globalname, gpGlobals->mapname, GLOBAL_ON );
8 years ago
//ALERT( at_console, "Added global entity %s (%s)\n", STRING( pEntity->pev->classname ), STRING( pEntity->pev->globalname ) );
9 years ago
}
}
}
return 0;
}
void DispatchKeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd )
{
8 years ago
if( !pkvd || !pentKeyvalue )
9 years ago
return;
8 years ago
EntvarsKeyvalue( VARS( pentKeyvalue ), pkvd );
9 years ago
// If the key was an entity variable, or there's no class set yet, don't look for the object, it may
// not exist yet.
if ( pkvd->fHandled || pkvd->szClassName == NULL )
return;
// Get the actualy entity object
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentKeyvalue );
9 years ago
8 years ago
if( !pEntity )
9 years ago
return;
pEntity->KeyValue( pkvd );
}
// HACKHACK -- this is a hack to keep the node graph entity from "touching" things (like triggers)
// while it builds the graph
BOOL gTouchDisabled = FALSE;
9 years ago
void DispatchTouch( edict_t *pentTouched, edict_t *pentOther )
{
8 years ago
if( gTouchDisabled )
9 years ago
return;
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentTouched );
9 years ago
CBaseEntity *pOther = (CBaseEntity *)GET_PRIVATE( pentOther );
8 years ago
if( pEntity && pOther && ! ( ( pEntity->pev->flags | pOther->pev->flags ) & FL_KILLME ) )
9 years ago
pEntity->Touch( pOther );
}
void DispatchUse( edict_t *pentUsed, edict_t *pentOther )
{
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentUsed );
CBaseEntity *pOther = (CBaseEntity *)GET_PRIVATE( pentOther );
9 years ago
8 years ago
if( pEntity && !( pEntity->pev->flags & FL_KILLME ) )
9 years ago
pEntity->Use( pOther, pOther, USE_TOGGLE, 0 );
}
void DispatchThink( edict_t *pent )
{
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
if( pEntity )
9 years ago
{
8 years ago
if( FBitSet( pEntity->pev->flags, FL_DORMANT ) )
ALERT( at_error, "Dormant entity %s is thinking!!\n", STRING( pEntity->pev->classname ) );
9 years ago
pEntity->Think();
}
}
void DispatchBlocked( edict_t *pentBlocked, edict_t *pentOther )
{
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentBlocked );
CBaseEntity *pOther = (CBaseEntity *)GET_PRIVATE( pentOther );
8 years ago
if( pEntity )
9 years ago
pEntity->Blocked( pOther );
}
void DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData )
{
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
if( pEntity && pSaveData )
9 years ago
{
8 years ago
ENTITYTABLE *pTable = &pSaveData->pTable[pSaveData->currentIndex];
9 years ago
8 years ago
if( pTable->pent != pent )
9 years ago
ALERT( at_error, "ENTITY TABLE OR INDEX IS WRONG!!!!\n" );
8 years ago
if( pEntity->ObjectCaps() & FCAP_DONT_SAVE )
9 years ago
return;
// These don't use ltime & nextthink as times really, but we'll fudge around it.
8 years ago
if( pEntity->pev->movetype == MOVETYPE_PUSH )
9 years ago
{
float delta = pEntity->pev->nextthink - pEntity->pev->ltime;
pEntity->pev->ltime = gpGlobals->time;
pEntity->pev->nextthink = pEntity->pev->ltime + delta;
}
pTable->location = pSaveData->size; // Remember entity position for file I/O
pTable->classname = pEntity->pev->classname; // Remember entity class for respawn
CSave saveHelper( pSaveData );
pEntity->Save( saveHelper );
pTable->size = pSaveData->size - pTable->location; // Size of entity block is data size written to block
}
}
// Find the matching global entity. Spit out an error if the designer made entities of
// different classes with the same global name
CBaseEntity *FindGlobalEntity( string_t classname, string_t globalname )
{
8 years ago
edict_t *pent = FIND_ENTITY_BY_STRING( NULL, "globalname", STRING( globalname ) );
9 years ago
CBaseEntity *pReturn = CBaseEntity::Instance( pent );
8 years ago
if( pReturn )
9 years ago
{
8 years ago
if( !FClassnameIs( pReturn->pev, STRING( classname ) ) )
9 years ago
{
8 years ago
ALERT( at_console, "Global entity found %s, wrong class %s\n", STRING( globalname ), STRING( pReturn->pev->classname ) );
9 years ago
pReturn = NULL;
}
}
return pReturn;
}
int DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity )
{
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
9 years ago
8 years ago
if( pEntity && pSaveData )
9 years ago
{
entvars_t tmpVars;
Vector oldOffset;
CRestore restoreHelper( pSaveData );
8 years ago
if( globalEntity )
9 years ago
{
CRestore tmpRestore( pSaveData );
tmpRestore.PrecacheMode( 0 );
tmpRestore.ReadEntVars( "ENTVARS", &tmpVars );
// HACKHACK - reset the save pointers, we're going to restore for real this time
pSaveData->size = pSaveData->pTable[pSaveData->currentIndex].location;
pSaveData->pCurrentData = pSaveData->pBaseData + pSaveData->size;
// -------------------
const globalentity_t *pGlobal = gGlobalState.EntityFromTable( tmpVars.globalname );
8 years ago
9 years ago
// Don't overlay any instance of the global that isn't the latest
// pSaveData->szCurrentMapName is the level this entity is coming from
// pGlobla->levelName is the last level the global entity was active in.
// If they aren't the same, then this global update is out of date.
8 years ago
if( !FStrEq( pSaveData->szCurrentMapName, pGlobal->levelName ) )
9 years ago
return 0;
// Compute the new global offset
oldOffset = pSaveData->vecLandmarkOffset;
CBaseEntity *pNewEntity = FindGlobalEntity( tmpVars.classname, tmpVars.globalname );
8 years ago
if( pNewEntity )
9 years ago
{
8 years ago
//ALERT( at_console, "Overlay %s with %s\n", STRING( pNewEntity->pev->classname ), STRING( tmpVars.classname ) );
9 years ago
// Tell the restore code we're overlaying a global entity from another level
restoreHelper.SetGlobalMode( 1 ); // Don't overwrite global fields
8 years ago
pSaveData->vecLandmarkOffset = ( pSaveData->vecLandmarkOffset - pNewEntity->pev->mins ) + tmpVars.mins;
9 years ago
pEntity = pNewEntity;// we're going to restore this data OVER the old entity
pent = ENT( pEntity->pev );
// Update the global table to say that the global definition of this entity should come from this level
gGlobalState.EntityUpdate( pEntity->pev->globalname, gpGlobals->mapname );
}
else
{
// This entity will be freed automatically by the engine. If we don't do a restore on a matching entity (below)
// or call EntityUpdate() to move it to this level, we haven't changed global state at all.
return 0;
}
}
8 years ago
if( pEntity->ObjectCaps() & FCAP_MUST_SPAWN )
9 years ago
{
pEntity->Restore( restoreHelper );
pEntity->Spawn();
}
else
{
pEntity->Restore( restoreHelper );
8 years ago
pEntity->Precache();
9 years ago
}
// Again, could be deleted, get the pointer again.
8 years ago
pEntity = (CBaseEntity *)GET_PRIVATE( pent );
9 years ago
#if 0
8 years ago
if( pEntity && pEntity->pev->globalname && globalEntity )
9 years ago
{
8 years ago
ALERT( at_console, "Global %s is %s\n", STRING( pEntity->pev->globalname ), STRING( pEntity->pev->model ) );
9 years ago
}
#endif
// Is this an overriding global entity (coming over the transition), or one restoring in a level
8 years ago
if( globalEntity )
9 years ago
{
8 years ago
//ALERT( at_console, "After: %f %f %f %s\n", pEntity->pev->origin.x, pEntity->pev->origin.y, pEntity->pev->origin.z, STRING( pEntity->pev->model ) );
9 years ago
pSaveData->vecLandmarkOffset = oldOffset;
8 years ago
if( pEntity )
9 years ago
{
UTIL_SetOrigin( pEntity->pev, pEntity->pev->origin );
pEntity->OverrideReset();
}
}
8 years ago
else if( pEntity && pEntity->pev->globalname )
9 years ago
{
const globalentity_t *pGlobal = gGlobalState.EntityFromTable( pEntity->pev->globalname );
8 years ago
if( pGlobal )
9 years ago
{
// Already dead? delete
8 years ago
if( pGlobal->state == GLOBAL_DEAD )
9 years ago
return -1;
8 years ago
else if( !FStrEq( STRING( gpGlobals->mapname ), pGlobal->levelName ) )
9 years ago
{
pEntity->MakeDormant(); // Hasn't been moved to this level yet, wait but stay alive
}
// In this level & not dead, continue on as normal
}
else
{
8 years ago
ALERT( at_error, "Global Entity %s (%s) not in table!!!\n", STRING( pEntity->pev->globalname ), STRING( pEntity->pev->classname ) );
9 years ago
// Spawned entities default to 'On'
gGlobalState.EntityAdd( pEntity->pev->globalname, gpGlobals->mapname, GLOBAL_ON );
}
}
}
return 0;
}
void DispatchObjectCollsionBox( edict_t *pent )
{
8 years ago
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
if( pEntity )
9 years ago
{
pEntity->SetObjectCollisionBox();
}
else
SetObjectCollisionBox( &pent->v );
}
void SaveWriteFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount )
{
CSave saveHelper( pSaveData );
saveHelper.WriteFields( pname, pBaseData, pFields, fieldCount );
}
void SaveReadFields( SAVERESTOREDATA *pSaveData, const char *pname, void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCount )
{
CRestore restoreHelper( pSaveData );
restoreHelper.ReadFields( pname, pBaseData, pFields, fieldCount );
}
8 years ago
edict_t *EHANDLE::Get( void )
9 years ago
{
8 years ago
if( m_pent )
9 years ago
{
8 years ago
if( m_pent->serialnumber == m_serialnumber )
9 years ago
return m_pent;
else
return NULL;
}
return NULL;
}
9 years ago
8 years ago
edict_t *EHANDLE::Set( edict_t *pent )
{
9 years ago
m_pent = pent;
8 years ago
if( pent )
9 years ago
m_serialnumber = m_pent->serialnumber;
return pent;
}
9 years ago
8 years ago
EHANDLE::operator CBaseEntity *()
9 years ago
{
8 years ago
return (CBaseEntity *)GET_PRIVATE( Get() );
}
9 years ago
8 years ago
CBaseEntity *EHANDLE::operator = ( CBaseEntity *pEntity )
9 years ago
{
8 years ago
if( pEntity )
9 years ago
{
m_pent = ENT( pEntity->pev );
8 years ago
if( m_pent )
9 years ago
m_serialnumber = m_pent->serialnumber;
}
else
{
m_pent = NULL;
m_serialnumber = 0;
}
return pEntity;
}
8 years ago
EHANDLE::operator int ()
9 years ago
{
return Get() != NULL;
}
8 years ago
CBaseEntity * EHANDLE::operator -> ()
9 years ago
{
8 years ago
return (CBaseEntity *)GET_PRIVATE( Get() );
9 years ago
}
// give health
8 years ago
int CBaseEntity::TakeHealth( float flHealth, int bitsDamageType )
9 years ago
{
8 years ago
if( !pev->takedamage )
9 years ago
return 0;
// heal
8 years ago
if( pev->health >= pev->max_health )
9 years ago
return 0;
pev->health += flHealth;
8 years ago
if( pev->health > pev->max_health )
9 years ago
pev->health = pev->max_health;
return 1;
}
// inflict damage on this entity. bitsDamageType indicates type of damage inflicted, ie: DMG_CRUSH
8 years ago
int CBaseEntity::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
8 years ago
Vector vecTemp;
9 years ago
8 years ago
if( !pev->takedamage )
9 years ago
return 0;
// UNDONE: some entity types may be immune or resistant to some bitsDamageType
// if Attacker == Inflictor, the attack was a melee or other instant-hit attack.
// (that is, no actual entity projectile was involved in the attack so use the shooter's origin).
8 years ago
if( pevAttacker == pevInflictor )
9 years ago
{
8 years ago
vecTemp = pevInflictor->origin - VecBModelOrigin( pev );
9 years ago
}
else
// an actual missile was involved.
{
8 years ago
vecTemp = pevInflictor->origin - VecBModelOrigin( pev );
9 years ago
}
// this global is still used for glass and other non-monster killables, along with decals.
9 years ago
g_vecAttackDir = vecTemp.Normalize();
8 years ago
// save damage based on the target's armor level
// figure momentum add (don't let hurt brushes or other triggers move player)
8 years ago
if( ( !FNullEnt( pevInflictor ) ) && (pev->movetype == MOVETYPE_WALK || pev->movetype == MOVETYPE_STEP ) && ( pevAttacker->solid != SOLID_TRIGGER ) )
9 years ago
{
8 years ago
Vector vecDir = pev->origin - ( pevInflictor->absmin + pevInflictor->absmax ) * 0.5;
9 years ago
vecDir = vecDir.Normalize();
8 years ago
float flForce = flDamage * ( ( 32 * 32 * 72.0 ) / ( pev->size.x * pev->size.y * pev->size.z ) ) * 5;
if( flForce > 1000.0 )
9 years ago
flForce = 1000.0;
pev->velocity = pev->velocity + vecDir * flForce;
}
// do the damage
9 years ago
pev->health -= flDamage;
8 years ago
if( pev->health <= 0 )
9 years ago
{
Killed( pevAttacker, GIB_NORMAL );
return 0;
}
return 1;
}
8 years ago
void CBaseEntity::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
pev->takedamage = DAMAGE_NO;
pev->deadflag = DEAD_DEAD;
UTIL_Remove( this );
}
CBaseEntity *CBaseEntity::GetNextTarget( void )
{
8 years ago
if( FStringNull( pev->target ) )
9 years ago
return NULL;
8 years ago
edict_t *pTarget = FIND_ENTITY_BY_TARGETNAME( NULL, STRING( pev->target ) );
if( FNullEnt( pTarget ) )
9 years ago
return NULL;
return Instance( pTarget );
}
// Global Savedata for Delay
8 years ago
TYPEDESCRIPTION CBaseEntity::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CBaseEntity, m_pGoalEnt, FIELD_CLASSPTR ),
DEFINE_FIELD( CBaseEntity, m_pfnThink, FIELD_FUNCTION ), // UNDONE: Build table of these!!!
DEFINE_FIELD( CBaseEntity, m_pfnTouch, FIELD_FUNCTION ),
DEFINE_FIELD( CBaseEntity, m_pfnUse, FIELD_FUNCTION ),
DEFINE_FIELD( CBaseEntity, m_pfnBlocked, FIELD_FUNCTION ),
};
int CBaseEntity::Save( CSave &save )
{
8 years ago
if( save.WriteEntVars( "ENTVARS", pev ) )
return save.WriteFields( "BASE", this, m_SaveData, ARRAYSIZE( m_SaveData ) );
9 years ago
return 0;
}
int CBaseEntity::Restore( CRestore &restore )
{
int status;
status = restore.ReadEntVars( "ENTVARS", pev );
8 years ago
if( status )
status = restore.ReadFields( "BASE", this, m_SaveData, ARRAYSIZE( m_SaveData ) );
9 years ago
8 years ago
if( pev->modelindex != 0 && !FStringNull( pev->model ) )
9 years ago
{
Vector mins, maxs;
mins = pev->mins; // Set model is about to destroy these
maxs = pev->maxs;
8 years ago
PRECACHE_MODEL( (char *)STRING( pev->model ) );
SET_MODEL( ENT( pev ), STRING( pev->model ) );
UTIL_SetSize( pev, mins, maxs ); // Reset them
9 years ago
}
return status;
}
// Initialize absmin & absmax to the appropriate box
void SetObjectCollisionBox( entvars_t *pev )
{
8 years ago
if( ( pev->solid == SOLID_BSP ) &&
( pev->angles.x || pev->angles.y || pev->angles.z ) )
{
// expand for rotation
float max, v;
int i;
9 years ago
max = 0;
8 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
8 years ago
v = fabs( ( (float *)pev->mins )[i] );
if( v > max )
9 years ago
max = v;
8 years ago
v = fabs( ( (float *)pev->maxs )[i] );
if( v > max )
9 years ago
max = v;
}
8 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
8 years ago
( (float *)pev->absmin )[i] = ( (float *)pev->origin )[i] - max;
( (float *)pev->absmax )[i] = ( (float *)pev->origin )[i] + max;
9 years ago
}
}
else
{
pev->absmin = pev->origin + pev->mins;
pev->absmax = pev->origin + pev->maxs;
}
pev->absmin.x -= 1;
pev->absmin.y -= 1;
pev->absmin.z -= 1;
pev->absmax.x += 1;
pev->absmax.y += 1;
pev->absmax.z += 1;
}
void CBaseEntity::SetObjectCollisionBox( void )
{
::SetObjectCollisionBox( pev );
}
8 years ago
int CBaseEntity::Intersects( CBaseEntity *pOther )
9 years ago
{
8 years ago
if( pOther->pev->absmin.x > pev->absmax.x ||
pOther->pev->absmin.y > pev->absmax.y ||
pOther->pev->absmin.z > pev->absmax.z ||
pOther->pev->absmax.x < pev->absmin.x ||
pOther->pev->absmax.y < pev->absmin.y ||
pOther->pev->absmax.z < pev->absmin.z )
return 0;
9 years ago
return 1;
}
8 years ago
void CBaseEntity::MakeDormant( void )
9 years ago
{
SetBits( pev->flags, FL_DORMANT );
// Don't touch
pev->solid = SOLID_NOT;
// Don't move
pev->movetype = MOVETYPE_NONE;
// Don't draw
SetBits( pev->effects, EF_NODRAW );
// Don't think
pev->nextthink = 0;
// Relink
UTIL_SetOrigin( pev, pev->origin );
}
8 years ago
int CBaseEntity::IsDormant( void )
9 years ago
{
return FBitSet( pev->flags, FL_DORMANT );
}
8 years ago
BOOL CBaseEntity::IsInWorld( void )
9 years ago
{
// position
8 years ago
if( pev->origin.x >= 4096 )
return FALSE;
if( pev->origin.y >= 4096 )
return FALSE;
if( pev->origin.z >= 4096 )
return FALSE;
if( pev->origin.x <= -4096 )
return FALSE;
if( pev->origin.y <= -4096 )
return FALSE;
if( pev->origin.z <= -4096 )
return FALSE;
9 years ago
// speed
8 years ago
if( pev->velocity.x >= 2000 )
return FALSE;
if( pev->velocity.y >= 2000 )
return FALSE;
if( pev->velocity.z >= 2000 )
return FALSE;
if( pev->velocity.x <= -2000 )
return FALSE;
if( pev->velocity.y <= -2000 )
return FALSE;
if( pev->velocity.z <= -2000 )
return FALSE;
9 years ago
return TRUE;
}
int CBaseEntity::ShouldToggle( USE_TYPE useType, BOOL currentState )
{
8 years ago
if( useType != USE_TOGGLE && useType != USE_SET )
9 years ago
{
8 years ago
if( ( currentState && useType == USE_ON ) || ( !currentState && useType == USE_OFF ) )
9 years ago
return 0;
}
return 1;
}
8 years ago
int CBaseEntity::DamageDecal( int bitsDamageType )
9 years ago
{
8 years ago
if( pev->rendermode == kRenderTransAlpha )
9 years ago
return -1;
8 years ago
if( pev->rendermode != kRenderNormal )
9 years ago
return DECAL_BPROOF1;
8 years ago
return DECAL_GUNSHOT1 + RANDOM_LONG( 0, 4 );
9 years ago
}
// NOTE: szName must be a pointer to constant memory, e.g. "monster_class" because the entity
// will keep a pointer to it after this call.
8 years ago
CBaseEntity *CBaseEntity::Create( char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner )
9 years ago
{
edict_t *pent;
CBaseEntity *pEntity;
8 years ago
pent = CREATE_NAMED_ENTITY( MAKE_STRING( szName ) );
if( FNullEnt( pent ) )
9 years ago
{
ALERT ( at_console, "NULL Ent in Create!\n" );
return NULL;
}
pEntity = Instance( pent );
pEntity->pev->owner = pentOwner;
pEntity->pev->origin = vecOrigin;
pEntity->pev->angles = vecAngles;
DispatchSpawn( pEntity->edict() );
return pEntity;
}