2015-10-25 16:07:56 +01:00
|
|
|
/***
|
|
|
|
*
|
|
|
|
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
|
2015-12-27 12:06:55 +01:00
|
|
|
*
|
|
|
|
* This product contains software technology licensed from Id
|
|
|
|
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
|
2015-10-25 16:07:56 +01:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
#include "stdafx.h"
|
2015-10-25 16:07:56 +01:00
|
|
|
#include "cbase.h"
|
|
|
|
#include "decals.h"
|
|
|
|
#include "explode.h"
|
|
|
|
|
|
|
|
class CShower : public CBaseEntity
|
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
public:
|
|
|
|
void Spawn(void);
|
|
|
|
void Think(void);
|
|
|
|
void Touch(CBaseEntity *pOther);
|
|
|
|
int ObjectCaps(void) { return FCAP_DONT_SAVE; }
|
2015-10-25 16:07:56 +01:00
|
|
|
};
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
LINK_ENTITY_TO_CLASS(spark_shower, CShower);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CShower::Spawn(void)
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
pev->velocity = RANDOM_FLOAT(200, 300) * pev->angles;
|
|
|
|
pev->velocity.x += RANDOM_FLOAT(-100, 100);
|
|
|
|
pev->velocity.y += RANDOM_FLOAT(-100, 100);
|
|
|
|
|
|
|
|
if (pev->velocity.z >= 0)
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->velocity.z += 200;
|
|
|
|
else
|
|
|
|
pev->velocity.z -= 200;
|
2015-12-27 12:06:55 +01:00
|
|
|
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->movetype = MOVETYPE_BOUNCE;
|
|
|
|
pev->gravity = 0.5;
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
SET_MODEL(edict(), "models/grenade.mdl");
|
|
|
|
UTIL_SetSize(pev, g_vecZero, g_vecZero);
|
|
|
|
|
|
|
|
pev->effects |= EF_NODRAW;
|
|
|
|
pev->speed = RANDOM_FLOAT(0.5, 1.5);
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->angles = g_vecZero;
|
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CShower::Think(void)
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
UTIL_Sparks(pev->origin);
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->speed -= 0.1;
|
2015-12-27 12:06:55 +01:00
|
|
|
|
|
|
|
if (pev->speed > 0)
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
else
|
2015-12-27 12:06:55 +01:00
|
|
|
UTIL_Remove(this);
|
|
|
|
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->flags &= ~FL_ONGROUND;
|
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CShower::Touch(CBaseEntity *pOther)
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
if (pev->flags & FL_ONGROUND)
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->velocity = pev->velocity * 0.1;
|
|
|
|
else
|
|
|
|
pev->velocity = pev->velocity * 0.6;
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if ((pev->velocity.x * pev->velocity.x + pev->velocity.y * pev->velocity.y) < 10)
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->speed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CEnvExplosion : public CBaseMonster
|
|
|
|
{
|
|
|
|
public:
|
2015-12-27 12:06:55 +01:00
|
|
|
void Spawn(void);
|
|
|
|
void KeyValue(KeyValueData *pkvd);
|
|
|
|
void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
|
|
|
int Save(CSave &save);
|
|
|
|
int Restore(CRestore &restore);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
public:
|
|
|
|
void EXPORT Smoke(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
public:
|
|
|
|
int m_iMagnitude;
|
|
|
|
int m_spriteScale;
|
2015-10-25 16:07:56 +01:00
|
|
|
};
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
TYPEDESCRIPTION CEnvExplosion::m_SaveData[] =
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
DEFINE_FIELD(CEnvExplosion, m_iMagnitude, FIELD_INTEGER),
|
|
|
|
DEFINE_FIELD(CEnvExplosion, m_spriteScale, FIELD_INTEGER),
|
2015-10-25 16:07:56 +01:00
|
|
|
};
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
IMPLEMENT_SAVERESTORE(CEnvExplosion, CBaseMonster);
|
|
|
|
LINK_ENTITY_TO_CLASS(env_explosion, CEnvExplosion);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CEnvExplosion::KeyValue(KeyValueData *pkvd)
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
|
|
|
if (FStrEq(pkvd->szKeyName, "iMagnitude"))
|
|
|
|
{
|
|
|
|
m_iMagnitude = atoi(pkvd->szValue);
|
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
else
|
2015-12-27 12:06:55 +01:00
|
|
|
CBaseEntity::KeyValue(pkvd);
|
2015-10-25 16:07:56 +01:00
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CEnvExplosion::Spawn(void)
|
|
|
|
{
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
pev->effects = EF_NODRAW;
|
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
float flSpriteScale = (m_iMagnitude - 50) * 0.6;
|
|
|
|
|
|
|
|
if (flSpriteScale < 10)
|
2015-10-25 16:07:56 +01:00
|
|
|
flSpriteScale = 10;
|
|
|
|
|
|
|
|
m_spriteScale = (int)flSpriteScale;
|
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CEnvExplosion::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
|
|
|
|
{
|
|
|
|
pev->model = iStringNull;
|
|
|
|
pev->solid = SOLID_NOT;
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
TraceResult tr;
|
|
|
|
Vector vecSpot = pev->origin + Vector(0, 0, 8);
|
|
|
|
UTIL_TraceLine(vecSpot, vecSpot + Vector(0, 0, -40), ignore_monsters, ENT(pev), &tr);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if (tr.flFraction != 1)
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->origin = tr.vecEndPos + (tr.vecPlaneNormal * (m_iMagnitude - 24) * 0.6);
|
2015-12-27 12:06:55 +01:00
|
|
|
/*
|
2015-10-25 16:07:56 +01:00
|
|
|
else
|
|
|
|
pev->origin = pev->origin;
|
2015-12-27 12:06:55 +01:00
|
|
|
*/
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if (!(pev->spawnflags & SF_ENVEXPLOSION_NODECAL))
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
if (RANDOM_FLOAT(0, 1) < 0.5)
|
|
|
|
UTIL_DecalTrace(&tr, DECAL_SCORCH1);
|
2015-10-25 16:07:56 +01:00
|
|
|
else
|
2015-12-27 12:06:55 +01:00
|
|
|
UTIL_DecalTrace(&tr, DECAL_SCORCH2);
|
2015-10-25 16:07:56 +01:00
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if (!(pev->spawnflags & SF_ENVEXPLOSION_NOFIREBALL))
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
MESSAGE_BEGIN(MSG_PAS, SVC_TEMPENTITY, pev->origin);
|
|
|
|
WRITE_BYTE(TE_EXPLOSION);
|
|
|
|
WRITE_COORD(pev->origin.x);
|
|
|
|
WRITE_COORD(pev->origin.y);
|
|
|
|
WRITE_COORD(pev->origin.z);
|
|
|
|
WRITE_SHORT(g_sModelIndexFireball);
|
|
|
|
WRITE_BYTE((BYTE)m_spriteScale);
|
|
|
|
WRITE_BYTE(15);
|
|
|
|
WRITE_BYTE(TE_EXPLFLAG_NONE);
|
2015-10-25 16:07:56 +01:00
|
|
|
MESSAGE_END();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
MESSAGE_BEGIN(MSG_PAS, SVC_TEMPENTITY, pev->origin);
|
|
|
|
WRITE_BYTE(TE_EXPLOSION);
|
|
|
|
WRITE_COORD(pev->origin.x);
|
|
|
|
WRITE_COORD(pev->origin.y);
|
|
|
|
WRITE_COORD(pev->origin.z);
|
|
|
|
WRITE_SHORT(g_sModelIndexFireball);
|
|
|
|
WRITE_BYTE(0);
|
|
|
|
WRITE_BYTE(15);
|
|
|
|
WRITE_BYTE(TE_EXPLFLAG_NONE);
|
2015-10-25 16:07:56 +01:00
|
|
|
MESSAGE_END();
|
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if (!(pev->spawnflags & SF_ENVEXPLOSION_NODAMAGE))
|
|
|
|
RadiusDamage(pev, pev, m_iMagnitude, CLASS_NONE, DMG_BLAST);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
SetThink(&CEnvExplosion::Smoke);
|
2015-10-25 16:07:56 +01:00
|
|
|
pev->nextthink = gpGlobals->time + 0.3;
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if (!(pev->spawnflags & SF_ENVEXPLOSION_NOSPARKS))
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
int sparkCount = RANDOM_LONG(0, 3);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
for (int i = 0; i < sparkCount; i++)
|
|
|
|
Create("spark_shower", pev->origin, tr.vecPlaneNormal, NULL);
|
2015-10-25 16:07:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void CEnvExplosion::Smoke(void)
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
if (!(pev->spawnflags & SF_ENVEXPLOSION_NOSMOKE))
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
MESSAGE_BEGIN(MSG_PAS, SVC_TEMPENTITY, pev->origin);
|
|
|
|
WRITE_BYTE(TE_SMOKE);
|
|
|
|
WRITE_COORD(pev->origin.x);
|
|
|
|
WRITE_COORD(pev->origin.y);
|
|
|
|
WRITE_COORD(pev->origin.z);
|
|
|
|
WRITE_SHORT(g_sModelIndexSmoke);
|
|
|
|
WRITE_BYTE((BYTE)m_spriteScale);
|
|
|
|
WRITE_BYTE(12);
|
2015-10-25 16:07:56 +01:00
|
|
|
MESSAGE_END();
|
|
|
|
}
|
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
if (!(pev->spawnflags & SF_ENVEXPLOSION_REPEATABLE))
|
|
|
|
UTIL_Remove(this);
|
|
|
|
}
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
void ExplosionCreate(const Vector ¢er, const Vector &angles, edict_t *pOwner, int magnitude, BOOL doDamage)
|
2015-10-25 16:07:56 +01:00
|
|
|
{
|
2015-12-27 12:06:55 +01:00
|
|
|
CBaseEntity *pExplosion = CBaseEntity::Create("env_explosion", center, angles, pOwner);
|
2015-10-25 16:07:56 +01:00
|
|
|
|
2015-12-27 12:06:55 +01:00
|
|
|
char buf[128];
|
|
|
|
sprintf(buf, "%3d", magnitude);
|
|
|
|
|
|
|
|
KeyValueData kvd;
|
2015-10-25 16:07:56 +01:00
|
|
|
kvd.szKeyName = "iMagnitude";
|
|
|
|
kvd.szValue = buf;
|
2015-12-27 12:06:55 +01:00
|
|
|
pExplosion->KeyValue(&kvd);
|
|
|
|
|
|
|
|
if (!doDamage)
|
2015-10-25 16:07:56 +01:00
|
|
|
pExplosion->pev->spawnflags |= SF_ENVEXPLOSION_NODAMAGE;
|
|
|
|
|
|
|
|
pExplosion->Spawn();
|
2015-12-27 12:06:55 +01:00
|
|
|
pExplosion->Use(NULL, NULL, USE_TOGGLE, 0);
|
|
|
|
}
|