2019-09-01 02:18:15 +00:00
|
|
|
/*
|
2022-03-11 19:40:43 +00:00
|
|
|
* Copyright (c) 2016-2020 Marco Cawthorne <marco@icculus.org>
|
2019-09-01 02:18:15 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-09-07 03:37:06 +00:00
|
|
|
/*QUAKED env_sprite (1 0 0) (-8 -8 -8) (8 8 8) ENVS_STARTON ENVS_PLAYONCE
|
2021-07-14 09:49:30 +00:00
|
|
|
A sprite entity manager with fancy overrides.
|
|
|
|
|
|
|
|
-------- KEYS --------
|
2021-07-17 19:04:34 +00:00
|
|
|
"targetname" : Name
|
|
|
|
"target" : Target when triggered.
|
|
|
|
"killtarget" : Target to kill when triggered.
|
|
|
|
"angles" : Sets the pitch, yaw and roll angles of the sprite.
|
|
|
|
"model" : Path to the sprite in question.
|
|
|
|
"rendercolor" : Color modifier of the sprite.
|
|
|
|
"renderamt" : Alpha modifier of the sprite.
|
|
|
|
"rendermode" : Render mode of the sprite.
|
|
|
|
"framerate" : Rate between frames in seconds.
|
|
|
|
"scale" : Scale modifier of the sprite.
|
|
|
|
|
|
|
|
-------- SPAWNFLAGS --------
|
|
|
|
ENVS_STARTON : Start visible.
|
|
|
|
ENVS_PLAYONCE : Play once from start to finish, then make invisible.
|
2019-09-07 03:37:06 +00:00
|
|
|
|
2021-07-14 09:49:30 +00:00
|
|
|
-------- NOTES --------
|
2019-09-07 03:37:06 +00:00
|
|
|
Only used with an external sprite format, like SPR, SPRHL and SPR32.
|
2020-10-25 11:38:41 +00:00
|
|
|
|
2021-07-14 09:49:30 +00:00
|
|
|
-------- TRIVIA --------
|
2020-10-25 11:38:41 +00:00
|
|
|
This entity was introduced in Half-Life (1998).
|
2019-09-07 03:37:06 +00:00
|
|
|
*/
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-01-03 01:26:39 +00:00
|
|
|
enumflags
|
|
|
|
{
|
2018-12-31 01:00:38 +00:00
|
|
|
ENVS_STARTON,
|
|
|
|
ENVS_PLAYONCE
|
|
|
|
};
|
|
|
|
|
2021-10-19 23:18:36 +00:00
|
|
|
class env_sprite:NSRenderableEntity
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2022-04-17 01:42:38 +00:00
|
|
|
bool m_iIsShader;
|
2019-01-04 20:39:07 +00:00
|
|
|
int m_iToggled;
|
2019-01-05 01:02:12 +00:00
|
|
|
float m_flFramerate;
|
|
|
|
float m_flScale;
|
|
|
|
float m_flEffects;
|
2022-04-17 01:42:38 +00:00
|
|
|
string m_strMaterial;
|
2019-01-05 01:02:12 +00:00
|
|
|
|
2020-04-12 13:50:42 +00:00
|
|
|
void(void) env_sprite;
|
2022-06-02 00:38:52 +00:00
|
|
|
|
|
|
|
virtual void(void) Spawned;
|
2020-08-10 10:32:18 +00:00
|
|
|
virtual void(entity, int) Trigger;
|
2020-10-24 03:02:14 +00:00
|
|
|
virtual float(entity, float) SendEntity;
|
2020-09-08 23:56:46 +00:00
|
|
|
virtual void(string, string) SpawnKey;
|
2022-04-17 01:42:38 +00:00
|
|
|
virtual void(entity, string, string) Input;
|
2018-12-31 01:00:38 +00:00
|
|
|
};
|
|
|
|
|
2022-04-17 01:42:38 +00:00
|
|
|
void
|
|
|
|
env_sprite::Input(entity eAct, string strInput, string strData)
|
|
|
|
{
|
|
|
|
switch (strInput) {
|
|
|
|
case "Color":
|
|
|
|
m_vecRenderColor = stov(strData) / 255;
|
|
|
|
SendFlags |= 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
super::Input(eAct, strInput, strData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 23:56:46 +00:00
|
|
|
float
|
2020-12-26 06:27:34 +00:00
|
|
|
env_sprite::SendEntity(entity ePEnt, float flags)
|
2019-01-04 20:39:07 +00:00
|
|
|
{
|
2020-12-26 06:27:34 +00:00
|
|
|
if (clienttype(ePEnt) != CLIENTTYPE_REAL)
|
2021-05-10 09:33:31 +00:00
|
|
|
return (0);
|
2020-12-26 06:27:34 +00:00
|
|
|
|
2022-04-02 07:10:25 +00:00
|
|
|
if (HasSpawnFlags(ENVS_PLAYONCE))
|
2021-05-10 09:33:31 +00:00
|
|
|
return (0);
|
2020-10-24 03:02:14 +00:00
|
|
|
|
2019-01-04 20:39:07 +00:00
|
|
|
/* Delete it on the client. */
|
2020-10-24 03:02:14 +00:00
|
|
|
if (m_iToggled == FALSE)
|
2021-05-10 09:33:31 +00:00
|
|
|
return (0);
|
2020-10-24 03:02:14 +00:00
|
|
|
|
2019-01-04 20:39:07 +00:00
|
|
|
WriteByte(MSG_ENTITY, ENT_SPRITE);
|
2020-03-28 10:43:08 +00:00
|
|
|
WriteFloat(MSG_ENTITY, 666);
|
2019-01-10 10:14:50 +00:00
|
|
|
WriteCoord(MSG_ENTITY, origin[0]);
|
|
|
|
WriteCoord(MSG_ENTITY, origin[1]);
|
|
|
|
WriteCoord(MSG_ENTITY, origin[2]);
|
2019-01-04 20:39:07 +00:00
|
|
|
WriteFloat(MSG_ENTITY, modelindex);
|
2019-01-05 01:02:12 +00:00
|
|
|
WriteFloat(MSG_ENTITY, m_flFramerate);
|
|
|
|
WriteFloat(MSG_ENTITY, m_flScale);
|
2022-04-17 01:42:38 +00:00
|
|
|
WriteString(MSG_ENTITY, m_strMaterial);
|
2020-11-13 10:17:42 +00:00
|
|
|
|
|
|
|
#ifdef GS_RENDERFX
|
2020-05-02 04:38:02 +00:00
|
|
|
WriteByte(MSG_ENTITY, m_iRenderFX);
|
|
|
|
WriteByte(MSG_ENTITY, m_iRenderMode);
|
|
|
|
WriteFloat(MSG_ENTITY, m_vecRenderColor[0]);
|
|
|
|
WriteFloat(MSG_ENTITY, m_vecRenderColor[1]);
|
|
|
|
WriteFloat(MSG_ENTITY, m_vecRenderColor[2]);
|
|
|
|
WriteFloat(MSG_ENTITY, m_flRenderAmt);
|
2020-11-13 10:17:42 +00:00
|
|
|
#else
|
|
|
|
WriteFloat(MSG_ENTITY, colormod[0]);
|
|
|
|
WriteFloat(MSG_ENTITY, colormod[1]);
|
|
|
|
WriteFloat(MSG_ENTITY, colormod[2]);
|
|
|
|
WriteFloat(MSG_ENTITY, alpha);
|
|
|
|
#endif
|
|
|
|
|
2021-05-10 09:33:31 +00:00
|
|
|
return (1);
|
2019-01-04 20:39:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-08 23:56:46 +00:00
|
|
|
void
|
|
|
|
env_sprite::NetworkOnce(void)
|
2019-01-04 20:39:07 +00:00
|
|
|
{
|
2020-04-12 13:50:42 +00:00
|
|
|
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
|
2019-01-10 10:14:50 +00:00
|
|
|
WriteByte(MSG_MULTICAST, EV_SPRITE);
|
|
|
|
WriteCoord(MSG_MULTICAST, origin[0]);
|
|
|
|
WriteCoord(MSG_MULTICAST, origin[1]);
|
|
|
|
WriteCoord(MSG_MULTICAST, origin[2]);
|
|
|
|
WriteFloat(MSG_MULTICAST, modelindex);
|
|
|
|
WriteFloat(MSG_MULTICAST, m_flFramerate);
|
|
|
|
WriteFloat(MSG_MULTICAST, m_flScale);
|
2022-04-17 01:42:38 +00:00
|
|
|
WriteString(MSG_MULTICAST, m_strMaterial);
|
2020-11-13 10:17:42 +00:00
|
|
|
|
|
|
|
#ifdef GS_RENDERFX
|
2020-05-31 20:41:57 +00:00
|
|
|
WriteByte(MSG_MULTICAST, m_iRenderFX);
|
|
|
|
WriteByte(MSG_MULTICAST, m_iRenderMode);
|
|
|
|
WriteFloat(MSG_MULTICAST, m_vecRenderColor[0]);
|
|
|
|
WriteFloat(MSG_MULTICAST, m_vecRenderColor[1]);
|
|
|
|
WriteFloat(MSG_MULTICAST, m_vecRenderColor[2]);
|
|
|
|
WriteFloat(MSG_MULTICAST, m_flRenderAmt);
|
2020-11-13 10:17:42 +00:00
|
|
|
#else
|
|
|
|
WriteFloat(MSG_MULTICAST, colormod[0]);
|
|
|
|
WriteFloat(MSG_MULTICAST, colormod[1]);
|
|
|
|
WriteFloat(MSG_MULTICAST, colormod[2]);
|
|
|
|
WriteFloat(MSG_MULTICAST, alpha);
|
|
|
|
#endif
|
|
|
|
|
2019-01-05 01:02:12 +00:00
|
|
|
msg_entity = this;
|
2020-04-12 13:50:42 +00:00
|
|
|
multicast(origin, MULTICAST_PVS);
|
2019-01-04 20:39:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 12:07:38 +00:00
|
|
|
/* TODO: Implement state */
|
2020-09-08 23:56:46 +00:00
|
|
|
void
|
|
|
|
env_sprite::Trigger(entity act, int state)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2022-04-02 07:10:25 +00:00
|
|
|
if (HasSpawnFlags(ENVS_PLAYONCE)) {
|
2019-01-04 20:39:07 +00:00
|
|
|
NetworkOnce();
|
|
|
|
} else {
|
|
|
|
m_iToggled = 1 - m_iToggled;
|
|
|
|
SendFlags = 1;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 23:56:46 +00:00
|
|
|
void
|
|
|
|
env_sprite::SpawnKey(string strKey, string strValue)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2020-09-08 23:56:46 +00:00
|
|
|
switch (strKey) {
|
2022-04-17 01:42:38 +00:00
|
|
|
case "shader":
|
|
|
|
case "material":
|
|
|
|
m_strMaterial = strValue;
|
|
|
|
break;
|
2020-09-08 23:56:46 +00:00
|
|
|
case "framerate":
|
|
|
|
m_flFramerate = stof(strValue);
|
|
|
|
break;
|
|
|
|
case "scale":
|
|
|
|
m_flScale = stof(strValue);
|
|
|
|
break;
|
|
|
|
default:
|
2021-10-19 23:18:36 +00:00
|
|
|
super::SpawnKey(strKey, strValue);
|
2019-03-19 19:01:24 +00:00
|
|
|
}
|
2020-09-08 23:56:46 +00:00
|
|
|
}
|
2019-01-05 01:02:12 +00:00
|
|
|
|
2020-09-08 23:56:46 +00:00
|
|
|
void
|
2022-06-02 00:38:52 +00:00
|
|
|
env_sprite::Spawned(void)
|
2020-09-08 23:56:46 +00:00
|
|
|
{
|
2022-04-02 07:10:25 +00:00
|
|
|
m_iToggled = (HasSpawnFlags(ENVS_STARTON) > 0) ? TRUE : FALSE;
|
2020-10-24 04:36:08 +00:00
|
|
|
|
|
|
|
/* how pointless this would be otherwise. */
|
|
|
|
if (!targetname)
|
|
|
|
m_iToggled = TRUE;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
2022-06-02 00:38:52 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
env_sprite::env_sprite(void)
|
|
|
|
{
|
|
|
|
m_iIsShader = false;
|
|
|
|
m_flFramerate = 10;
|
|
|
|
m_flScale = 1.0f;
|
|
|
|
}
|