func_tracktrain: Save/Restore more fields, keep track of when to play the movement sounds.

This commit is contained in:
Marco Cawthorne 2024-03-05 08:19:56 -08:00
parent a3268ef65b
commit f11a10d343
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
6 changed files with 83 additions and 12 deletions

View File

@ -186,7 +186,7 @@ func_plat::MoverFinishesMoving(void)
{
/* cancel out any moving sfx */
if (m_strSndMove) {
StartSound("common/null.wav", CHAN_VOICE, 0, true);
StopSound(CHAN_VOICE, 0, true);
}
if (m_strSndStop) {

View File

@ -146,7 +146,6 @@ private:
int m_iOldInputDirection;
int m_iInputLevel;
int m_iOldInputLevel;
float m_flStartSpeed;
NSTimer m_timerAngled;
float m_flTrainLength;
bool _m_bDriving;
@ -169,10 +168,17 @@ func_tracktrain::func_tracktrain(void)
m_flDamage = 0.0f;
m_flHeight = 0.0f;
m_flStartSpeed = 0.0f;
m_flCurrentSpeed = 0.0f;
m_flBank = 0.0f;
m_strMoveSnd = __NULL__;
m_strStopSnd = __NULL__;
m_flStartSpeed = 0.0f;
m_vecRelationTarget = g_vec_null;
m_flUseTime = 0.0f;
m_iInputDirection = 0i;
m_iOldInputDirection = 0i;
m_iInputLevel = 0i;
m_iOldInputLevel = 0i;
m_timerAngled = __NULL__;
m_flTrainLength = 0.0f;
_m_bDriving = false;
#endif
@ -378,8 +384,17 @@ func_tracktrain::Save(float handle)
SaveFloat(handle, "m_flDamage", m_flDamage);
SaveFloat(handle, "m_flHeight", m_flHeight);
SaveFloat(handle, "m_flStartSpeed", m_flStartSpeed);
SaveFloat(handle, "m_flCurrentSpeed", m_flCurrentSpeed);
SaveFloat(handle, "m_flBank", m_flBank);
SaveString(handle, "m_strMoveSnd", m_strMoveSnd);
SaveString(handle, "m_strStopSnd", m_strStopSnd);
SaveFloat(handle, "m_flUseTime", m_flUseTime);
SaveInt(handle, "m_iInputDirection", m_iInputDirection);
SaveInt(handle, "m_iOldInputDirection", m_iOldInputDirection);
SaveInt(handle, "m_iInputLevel", m_iInputLevel);
SaveEntity(handle, "m_timerAngled", m_timerAngled);
SaveFloat(handle, "m_flTrainLength", m_flTrainLength);
SaveBool(handle, "_m_bDriving", _m_bDriving);
/* if we are on a track, take the difference in offset so we can smoothly transition */
if (target) {
@ -411,12 +426,39 @@ func_tracktrain::Restore(string strKey, string strValue)
case "m_flStartSpeed":
m_flStartSpeed = ReadFloat(strValue);
break;
case "m_flCurrentSpeed":
m_flCurrentSpeed = ReadFloat(strValue);
break;
case "m_flBank":
m_flBank = ReadFloat(strValue);
break;
case "m_strMoveSnd":
m_strMoveSnd = ReadString(strValue);
break;
case "m_strStopSnd":
m_strStopSnd = ReadString(strValue);
break;
case "m_flUseTime":
m_flUseTime = ReadFloat(strValue);
break;
case "m_iInputDirection":
m_iInputDirection = ReadInt(strValue);
break;
case "m_iOldInputDirection":
m_iOldInputDirection = ReadInt(strValue);
break;
case "m_iInputLevel":
m_iInputLevel = ReadInt(strValue);
break;
case "m_timerAngled":
m_timerAngled = ReadEntity(strValue);
break;
case "m_flTrainLength":
m_flTrainLength = ReadFloat(strValue);
break;
case "_m_bDriving":
_m_bDriving = ReadBool(strValue);
break;
case "m_vecRelationTarget":
m_vecRelationTarget = ReadVector(strValue);
break;
@ -535,7 +577,7 @@ void
func_tracktrain::_SoundMove(void)
{
if (m_strMoveSnd) {
Sound_Play(this, CHAN_VOICE, m_strMoveSnd);
StartSoundDef(m_strMoveSnd, CHAN_VOICE, true);
}
}
@ -543,14 +585,14 @@ void
func_tracktrain::_SoundStop(void)
{
if (m_strStopSnd) {
Sound_Play(this, CHAN_BODY, m_strStopSnd);
StartSoundDef(m_strStopSnd, CHAN_BODY, true);
}
if (m_strMoveSnd) {
if (!m_strStopSnd) {
Sound_Play(this, CHAN_BODY, "func_tracktrain.stop_1");
StartSoundDef("func_tracktrain.stop_1", CHAN_BODY, true);
}
sound(this, CHAN_VOICE, "common/null.wav", 1.0, ATTN_NORM);
StopSound(CHAN_VOICE, true);
}
}
@ -597,7 +639,10 @@ func_tracktrain::PathMoveForward(void)
NSVehicle_Log("^1func_tracktrain::^3PathMoveForward^7: Changing velocity from '%v' to '%v'", GetVelocity(), vecVelocity);
SetVelocity(vecVelocity * (1 / flTravelTime));
_SoundMove();
if (_m_bDriving == false) {
_SoundMove();
}
/* the direction we're aiming for */
vecDiff = GetOrigin() - (eNode.GetOrigin() + [0, 0, m_flHeight]);
@ -788,6 +833,7 @@ func_tracktrain::_PathArrivedForward(void)
/* first clear velocity, in case our trigger targets our train */
PathClear();
eNode.PathEndTrigger(this, TRIG_TOGGLE);
return;
}
/* warp */
@ -880,6 +926,7 @@ func_tracktrain::Trigger(entity act, triggermode_t state)
break;
case TRIG_OFF:
PathClear();
break;
case TRIG_TOGGLE:
default:
if (_m_bDriving == false)

View File

@ -43,6 +43,8 @@ info_node::info_node(void)
void
info_node::Respawn(void)
{
InitPointTrigger();
SetSize([0,0,0], [0,0,0]);
SetSolid(SOLID_NOT);
SetMovetype(MOVETYPE_NONE);

View File

@ -79,6 +79,7 @@ public:
virtual void Respawn(void);
virtual void RestoreComplete(void);
virtual void Trigger(entity, triggermode_t);
virtual void DebugDraw(void);
private:
int m_iEnabled;
@ -86,6 +87,8 @@ private:
float m_flStyle;
float m_flSwitchStyle;
string m_strPattern;
vector _lightColor;
};
void
@ -96,6 +99,7 @@ light::light(void)
m_strPattern = "m";
m_flStyle = 0;
m_flSwitchStyle = 0;
_lightColor = [1,1,1];
}
void
@ -168,8 +172,6 @@ light::SpawnKey(string strKey, string strValue)
case "_cone":
case "_cone2":
case "_sky":
case "_light":
break;
/* mostly for light_environment */
case "pitch":
angles[0] = ReadFloat(strValue);
@ -177,6 +179,13 @@ light::SpawnKey(string strKey, string strValue)
case "sunangle":
angles[1] = ReadFloat(strValue);
break;
case "color":
_lightColor = ReadVector(strValue);
break;
case "_light":
case "color255":
_lightColor = ReadVector(strValue) / 255;
break;
default:
super::SpawnKey(strKey, strValue);
}
@ -243,6 +252,19 @@ light::Trigger(entity act, triggermode_t state)
RestoreComplete();
}
void
light::DebugDraw(void)
{
#ifdef SERVER
R_BeginPolygon(m_strDebugTexture, 0, 0);
R_PolygonVertex(GetOrigin() + v_right * 16 - v_up * 16, [1,1], _lightColor, 1.0f);
R_PolygonVertex(GetOrigin() - v_right * 16 - v_up * 16, [0,1], _lightColor, 1.0f);
R_PolygonVertex(GetOrigin() - v_right * 16 + v_up * 16, [0,0], _lightColor, 1.0f);
R_PolygonVertex(GetOrigin() + v_right * 16 + v_up * 16, [1,0], _lightColor, 1.0f);
R_EndPolygon();
#endif
}
CLASSEXPORT(light_spot, light)
class

View File

@ -359,7 +359,7 @@ NSRenderableEntity::RenderFXPass(void)
break;
case RM_GLOW:
colormod = [1,1,1];
colormod = m_vecRenderColor;
alpha = m_flRenderAmt == 0.0 ? 0.0f : 1.0f;
case RM_WORLDGLOW: /* TODO: Figure out what this does differently */
if (checkpvs(vecPlayer, this) == FALSE)

View File

@ -118,7 +118,7 @@ NSTrigger::UseTargets(entity act, int state, float triggerDelay)
env_message_single(act, m_strMessage);
}
if (HasTriggerTarget() == true)
if (target && target != "" && target != targetname)
for (entity f = world; (f = find(f, ::targetname, target));) {
NSTrigger trigger = (NSTrigger)f;