halflife-photomode/dlls/hornetgun.cpp

308 lines
6.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 "monsters.h"
#include "weapons.h"
#include "player.h"
#include "hornet.h"
#include "gamerules.h"
#include "UserMessages.h"
2013-08-30 13:34:05 -07:00
static float GetRechargeTime()
{
if (gpGlobals->maxClients > 1)
{
return 0.3f;
}
return 0.5f;
}
2013-08-30 13:34:05 -07:00
enum firemode_e
{
FIREMODE_TRACK = 0,
FIREMODE_FAST
};
LINK_ENTITY_TO_CLASS(weapon_hornetgun, CHgun);
2013-08-30 13:34:05 -07:00
bool CHgun::IsUseable()
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 CHgun::Spawn()
2013-08-30 13:34:05 -07:00
{
Precache();
2013-08-30 13:34:05 -07:00
m_iId = WEAPON_HORNETGUN;
SET_MODEL(ENT(pev), "models/w_hgun.mdl");
m_iDefaultAmmo = HIVEHAND_DEFAULT_GIVE;
m_iFirePhase = 0;
FallInit(); // get ready to fall down.
2013-08-30 13:34:05 -07:00
}
void CHgun::Precache()
2013-08-30 13:34:05 -07:00
{
PRECACHE_MODEL("models/v_hgun.mdl");
PRECACHE_MODEL("models/w_hgun.mdl");
PRECACHE_MODEL("models/p_hgun.mdl");
m_usHornetFire = PRECACHE_EVENT(1, "events/firehornet.sc");
2013-08-30 13:34:05 -07:00
UTIL_PrecacheOther("hornet");
}
void CHgun::AddToPlayer(CBasePlayer* pPlayer)
2013-08-30 13:34:05 -07:00
{
#ifndef CLIENT_DLL
if (g_pGameRules->IsMultiplayer())
{
// in multiplayer, all hivehands come full.
m_iDefaultAmmo = HORNET_MAX_CARRY;
}
2013-08-30 13:34:05 -07:00
#endif
CBasePlayerWeapon::AddToPlayer(pPlayer);
2013-08-30 13:34:05 -07:00
}
bool CHgun::GetItemInfo(ItemInfo* p)
2013-08-30 13:34:05 -07:00
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "Hornets";
p->iMaxAmmo1 = HORNET_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 3;
p->iPosition = 3;
p->iId = m_iId = WEAPON_HORNETGUN;
p->iFlags = ITEM_FLAG_NOAUTOSWITCHEMPTY | ITEM_FLAG_NOAUTORELOAD;
p->iWeight = HORNETGUN_WEIGHT;
return true;
2013-08-30 13:34:05 -07:00
}
bool CHgun::Deploy()
2013-08-30 13:34:05 -07:00
{
return DefaultDeploy("models/v_hgun.mdl", "models/p_hgun.mdl", HGUN_UP, "hive");
2013-08-30 13:34:05 -07:00
}
void CHgun::Holster()
2013-08-30 13:34:05 -07:00
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
SendWeaponAnim(HGUN_DOWN);
2013-08-30 13:34:05 -07:00
//!!!HACKHACK - can't select hornetgun if it's empty! no way to get ammo for it, either.
if (0 == m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()])
2013-08-30 13:34:05 -07:00
{
m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] = 1;
2013-08-30 13:34:05 -07:00
}
}
void CHgun::PrimaryAttack()
{
Reload();
2013-08-30 13:34:05 -07:00
if (m_pPlayer->ammo_hornets <= 0)
2013-08-30 13:34:05 -07:00
{
return;
}
#ifndef CLIENT_DLL
UTIL_MakeVectors(m_pPlayer->pev->v_angle);
2013-08-30 13:34:05 -07:00
CBaseEntity* pHornet = CBaseEntity::Create("hornet", m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 16 + gpGlobals->v_right * 8 + gpGlobals->v_up * -12, m_pPlayer->pev->v_angle, m_pPlayer->edict());
2013-08-30 13:34:05 -07:00
pHornet->pev->velocity = gpGlobals->v_forward * 300;
m_flRechargeTime = gpGlobals->time + GetRechargeTime();
2013-08-30 13:34:05 -07:00
#endif
2013-08-30 13:34:05 -07:00
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
2013-08-30 13:34:05 -07:00
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
int flags;
#if defined(CLIENT_WEAPONS)
2013-08-30 13:34:05 -07:00
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
2021-12-02 19:04:20 -05:00
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usHornetFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, 0, 0, 0);
2013-08-30 13:34:05 -07:00
// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = GetNextAttackDelay(0.25);
if (m_flNextPrimaryAttack < UTIL_WeaponTimeBase())
2013-08-30 13:34:05 -07:00
{
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.25;
}
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0)
{
m_flNextPrimaryAttack += GetRechargeTime();
}
2013-08-30 13:34:05 -07:00
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
2013-08-30 13:34:05 -07:00
}
void CHgun::SecondaryAttack()
2013-08-30 13:34:05 -07:00
{
Reload();
if (m_pPlayer->ammo_hornets <= 0)
2013-08-30 13:34:05 -07:00
{
return;
}
//Wouldn't be a bad idea to completely predict these, since they fly so fast...
#ifndef CLIENT_DLL
CBaseEntity* pHornet;
2013-08-30 13:34:05 -07:00
Vector vecSrc;
UTIL_MakeVectors(m_pPlayer->pev->v_angle);
2013-08-30 13:34:05 -07:00
vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 16 + gpGlobals->v_right * 8 + gpGlobals->v_up * -12;
2013-08-30 13:34:05 -07:00
m_iFirePhase++;
switch (m_iFirePhase)
2013-08-30 13:34:05 -07:00
{
case 1:
vecSrc = vecSrc + gpGlobals->v_up * 8;
break;
case 2:
vecSrc = vecSrc + gpGlobals->v_up * 8;
vecSrc = vecSrc + gpGlobals->v_right * 8;
break;
case 3:
vecSrc = vecSrc + gpGlobals->v_right * 8;
break;
case 4:
vecSrc = vecSrc + gpGlobals->v_up * -8;
vecSrc = vecSrc + gpGlobals->v_right * 8;
break;
case 5:
vecSrc = vecSrc + gpGlobals->v_up * -8;
break;
case 6:
vecSrc = vecSrc + gpGlobals->v_up * -8;
vecSrc = vecSrc + gpGlobals->v_right * -8;
break;
case 7:
vecSrc = vecSrc + gpGlobals->v_right * -8;
break;
case 8:
vecSrc = vecSrc + gpGlobals->v_up * 8;
vecSrc = vecSrc + gpGlobals->v_right * -8;
m_iFirePhase = 0;
break;
}
pHornet = CBaseEntity::Create("hornet", vecSrc, m_pPlayer->pev->v_angle, m_pPlayer->edict());
2013-08-30 13:34:05 -07:00
pHornet->pev->velocity = gpGlobals->v_forward * 1200;
pHornet->pev->angles = UTIL_VecToAngles(pHornet->pev->velocity);
2013-08-30 13:34:05 -07:00
pHornet->SetThink(&CHornet::StartDart);
2013-08-30 13:34:05 -07:00
m_flRechargeTime = gpGlobals->time + GetRechargeTime();
2013-08-30 13:34:05 -07:00
#endif
int flags;
#if defined(CLIENT_WEAPONS)
2013-08-30 13:34:05 -07:00
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
2021-12-02 19:04:20 -05:00
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usHornetFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, 0, 0, 0);
2013-08-30 13:34:05 -07:00
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
// player "shoot" animation
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
2013-08-30 13:34:05 -07:00
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.1;
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 0)
{
m_flRechargeTime = gpGlobals->time + 0.5;
m_flNextSecondaryAttack += 0.5;
m_flNextPrimaryAttack += 0.5;
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
2013-08-30 13:34:05 -07:00
}
void CHgun::Reload()
2013-08-30 13:34:05 -07:00
{
#ifndef CLIENT_DLL
2013-08-30 13:34:05 -07:00
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= HORNET_MAX_CARRY)
return;
while (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] < HORNET_MAX_CARRY && m_flRechargeTime < gpGlobals->time)
{
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]++;
m_flRechargeTime += GetRechargeTime();
2013-08-30 13:34:05 -07:00
}
m_pPlayer->TabulateAmmo();
#endif
2013-08-30 13:34:05 -07:00
}
void CHgun::WeaponIdle()
2013-08-30 13:34:05 -07:00
{
Reload();
2013-08-30 13:34:05 -07:00
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
return;
int iAnim;
float flRand = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 0, 1);
2013-08-30 13:34:05 -07:00
if (flRand <= 0.75)
{
iAnim = HGUN_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 30.0 / 16 * (2);
}
else if (flRand <= 0.875)
{
iAnim = HGUN_FIDGETSWAY;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 40.0 / 16.0;
}
else
{
iAnim = HGUN_FIDGETSHAKE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 35.0 / 16.0;
}
SendWeaponAnim(iAnim);
2013-08-30 13:34:05 -07:00
}