NSProjectile: Implement "thrust", "thrust_start" and "thrust_end" spawn keys, as well as "thrust_homing"

NSTimer: Destroy when receiver becomes invalidated.
This commit is contained in:
Marco Cawthorne 2023-07-27 13:29:58 -07:00
parent bd470605a3
commit dea5168998
Signed by: eukara
GPG key ID: CE2032F0A2882A22
3 changed files with 69 additions and 0 deletions

View file

@ -100,9 +100,15 @@ private:
/* Nuclide additions */
bool m_bStickToWorld;
bool m_bStickToActor;
bool m_bThrustHoming;
NSTimer m_thrustHandler;
nonvirtual void _AnimateThink(void);
nonvirtual void _ThrustThink(void);
nonvirtual void _AnimateThinkDead(void);
virtual void OnRemoveEntity(void);
#endif
public:

View file

@ -217,6 +217,9 @@ NSProjectile::SpawnKey(string strKey, string strValue)
case "maxs":
m_vecSpawnMaxs = ReadVector(strValue);
break;
case "thrust_homing":
m_bThrustHoming = ReadBool(strValue);
break;
default:
super::SpawnKey(strKey, strValue);
break;
@ -272,6 +275,8 @@ NSProjectile::Save(float handle)
SaveBool(handle, "m_bStickToActor", m_bStickToActor);
SaveVector(handle, "m_vecSpawnMins", m_vecSpawnMins);
SaveVector(handle, "m_vecSpawnMaxs", m_vecSpawnMaxs);
SaveBool(handle, "m_bThrustHoming", m_bThrustHoming);
SaveEntity(handle, "m_thrustHandler", m_thrustHandler);
}
void
@ -410,6 +415,12 @@ NSProjectile::Restore(string strKey, string strValue)
case "m_vecSpawnMaxs":
m_vecSpawnMaxs = ReadVector(strValue);
break;
case "m_bThrustHoming":
m_bThrustHoming = ReadBool(strValue);
break;
case "m_thrustHandler":
m_thrustHandler = (NSTimer)ReadEntity(strValue);
break;
default:
super::Restore(strKey, strValue);
break;
@ -595,6 +606,49 @@ NSProjectile::_LaunchHitscan(vector startPos, vector launchDir, float dmgMultipl
}
void
NSProjectile::_ThrustThink(void)
{
vector currentVelocity;
float currentSpeed;
float newSpeed;
vector newVelocity;
currentVelocity = GetVelocity();
currentSpeed = vlen(currentVelocity);
newSpeed = (currentSpeed + (m_flThrust * frametime));
/* homing mode */
if (m_bThrustHoming) {
NSSurfacePropEntity projectileOwner = (NSSurfacePropEntity)GetOwner();
vector ownerPos = projectileOwner.GetEyePos();
makevectors(projectileOwner.v_angle);
traceline(ownerPos, ownerPos + v_forward * 8096, FALSE, projectileOwner);
SetAngles(vectoangles(trace_endpos - GetOrigin()));
}
makevectors(GetAngles());
newVelocity = v_forward * (newSpeed);
/* prevent thrusting early */
if ((m_flThrustStart > 0) && GetSpawnAge() < m_flThrustStart) {
return;
}
/* stop thrusting when we reach the end time */
if ((m_flThrustEnd > 0) && (GetSpawnAge() > m_flThrustEnd)) {
m_thrustHandler.Destroy(); /* invalidate */
return;
}
SetVelocity(newVelocity);
}
void
NSProjectile::OnRemoveEntity(void)
{
}
void
NSProjectile::Launch(vector startPos, vector launchDir, float fuseOffset, float powerMultiplier, float dmgMultiplier)
{
@ -656,6 +710,10 @@ NSProjectile::Launch(vector startPos, vector launchDir, float fuseOffset, float
ScheduleThink(_FuseEnded, m_flFuse + fuseOffset);
}
if (m_flThrust != 0) {
m_thrustHandler = NSTimer::TemporaryTimer(this, _ThrustThink, 0.0, true);
}
StartSoundDef(m_sndFly, CHAN_BODY, true);
SendFlags = (-1);
//SendEntity = 0; /* HACK: remove this once Spike fixes CSQC-set traileffectnum etc. */

View file

@ -36,6 +36,11 @@ _NSTimerWrapper(entity receiver, void() func)
void
NSTimer::_TimerThink(void)
{
if (!m_eReceiver) {
Destroy();
return;
}
_NSTimerWrapper(m_eReceiver, _m_NSTimerFunc);
if (m_bRepeats == true)