1999-04-07 00:00:00 +00:00
|
|
|
/***
|
|
|
|
*
|
2001-11-08 00:00:00 +00:00
|
|
|
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
|
1999-04-07 00:00:00 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
//=========================================================
|
|
|
|
// GameRules.cpp
|
|
|
|
//=========================================================
|
|
|
|
|
|
|
|
#include "extdll.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
#include "gamerules.h"
|
|
|
|
#include "teamplay_gamerules.h"
|
2001-08-29 00:00:00 +00:00
|
|
|
#include "game.h"
|
2023-09-04 20:28:44 +00:00
|
|
|
#include "pm_shared.h"
|
1999-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );
|
|
|
|
|
|
|
|
DLL_GLOBAL CGameRules* g_pGameRules = NULL;
|
|
|
|
extern DLL_GLOBAL BOOL g_fGameOver;
|
|
|
|
extern int gmsgDeathMsg; // client dll messages
|
|
|
|
extern int gmsgMOTD;
|
|
|
|
|
2023-09-04 20:28:44 +00:00
|
|
|
int g_gametype = 0;
|
2001-08-29 00:00:00 +00:00
|
|
|
|
1999-04-07 00:00:00 +00:00
|
|
|
//=========================================================
|
|
|
|
//=========================================================
|
|
|
|
BOOL CGameRules::CanHaveAmmo( CBasePlayer *pPlayer, const char *pszAmmoName, int iMaxCarry )
|
|
|
|
{
|
|
|
|
int iAmmoIndex;
|
|
|
|
|
|
|
|
if ( pszAmmoName )
|
|
|
|
{
|
|
|
|
iAmmoIndex = pPlayer->GetAmmoIndex( pszAmmoName );
|
|
|
|
|
|
|
|
if ( iAmmoIndex > -1 )
|
|
|
|
{
|
|
|
|
if ( pPlayer->AmmoInventory( iAmmoIndex ) < iMaxCarry )
|
|
|
|
{
|
|
|
|
// player has room for more of this type of ammo
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
//=========================================================
|
|
|
|
edict_t *CGameRules :: GetPlayerSpawnSpot( CBasePlayer *pPlayer )
|
|
|
|
{
|
|
|
|
edict_t *pentSpawnSpot = EntSelectSpawnPoint( pPlayer );
|
|
|
|
|
|
|
|
pPlayer->pev->origin = VARS(pentSpawnSpot)->origin + Vector(0,0,1);
|
|
|
|
pPlayer->pev->v_angle = g_vecZero;
|
|
|
|
pPlayer->pev->velocity = g_vecZero;
|
|
|
|
pPlayer->pev->angles = VARS(pentSpawnSpot)->angles;
|
|
|
|
pPlayer->pev->punchangle = g_vecZero;
|
|
|
|
pPlayer->pev->fixangle = TRUE;
|
|
|
|
|
|
|
|
return pentSpawnSpot;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
//=========================================================
|
|
|
|
BOOL CGameRules::CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon )
|
|
|
|
{
|
2000-06-05 00:00:00 +00:00
|
|
|
// only living players can have items
|
|
|
|
if ( pPlayer->pev->deadflag != DEAD_NO )
|
|
|
|
return FALSE;
|
|
|
|
|
1999-04-07 00:00:00 +00:00
|
|
|
if ( pWeapon->pszAmmo1() )
|
|
|
|
{
|
|
|
|
if ( !CanHaveAmmo( pPlayer, pWeapon->pszAmmo1(), pWeapon->iMaxAmmo1() ) )
|
|
|
|
{
|
|
|
|
// we can't carry anymore ammo for this gun. We can only
|
|
|
|
// have the gun if we aren't already carrying one of this type
|
|
|
|
if ( pPlayer->HasPlayerItem( pWeapon ) )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// weapon doesn't use ammo, don't take another if you already have it.
|
|
|
|
if ( pPlayer->HasPlayerItem( pWeapon ) )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note: will fall through to here if GetItemInfo doesn't fill the struct!
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// load the SkillData struct with the proper values based on the skill level.
|
|
|
|
//=========================================================
|
|
|
|
void CGameRules::RefreshSkillData ( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
// instantiate the proper game rules object
|
|
|
|
//=========================================================
|
|
|
|
|
|
|
|
CGameRules *InstallGameRules( void )
|
|
|
|
{
|
|
|
|
SERVER_COMMAND( "exec game.cfg\n" );
|
|
|
|
SERVER_EXECUTE( );
|
|
|
|
|
|
|
|
if ( !gpGlobals->deathmatch )
|
|
|
|
{
|
|
|
|
// generic half-life
|
2023-09-04 20:28:44 +00:00
|
|
|
g_gametype = 0;
|
1999-04-07 00:00:00 +00:00
|
|
|
return new CHalfLifeRules;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-04 20:28:44 +00:00
|
|
|
switch((int)CVAR_GET_FLOAT("mp_gametype"))
|
1999-04-07 00:00:00 +00:00
|
|
|
{
|
2023-09-04 20:28:44 +00:00
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
g_gametype = 0;
|
1999-04-07 00:00:00 +00:00
|
|
|
return new CHalfLifeMultiplay;
|
2023-09-04 20:28:44 +00:00
|
|
|
// TODO: Change this out later :)
|
|
|
|
/* case 1:
|
|
|
|
g_gametype = 1;
|
|
|
|
return new CWastesLMS;
|
|
|
|
case 2:
|
|
|
|
g_gametype = 2;
|
|
|
|
return new CHalfLifeTeamplay;*/
|
1999-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|