2015-09-28 03:13:39 +03:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2017-01-29 02:56:29 +03:00
|
|
|
LINK_ENTITY_TO_CLASS(weapon_c4, CC4, CCSC4)
|
2015-09-28 03:13:39 +03:00
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::Spawn()
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
SET_MODEL(edict(), "models/w_backpack.mdl");
|
|
|
|
|
|
|
|
pev->frame = 0;
|
|
|
|
pev->body = 3;
|
|
|
|
pev->sequence = 0;
|
|
|
|
pev->framerate = 0;
|
|
|
|
|
|
|
|
m_iId = WEAPON_C4;
|
|
|
|
m_iDefaultAmmo = C4_DEFAULT_GIVE;
|
|
|
|
m_bStartedArming = false;
|
|
|
|
m_fArmedTime = 0;
|
|
|
|
|
|
|
|
if (!FStringNull(pev->targetname))
|
|
|
|
{
|
|
|
|
pev->effects |= EF_NODRAW;
|
|
|
|
DROP_TO_FLOOR(edict());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FallInit();
|
|
|
|
SetThink(&CBasePlayerItem::FallThink);
|
2016-02-04 03:18:26 +03:00
|
|
|
pev->nextthink = UTIL_WeaponTimeBase() + 0.1f;
|
2017-10-19 20:12:02 +03:00
|
|
|
CSPlayerItem()->SetItemInfo(&m_ItemInfoArray[m_iId]);
|
2015-09-28 03:13:39 +03:00
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::Precache()
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
PRECACHE_MODEL("models/v_c4.mdl");
|
|
|
|
PRECACHE_MODEL("models/w_backpack.mdl");
|
|
|
|
|
|
|
|
PRECACHE_SOUND("weapons/c4_click.wav");
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
int CC4::GetItemInfo(ItemInfo *p)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
p->pszName = STRING(pev->classname);
|
|
|
|
p->pszAmmo1 = "C4";
|
|
|
|
p->iMaxAmmo1 = C4_MAX_AMMO;
|
2017-10-12 17:50:56 +03:00
|
|
|
p->pszAmmo2 = nullptr;
|
2015-09-28 03:13:39 +03:00
|
|
|
p->iMaxAmmo2 = -1;
|
|
|
|
p->iMaxClip = WEAPON_NOCLIP;
|
|
|
|
p->iSlot = 4;
|
|
|
|
p->iPosition = 3;
|
|
|
|
p->iId = m_iId = WEAPON_C4;
|
|
|
|
p->iWeight = C4_WEIGHT;
|
2015-11-24 00:01:09 +03:00
|
|
|
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
|
2015-09-28 03:13:39 +03:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
BOOL CC4::Deploy()
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
pev->body = 0;
|
|
|
|
|
|
|
|
m_bStartedArming = false;
|
|
|
|
m_fArmedTime = 0;
|
|
|
|
|
|
|
|
if (m_pPlayer->HasShield())
|
|
|
|
{
|
|
|
|
m_bHasShield = true;
|
|
|
|
m_pPlayer->pev->gamestate = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefaultDeploy("models/v_c4.mdl", "models/p_c4.mdl", C4_DRAW, "c4", UseDecrement() != FALSE);
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::Holster(int skiplocal)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
|
2017-08-19 18:01:33 +03:00
|
|
|
|
|
|
|
#ifdef REGAMEDLL_FIXES
|
|
|
|
if(m_bStartedArming)
|
|
|
|
{
|
|
|
|
m_pPlayer->SetProgressBarTime(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
m_bStartedArming = false; // stop arming sequence
|
2015-09-28 03:13:39 +03:00
|
|
|
|
|
|
|
if (!m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
|
|
|
{
|
|
|
|
m_pPlayer->pev->weapons &= ~(1 << WEAPON_C4);
|
|
|
|
DestroyItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_bHasShield)
|
|
|
|
{
|
|
|
|
m_pPlayer->pev->gamestate = 0;
|
|
|
|
m_bHasShield = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::PrimaryAttack()
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
|
|
|
return;
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
int inBombZone = (m_pPlayer->m_signals.GetState() & SIGNAL_BOMB) == SIGNAL_BOMB;
|
|
|
|
int onGround = (m_pPlayer->pev->flags & FL_ONGROUND) == FL_ONGROUND;
|
2016-02-23 02:13:52 +03:00
|
|
|
bool bPlaceBomb = (onGround && inBombZone);
|
2015-09-28 03:13:39 +03:00
|
|
|
|
|
|
|
if (!m_bStartedArming)
|
|
|
|
{
|
|
|
|
if (!inBombZone)
|
|
|
|
{
|
|
|
|
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Plant_At_Bomb_Spot");
|
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(1.0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!onGround)
|
|
|
|
{
|
|
|
|
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Plant_Must_Be_On_Ground");
|
2016-01-19 14:54:31 +03:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(1.0);
|
2015-09-28 03:13:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bStartedArming = true;
|
|
|
|
m_bBombPlacedAnimation = false;
|
|
|
|
m_fArmedTime = gpGlobals->time + C4_ARMING_ON_TIME;
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// player "arming bomb" animation
|
2015-09-28 03:13:39 +03:00
|
|
|
SendWeaponAnim(C4_ARM, UseDecrement() != FALSE);
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// freeze the player in place while planting
|
2015-09-28 03:13:39 +03:00
|
|
|
SET_CLIENT_MAXSPEED(m_pPlayer->edict(), 1.0);
|
|
|
|
|
|
|
|
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
m_pPlayer->SetProgressBarTime(C4_ARMING_ON_TIME);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
if (bPlaceBomb)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
CBaseEntity *pEntity = nullptr;
|
|
|
|
CBasePlayer *pTempPlayer = nullptr;
|
2015-09-28 03:13:39 +03:00
|
|
|
|
|
|
|
if (m_fArmedTime <= gpGlobals->time)
|
|
|
|
{
|
|
|
|
if (m_bStartedArming)
|
|
|
|
{
|
|
|
|
m_bStartedArming = false;
|
|
|
|
m_fArmedTime = 0;
|
|
|
|
|
|
|
|
Broadcast("BOMBPL");
|
|
|
|
m_pPlayer->m_bHasC4 = false;
|
|
|
|
|
2016-12-06 22:21:52 +03:00
|
|
|
if (pev->speed != 0 && CSGameRules())
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
CSGameRules()->m_iC4Timer = int(pev->speed);
|
2015-09-28 03:13:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CGrenade *pBomb = CGrenade::ShootSatchelCharge(m_pPlayer->pev, m_pPlayer->pev->origin, Vector(0, 0, 0));
|
|
|
|
|
|
|
|
MESSAGE_BEGIN(MSG_SPEC, SVC_DIRECTOR);
|
|
|
|
WRITE_BYTE(9);
|
|
|
|
WRITE_BYTE(DRC_CMD_EVENT);
|
|
|
|
WRITE_SHORT(m_pPlayer->entindex());
|
|
|
|
WRITE_SHORT(0);
|
|
|
|
WRITE_LONG(DRC_FLAG_FACEPLAYER | 11);
|
|
|
|
MESSAGE_END();
|
|
|
|
|
|
|
|
MESSAGE_BEGIN(MSG_ALL, gmsgBombDrop);
|
|
|
|
WRITE_COORD(pBomb->pev->origin.x);
|
|
|
|
WRITE_COORD(pBomb->pev->origin.y);
|
|
|
|
WRITE_COORD(pBomb->pev->origin.z);
|
2016-12-06 22:21:52 +03:00
|
|
|
WRITE_BYTE(BOMB_FLAG_PLANTED);
|
2015-09-28 03:13:39 +03:00
|
|
|
MESSAGE_END();
|
|
|
|
|
|
|
|
UTIL_ClientPrintAll(HUD_PRINTCENTER, "#Bomb_Planted");
|
2016-12-06 22:21:52 +03:00
|
|
|
if (TheBots)
|
2015-12-05 22:40:30 +03:00
|
|
|
{
|
|
|
|
TheBots->OnEvent(EVENT_BOMB_PLANTED, m_pPlayer, pBomb);
|
|
|
|
}
|
2015-09-28 03:13:39 +03:00
|
|
|
|
2016-12-06 22:21:52 +03:00
|
|
|
if (TheCareerTasks && CSGameRules()->IsCareer() && !m_pPlayer->IsBot())
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
TheCareerTasks->HandleEvent(EVENT_BOMB_PLANTED, m_pPlayer);
|
|
|
|
}
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
UTIL_LogPrintf("\"%s<%i><%s><TERRORIST>\" triggered \"Planted_The_Bomb\"\n",
|
2015-09-28 03:13:39 +03:00
|
|
|
STRING(m_pPlayer->pev->netname),
|
|
|
|
GETPLAYERUSERID(m_pPlayer->edict()),
|
2016-01-19 14:54:31 +03:00
|
|
|
GETPLAYERAUTHID(m_pPlayer->edict()));
|
2015-09-28 03:13:39 +03:00
|
|
|
|
|
|
|
g_pGameRules->m_bBombDropped = FALSE;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// Play the plant sound.
|
2015-09-28 03:13:39 +03:00
|
|
|
EMIT_SOUND(edict(), CHAN_WEAPON, "weapons/c4_plant.wav", VOL_NORM, ATTN_NORM);
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// hide the backpack in Terrorist's models.
|
2015-09-28 03:13:39 +03:00
|
|
|
m_pPlayer->pev->body = 0;
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// release the player from being frozen
|
2015-09-28 03:13:39 +03:00
|
|
|
m_pPlayer->ResetMaxSpeed();
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// No more c4!
|
|
|
|
m_pPlayer->SetBombIcon(FALSE);
|
2015-09-28 03:13:39 +03:00
|
|
|
|
2016-02-23 02:13:52 +03:00
|
|
|
if (--m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
RetireWeapon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
if (m_fArmedTime - 0.75f <= gpGlobals->time && !m_bBombPlacedAnimation)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// call the c4 Placement animation
|
2015-09-28 03:13:39 +03:00
|
|
|
m_bBombPlacedAnimation = true;
|
|
|
|
SendWeaponAnim(C4_DROP, UseDecrement() != FALSE);
|
2016-01-19 14:54:31 +03:00
|
|
|
|
|
|
|
// player "place" animation
|
2015-09-28 03:13:39 +03:00
|
|
|
m_pPlayer->SetAnimation(PLAYER_HOLDBOMB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (inBombZone)
|
|
|
|
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Plant_Must_Be_On_Ground");
|
|
|
|
else
|
|
|
|
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Arming_Cancelled");
|
|
|
|
|
|
|
|
m_bStartedArming = false;
|
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(1.5);
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// release the player from being frozen, we've somehow left the bomb zone
|
2015-09-28 03:13:39 +03:00
|
|
|
m_pPlayer->ResetMaxSpeed();
|
|
|
|
m_pPlayer->SetProgressBarTime(0);
|
|
|
|
m_pPlayer->SetAnimation(PLAYER_HOLDBOMB);
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// this means the placement animation is canceled
|
|
|
|
if (m_bBombPlacedAnimation)
|
|
|
|
SendWeaponAnim(C4_DRAW, UseDecrement() != FALSE);
|
|
|
|
else
|
|
|
|
SendWeaponAnim(C4_IDLE1, UseDecrement() != FALSE);
|
|
|
|
|
2015-09-28 03:13:39 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(0.3);
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + RANDOM_FLOAT(10, 15);
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::WeaponIdle()
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
if (m_bStartedArming)
|
|
|
|
{
|
2016-01-19 14:54:31 +03:00
|
|
|
// if the player releases the attack button cancel the arming sequence
|
2015-09-28 03:13:39 +03:00
|
|
|
m_bStartedArming = false;
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// release the player from being frozen
|
2015-09-28 03:13:39 +03:00
|
|
|
m_pPlayer->ResetMaxSpeed();
|
2016-01-19 14:54:31 +03:00
|
|
|
|
2015-09-28 03:13:39 +03:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(1.0);
|
|
|
|
m_pPlayer->SetProgressBarTime(0);
|
|
|
|
|
2016-01-19 14:54:31 +03:00
|
|
|
// this means the placement animation is canceled
|
|
|
|
if (m_bBombPlacedAnimation)
|
|
|
|
SendWeaponAnim(C4_DRAW, UseDecrement() != FALSE);
|
|
|
|
else
|
|
|
|
SendWeaponAnim(C4_IDLE1, UseDecrement() != FALSE);
|
2015-09-28 03:13:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_flTimeWeaponIdle <= UTIL_WeaponTimeBase())
|
|
|
|
{
|
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
|
|
|
{
|
|
|
|
RetireWeapon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendWeaponAnim(C4_DRAW, UseDecrement() != FALSE);
|
|
|
|
SendWeaponAnim(C4_IDLE1, UseDecrement() != FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::KeyValue(KeyValueData *pkvd)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
if (FStrEq(pkvd->szKeyName, "detonatedelay"))
|
|
|
|
{
|
|
|
|
pev->speed = Q_atof(pkvd->szValue);
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else if (FStrEq(pkvd->szKeyName, "detonatetarget"))
|
|
|
|
{
|
|
|
|
pev->noise1 = ALLOC_STRING(pkvd->szValue);
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else if (FStrEq(pkvd->szKeyName, "defusetarget"))
|
|
|
|
{
|
|
|
|
pev->target = ALLOC_STRING(pkvd->szValue);
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CBaseEntity::KeyValue(pkvd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
void CC4::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2016-12-06 22:21:52 +03:00
|
|
|
if (m_pPlayer)
|
2015-09-28 03:13:39 +03:00
|
|
|
return;
|
|
|
|
|
2016-05-31 17:04:51 +03:00
|
|
|
CBasePlayer *pPlayer = UTIL_PlayerByIndex(1);
|
2016-12-06 22:21:52 +03:00
|
|
|
if (pPlayer)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
edict_t *m_pentOldCurBombTarget = pPlayer->m_pentCurBombTarget;
|
2017-10-12 17:50:56 +03:00
|
|
|
pPlayer->m_pentCurBombTarget = nullptr;
|
2015-09-28 03:13:39 +03:00
|
|
|
|
2016-12-06 22:21:52 +03:00
|
|
|
if (pev->speed != 0 && CSGameRules())
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2016-02-23 02:13:52 +03:00
|
|
|
CSGameRules()->m_iC4Timer = int(pev->speed);
|
2015-09-28 03:13:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
EMIT_SOUND(edict(), CHAN_WEAPON, "weapons/c4_plant.wav", VOL_NORM, ATTN_NORM);
|
|
|
|
|
2017-09-23 01:15:38 +03:00
|
|
|
CGrenade::ShootSatchelCharge(pPlayer->pev, pev->origin, Vector(0, 0, 0));
|
2015-09-28 03:13:39 +03:00
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
CGrenade *pBomb = nullptr;
|
|
|
|
while ((pBomb = (CGrenade *)UTIL_FindEntityByClassname(pBomb, "grenade")))
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
if (pBomb->m_bIsC4 && pBomb->m_flNextFreq == gpGlobals->time)
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
2017-10-12 17:50:56 +03:00
|
|
|
pBomb->pev->target = pev->target;
|
|
|
|
pBomb->pev->noise1 = pev->noise1;
|
2015-09-28 03:13:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pPlayer->m_pentCurBombTarget = m_pentOldCurBombTarget;
|
|
|
|
SUB_Remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-01 23:40:10 +03:00
|
|
|
float CC4::GetMaxSpeed()
|
2015-09-28 03:13:39 +03:00
|
|
|
{
|
|
|
|
return C4_MAX_SPEED;
|
|
|
|
}
|