source-engine/game/server/swarm/asw_client.cpp

174 lines
4.0 KiB
C++
Raw Normal View History

2023-10-03 14:23:56 +00:00
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
2022-04-16 09:05:19 +00:00
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
/*
2023-10-03 14:23:56 +00:00
===== asw_client.cpp ========================================================
2022-04-16 09:05:19 +00:00
2023-10-03 14:23:56 +00:00
Infested client/server game specific stuff
2022-04-16 09:05:19 +00:00
*/
#include "cbase.h"
2023-10-03 14:23:56 +00:00
#include "asw_player.h"
#include "asw_gamerules.h"
2022-04-16 09:05:19 +00:00
#include "gamerules.h"
#include "teamplay_gamerules.h"
2023-10-03 14:23:56 +00:00
#include "EntityList.h"
2022-04-16 09:05:19 +00:00
#include "physics.h"
#include "game.h"
#include "player_resource.h"
#include "engine/IEngineSound.h"
#include "tier0/vprof.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
void Host_Say( edict_t *pEdict, bool teamonly );
extern bool g_fGameOver;
/*
===========
ClientPutInServer
called each time a player is spawned into the game
============
*/
void ClientPutInServer( edict_t *pEdict, const char *playername )
{
// Allocate a CBasePlayer for pev, and call spawn
2023-10-03 14:23:56 +00:00
CASW_Player *pPlayer = CASW_Player::CreatePlayer( "player", pEdict );
pPlayer->SetPlayerName( playername );
2022-04-16 09:05:19 +00:00
}
void ClientActive( edict_t *pEdict, bool bLoadGame )
{
2023-10-03 14:23:56 +00:00
CASW_Player *pPlayer = dynamic_cast< CASW_Player* >( CBaseEntity::Instance( pEdict ) );
2022-04-16 09:05:19 +00:00
Assert( pPlayer );
2023-10-03 14:23:56 +00:00
if ( !pPlayer )
{
return;
}
2022-04-16 09:05:19 +00:00
pPlayer->InitialSpawn();
if ( !bLoadGame )
{
pPlayer->Spawn();
}
}
2023-10-03 14:23:56 +00:00
void ClientFullyConnect( edict_t *pEntity )
{
}
2022-04-16 09:05:19 +00:00
/*
===============
const char *GetGameDescription()
Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
===============
*/
const char *GetGameDescription()
{
if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
return g_pGameRules->GetGameDescription();
else
2023-10-03 14:23:56 +00:00
return "Alien Swarm: Infested";
2022-04-16 09:05:19 +00:00
}
//-----------------------------------------------------------------------------
// Purpose: Given a player and optional name returns the entity of that
// classname that the player is nearest facing
//
// Input :
// Output :
//-----------------------------------------------------------------------------
CBaseEntity* FindEntity( edict_t *pEdict, char *classname)
{
// If no name was given set bits based on the picked
if (FStrEq(classname,""))
{
2023-10-03 14:23:56 +00:00
CBasePlayer *pPlayer = static_cast<CBasePlayer*>(GetContainingEntity(pEdict));
if ( pPlayer )
{
return pPlayer->FindPickerEntityClass( classname );
}
2022-04-16 09:05:19 +00:00
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Precache game-specific models & sounds
//-----------------------------------------------------------------------------
2023-10-03 14:23:56 +00:00
PRECACHE_REGISTER_BEGIN( GLOBAL, ClientGamePrecache )
PRECACHE( MODEL, "models/player.mdl");
PRECACHE( MODEL, "models/gibs/agibs.mdl" );
PRECACHE( MODEL, "models/gibs/hgibs.mdl" );
PRECACHE( MODEL, "models/gibs/hgibs_spine.mdl" );
PRECACHE( MODEL, "models/gibs/hgibs_scapula.mdl" );
2022-04-16 09:05:19 +00:00
2023-10-03 14:23:56 +00:00
PRECACHE( GAMESOUND, "FX_AntlionImpact.ShellImpact" );
PRECACHE( GAMESOUND, "Missile.ShotDown" );
PRECACHE( GAMESOUND, "Geiger.BeepHigh" );
PRECACHE( GAMESOUND, "Geiger.BeepLow" );
PRECACHE( KV_DEP_FILE, "resource/ParticleEmitters.txt" )
PRECACHE_REGISTER_END()
2022-04-16 09:05:19 +00:00
2023-10-03 14:23:56 +00:00
void ClientGamePrecache( void )
{
2022-04-16 09:05:19 +00:00
}
// called by ClientKill and DeadThink
void respawn( CBaseEntity *pEdict, bool fCopyCorpse )
{
if (gpGlobals->coop || gpGlobals->deathmatch)
{
if ( fCopyCorpse )
{
// make a copy of the dead body for appearances sake
2023-10-03 14:23:56 +00:00
((CASW_Player *)pEdict)->CreateCorpse();
2022-04-16 09:05:19 +00:00
}
// respawn player
pEdict->Spawn();
}
else
{ // restart the entire server
engine->ServerCommand("reload\n");
}
}
void GameStartFrame( void )
{
VPROF("GameStartFrame()");
if ( g_fGameOver )
return;
gpGlobals->teamplay = (teamplay.GetInt() != 0);
}
2023-10-03 14:23:56 +00:00
2022-04-16 09:05:19 +00:00
//=========================================================
// instantiate the proper game rules object
//=========================================================
void InstallGameRules()
{
2023-10-03 14:23:56 +00:00
CreateGameRulesObject( "CAlienSwarm" );
2022-04-16 09:05:19 +00:00
}