2016-06-04 15:24:23 +02:00
|
|
|
/***
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****/
|
2016-06-25 18:33:39 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
#include "extdll.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "saverestore.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "decals.h"
|
|
|
|
#include "gamerules.h"
|
|
|
|
#include "game.h"
|
|
|
|
|
2024-02-23 20:15:37 +01:00
|
|
|
bool g_fIsXash3D = false;
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
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 );
|
2017-06-29 15:56:03 +02:00
|
|
|
extern "C" char PM_FindTextureType( const char *name );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
extern Vector VecBModelOrigin( entvars_t* pevBModel );
|
2016-07-31 15:48:50 +02:00
|
|
|
extern DLL_GLOBAL Vector g_vecAttackDir;
|
|
|
|
extern DLL_GLOBAL int g_iSkillLevel;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
static DLL_FUNCTIONS gFunctionTable =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
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 );
|
|
|
|
|
2023-10-31 21:25:07 +01:00
|
|
|
#if !XASH_WIN32
|
2016-06-04 15:24:23 +02:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
int GetEntityAPI( DLL_FUNCTIONS *pFunctionTable, int interfaceVersion )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pFunctionTable || interfaceVersion != INTERFACE_VERSION )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
memcpy( pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS) );
|
2016-06-04 15:24:23 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetEntityAPI2( DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pFunctionTable || *interfaceVersion != INTERFACE_VERSION )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Tell engine what version we had, so it can figure out who is out of date.
|
|
|
|
*interfaceVersion = INTERFACE_VERSION;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
memcpy( pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS) );
|
2016-06-04 15:24:23 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2024-02-23 20:15:37 +01:00
|
|
|
int Server_GetPhysicsInterface( int version, server_physics_api_t *api, physics_interface_t *interface )
|
|
|
|
{
|
|
|
|
g_fIsXash3D = true;
|
|
|
|
return FALSE; // do not tell engine to init physics interface, as we're not using it
|
|
|
|
}
|
2023-10-31 21:25:07 +01:00
|
|
|
#if !XASH_WIN32
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int DispatchSpawn( edict_t *pent )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Initialize these or entities who don't link to the world won't have anything in here
|
2019-10-13 13:49:25 +02:00
|
|
|
pEntity->pev->absmin = pEntity->pev->origin - Vector( 1.0f, 1.0f, 1.0f );
|
|
|
|
pEntity->pev->absmax = pEntity->pev->origin + Vector( 1.0f, 1.0f, 1.0f );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
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.
|
2016-07-31 15:48:50 +02:00
|
|
|
pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( g_pGameRules && !g_pGameRules->IsAllowedToSpawn( pEntity ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return -1; // return that this entity should be deleted
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity->pev->flags & FL_KILLME )
|
2016-06-04 15:24:23 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle global stuff here
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity && pEntity->pev->globalname )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
const globalentity_t *pGlobal = gGlobalState.EntityFromTable( pEntity->pev->globalname );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pGlobal )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Already dead? delete
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pGlobal->state == GLOBAL_DEAD )
|
2016-06-04 15:24:23 +02:00
|
|
|
return -1;
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( !FStrEq( STRING( gpGlobals->mapname ), pGlobal->levelName ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
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 );
|
2016-07-31 15:48:50 +02:00
|
|
|
//ALERT( at_console, "Added global entity %s (%s)\n", STRING( pEntity->pev->classname ), STRING( pEntity->pev->globalname ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchKeyValue( edict_t *pentKeyvalue, KeyValueData *pkvd )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pkvd || !pentKeyvalue )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
EntvarsKeyvalue( VARS( pentKeyvalue ), pkvd );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// 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
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentKeyvalue );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
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;
|
2016-06-25 18:33:39 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
void DispatchTouch( edict_t *pentTouched, edict_t *pentOther )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( gTouchDisabled )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentTouched );
|
2016-06-04 15:24:23 +02:00
|
|
|
CBaseEntity *pOther = (CBaseEntity *)GET_PRIVATE( pentOther );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity && pOther && ! ( ( pEntity->pev->flags | pOther->pev->flags ) & FL_KILLME ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
pEntity->Touch( pOther );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchUse( edict_t *pentUsed, edict_t *pentOther )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentUsed );
|
|
|
|
CBaseEntity *pOther = (CBaseEntity *)GET_PRIVATE( pentOther );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity && !( pEntity->pev->flags & FL_KILLME ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
pEntity->Use( pOther, pOther, USE_TOGGLE, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchThink( edict_t *pent )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FBitSet( pEntity->pev->flags, FL_DORMANT ) )
|
|
|
|
ALERT( at_error, "Dormant entity %s is thinking!!\n", STRING( pEntity->pev->classname ) );
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
pEntity->Think();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchBlocked( edict_t *pentBlocked, edict_t *pentOther )
|
|
|
|
{
|
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pentBlocked );
|
|
|
|
CBaseEntity *pOther = (CBaseEntity *)GET_PRIVATE( pentOther );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
pEntity->Blocked( pOther );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
|
|
|
|
|
|
|
if( pEntity && pSaveData )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
ENTITYTABLE *pTable = &pSaveData->pTable[pSaveData->currentIndex];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2021-04-04 19:26:27 +02:00
|
|
|
gpGlobals->time = pSaveData->time;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pTable->pent != pent )
|
2016-06-04 15:24:23 +02:00
|
|
|
ALERT( at_error, "ENTITY TABLE OR INDEX IS WRONG!!!!\n" );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity->ObjectCaps() & FCAP_DONT_SAVE )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// These don't use ltime & nextthink as times really, but we'll fudge around it.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity->pev->movetype == MOVETYPE_PUSH )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
edict_t *pent = FIND_ENTITY_BY_STRING( NULL, "globalname", STRING( globalname ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
CBaseEntity *pReturn = CBaseEntity::Instance( pent );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pReturn )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FClassnameIs( pReturn->pev, STRING( classname ) ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
ALERT( at_console, "Global entity found %s, wrong class %s\n", STRING( globalname ), STRING( pReturn->pev->classname ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pReturn = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity && pSaveData )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
entvars_t tmpVars;
|
|
|
|
Vector oldOffset;
|
|
|
|
|
|
|
|
CRestore restoreHelper( pSaveData );
|
2021-04-04 19:26:27 +02:00
|
|
|
|
|
|
|
gpGlobals->time = pSaveData->time;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( globalEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 );
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// 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.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStrEq( pSaveData->szCurrentMapName, pGlobal->levelName ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Compute the new global offset
|
|
|
|
oldOffset = pSaveData->vecLandmarkOffset;
|
|
|
|
CBaseEntity *pNewEntity = FindGlobalEntity( tmpVars.classname, tmpVars.globalname );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pNewEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
//ALERT( at_console, "Overlay %s with %s\n", STRING( pNewEntity->pev->classname ), STRING( tmpVars.classname ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
// Tell the restore code we're overlaying a global entity from another level
|
|
|
|
restoreHelper.SetGlobalMode( 1 ); // Don't overwrite global fields
|
2016-07-31 15:48:50 +02:00
|
|
|
pSaveData->vecLandmarkOffset = ( pSaveData->vecLandmarkOffset - pNewEntity->pev->mins ) + tmpVars.mins;
|
2016-06-04 15:24:23 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity->ObjectCaps() & FCAP_MUST_SPAWN )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pEntity->Restore( restoreHelper );
|
|
|
|
pEntity->Spawn();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pEntity->Restore( restoreHelper );
|
2016-07-31 15:48:50 +02:00
|
|
|
pEntity->Precache();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Again, could be deleted, get the pointer again.
|
2016-07-31 15:48:50 +02:00
|
|
|
pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
2016-06-04 15:24:23 +02:00
|
|
|
#if 0
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity && pEntity->pev->globalname && globalEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
ALERT( at_console, "Global %s is %s\n", STRING( pEntity->pev->globalname ), STRING( pEntity->pev->model ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Is this an overriding global entity (coming over the transition), or one restoring in a level
|
2016-07-31 15:48:50 +02:00
|
|
|
if( globalEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
//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 ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
pSaveData->vecLandmarkOffset = oldOffset;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
UTIL_SetOrigin( pEntity->pev, pEntity->pev->origin );
|
|
|
|
pEntity->OverrideReset();
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( pEntity && pEntity->pev->globalname )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
const globalentity_t *pGlobal = gGlobalState.EntityFromTable( pEntity->pev->globalname );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pGlobal )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// Already dead? delete
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pGlobal->state == GLOBAL_DEAD )
|
2016-06-04 15:24:23 +02:00
|
|
|
return -1;
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( !FStrEq( STRING( gpGlobals->mapname ), pGlobal->levelName ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pEntity->MakeDormant(); // Hasn't been moved to this level yet, wait but stay alive
|
|
|
|
}
|
|
|
|
// In this level & not dead, continue on as normal
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
ALERT( at_error, "Global Entity %s (%s) not in table!!!\n", STRING( pEntity->pev->globalname ), STRING( pEntity->pev->classname ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
// Spawned entities default to 'On'
|
|
|
|
gGlobalState.EntityAdd( pEntity->pev->globalname, gpGlobals->mapname, GLOBAL_ON );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchObjectCollsionBox( edict_t *pent )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE( pent );
|
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
edict_t *EHANDLE::Get( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pent )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pent->serialnumber == m_serialnumber )
|
2016-06-04 15:24:23 +02:00
|
|
|
return m_pent;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return NULL;
|
2016-06-25 18:33:39 +02:00
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
edict_t *EHANDLE::Set( edict_t *pent )
|
|
|
|
{
|
2017-07-17 07:15:17 +02:00
|
|
|
if( pent )
|
|
|
|
{
|
|
|
|
m_pent = pent;
|
|
|
|
m_serialnumber = m_pent->serialnumber;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pent = NULL;
|
|
|
|
m_serialnumber = 0;
|
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
return pent;
|
2016-06-25 18:33:39 +02:00
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
EHANDLE::operator CBaseEntity *()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
return (CBaseEntity *)GET_PRIVATE( Get() );
|
2016-06-25 18:33:39 +02:00
|
|
|
}
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *EHANDLE::operator = ( CBaseEntity *pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_pent = ENT( pEntity->pev );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pent )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_serialnumber = m_pent->serialnumber;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pent = NULL;
|
|
|
|
m_serialnumber = 0;
|
|
|
|
}
|
|
|
|
return pEntity;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
EHANDLE::operator int ()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return Get() != NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity * EHANDLE::operator -> ()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
return (CBaseEntity *)GET_PRIVATE( Get() );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// give health
|
2016-07-31 15:48:50 +02:00
|
|
|
int CBaseEntity::TakeHealth( float flHealth, int bitsDamageType )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pev->takedamage )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
// heal
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->health >= pev->max_health )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
pev->health += flHealth;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->health > pev->max_health )
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->health = pev->max_health;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// inflict damage on this entity. bitsDamageType indicates type of damage inflicted, ie: DMG_CRUSH
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CBaseEntity::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
Vector vecTemp;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !pev->takedamage )
|
2016-06-04 15:24:23 +02:00
|
|
|
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).
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pevAttacker == pevInflictor )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2017-07-01 23:42:30 +02:00
|
|
|
vecTemp = pevAttacker->origin - VecBModelOrigin( pev );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// an actual missile was involved.
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vecTemp = pevInflictor->origin - VecBModelOrigin( pev );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
// this global is still used for glass and other non-monster killables, along with decals.
|
2016-06-04 15:24:23 +02:00
|
|
|
g_vecAttackDir = vecTemp.Normalize();
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
// save damage based on the target's armor level
|
|
|
|
// figure momentum add (don't let hurt brushes or other triggers move player)
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( !FNullEnt( pevInflictor ) ) && (pev->movetype == MOVETYPE_WALK || pev->movetype == MOVETYPE_STEP ) && ( pevAttacker->solid != SOLID_TRIGGER ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
Vector vecDir = pev->origin - ( pevInflictor->absmin + pevInflictor->absmax ) * 0.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
vecDir = vecDir.Normalize();
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
float flForce = flDamage * ( ( 32.0f * 32.0f * 72.0f ) / ( pev->size.x * pev->size.y * pev->size.z ) ) * 5.0f;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( flForce > 1000.0f )
|
|
|
|
flForce = 1000.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->velocity = pev->velocity + vecDir * flForce;
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
// do the damage
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->health -= flDamage;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->health <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Killed( pevAttacker, GIB_NORMAL );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBaseEntity::Killed( entvars_t *pevAttacker, int iGib )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->takedamage = DAMAGE_NO;
|
|
|
|
pev->deadflag = DEAD_DEAD;
|
|
|
|
UTIL_Remove( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
CBaseEntity *CBaseEntity::GetNextTarget( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStringNull( pev->target ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return NULL;
|
2016-07-31 15:48:50 +02:00
|
|
|
edict_t *pTarget = FIND_ENTITY_BY_TARGETNAME( NULL, STRING( pev->target ) );
|
|
|
|
if( FNullEnt( pTarget ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return Instance( pTarget );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Global Savedata for Delay
|
2016-07-31 15:48:50 +02:00
|
|
|
TYPEDESCRIPTION CBaseEntity::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( save.WriteEntVars( "ENTVARS", pev ) )
|
|
|
|
return save.WriteFields( "BASE", this, m_SaveData, ARRAYSIZE( m_SaveData ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CBaseEntity::Restore( CRestore &restore )
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = restore.ReadEntVars( "ENTVARS", pev );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( status )
|
|
|
|
status = restore.ReadFields( "BASE", this, m_SaveData, ARRAYSIZE( m_SaveData ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->modelindex != 0 && !FStringNull( pev->model ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector mins, maxs;
|
|
|
|
mins = pev->mins; // Set model is about to destroy these
|
|
|
|
maxs = pev->maxs;
|
|
|
|
|
2017-07-23 23:24:55 +02:00
|
|
|
PRECACHE_MODEL( STRING( pev->model ) );
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), STRING( pev->model ) );
|
|
|
|
UTIL_SetSize( pev, mins, maxs ); // Reset them
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize absmin & absmax to the appropriate box
|
|
|
|
void SetObjectCollisionBox( entvars_t *pev )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( pev->solid == SOLID_BSP ) &&
|
|
|
|
( pev->angles.x || pev->angles.y || pev->angles.z ) )
|
|
|
|
{
|
|
|
|
// expand for rotation
|
|
|
|
float max, v;
|
|
|
|
int i;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
max = 0;
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
v = fabs( ( (float *)pev->mins )[i] );
|
|
|
|
if( v > max )
|
2016-06-04 15:24:23 +02:00
|
|
|
max = v;
|
2016-07-31 15:48:50 +02:00
|
|
|
v = fabs( ( (float *)pev->maxs )[i] );
|
|
|
|
if( v > max )
|
2016-06-04 15:24:23 +02:00
|
|
|
max = v;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
( (float *)pev->absmin )[i] = ( (float *)pev->origin )[i] - max;
|
|
|
|
( (float *)pev->absmax )[i] = ( (float *)pev->origin )[i] + max;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CBaseEntity::Intersects( CBaseEntity *pOther )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
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;
|
2016-06-04 15:24:23 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CBaseEntity::MakeDormant( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = 0.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
// Relink
|
|
|
|
UTIL_SetOrigin( pev, pev->origin );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CBaseEntity::IsDormant( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
return FBitSet( pev->flags, FL_DORMANT );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
BOOL CBaseEntity::IsInWorld( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// position
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->origin.x >= 4096.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->origin.y >= 4096.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->origin.z >= 4096.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->origin.x <= -4096.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->origin.y <= -4096.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->origin.z <= -4096.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2016-06-04 15:24:23 +02:00
|
|
|
// speed
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->velocity.x >= 2000.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->velocity.y >= 2000.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->velocity.z >= 2000.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->velocity.x <= -2000.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->velocity.y <= -2000.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2019-10-13 13:49:25 +02:00
|
|
|
if( pev->velocity.z <= -2000.0f )
|
2016-07-31 15:48:50 +02:00
|
|
|
return FALSE;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CBaseEntity::ShouldToggle( USE_TYPE useType, BOOL currentState )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( useType != USE_TOGGLE && useType != USE_SET )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( ( currentState && useType == USE_ON ) || ( !currentState && useType == USE_OFF ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CBaseEntity::DamageDecal( int bitsDamageType )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->rendermode == kRenderTransAlpha )
|
2016-06-04 15:24:23 +02:00
|
|
|
return -1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->rendermode != kRenderNormal )
|
2016-06-04 15:24:23 +02:00
|
|
|
return DECAL_BPROOF1;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
return DECAL_GUNSHOT1 + RANDOM_LONG( 0, 4 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2017-06-29 15:56:03 +02:00
|
|
|
CBaseEntity *CBaseEntity::Create( const char *szName, const Vector &vecOrigin, const Vector &vecAngles, edict_t *pentOwner )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
edict_t *pent;
|
|
|
|
CBaseEntity *pEntity;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pent = CREATE_NAMED_ENTITY( MAKE_STRING( szName ) );
|
|
|
|
if( FNullEnt( pent ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|