2022-12-17 13:32:43 +01:00
|
|
|
/***
|
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.
|
|
|
|
*
|
|
|
|
****/
|
2021-11-18 19:17:53 +01:00
|
|
|
|
|
|
|
#pragma once
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
#define SF_BEAM_STARTON 0x0001
|
|
|
|
#define SF_BEAM_TOGGLE 0x0002
|
|
|
|
#define SF_BEAM_RANDOM 0x0004
|
|
|
|
#define SF_BEAM_RING 0x0008
|
|
|
|
#define SF_BEAM_SPARKSTART 0x0010
|
|
|
|
#define SF_BEAM_SPARKEND 0x0020
|
|
|
|
#define SF_BEAM_DECALS 0x0040
|
|
|
|
#define SF_BEAM_SHADEIN 0x0080
|
|
|
|
#define SF_BEAM_SHADEOUT 0x0100
|
|
|
|
#define SF_BEAM_TEMPORARY 0x8000
|
|
|
|
|
|
|
|
#define SF_SPRITE_STARTON 0x0001
|
|
|
|
#define SF_SPRITE_ONCE 0x0002
|
|
|
|
#define SF_SPRITE_TEMPORARY 0x8000
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
class CSprite : public CPointEntity
|
|
|
|
{
|
|
|
|
public:
|
2021-03-05 23:07:22 +01:00
|
|
|
void Spawn() override;
|
|
|
|
void Precache() override;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
int ObjectCaps() override
|
|
|
|
{
|
2013-08-30 13:34:05 -07:00
|
|
|
int flags = 0;
|
2021-11-28 16:54:48 +01:00
|
|
|
if (pev->spawnflags & SF_SPRITE_TEMPORARY)
|
2013-08-30 13:34:05 -07:00
|
|
|
flags = FCAP_DONT_SAVE;
|
2021-11-29 20:31:17 +01:00
|
|
|
return (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | flags;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
2021-03-05 20:54:33 +01:00
|
|
|
void EXPORT AnimateThink();
|
|
|
|
void EXPORT ExpandThink();
|
2021-11-28 16:54:48 +01:00
|
|
|
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) override;
|
|
|
|
void Animate(float frames);
|
|
|
|
void Expand(float scaleSpeed, float fadeSpeed);
|
|
|
|
void SpriteInit(const char* pSpriteName, const Vector& origin);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
inline void SetAttachment(edict_t* pEntity, int attachment)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
if (pEntity)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pev->skin = ENTINDEX(pEntity);
|
|
|
|
pev->body = attachment;
|
|
|
|
pev->aiment = pEntity;
|
|
|
|
pev->movetype = MOVETYPE_FOLLOW;
|
|
|
|
}
|
|
|
|
}
|
2021-03-05 20:54:33 +01:00
|
|
|
void TurnOff();
|
|
|
|
void TurnOn();
|
|
|
|
inline float Frames() { return m_maxFrame; }
|
2021-11-28 16:54:48 +01:00
|
|
|
inline void SetTransparency(int rendermode, int r, int g, int b, int a, int fx)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pev->rendermode = rendermode;
|
|
|
|
pev->rendercolor.x = r;
|
|
|
|
pev->rendercolor.y = g;
|
|
|
|
pev->rendercolor.z = b;
|
|
|
|
pev->renderamt = a;
|
|
|
|
pev->renderfx = fx;
|
|
|
|
}
|
2021-11-28 16:54:48 +01:00
|
|
|
inline void SetTexture(int spriteIndex) { pev->modelindex = spriteIndex; }
|
|
|
|
inline void SetScale(float scale) { pev->scale = scale; }
|
|
|
|
inline void SetColor(int r, int g, int b)
|
|
|
|
{
|
|
|
|
pev->rendercolor.x = r;
|
|
|
|
pev->rendercolor.y = g;
|
|
|
|
pev->rendercolor.z = b;
|
|
|
|
}
|
|
|
|
inline void SetBrightness(int brightness) { pev->renderamt = brightness; }
|
|
|
|
|
|
|
|
inline void AnimateAndDie(float framerate)
|
|
|
|
{
|
|
|
|
SetThink(&CSprite::AnimateUntilDead);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->framerate = framerate;
|
2021-11-28 16:54:48 +01:00
|
|
|
pev->dmgtime = gpGlobals->time + (m_maxFrame / framerate);
|
|
|
|
pev->nextthink = gpGlobals->time;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void EXPORT AnimateUntilDead();
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
bool Save(CSave& save) override;
|
|
|
|
bool Restore(CRestore& restore) override;
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
|
|
|
static CSprite* SpriteCreate(const char* pSpriteName, const Vector& origin, bool animate);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
private:
|
2021-11-28 16:54:48 +01:00
|
|
|
float m_lastTime;
|
|
|
|
float m_maxFrame;
|
2013-08-30 13:34:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CBeam : public CBaseEntity
|
|
|
|
{
|
|
|
|
public:
|
2021-11-28 16:54:48 +01:00
|
|
|
void Spawn() override;
|
|
|
|
void Precache() override;
|
|
|
|
int ObjectCaps() override
|
|
|
|
{
|
2013-08-30 13:34:05 -07:00
|
|
|
int flags = 0;
|
2021-11-28 16:54:48 +01:00
|
|
|
if (pev->spawnflags & SF_BEAM_TEMPORARY)
|
2013-08-30 13:34:05 -07:00
|
|
|
flags = FCAP_DONT_SAVE;
|
2021-11-29 20:31:17 +01:00
|
|
|
return (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | flags;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void EXPORT TriggerTouch(CBaseEntity* pOther);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
// These functions are here to show the way beams are encoded as entities.
|
|
|
|
// Encoding beams as entities simplifies their management in the client/server architecture
|
2021-11-28 16:54:48 +01:00
|
|
|
inline void SetType(int type) { pev->rendermode = (pev->rendermode & 0xF0) | (type & 0x0F); }
|
|
|
|
inline void SetFlags(int flags) { pev->rendermode = (pev->rendermode & 0x0F) | (flags & 0xF0); }
|
|
|
|
inline void SetStartPos(const Vector& pos) { pev->origin = pos; }
|
|
|
|
inline void SetEndPos(const Vector& pos) { pev->angles = pos; }
|
|
|
|
void SetStartEntity(int entityIndex);
|
|
|
|
void SetEndEntity(int entityIndex);
|
|
|
|
|
|
|
|
inline void SetStartAttachment(int attachment) { pev->sequence = (pev->sequence & 0x0FFF) | ((attachment & 0xF) << 12); }
|
|
|
|
inline void SetEndAttachment(int attachment) { pev->skin = (pev->skin & 0x0FFF) | ((attachment & 0xF) << 12); }
|
|
|
|
|
|
|
|
inline void SetTexture(int spriteIndex) { pev->modelindex = spriteIndex; }
|
|
|
|
inline void SetWidth(int width) { pev->scale = width; }
|
|
|
|
inline void SetNoise(int amplitude) { pev->body = amplitude; }
|
|
|
|
inline void SetColor(int r, int g, int b)
|
|
|
|
{
|
|
|
|
pev->rendercolor.x = r;
|
|
|
|
pev->rendercolor.y = g;
|
|
|
|
pev->rendercolor.z = b;
|
|
|
|
}
|
|
|
|
inline void SetBrightness(int brightness) { pev->renderamt = brightness; }
|
|
|
|
inline void SetFrame(float frame) { pev->frame = frame; }
|
|
|
|
inline void SetScrollRate(int speed) { pev->animtime = speed; }
|
|
|
|
|
|
|
|
inline int GetType() { return pev->rendermode & 0x0F; }
|
|
|
|
inline int GetFlags() { return pev->rendermode & 0xF0; }
|
|
|
|
inline int GetStartEntity() { return pev->sequence & 0xFFF; }
|
|
|
|
inline int GetEndEntity() { return pev->skin & 0xFFF; }
|
|
|
|
|
|
|
|
const Vector& GetStartPos();
|
|
|
|
const Vector& GetEndPos();
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-03-05 23:48:27 +01:00
|
|
|
Vector Center() override { return (GetStartPos() + GetEndPos()) * 0.5; } // center point of beam
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
inline int GetTexture() { return pev->modelindex; }
|
|
|
|
inline int GetWidth() { return pev->scale; }
|
|
|
|
inline int GetNoise() { return pev->body; }
|
2013-08-30 13:34:05 -07:00
|
|
|
// inline void GetColor( int r, int g, int b ) { pev->rendercolor.x = r; pev->rendercolor.y = g; pev->rendercolor.z = b; }
|
2021-11-28 16:54:48 +01:00
|
|
|
inline int GetBrightness() { return pev->renderamt; }
|
|
|
|
inline int GetFrame() { return pev->frame; }
|
|
|
|
inline int GetScrollRate() { return pev->animtime; }
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
// Call after you change start/end positions
|
2021-11-28 16:54:48 +01:00
|
|
|
void RelinkBeam();
|
|
|
|
// void SetObjectCollisionBox();
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void DoSparks(const Vector& start, const Vector& end);
|
|
|
|
CBaseEntity* RandomTargetname(const char* szName);
|
|
|
|
void BeamDamage(TraceResult* ptr);
|
2013-08-30 13:34:05 -07:00
|
|
|
// Init after BeamCreate()
|
2021-11-28 16:54:48 +01:00
|
|
|
void BeamInit(const char* pSpriteName, int width);
|
|
|
|
void PointsInit(const Vector& start, const Vector& end);
|
|
|
|
void PointEntInit(const Vector& start, int endIndex);
|
|
|
|
void EntsInit(int startIndex, int endIndex);
|
|
|
|
void HoseInit(const Vector& start, const Vector& direction);
|
|
|
|
|
|
|
|
static CBeam* BeamCreate(const char* pSpriteName, int width);
|
|
|
|
|
|
|
|
inline void LiveForTime(float time)
|
|
|
|
{
|
|
|
|
SetThink(&CBeam::SUB_Remove);
|
|
|
|
pev->nextthink = gpGlobals->time + time;
|
|
|
|
}
|
|
|
|
inline void BeamDamageInstant(TraceResult* ptr, float damage)
|
|
|
|
{
|
|
|
|
pev->dmg = damage;
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->dmgtime = gpGlobals->time - 1;
|
2021-11-28 16:54:48 +01:00
|
|
|
BeamDamage(ptr);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
#define SF_MESSAGE_ONCE 0x0001 // Fade in, not out
|
|
|
|
#define SF_MESSAGE_ALL 0x0002 // Send to all clients
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
|
|
|
|
class CLaser : public CBeam
|
|
|
|
{
|
|
|
|
public:
|
2021-11-28 16:54:48 +01:00
|
|
|
void Spawn() override;
|
|
|
|
void Precache() override;
|
|
|
|
bool KeyValue(KeyValueData* pkvd) override;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void TurnOn();
|
|
|
|
void TurnOff();
|
|
|
|
bool IsOn();
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void FireAtPoint(TraceResult& point);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void EXPORT StrikeThink();
|
|
|
|
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) override;
|
|
|
|
bool Save(CSave& save) override;
|
|
|
|
bool Restore(CRestore& restore) override;
|
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
CSprite* m_pSprite;
|
|
|
|
int m_iszSpriteName;
|
|
|
|
Vector m_firePosition;
|
2013-08-30 13:34:05 -07:00
|
|
|
};
|