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.

212 lines
5.0 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.
*
****/
//=========================================================
// GameRules.cpp
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "player.h"
#include "weapons.h"
#include "gamerules.h"
#include "teamplay_gamerules.h"
#include "skill.h"
#include "game.h"
#include "threewave_gamerules.h"
9 years ago
extern Vector g_vecTeleMins[MAX_TELES];
extern Vector g_vecTeleMaxs[MAX_TELES];
extern int g_iTeleNum;
extern bool g_bIsThreeWave;
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer, bool bCheckDM );
9 years ago
8 years ago
DLL_GLOBAL CGameRules *g_pGameRules = NULL;
extern DLL_GLOBAL BOOL g_fGameOver;
9 years ago
extern int gmsgDeathMsg; // client dll messages
extern int gmsgMOTD;
int g_teamplay = 0;
//=========================================================
//=========================================================
BOOL CGameRules::CanHaveAmmo( CBasePlayer *pPlayer, const char *pszAmmoName, int iMaxCarry )
{
int iAmmoIndex;
8 years ago
if( pszAmmoName )
9 years ago
{
iAmmoIndex = pPlayer->GetAmmoIndex( pszAmmoName );
8 years ago
if( iAmmoIndex > -1 )
9 years ago
{
8 years ago
if( pPlayer->AmmoInventory( iAmmoIndex ) < iMaxCarry )
9 years ago
{
// player has room for more of this type of ammo
return TRUE;
}
}
}
return FALSE;
}
//=========================================================
//=========================================================
8 years ago
edict_t *CGameRules::GetPlayerSpawnSpot( CBasePlayer *pPlayer )
9 years ago
{
edict_t *pentSpawnSpot = EntSelectSpawnPoint( pPlayer, TRUE );
9 years ago
8 years ago
pPlayer->pev->origin = VARS( pentSpawnSpot )->origin + Vector( 0, 0, 1 );
9 years ago
pPlayer->pev->v_angle = g_vecZero;
pPlayer->pev->velocity = g_vecZero;
8 years ago
pPlayer->pev->angles = VARS( pentSpawnSpot )->angles;
9 years ago
pPlayer->pev->punchangle = g_vecZero;
pPlayer->pev->fixangle = TRUE;
8 years ago
9 years ago
return pentSpawnSpot;
}
//=========================================================
//=========================================================
BOOL CGameRules::CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon )
{
// only living players can have items
8 years ago
if( pPlayer->pev->deadflag != DEAD_NO )
9 years ago
return FALSE;
8 years ago
if( pWeapon->pszAmmo1() )
9 years ago
{
8 years ago
if( !CanHaveAmmo( pPlayer, pWeapon->pszAmmo1(), pWeapon->iMaxAmmo1() ) )
9 years ago
{
// 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
8 years ago
if( pPlayer->HasPlayerItem( pWeapon ) )
9 years ago
{
return FALSE;
}
}
}
else
{
// weapon doesn't use ammo, don't take another if you already have it.
8 years ago
if( pPlayer->HasPlayerItem( pWeapon ) )
9 years ago
{
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 )
{
8 years ago
int iSkill;
9 years ago
8 years ago
iSkill = (int)CVAR_GET_FLOAT( "skill" );
9 years ago
g_iSkillLevel = iSkill;
8 years ago
if( iSkill < 1 )
9 years ago
{
iSkill = 1;
}
8 years ago
else if( iSkill > 3 )
9 years ago
{
iSkill = 3;
}
gSkillData.iSkillLevel = iSkill;
}
void CGameRules::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer )
{
pPlayer->SetPrefsFromUserinfo( infobuffer );
}
9 years ago
//=========================================================
// instantiate the proper game rules object
//=========================================================
CGameRules *InstallGameRules( void )
{
SERVER_COMMAND( "exec game.cfg\n" );
8 years ago
SERVER_EXECUTE();
9 years ago
//Clear all the teleporters
for( int i = 0; i < MAX_TELES; i++ )
{
g_vecTeleMins[i].x = 0.0;
g_vecTeleMins[i].y = 0.0;
g_vecTeleMins[i].z = 0.0;
g_vecTeleMaxs[i].x = 0.0;
g_vecTeleMaxs[i].y = 0.0;
g_vecTeleMaxs[i].z = 0.0;
}
g_iTeleNum = 0;
8 years ago
if( !gpGlobals->deathmatch )
9 years ago
{
// generic half-life
g_teamplay = 0;
return new CHalfLifeRules;
}
else
{
if( g_bIsThreeWave )
{
return new CThreeWave;
}
else if( CVAR_GET_FLOAT( "mp_teamplay" ) >= LTS )
{
// lts
return new CHalfLifeTeamplay;
}
else if( CVAR_GET_FLOAT( "mp_teamplay" ) == LMS )
{
// lms
return new CHalfLifeMultiplay;
}
else if( CVAR_GET_FLOAT( "mp_teamplay" ) == ARENA )
{
// arena
return new CHalfLifeMultiplay;
}
else if( teamplay.value > 0 )
9 years ago
{
// teamplay
g_teamplay = 1;
return new CHalfLifeTeamplay;
}
else if( (int)gpGlobals->deathmatch == 1 )
9 years ago
{
// vanilla deathmatch
g_teamplay = 0;
return new CHalfLifeMultiplay;
}
else
{
// vanilla deathmatch??
g_teamplay = 0;
return new CHalfLifeMultiplay;
}
}
}