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.

457 lines
16 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 "ctf_gamerules.h"
9 years ago
extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer );
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 );
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;
8 years ago
ALERT( at_console, "\nGAME SKILL LEVEL:%d\n",iSkill );
9 years ago
//Agrunt
gSkillData.agruntHealth = GetSkillCvar( "sk_agrunt_health" );
8 years ago
gSkillData.agruntDmgPunch = GetSkillCvar( "sk_agrunt_dmg_punch" );
9 years ago
// Apache
8 years ago
gSkillData.apacheHealth = GetSkillCvar( "sk_apache_health" );
9 years ago
// Barney
8 years ago
gSkillData.barneyHealth = GetSkillCvar( "sk_barney_health" );
9 years ago
// 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
8 years ago
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" );
9 years ago
// Gargantua
8 years ago
gSkillData.gargantuaHealth = GetSkillCvar( "sk_gargantua_health" );
gSkillData.gargantuaDmgSlash = GetSkillCvar( "sk_gargantua_dmg_slash" );
gSkillData.gargantuaDmgFire = GetSkillCvar( "sk_gargantua_dmg_fire" );
gSkillData.gargantuaDmgStomp = GetSkillCvar( "sk_gargantua_dmg_stomp" );
9 years ago
// Hassassin
8 years ago
gSkillData.hassassinHealth = GetSkillCvar( "sk_hassassin_health" );
9 years ago
// Headcrab
8 years ago
gSkillData.headcrabHealth = GetSkillCvar( "sk_headcrab_health" );
gSkillData.headcrabDmgBite = GetSkillCvar( "sk_headcrab_dmg_bite" );
9 years ago
// Hgrunt
8 years ago
gSkillData.hgruntHealth = GetSkillCvar( "sk_hgrunt_health" );
gSkillData.hgruntDmgKick = GetSkillCvar( "sk_hgrunt_kick" );
gSkillData.hgruntShotgunPellets = GetSkillCvar( "sk_hgrunt_pellets" );
gSkillData.hgruntGrenadeSpeed = GetSkillCvar( "sk_hgrunt_gspeed" );
9 years ago
// Houndeye
8 years ago
gSkillData.houndeyeHealth = GetSkillCvar( "sk_houndeye_health" );
gSkillData.houndeyeDmgBlast = GetSkillCvar( "sk_houndeye_dmg_blast" );
9 years ago
// ISlave
8 years ago
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" );
9 years ago
// Icthyosaur
8 years ago
gSkillData.ichthyosaurHealth = GetSkillCvar( "sk_ichthyosaur_health" );
gSkillData.ichthyosaurDmgShake = GetSkillCvar( "sk_ichthyosaur_shake" );
9 years ago
// Leech
8 years ago
gSkillData.leechHealth = GetSkillCvar( "sk_leech_health" );
9 years ago
8 years ago
gSkillData.leechDmgBite = GetSkillCvar( "sk_leech_dmg_bite" );
9 years ago
// Controller
8 years ago
gSkillData.controllerHealth = GetSkillCvar( "sk_controller_health" );
gSkillData.controllerDmgZap = GetSkillCvar( "sk_controller_dmgzap" );
gSkillData.controllerSpeedBall = GetSkillCvar( "sk_controller_speedball" );
gSkillData.controllerDmgBall = GetSkillCvar( "sk_controller_dmgball" );
9 years ago
// Nihilanth
8 years ago
gSkillData.nihilanthHealth = GetSkillCvar( "sk_nihilanth_health" );
gSkillData.nihilanthZap = GetSkillCvar( "sk_nihilanth_zap" );
9 years ago
// Scientist
8 years ago
gSkillData.scientistHealth = GetSkillCvar( "sk_scientist_health" );
9 years ago
// Snark
8 years ago
gSkillData.snarkHealth = GetSkillCvar( "sk_snark_health" );
gSkillData.snarkDmgBite = GetSkillCvar( "sk_snark_dmg_bite" );
gSkillData.snarkDmgPop = GetSkillCvar( "sk_snark_dmg_pop" );
9 years ago
// Zombie
8 years ago
gSkillData.zombieHealth = GetSkillCvar( "sk_zombie_health" );
gSkillData.zombieDmgOneSlash = GetSkillCvar( "sk_zombie_dmg_one_slash" );
gSkillData.zombieDmgBothSlash = GetSkillCvar( "sk_zombie_dmg_both_slash" );
9 years ago
//Turret
8 years ago
gSkillData.turretHealth = GetSkillCvar( "sk_turret_health" );
9 years ago
// MiniTurret
8 years ago
gSkillData.miniturretHealth = GetSkillCvar( "sk_miniturret_health" );
9 years ago
// Sentry Turret
8 years ago
gSkillData.sentryHealth = GetSkillCvar( "sk_sentry_health" );
9 years ago
//
// Op4 Monsters
//
// Otis
gSkillData.otisHealth = GetSkillCvar( "sk_otis_health" );
// Pitdrone
gSkillData.pitdroneHealth = GetSkillCvar( "sk_pitdrone_health" );
gSkillData.pitdroneDmgBite = GetSkillCvar( "sk_pitdrone_dmg_bite" );
gSkillData.pitdroneDmgWhip = GetSkillCvar( "sk_pitdrone_dmg_whip" );
gSkillData.pitdroneDmgSpit = GetSkillCvar( "sk_pitdrone_dmg_spit" );
// Hgrunt Ally
5 years ago
gSkillData.fgruntHealth = GetSkillCvar( "sk_hgrunt_ally_health" );
gSkillData.fgruntDmgKick = GetSkillCvar( "sk_hgrunt_ally_kick" );
gSkillData.fgruntShotgunPellets = GetSkillCvar( "sk_hgrunt_ally_pellets" );
gSkillData.fgruntGrenadeSpeed = GetSkillCvar( "sk_hgrunt_ally_gspeed" );
// Medic Ally
5 years ago
gSkillData.medicHealth = GetSkillCvar( "sk_medic_ally_health" );
gSkillData.medicDmgKick = GetSkillCvar( "sk_medic_ally_kick" );
gSkillData.medicGrenadeSpeed = GetSkillCvar( "sk_medic_ally_gspeed" );
gSkillData.medicHeal = GetSkillCvar( "sk_medic_ally_heal" );
// Torch Ally
5 years ago
gSkillData.torchHealth = GetSkillCvar( "sk_torch_ally_health" );
gSkillData.torchDmgKick = GetSkillCvar( "sk_torch_ally_kick" );
gSkillData.torchGrenadeSpeed = GetSkillCvar( "sk_torch_ally_gspeed" );
// Male Assassin
gSkillData.massnHealth = GetSkillCvar( "sk_massassin_health" );
gSkillData.massnDmgKick = GetSkillCvar( "sk_massassin_kick" );
gSkillData.massnGrenadeSpeed = GetSkillCvar( "sk_massassin_gspeed" );
// ShockTrooper
gSkillData.strooperHealth = GetSkillCvar( "sk_shocktrooper_health" );
gSkillData.strooperDmgKick = GetSkillCvar( "sk_shocktrooper_kick" );
gSkillData.strooperGrenadeSpeed = GetSkillCvar( "sk_shocktrooper_gspeed" );
gSkillData.strooperMaxCharge = GetSkillCvar( "sk_shocktrooper_maxcharge" );
gSkillData.strooperRchgSpeed = GetSkillCvar( "sk_shocktrooper_rchgspeed" );
// Scientist
gSkillData.cleansuitScientistHealth = GetSkillCvar( "sk_cleansuit_scientist_health" );
gSkillData.cleansuitScientistHeal = GetSkillCvar( "sk_cleansuit_scientist_heal" );
// Voltigore
gSkillData.voltigoreHealth = GetSkillCvar( "sk_voltigore_health" );
gSkillData.voltigoreDmgPunch = GetSkillCvar( "sk_voltigore_dmg_punch" );
gSkillData.voltigoreDmgBeam = GetSkillCvar( "sk_voltigore_dmg_beam" );
// Baby Voltigore
gSkillData.babyVoltigoreHealth = GetSkillCvar( "sk_babyvoltigore_health" );
gSkillData.babyVoltigoreDmgPunch = GetSkillCvar( "sk_babyvoltigore_dmg_punch" );
// Pitworm
gSkillData.pwormHealth = GetSkillCvar( "sk_pitworm_health" );
gSkillData.pwormDmgSwipe = GetSkillCvar( "sk_pitworm_dmg_swipe" );
gSkillData.pwormDmgBeam = GetSkillCvar( "sk_pitworm_dmg_beam" );
// Geneworm
gSkillData.gwormHealth = GetSkillCvar( "sk_geneworm_health" );
gSkillData.gwormDmgSpit = GetSkillCvar( "sk_geneworm_dmg_spit" );
gSkillData.gwormDmgHit = GetSkillCvar( "sk_geneworm_dmg_hit" );
// Zombie Barney
gSkillData.zbarneyHealth = GetSkillCvar( "sk_zombie_barney_health" );
gSkillData.zbarneyDmgOneSlash = GetSkillCvar( "sk_zombie_barney_dmg_one_slash" );
gSkillData.zbarneyDmgBothSlash = GetSkillCvar( "sk_zombie_barney_dmg_both_slash" );
// Zombie Soldier
gSkillData.zgruntHealth = GetSkillCvar( "sk_zombie_soldier_health" );
gSkillData.zgruntDmgOneSlash = GetSkillCvar( "sk_zombie_soldier_dmg_one_slash" );
gSkillData.zgruntDmgBothSlash = GetSkillCvar( "sk_zombie_soldier_dmg_both_slash" );
// Gonome
gSkillData.gonomeHealth = GetSkillCvar( "sk_gonome_health" );
gSkillData.gonomeDmgOneSlash = GetSkillCvar( "sk_gonome_dmg_one_slash" );
gSkillData.gonomeDmgGuts = GetSkillCvar( "sk_gonome_dmg_guts" );
gSkillData.gonomeDmgOneBite = GetSkillCvar( "sk_gonome_dmg_one_bite" );
// Shock Roach
gSkillData.sroachHealth = GetSkillCvar( "sk_shockroach_health" );
gSkillData.sroachDmgBite = GetSkillCvar( "sk_shockroach_dmg_bite" );
gSkillData.sroachLifespan = GetSkillCvar( "sk_shockroach_lifespan" );
8 years ago
// PLAYER WEAPONS
9 years ago
// Crowbar whack
8 years ago
gSkillData.plrDmgCrowbar = GetSkillCvar( "sk_plr_crowbar" );
9 years ago
// Glock Round
8 years ago
gSkillData.plrDmg9MM = GetSkillCvar( "sk_plr_9mm_bullet" );
9 years ago
// 357 Round
8 years ago
gSkillData.plrDmg357 = GetSkillCvar( "sk_plr_357_bullet" );
9 years ago
// MP5 Round
8 years ago
gSkillData.plrDmgMP5 = GetSkillCvar( "sk_plr_9mmAR_bullet" );
9 years ago
// M203 grenade
8 years ago
gSkillData.plrDmgM203Grenade = GetSkillCvar( "sk_plr_9mmAR_grenade" );
9 years ago
// Shotgun buckshot
8 years ago
gSkillData.plrDmgBuckshot = GetSkillCvar( "sk_plr_buckshot" );
9 years ago
// Crossbow
8 years ago
gSkillData.plrDmgCrossbowClient = GetSkillCvar( "sk_plr_xbow_bolt_client" );
gSkillData.plrDmgCrossbowMonster = GetSkillCvar( "sk_plr_xbow_bolt_monster" );
9 years ago
// RPG
8 years ago
gSkillData.plrDmgRPG = GetSkillCvar( "sk_plr_rpg" );
9 years ago
// Gauss gun
8 years ago
gSkillData.plrDmgGauss = GetSkillCvar( "sk_plr_gauss" );
9 years ago
// Egon Gun
8 years ago
gSkillData.plrDmgEgonNarrow = GetSkillCvar( "sk_plr_egon_narrow" );
gSkillData.plrDmgEgonWide = GetSkillCvar( "sk_plr_egon_wide" );
9 years ago
// Hand Grendade
8 years ago
gSkillData.plrDmgHandGrenade = GetSkillCvar( "sk_plr_hand_grenade" );
9 years ago
// Satchel Charge
8 years ago
gSkillData.plrDmgSatchel = GetSkillCvar( "sk_plr_satchel" );
9 years ago
// Tripmine
8 years ago
gSkillData.plrDmgTripmine = GetSkillCvar( "sk_plr_tripmine" );
9 years ago
// MONSTER WEAPONS
8 years ago
gSkillData.monDmg12MM = GetSkillCvar( "sk_12mm_bullet" );
9 years ago
gSkillData.monDmgMP5 = GetSkillCvar ("sk_9mmAR_bullet" );
8 years ago
gSkillData.monDmg9MM = GetSkillCvar( "sk_9mm_bullet" );
9 years ago
// MONSTER HORNET
8 years ago
gSkillData.monDmgHornet = GetSkillCvar( "sk_hornet_dmg" );
9 years ago
// 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;
//
// Op4 Player weapons
//
gSkillData.plrDmgPWrench = GetSkillCvar( "sk_plr_pipewrench" );
gSkillData.plrDmgKnife = GetSkillCvar( "sk_plr_knife" );
gSkillData.plrDmgGrapple = GetSkillCvar( "sk_plr_grapple" );
gSkillData.plrDmgEagle = GetSkillCvar( "sk_plr_eagle" );
gSkillData.plrDmgDisplacer = GetSkillCvar( "sk_plr_displacer_self" );
gSkillData.plrDmgShockroachSingleplayer = GetSkillCvar( "sk_plr_shockroachs" );
gSkillData.plrDmgSpore = GetSkillCvar( "sk_plr_spore" );
gSkillData.plrDmg762 = GetSkillCvar( "sk_plr_762_bullet" );
gSkillData.plrDmg556 = GetSkillCvar( "sk_plr_556_bullet" );
gSkillData.monDmg762 = GetSkillCvar( "sk_plr_762_bullet" );
gSkillData.monDmg556 = GetSkillCvar( "sk_plr_556_bullet" );
gSkillData.monDmgDisplacer = GetSkillCvar( "sk_plr_displacer_other" );
gSkillData.plrDmgShockroachMultiplayer = GetSkillCvar( "sk_plr_shockroachm" );
9 years ago
// 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" );
//
// Op4 additional cvars
//
gSkillData.displacerDmgRadius = GetSkillCvar( "sk_plr_displacer_radius" );
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
8 years ago
if( !gpGlobals->deathmatch )
9 years ago
{
// generic half-life
g_teamplay = 0;
return new CHalfLifeRules;
}
else
{
// HACK HACK!! Put here to tell whether the current map supports
// CTF gamerules since there is no explicit way to specify
// the CTF gamerule in server creation page.
if( !strnicmp( STRING( gpGlobals->mapname ), "op4ctf", 6 ) )
{
// capture the flag
g_teamplay = 1;
return new CCTFMultiplay;
}
8 years ago
if( teamplay.value > 0 )
9 years ago
{
// teamplay
g_teamplay = 1;
return new CHalfLifeTeamplay;
}
else
{
// vanilla deathmatch??
g_teamplay = 0;
return new CHalfLifeMultiplay;
}
}
}