halflife-photomode/dlls/python.cpp

278 lines
5.7 KiB
C++
Raw Normal View History

/***
2013-08-30 13:34:05 -07:00
*
* Copyright (c) 1996-2001, 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.
*
****/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "weapons.h"
#include "monsters.h"
#include "player.h"
#include "gamerules.h"
#include "UserMessages.h"
2013-08-30 13:34:05 -07:00
LINK_ENTITY_TO_CLASS(weapon_python, CPython);
LINK_ENTITY_TO_CLASS(weapon_357, CPython);
2013-08-30 13:34:05 -07:00
bool CPython::GetItemInfo(ItemInfo* p)
2013-08-30 13:34:05 -07:00
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "357";
p->iMaxAmmo1 = _357_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = PYTHON_MAX_CLIP;
p->iFlags = 0;
p->iSlot = 1;
p->iPosition = 1;
p->iId = m_iId = WEAPON_PYTHON;
p->iWeight = PYTHON_WEIGHT;
return true;
2013-08-30 13:34:05 -07:00
}
void CPython::Spawn()
2013-08-30 13:34:05 -07:00
{
pev->classname = MAKE_STRING("weapon_357"); // hack to allow for old names
Precache();
2013-08-30 13:34:05 -07:00
m_iId = WEAPON_PYTHON;
SET_MODEL(ENT(pev), "models/w_357.mdl");
m_iDefaultAmmo = PYTHON_DEFAULT_GIVE;
FallInit(); // get ready to fall down.
2013-08-30 13:34:05 -07:00
}
void CPython::Precache()
2013-08-30 13:34:05 -07:00
{
PRECACHE_MODEL("models/v_357.mdl");
PRECACHE_MODEL("models/w_357.mdl");
PRECACHE_MODEL("models/p_357.mdl");
PRECACHE_MODEL("models/w_357ammobox.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
2013-08-30 13:34:05 -07:00
PRECACHE_SOUND("weapons/357_reload1.wav");
PRECACHE_SOUND("weapons/357_cock1.wav");
PRECACHE_SOUND("weapons/357_shot1.wav");
PRECACHE_SOUND("weapons/357_shot2.wav");
2013-08-30 13:34:05 -07:00
m_usFirePython = PRECACHE_EVENT(1, "events/python.sc");
2013-08-30 13:34:05 -07:00
}
bool CPython::Deploy()
2013-08-30 13:34:05 -07:00
{
#ifdef CLIENT_DLL
if (bIsMultiplayer())
2013-08-30 13:34:05 -07:00
#else
if (g_pGameRules->IsMultiplayer())
2013-08-30 13:34:05 -07:00
#endif
{
// enable laser sight geometry.
pev->body = 1;
}
else
{
pev->body = 0;
}
return DefaultDeploy("models/v_357.mdl", "models/p_357.mdl", PYTHON_DRAW, "python", pev->body);
2013-08-30 13:34:05 -07:00
}
void CPython::Holster()
2013-08-30 13:34:05 -07:00
{
m_fInReload = false; // cancel any reload in progress.
2013-08-30 13:34:05 -07:00
if (m_pPlayer->m_iFOV != 0)
2013-08-30 13:34:05 -07:00
{
SecondaryAttack();
}
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0;
m_flTimeWeaponIdle = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
SendWeaponAnim(PYTHON_HOLSTER);
2013-08-30 13:34:05 -07:00
}
void CPython::SecondaryAttack()
2013-08-30 13:34:05 -07:00
{
#ifdef CLIENT_DLL
if (!bIsMultiplayer())
2013-08-30 13:34:05 -07:00
#else
if (!g_pGameRules->IsMultiplayer())
2013-08-30 13:34:05 -07:00
#endif
{
return;
}
if (m_pPlayer->m_iFOV != 0)
2013-08-30 13:34:05 -07:00
{
m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
2013-08-30 13:34:05 -07:00
}
else if (m_pPlayer->m_iFOV != 40)
2013-08-30 13:34:05 -07:00
{
m_pPlayer->m_iFOV = 40;
2013-08-30 13:34:05 -07:00
}
m_flNextSecondaryAttack = 0.5;
}
void CPython::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound();
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = 0.15;
return;
}
if (m_iClip <= 0)
{
if (m_fFireOnEmpty)
2013-08-30 13:34:05 -07:00
{
PlayEmptySound();
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = 0.15;
}
return;
}
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
m_iClip--;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
2013-08-30 13:34:05 -07:00
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
2013-08-30 13:34:05 -07:00
Vector vecSrc = m_pPlayer->GetGunPosition();
Vector vecAiming = m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);
2013-08-30 13:34:05 -07:00
Vector vecDir;
vecDir = m_pPlayer->FireBulletsPlayer(1, vecSrc, vecAiming, VECTOR_CONE_1DEGREES, 8192, BULLET_PLAYER_357, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed);
2013-08-30 13:34:05 -07:00
int flags;
#if defined(CLIENT_WEAPONS)
2013-08-30 13:34:05 -07:00
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usFirePython, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0);
2013-08-30 13:34:05 -07:00
if (0 == m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
2013-08-30 13:34:05 -07:00
// HEV suit - indicate out of ammo condition
2021-11-19 13:43:33 +01:00
m_pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = 0.75;
m_flTimeWeaponIdle = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
2013-08-30 13:34:05 -07:00
}
void CPython::Reload()
2013-08-30 13:34:05 -07:00
{
if (m_pPlayer->ammo_357 <= 0)
2013-08-30 13:34:05 -07:00
return;
if (m_pPlayer->m_iFOV != 0)
2013-08-30 13:34:05 -07:00
{
m_pPlayer->m_iFOV = 0; // 0 means reset to default fov
2013-08-30 13:34:05 -07:00
}
bool bUseScope = false;
2013-08-30 13:34:05 -07:00
#ifdef CLIENT_DLL
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
DefaultReload(6, PYTHON_RELOAD, 2.0, bUseScope ? 1 : 0);
2013-08-30 13:34:05 -07:00
}
void CPython::WeaponIdle()
2013-08-30 13:34:05 -07:00
{
ResetEmptySound();
2013-08-30 13:34:05 -07:00
m_pPlayer->GetAutoaimVector(AUTOAIM_10DEGREES);
2013-08-30 13:34:05 -07:00
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
2013-08-30 13:34:05 -07:00
return;
int iAnim;
float flRand = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 0, 1);
2013-08-30 13:34:05 -07:00
if (flRand <= 0.5)
{
iAnim = PYTHON_IDLE1;
m_flTimeWeaponIdle = (70.0 / 30.0);
2013-08-30 13:34:05 -07:00
}
else if (flRand <= 0.7)
{
iAnim = PYTHON_IDLE2;
m_flTimeWeaponIdle = (60.0 / 30.0);
2013-08-30 13:34:05 -07:00
}
else if (flRand <= 0.9)
{
iAnim = PYTHON_IDLE3;
m_flTimeWeaponIdle = (88.0 / 30.0);
2013-08-30 13:34:05 -07:00
}
else
{
iAnim = PYTHON_FIDGET;
m_flTimeWeaponIdle = (170.0 / 30.0);
2013-08-30 13:34:05 -07:00
}
bool bUseScope = false;
2013-08-30 13:34:05 -07:00
#ifdef CLIENT_DLL
bUseScope = bIsMultiplayer();
#else
bUseScope = g_pGameRules->IsMultiplayer();
#endif
SendWeaponAnim(iAnim, bUseScope ? 1 : 0);
2013-08-30 13:34:05 -07:00
}
class CPythonAmmo : public CBasePlayerAmmo
{
void Spawn() override
{
Precache();
2013-08-30 13:34:05 -07:00
SET_MODEL(ENT(pev), "models/w_357ammobox.mdl");
CBasePlayerAmmo::Spawn();
2013-08-30 13:34:05 -07:00
}
void Precache() override
2013-08-30 13:34:05 -07:00
{
PRECACHE_MODEL("models/w_357ammobox.mdl");
2013-08-30 13:34:05 -07:00
PRECACHE_SOUND("items/9mmclip1.wav");
}
bool AddAmmo(CBaseEntity* pOther) override
{
if (pOther->GiveAmmo(AMMO_357BOX_GIVE, "357", _357_MAX_CARRY) != -1)
2013-08-30 13:34:05 -07:00
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
2021-11-19 13:45:16 +01:00
return true;
2013-08-30 13:34:05 -07:00
}
2021-11-19 13:43:33 +01:00
return false;
2013-08-30 13:34:05 -07:00
}
};
LINK_ENTITY_TO_CLASS(ammo_357, CPythonAmmo);