halflife-photomode/dlls/egon.cpp

558 lines
12 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 "player.h"
#include "monsters.h"
#include "weapons.h"
#include "effects.h"
#include "customentity.h"
#include "gamerules.h"
#include "UserMessages.h"
2013-08-30 13:34:05 -07:00
#ifdef CLIENT_DLL
#include "hud.h"
#include "com_weapons.h"
#else
extern bool IsBustingGame();
#endif
#define EGON_SWITCH_NARROW_TIME 0.75 // Time it takes to switch fire modes
#define EGON_SWITCH_WIDE_TIME 1.5
2013-08-30 13:34:05 -07:00
LINK_ENTITY_TO_CLASS(weapon_egon, CEgon);
2013-08-30 13:34:05 -07:00
void CEgon::Spawn()
2013-08-30 13:34:05 -07:00
{
Precache();
2013-08-30 13:34:05 -07:00
m_iId = WEAPON_EGON;
SET_MODEL(ENT(pev), "models/w_egon.mdl");
m_iDefaultAmmo = EGON_DEFAULT_GIVE;
FallInit(); // get ready to fall down.
2013-08-30 13:34:05 -07:00
}
void CEgon::Precache()
2013-08-30 13:34:05 -07:00
{
PRECACHE_MODEL("models/w_egon.mdl");
PRECACHE_MODEL("models/v_egon.mdl");
PRECACHE_MODEL("models/p_egon.mdl");
PRECACHE_MODEL("models/w_9mmclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND(EGON_SOUND_OFF);
PRECACHE_SOUND(EGON_SOUND_RUN);
PRECACHE_SOUND(EGON_SOUND_STARTUP);
2013-08-30 13:34:05 -07:00
PRECACHE_MODEL(EGON_BEAM_SPRITE);
PRECACHE_MODEL(EGON_FLARE_SPRITE);
2013-08-30 13:34:05 -07:00
PRECACHE_SOUND("weapons/357_cock1.wav");
2013-08-30 13:34:05 -07:00
m_usEgonFire = PRECACHE_EVENT(1, "events/egon_fire.sc");
m_usEgonStop = PRECACHE_EVENT(1, "events/egon_stop.sc");
2013-08-30 13:34:05 -07:00
}
bool CEgon::Deploy()
2013-08-30 13:34:05 -07:00
{
2021-11-19 13:43:33 +01:00
m_deployed = false;
2013-08-30 13:34:05 -07:00
m_fireState = FIRE_OFF;
return DefaultDeploy("models/v_egon.mdl", "models/p_egon.mdl", EGON_DRAW, "egon");
2013-08-30 13:34:05 -07:00
}
void CEgon::Holster()
2013-08-30 13:34:05 -07:00
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
SendWeaponAnim(EGON_HOLSTER);
2013-08-30 13:34:05 -07:00
EndAttack();
2013-08-30 13:34:05 -07:00
}
bool CEgon::GetItemInfo(ItemInfo* p)
2013-08-30 13:34:05 -07:00
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "uranium";
p->iMaxAmmo1 = URANIUM_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 3;
p->iPosition = 2;
p->iId = m_iId = WEAPON_EGON;
p->iFlags = 0;
p->iWeight = EGON_WEIGHT;
return true;
2013-08-30 13:34:05 -07:00
}
#define EGON_PULSE_INTERVAL 0.1
#define EGON_DISCHARGE_INTERVAL 0.1
2013-08-30 13:34:05 -07:00
float CEgon::GetPulseInterval()
2013-08-30 13:34:05 -07:00
{
return EGON_PULSE_INTERVAL;
}
float CEgon::GetDischargeInterval()
2013-08-30 13:34:05 -07:00
{
return EGON_DISCHARGE_INTERVAL;
}
bool CEgon::HasAmmo()
2013-08-30 13:34:05 -07:00
{
if (m_pPlayer->ammo_uranium <= 0)
2021-11-19 13:43:33 +01:00
return false;
2013-08-30 13:34:05 -07:00
2021-11-19 13:45:16 +01:00
return true;
2013-08-30 13:34:05 -07:00
}
void CEgon::UseAmmo(int count)
2013-08-30 13:34:05 -07:00
{
#ifndef CLIENT_DLL
if (IsBustingGame())
return;
#endif
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= count)
2013-08-30 13:34:05 -07:00
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= count;
else
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] = 0;
}
void CEgon::Attack()
2013-08-30 13:34:05 -07:00
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3)
2013-08-30 13:34:05 -07:00
{
if (m_fireState != FIRE_OFF || m_pBeam)
2013-08-30 13:34:05 -07:00
{
EndAttack();
}
else
{
PlayEmptySound();
2013-08-30 13:34:05 -07:00
}
return;
}
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
2013-08-30 13:34:05 -07:00
Vector vecAiming = gpGlobals->v_forward;
Vector vecSrc = m_pPlayer->GetGunPosition();
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
switch (m_fireState)
2013-08-30 13:34:05 -07:00
{
2021-11-29 20:55:01 +01:00
case FIRE_OFF:
{
if (!HasAmmo())
2013-08-30 13:34:05 -07:00
{
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.25;
PlayEmptySound();
return;
}
2013-08-30 13:34:05 -07:00
m_flAmmoUseTime = gpGlobals->time; // start using ammo ASAP.
2013-08-30 13:34:05 -07:00
2021-12-02 19:04:20 -05:00
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usEgonFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, m_fireMode, 1, 0);
2013-08-30 13:34:05 -07:00
m_shakeTime = 0;
2013-08-30 13:34:05 -07:00
m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1;
pev->fuser1 = UTIL_WeaponTimeBase() + 2;
2013-08-30 13:34:05 -07:00
pev->dmgtime = gpGlobals->time + GetPulseInterval();
m_fireState = FIRE_CHARGE;
}
break;
2013-08-30 13:34:05 -07:00
2021-11-29 20:55:01 +01:00
case FIRE_CHARGE:
{
Fire(vecSrc, vecAiming);
m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME;
2013-08-30 13:34:05 -07:00
if (pev->fuser1 <= UTIL_WeaponTimeBase())
{
2021-12-02 19:04:20 -05:00
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usEgonFire, 0, g_vecZero, g_vecZero, 0.0, 0.0, 0, m_fireMode, 0, 0);
pev->fuser1 = 1000;
}
if (!HasAmmo())
{
EndAttack();
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0;
2013-08-30 13:34:05 -07:00
}
}
break;
2013-08-30 13:34:05 -07:00
}
}
void CEgon::PrimaryAttack()
2013-08-30 13:34:05 -07:00
{
m_fireMode = FIRE_WIDE;
Attack();
}
void CEgon::Fire(const Vector& vecOrigSrc, const Vector& vecDir)
2013-08-30 13:34:05 -07:00
{
Vector vecDest = vecOrigSrc + vecDir * 2048;
edict_t* pentIgnore;
2013-08-30 13:34:05 -07:00
TraceResult tr;
pentIgnore = m_pPlayer->edict();
Vector tmpSrc = vecOrigSrc + gpGlobals->v_up * -8 + gpGlobals->v_right * 3;
// ALERT( at_console, "." );
UTIL_TraceLine(vecOrigSrc, vecDest, dont_ignore_monsters, pentIgnore, &tr);
2013-08-30 13:34:05 -07:00
if (0 != tr.fAllSolid)
2013-08-30 13:34:05 -07:00
return;
#ifndef CLIENT_DLL
CBaseEntity* pEntity = CBaseEntity::Instance(tr.pHit);
2013-08-30 13:34:05 -07:00
if (pEntity == NULL)
return;
if (g_pGameRules->IsMultiplayer())
2013-08-30 13:34:05 -07:00
{
if (m_pSprite && 0 != pEntity->pev->takedamage)
2013-08-30 13:34:05 -07:00
{
m_pSprite->pev->effects &= ~EF_NODRAW;
}
else if (m_pSprite)
2013-08-30 13:34:05 -07:00
{
m_pSprite->pev->effects |= EF_NODRAW;
}
}
#endif
float timedist;
switch (m_fireMode)
2013-08-30 13:34:05 -07:00
{
default:
2013-08-30 13:34:05 -07:00
case FIRE_NARROW:
#ifndef CLIENT_DLL
if (pev->dmgtime < gpGlobals->time)
2013-08-30 13:34:05 -07:00
{
// Narrow mode only does damage to the entity it hits
ClearMultiDamage();
if (0 != pEntity->pev->takedamage)
2013-08-30 13:34:05 -07:00
{
pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgEgonNarrow, vecDir, &tr, DMG_ENERGYBEAM);
2013-08-30 13:34:05 -07:00
}
ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);
if (g_pGameRules->IsMultiplayer())
2013-08-30 13:34:05 -07:00
{
// multiplayer uses 1 ammo every 1/10th second
if (gpGlobals->time >= m_flAmmoUseTime)
2013-08-30 13:34:05 -07:00
{
UseAmmo(1);
2013-08-30 13:34:05 -07:00
m_flAmmoUseTime = gpGlobals->time + 0.1;
}
}
else
{
// single player, use 3 ammo/second
if (gpGlobals->time >= m_flAmmoUseTime)
2013-08-30 13:34:05 -07:00
{
UseAmmo(1);
2013-08-30 13:34:05 -07:00
m_flAmmoUseTime = gpGlobals->time + 0.166;
}
}
pev->dmgtime = gpGlobals->time + GetPulseInterval();
}
#endif
timedist = (pev->dmgtime - gpGlobals->time) / GetPulseInterval();
2013-08-30 13:34:05 -07:00
break;
2013-08-30 13:34:05 -07:00
case FIRE_WIDE:
#ifndef CLIENT_DLL
if (pev->dmgtime < gpGlobals->time)
2013-08-30 13:34:05 -07:00
{
// wide mode does damage to the ent, and radius damage
ClearMultiDamage();
if (0 != pEntity->pev->takedamage)
2013-08-30 13:34:05 -07:00
{
pEntity->TraceAttack(m_pPlayer->pev, gSkillData.plrDmgEgonWide, vecDir, &tr, DMG_ENERGYBEAM | DMG_ALWAYSGIB);
2013-08-30 13:34:05 -07:00
}
ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);
if (g_pGameRules->IsMultiplayer())
2013-08-30 13:34:05 -07:00
{
// radius damage a little more potent in multiplayer.
::RadiusDamage(tr.vecEndPos, pev, m_pPlayer->pev, gSkillData.plrDmgEgonWide / 4, 128, CLASS_NONE, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB);
2013-08-30 13:34:05 -07:00
}
if (!m_pPlayer->IsAlive())
2013-08-30 13:34:05 -07:00
return;
if (g_pGameRules->IsMultiplayer())
2013-08-30 13:34:05 -07:00
{
//multiplayer uses 5 ammo/second
if (gpGlobals->time >= m_flAmmoUseTime)
2013-08-30 13:34:05 -07:00
{
UseAmmo(1);
2013-08-30 13:34:05 -07:00
m_flAmmoUseTime = gpGlobals->time + 0.2;
}
}
else
{
// Wide mode uses 10 charges per second in single player
if (gpGlobals->time >= m_flAmmoUseTime)
2013-08-30 13:34:05 -07:00
{
UseAmmo(1);
2013-08-30 13:34:05 -07:00
m_flAmmoUseTime = gpGlobals->time + 0.1;
}
}
pev->dmgtime = gpGlobals->time + GetDischargeInterval();
if (m_shakeTime < gpGlobals->time)
2013-08-30 13:34:05 -07:00
{
UTIL_ScreenShake(tr.vecEndPos, 5.0, 150.0, 0.75, 250.0);
2013-08-30 13:34:05 -07:00
m_shakeTime = gpGlobals->time + 1.5;
}
}
#endif
timedist = (pev->dmgtime - gpGlobals->time) / GetDischargeInterval();
2013-08-30 13:34:05 -07:00
break;
}
if (timedist < 0)
2013-08-30 13:34:05 -07:00
timedist = 0;
else if (timedist > 1)
2013-08-30 13:34:05 -07:00
timedist = 1;
timedist = 1 - timedist;
2013-08-30 13:34:05 -07:00
UpdateEffect(tmpSrc, tr.vecEndPos, timedist);
2013-08-30 13:34:05 -07:00
}
void CEgon::UpdateEffect(const Vector& startPoint, const Vector& endPoint, float timeBlend)
2013-08-30 13:34:05 -07:00
{
#ifndef CLIENT_DLL
if (!m_pBeam)
2013-08-30 13:34:05 -07:00
{
CreateEffect();
}
m_pBeam->SetStartPos(endPoint);
m_pBeam->SetBrightness(255 - (timeBlend * 180));
m_pBeam->SetWidth(40 - (timeBlend * 20));
2013-08-30 13:34:05 -07:00
if (m_fireMode == FIRE_WIDE)
m_pBeam->SetColor(30 + (25 * timeBlend), 30 + (30 * timeBlend), 64 + 80 * fabs(sin(gpGlobals->time * 10)));
2013-08-30 13:34:05 -07:00
else
m_pBeam->SetColor(60 + (25 * timeBlend), 120 + (30 * timeBlend), 64 + 80 * fabs(sin(gpGlobals->time * 10)));
2013-08-30 13:34:05 -07:00
UTIL_SetOrigin(m_pSprite->pev, endPoint);
2013-08-30 13:34:05 -07:00
m_pSprite->pev->frame += 8 * gpGlobals->frametime;
if (m_pSprite->pev->frame > m_pSprite->Frames())
2013-08-30 13:34:05 -07:00
m_pSprite->pev->frame = 0;
m_pNoise->SetStartPos(endPoint);
2013-08-30 13:34:05 -07:00
#endif
}
void CEgon::CreateEffect()
2013-08-30 13:34:05 -07:00
{
#ifndef CLIENT_DLL
DestroyEffect();
m_pBeam = CBeam::BeamCreate(EGON_BEAM_SPRITE, 40);
m_pBeam->PointEntInit(pev->origin, m_pPlayer->entindex());
m_pBeam->SetFlags(BEAM_FSINE);
m_pBeam->SetEndAttachment(1);
m_pBeam->pev->spawnflags |= SF_BEAM_TEMPORARY; // Flag these to be destroyed on save/restore or level transition
2013-08-30 13:34:05 -07:00
m_pBeam->pev->flags |= FL_SKIPLOCALHOST;
m_pBeam->pev->owner = m_pPlayer->edict();
m_pNoise = CBeam::BeamCreate(EGON_BEAM_SPRITE, 55);
m_pNoise->PointEntInit(pev->origin, m_pPlayer->entindex());
m_pNoise->SetScrollRate(25);
m_pNoise->SetBrightness(100);
m_pNoise->SetEndAttachment(1);
2013-08-30 13:34:05 -07:00
m_pNoise->pev->spawnflags |= SF_BEAM_TEMPORARY;
m_pNoise->pev->flags |= FL_SKIPLOCALHOST;
m_pNoise->pev->owner = m_pPlayer->edict();
m_pSprite = CSprite::SpriteCreate(EGON_FLARE_SPRITE, pev->origin, false);
2013-08-30 13:34:05 -07:00
m_pSprite->pev->scale = 1.0;
m_pSprite->SetTransparency(kRenderGlow, 255, 255, 255, 255, kRenderFxNoDissipation);
2013-08-30 13:34:05 -07:00
m_pSprite->pev->spawnflags |= SF_SPRITE_TEMPORARY;
// Josh: This sprite is not predicted on the client, so was missing
// for many years after it got broken in an update.
// m_pSprite->pev->flags |= FL_SKIPLOCALHOST;
2013-08-30 13:34:05 -07:00
m_pSprite->pev->owner = m_pPlayer->edict();
if (m_fireMode == FIRE_WIDE)
2013-08-30 13:34:05 -07:00
{
m_pBeam->SetScrollRate(50);
m_pBeam->SetNoise(20);
m_pNoise->SetColor(50, 50, 255);
m_pNoise->SetNoise(8);
2013-08-30 13:34:05 -07:00
}
else
{
m_pBeam->SetScrollRate(110);
m_pBeam->SetNoise(5);
m_pNoise->SetColor(80, 120, 255);
m_pNoise->SetNoise(2);
2013-08-30 13:34:05 -07:00
}
#endif
}
void CEgon::DestroyEffect()
2013-08-30 13:34:05 -07:00
{
#ifndef CLIENT_DLL
if (m_pBeam)
2013-08-30 13:34:05 -07:00
{
UTIL_Remove(m_pBeam);
2013-08-30 13:34:05 -07:00
m_pBeam = NULL;
}
if (m_pNoise)
2013-08-30 13:34:05 -07:00
{
UTIL_Remove(m_pNoise);
2013-08-30 13:34:05 -07:00
m_pNoise = NULL;
}
if (m_pSprite)
2013-08-30 13:34:05 -07:00
{
if (m_fireMode == FIRE_WIDE)
m_pSprite->Expand(10, 500);
2013-08-30 13:34:05 -07:00
else
UTIL_Remove(m_pSprite);
2013-08-30 13:34:05 -07:00
m_pSprite = NULL;
}
#endif
}
void CEgon::WeaponIdle()
2013-08-30 13:34:05 -07:00
{
if ((m_pPlayer->m_afButtonPressed & IN_ATTACK2) == 0 && (m_pPlayer->pev->button & IN_ATTACK) != 0)
{
return;
}
ResetEmptySound();
2013-08-30 13:34:05 -07:00
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
2013-08-30 13:34:05 -07:00
return;
if (m_fireState != FIRE_OFF)
EndAttack();
2013-08-30 13:34:05 -07:00
int iAnim;
float flRand = RANDOM_FLOAT(0, 1);
2013-08-30 13:34:05 -07:00
if (flRand <= 0.5)
2013-08-30 13:34:05 -07:00
{
iAnim = EGON_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
2013-08-30 13:34:05 -07:00
}
else
2013-08-30 13:34:05 -07:00
{
iAnim = EGON_FIDGET1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3;
}
SendWeaponAnim(iAnim);
2021-11-19 13:45:16 +01:00
m_deployed = true;
2013-08-30 13:34:05 -07:00
}
bool CEgon::CanHolster()
{
#ifndef CLIENT_DLL
if (IsBustingGame())
{
return false;
}
#endif
2013-08-30 13:34:05 -07:00
return true;
}
2013-08-30 13:34:05 -07:00
void CEgon::EndAttack()
2013-08-30 13:34:05 -07:00
{
bool bMakeNoise = false;
if (m_fireState != FIRE_OFF) //Checking the button just in case!.
bMakeNoise = true;
PLAYBACK_EVENT_FULL(FEV_GLOBAL | FEV_RELIABLE, m_pPlayer->edict(), m_usEgonStop, 0, m_pPlayer->pev->origin, m_pPlayer->pev->angles, 0.0, 0.0,
static_cast<int>(bMakeNoise), 0, 0, 0);
2013-08-30 13:34:05 -07:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0;
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_fireState = FIRE_OFF;
DestroyEffect();
}
class CEgonAmmo : public CBasePlayerAmmo
{
void Spawn() override
{
Precache();
2013-08-30 13:34:05 -07:00
SET_MODEL(ENT(pev), "models/w_chainammo.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_chainammo.mdl");
2013-08-30 13:34:05 -07:00
PRECACHE_SOUND("items/9mmclip1.wav");
}
bool AddAmmo(CBaseEntity* pOther) override
{
if (pOther->GiveAmmo(AMMO_URANIUMBOX_GIVE, "uranium", URANIUM_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_egonclip, CEgonAmmo);