2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 01:47:45 +01:00
hlsdk-xash3d/dlls/gamerules.cpp

353 lines
11 KiB
C++
Raw Normal View History

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.
*
****/
//=========================================================
// 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"
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );
2016-07-31 15:48:50 +02:00
DLL_GLOBAL CGameRules *g_pGameRules = NULL;
extern DLL_GLOBAL BOOL g_fGameOver;
2016-06-04 15:24:23 +02:00
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;
2016-07-31 15:48:50 +02:00
if( pszAmmoName )
2016-06-04 15:24:23 +02:00
{
iAmmoIndex = pPlayer->GetAmmoIndex( pszAmmoName );
2016-07-31 15:48:50 +02:00
if( iAmmoIndex > -1 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pPlayer->AmmoInventory( iAmmoIndex ) < iMaxCarry )
2016-06-04 15:24:23 +02:00
{
// player has room for more of this type of ammo
return TRUE;
}
}
}
return FALSE;
}
//=========================================================
//=========================================================
2016-07-31 15:48:50 +02:00
edict_t *CGameRules::GetPlayerSpawnSpot( CBasePlayer *pPlayer )
2016-06-04 15:24:23 +02:00
{
edict_t *pentSpawnSpot = EntSelectSpawnPoint( pPlayer );
2016-07-31 15:48:50 +02:00
pPlayer->pev->origin = VARS( pentSpawnSpot )->origin + Vector( 0, 0, 1 );
2016-06-04 15:24:23 +02:00
pPlayer->pev->v_angle = g_vecZero;
pPlayer->pev->velocity = g_vecZero;
2016-07-31 15:48:50 +02:00
pPlayer->pev->angles = VARS( pentSpawnSpot )->angles;
2016-06-04 15:24:23 +02:00
pPlayer->pev->punchangle = g_vecZero;
pPlayer->pev->fixangle = TRUE;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
return pentSpawnSpot;
}
//=========================================================
//=========================================================
BOOL CGameRules::CanHavePlayerItem( CBasePlayer *pPlayer, CBasePlayerItem *pWeapon )
{
// only living players can have items
2016-07-31 15:48:50 +02:00
if( pPlayer->pev->deadflag != DEAD_NO )
2016-06-04 15:24:23 +02:00
return FALSE;
2016-07-31 15:48:50 +02:00
if( pWeapon->pszAmmo1() )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( !CanHaveAmmo( pPlayer, pWeapon->pszAmmo1(), pWeapon->iMaxAmmo1() ) )
2016-06-04 15:24:23 +02:00
{
// 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
2016-07-31 15:48:50 +02:00
if( pPlayer->HasPlayerItem( pWeapon ) )
2016-06-04 15:24:23 +02:00
{
return FALSE;
}
}
}
else
{
// weapon doesn't use ammo, don't take another if you already have it.
2016-07-31 15:48:50 +02:00
if( pPlayer->HasPlayerItem( pWeapon ) )
2016-06-04 15:24:23 +02:00
{
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 )
{
2016-07-31 15:48:50 +02:00
int iSkill;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
iSkill = (int)CVAR_GET_FLOAT( "skill" );
2016-06-04 15:24:23 +02:00
g_iSkillLevel = iSkill;
2016-07-31 15:48:50 +02:00
if( iSkill < 1 )
2016-06-04 15:24:23 +02:00
{
iSkill = 1;
}
2016-07-31 15:48:50 +02:00
else if( iSkill > 3 )
2016-06-04 15:24:23 +02:00
{
iSkill = 3;
}
gSkillData.iSkillLevel = iSkill;
2016-07-31 15:48:50 +02:00
ALERT( at_console, "\nGAME SKILL LEVEL:%d\n",iSkill );
2016-06-04 15:24:23 +02:00
//Agrunt
gSkillData.agruntHealth = GetSkillCvar( "sk_agrunt_health" );
2016-07-31 15:48:50 +02:00
gSkillData.agruntDmgPunch = GetSkillCvar( "sk_agrunt_dmg_punch" );
2016-06-04 15:24:23 +02:00
// Apache
2016-07-31 15:48:50 +02:00
gSkillData.apacheHealth = GetSkillCvar( "sk_apache_health" );
2016-06-04 15:24:23 +02:00
// Barney
2016-07-31 15:48:50 +02:00
gSkillData.barneyHealth = GetSkillCvar( "sk_barney_health" );
2016-06-04 15:24:23 +02:00
// Big Momma
gSkillData.bigmommaHealthFactor = GetSkillCvar( "sk_bigmomma_health_factor" );
gSkillData.bigmommaDmgSlash = GetSkillCvar( "sk_bigmomma_dmg_slash" );
gSkillData.bigmommaDmgBlast = GetSkillCvar( "sk_bigmomma_dmg_blast" );
gSkillData.bigmommaRadiusBlast = GetSkillCvar( "sk_bigmomma_radius_blast" );
// Bullsquid
2016-07-31 15:48:50 +02:00
gSkillData.bullsquidHealth = GetSkillCvar( "sk_bullsquid_health" );
gSkillData.bullsquidDmgBite = GetSkillCvar( "sk_bullsquid_dmg_bite" );
gSkillData.bullsquidDmgWhip = GetSkillCvar( "sk_bullsquid_dmg_whip" );
gSkillData.bullsquidDmgSpit = GetSkillCvar( "sk_bullsquid_dmg_spit" );
2016-06-04 15:24:23 +02:00
// Gargantua
2016-07-31 15:48:50 +02:00
gSkillData.gargantuaHealth = GetSkillCvar( "sk_gargantua_health" );
gSkillData.gargantuaDmgSlash = GetSkillCvar( "sk_gargantua_dmg_slash" );
gSkillData.gargantuaDmgFire = GetSkillCvar( "sk_gargantua_dmg_fire" );
2016-08-02 23:40:57 +02:00
gSkillData.gargantuaDmgStomp = GetSkillCvar( "sk_gargantua_dmg_stomp" );
2016-06-04 15:24:23 +02:00
// Hassassin
2016-07-31 15:48:50 +02:00
gSkillData.hassassinHealth = GetSkillCvar( "sk_hassassin_health" );
2016-06-04 15:24:23 +02:00
// Headcrab
2016-07-31 15:48:50 +02:00
gSkillData.headcrabHealth = GetSkillCvar( "sk_headcrab_health" );
gSkillData.headcrabDmgBite = GetSkillCvar( "sk_headcrab_dmg_bite" );
2016-06-04 15:24:23 +02:00
// Hgrunt
2016-07-31 15:48:50 +02:00
gSkillData.hgruntHealth = GetSkillCvar( "sk_hgrunt_health" );
gSkillData.hgruntDmgKick = GetSkillCvar( "sk_hgrunt_kick" );
gSkillData.hgruntShotgunPellets = GetSkillCvar( "sk_hgrunt_pellets" );
gSkillData.hgruntGrenadeSpeed = GetSkillCvar( "sk_hgrunt_gspeed" );
2016-06-04 15:24:23 +02:00
// Houndeye
2016-07-31 15:48:50 +02:00
gSkillData.houndeyeHealth = GetSkillCvar( "sk_houndeye_health" );
gSkillData.houndeyeDmgBlast = GetSkillCvar( "sk_houndeye_dmg_blast" );
2016-06-04 15:24:23 +02:00
// ISlave
2016-07-31 15:48:50 +02:00
gSkillData.slaveHealth = GetSkillCvar( "sk_islave_health" );
gSkillData.slaveDmgClaw = GetSkillCvar( "sk_islave_dmg_claw" );
gSkillData.slaveDmgClawrake = GetSkillCvar( "sk_islave_dmg_clawrake" );
gSkillData.slaveDmgZap = GetSkillCvar( "sk_islave_dmg_zap" );
2016-06-04 15:24:23 +02:00
// Icthyosaur
2016-07-31 15:48:50 +02:00
gSkillData.ichthyosaurHealth = GetSkillCvar( "sk_ichthyosaur_health" );
gSkillData.ichthyosaurDmgShake = GetSkillCvar( "sk_ichthyosaur_shake" );
2016-06-04 15:24:23 +02:00
// Leech
2016-07-31 15:48:50 +02:00
gSkillData.leechHealth = GetSkillCvar( "sk_leech_health" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
gSkillData.leechDmgBite = GetSkillCvar( "sk_leech_dmg_bite" );
2016-06-04 15:24:23 +02:00
// Controller
2016-07-31 15:48:50 +02:00
gSkillData.controllerHealth = GetSkillCvar( "sk_controller_health" );
gSkillData.controllerDmgZap = GetSkillCvar( "sk_controller_dmgzap" );
gSkillData.controllerSpeedBall = GetSkillCvar( "sk_controller_speedball" );
gSkillData.controllerDmgBall = GetSkillCvar( "sk_controller_dmgball" );
2016-06-04 15:24:23 +02:00
// Nihilanth
2016-07-31 15:48:50 +02:00
gSkillData.nihilanthHealth = GetSkillCvar( "sk_nihilanth_health" );
gSkillData.nihilanthZap = GetSkillCvar( "sk_nihilanth_zap" );
2016-06-04 15:24:23 +02:00
// Scientist
2016-07-31 15:48:50 +02:00
gSkillData.scientistHealth = GetSkillCvar( "sk_scientist_health" );
2016-06-04 15:24:23 +02:00
// Snark
2016-07-31 15:48:50 +02:00
gSkillData.snarkHealth = GetSkillCvar( "sk_snark_health" );
gSkillData.snarkDmgBite = GetSkillCvar( "sk_snark_dmg_bite" );
gSkillData.snarkDmgPop = GetSkillCvar( "sk_snark_dmg_pop" );
2016-06-04 15:24:23 +02:00
// Zombie
2016-07-31 15:48:50 +02:00
gSkillData.zombieHealth = GetSkillCvar( "sk_zombie_health" );
gSkillData.zombieDmgOneSlash = GetSkillCvar( "sk_zombie_dmg_one_slash" );
gSkillData.zombieDmgBothSlash = GetSkillCvar( "sk_zombie_dmg_both_slash" );
2016-06-04 15:24:23 +02:00
//Turret
2016-07-31 15:48:50 +02:00
gSkillData.turretHealth = GetSkillCvar( "sk_turret_health" );
2016-06-04 15:24:23 +02:00
// MiniTurret
2016-07-31 15:48:50 +02:00
gSkillData.miniturretHealth = GetSkillCvar( "sk_miniturret_health" );
2016-06-04 15:24:23 +02:00
// Sentry Turret
2016-07-31 15:48:50 +02:00
gSkillData.sentryHealth = GetSkillCvar( "sk_sentry_health" );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
// PLAYER WEAPONS
2016-06-04 15:24:23 +02:00
// Crowbar whack
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgCrowbar = GetSkillCvar( "sk_plr_crowbar" );
2016-06-04 15:24:23 +02:00
// Glock Round
2016-07-31 15:48:50 +02:00
gSkillData.plrDmg9MM = GetSkillCvar( "sk_plr_9mm_bullet" );
2016-06-04 15:24:23 +02:00
// 357 Round
2016-07-31 15:48:50 +02:00
gSkillData.plrDmg357 = GetSkillCvar( "sk_plr_357_bullet" );
2016-06-04 15:24:23 +02:00
// MP5 Round
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgMP5 = GetSkillCvar( "sk_plr_9mmAR_bullet" );
2016-06-04 15:24:23 +02:00
// M203 grenade
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgM203Grenade = GetSkillCvar( "sk_plr_9mmAR_grenade" );
2016-06-04 15:24:23 +02:00
// Shotgun buckshot
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgBuckshot = GetSkillCvar( "sk_plr_buckshot" );
2016-06-04 15:24:23 +02:00
// Crossbow
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgCrossbowClient = GetSkillCvar( "sk_plr_xbow_bolt_client" );
gSkillData.plrDmgCrossbowMonster = GetSkillCvar( "sk_plr_xbow_bolt_monster" );
2016-06-04 15:24:23 +02:00
// RPG
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgRPG = GetSkillCvar( "sk_plr_rpg" );
2016-06-04 15:24:23 +02:00
// Gauss gun
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgGauss = GetSkillCvar( "sk_plr_gauss" );
2016-06-04 15:24:23 +02:00
// Egon Gun
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgEgonNarrow = GetSkillCvar( "sk_plr_egon_narrow" );
gSkillData.plrDmgEgonWide = GetSkillCvar( "sk_plr_egon_wide" );
2016-06-04 15:24:23 +02:00
// Hand Grendade
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgHandGrenade = GetSkillCvar( "sk_plr_hand_grenade" );
2016-06-04 15:24:23 +02:00
// Satchel Charge
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgSatchel = GetSkillCvar( "sk_plr_satchel" );
2016-06-04 15:24:23 +02:00
// Tripmine
2016-07-31 15:48:50 +02:00
gSkillData.plrDmgTripmine = GetSkillCvar( "sk_plr_tripmine" );
2016-06-04 15:24:23 +02:00
// MONSTER WEAPONS
2016-07-31 15:48:50 +02:00
gSkillData.monDmg12MM = GetSkillCvar( "sk_12mm_bullet" );
2016-06-04 15:24:23 +02:00
gSkillData.monDmgMP5 = GetSkillCvar ("sk_9mmAR_bullet" );
2016-07-31 15:48:50 +02:00
gSkillData.monDmg9MM = GetSkillCvar( "sk_9mm_bullet" );
2016-06-04 15:24:23 +02:00
// MONSTER HORNET
2016-07-31 15:48:50 +02:00
gSkillData.monDmgHornet = GetSkillCvar( "sk_hornet_dmg" );
2016-06-04 15:24:23 +02:00
// PLAYER HORNET
// Up to this point, player hornet damage and monster hornet damage were both using
// monDmgHornet to determine how much damage to do. In tuning the hivehand, we now need
// to separate player damage and monster hivehand damage. Since it's so late in the project, we've
// added plrDmgHornet to the SKILLDATA struct, but not to the engine CVar list, so it's inaccesible
// via SKILLS.CFG. Any player hivehand tuning must take place in the code. (sjb)
gSkillData.plrDmgHornet = 7;
// HEALTH/CHARGE
gSkillData.suitchargerCapacity = GetSkillCvar( "sk_suitcharger" );
gSkillData.batteryCapacity = GetSkillCvar( "sk_battery" );
gSkillData.healthchargerCapacity = GetSkillCvar ( "sk_healthcharger" );
gSkillData.healthkitCapacity = GetSkillCvar ( "sk_healthkit" );
gSkillData.scientistHeal = GetSkillCvar ( "sk_scientist_heal" );
// monster damage adj
gSkillData.monHead = GetSkillCvar( "sk_monster_head" );
gSkillData.monChest = GetSkillCvar( "sk_monster_chest" );
gSkillData.monStomach = GetSkillCvar( "sk_monster_stomach" );
gSkillData.monLeg = GetSkillCvar( "sk_monster_leg" );
gSkillData.monArm = GetSkillCvar( "sk_monster_arm" );
// player damage adj
gSkillData.plrHead = GetSkillCvar( "sk_player_head" );
gSkillData.plrChest = GetSkillCvar( "sk_player_chest" );
gSkillData.plrStomach = GetSkillCvar( "sk_player_stomach" );
gSkillData.plrLeg = GetSkillCvar( "sk_player_leg" );
gSkillData.plrArm = GetSkillCvar( "sk_player_arm" );
}
void CGameRules::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer )
{
pPlayer->SetPrefsFromUserinfo( infobuffer );
}
2016-06-04 15:24:23 +02:00
//=========================================================
// instantiate the proper game rules object
//=========================================================
CGameRules *InstallGameRules( void )
{
SERVER_COMMAND( "exec game.cfg\n" );
2016-07-31 15:48:50 +02:00
SERVER_EXECUTE();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !gpGlobals->deathmatch )
2016-06-04 15:24:23 +02:00
{
// generic half-life
g_teamplay = 0;
return new CHalfLifeRules;
}
else
{
2016-07-31 15:48:50 +02:00
if( teamplay.value > 0 )
2016-06-04 15:24:23 +02:00
{
// teamplay
g_teamplay = 1;
return new CHalfLifeTeamplay;
}
if( sv_busters.value > 0 )
{
g_teamplay = 0;
return new CMultiplayBusters;
}
2016-07-31 15:48:50 +02:00
if( (int)gpGlobals->deathmatch == 1 )
2016-06-04 15:24:23 +02:00
{
// vanilla deathmatch
g_teamplay = 0;
return new CHalfLifeMultiplay;
}
else
{
// vanilla deathmatch??
g_teamplay = 0;
return new CHalfLifeMultiplay;
}
}
}