func_platrot: Cleanup and rewrite the essential parts. Now inherits most of func_plat.
This commit is contained in:
parent
29b6a200b8
commit
ca04a7d637
2 changed files with 53 additions and 140 deletions
|
@ -68,6 +68,7 @@ public:
|
||||||
|
|
||||||
virtual void MoverStartsMoving(void);
|
virtual void MoverStartsMoving(void);
|
||||||
virtual void MoverFinishesMoving(void);
|
virtual void MoverFinishesMoving(void);
|
||||||
|
virtual void PlatformReturn(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_flSpeed;
|
float m_flSpeed;
|
||||||
|
@ -174,12 +175,14 @@ func_plat::MoverStartsMoving(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
func_plat::MoverFinishesMoving(void)
|
func_plat::PlatformReturn(void)
|
||||||
{
|
{
|
||||||
static void MoveDown(void) {
|
|
||||||
MoveToPosition(GetMoverPosition2(), m_flSpeed);
|
MoveToPosition(GetMoverPosition2(), m_flSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
func_plat::MoverFinishesMoving(void)
|
||||||
|
{
|
||||||
/* cancel out any moving sfx */
|
/* cancel out any moving sfx */
|
||||||
if (m_strSndMove) {
|
if (m_strSndMove) {
|
||||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||||
|
@ -189,8 +192,10 @@ func_plat::MoverFinishesMoving(void)
|
||||||
StartSoundDef(m_strSndStop, CHAN_VOICE, true);
|
StartSoundDef(m_strSndStop, CHAN_VOICE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HasTargetname() == false) {
|
||||||
if (GetMoverState() == MOVER_POS1) {
|
if (GetMoverState() == MOVER_POS1) {
|
||||||
ScheduleThink(MoveDown, 3.0);
|
ScheduleThink(PlatformReturn, 3.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +225,13 @@ func_plat::Respawn(void)
|
||||||
m_handler.SetTargetPlatform(this);
|
m_handler.SetTargetPlatform(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (HasTargetname() == false) {
|
||||||
SetOrigin(GetMoverPosition2());
|
SetOrigin(GetMoverPosition2());
|
||||||
SetMoverState(MOVER_POS2);
|
SetMoverState(MOVER_POS2);
|
||||||
|
} else {
|
||||||
|
SetOrigin(GetMoverPosition1());
|
||||||
|
SetMoverState(MOVER_POS1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -301,7 +311,7 @@ func_plat_helper::Touch(entity eToucher)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (targetPlat.GetMoverState() == MOVER_POS2)
|
if (targetPlat.GetMoverState() == MOVER_POS2)
|
||||||
targetPlat.MoveToPosition(targetPlat.GetMoverPosition1(), targetPlat.m_flSpeed);
|
targetPlat.Trigger(eToucher, TRIG_OFF);
|
||||||
else
|
else
|
||||||
targetPlat.SetNextThink(1.0);
|
targetPlat.SetNextThink(1.0);
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2022 Vera Visions LLC.
|
* Copyright (c) 2016-2023 Vera Visions LLC.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -16,7 +16,14 @@
|
||||||
|
|
||||||
enumflags
|
enumflags
|
||||||
{
|
{
|
||||||
FNCPLAT_TRIGGER,
|
FNCPLATROT_TOGGLE,
|
||||||
|
FNCPLATROT_UNUSED1,
|
||||||
|
FNCPLATROT_UNUSED2,
|
||||||
|
FNCPLATROT_UNUSED3,
|
||||||
|
FNCPLATROT_UNUSED4,
|
||||||
|
FNCPLATROT_UNUSED5,
|
||||||
|
FNCPLATROT_AXISX,
|
||||||
|
FNCPLATROT_AXISY,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -28,7 +35,7 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*!QUAKED func_platrot (0 .5 .8) ?
|
/*!QUAKED func_platrot (0 .5 .8) ? TOGGLE x x x x x AXIS_X AXIS_Y
|
||||||
# OVERVIEW
|
# OVERVIEW
|
||||||
A vertically moving platform that rotates.
|
A vertically moving platform that rotates.
|
||||||
|
|
||||||
|
@ -40,6 +47,11 @@ A vertically moving platform that rotates.
|
||||||
- "height" : Vertical travel distance
|
- "height" : Vertical travel distance
|
||||||
- "rotation" : Rotation amount, in degrees
|
- "rotation" : Rotation amount, in degrees
|
||||||
|
|
||||||
|
# SPAWNFLAGS
|
||||||
|
- TOGGLE (1) : Won't respond to touch.
|
||||||
|
- AXIS_X (64) : Will rotate on the X-Axis. (Spirit of Half-Life addition)
|
||||||
|
- AXIS_Y (128) : Will rotate on the Y-Axis. (Spirit of Half-Life addition)
|
||||||
|
|
||||||
# NOTES
|
# NOTES
|
||||||
Spins.
|
Spins.
|
||||||
|
|
||||||
|
@ -47,7 +59,7 @@ Spins.
|
||||||
This entity was introduced in Half-Life (1998).
|
This entity was introduced in Half-Life (1998).
|
||||||
*/
|
*/
|
||||||
class
|
class
|
||||||
func_platrot:NSRenderableEntity
|
func_platrot:func_plat
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void func_platrot(void);
|
void func_platrot(void);
|
||||||
|
@ -56,31 +68,17 @@ public:
|
||||||
virtual void Restore(string,string);
|
virtual void Restore(string,string);
|
||||||
virtual void Trigger(entity, triggermode_t);
|
virtual void Trigger(entity, triggermode_t);
|
||||||
virtual void Respawn(void);
|
virtual void Respawn(void);
|
||||||
virtual void Touch(entity);
|
|
||||||
virtual void SpawnKey(string,string);
|
virtual void SpawnKey(string,string);
|
||||||
|
virtual void PlatformReturn(void);
|
||||||
|
|
||||||
nonvirtual void Move(vector, vector, void(void));
|
|
||||||
nonvirtual void ArrivedUp(void);
|
|
||||||
nonvirtual void ArrivedDown(void);
|
|
||||||
nonvirtual void MoveToggle(void);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_iState;
|
|
||||||
float m_flSpeed;
|
|
||||||
float m_flHeight;
|
|
||||||
string m_strNoise1;
|
|
||||||
string m_strNoise2;
|
|
||||||
float m_flRotation;
|
float m_flRotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
func_platrot::func_platrot(void)
|
func_platrot::func_platrot(void)
|
||||||
{
|
{
|
||||||
m_iState = 0i;
|
|
||||||
m_flSpeed = 100.0f;
|
|
||||||
m_flHeight = 0.0f;
|
|
||||||
m_strNoise1 = __NULL__;
|
|
||||||
m_strNoise2 = __NULL__;
|
|
||||||
m_flRotation = 0.0f;
|
m_flRotation = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +86,6 @@ void
|
||||||
func_platrot::Save(float handle)
|
func_platrot::Save(float handle)
|
||||||
{
|
{
|
||||||
super::Save(handle);
|
super::Save(handle);
|
||||||
SaveInt(handle, "m_iState", m_iState);
|
|
||||||
SaveFloat(handle, "m_flSpeed", m_flSpeed);
|
|
||||||
SaveFloat(handle, "m_flHeight", m_flHeight);
|
|
||||||
SaveString(handle, "m_strNoise1", m_strNoise1);
|
|
||||||
SaveString(handle, "m_strNoise2", m_strNoise2);
|
|
||||||
SaveFloat(handle, "m_flRotation", m_flRotation);
|
SaveFloat(handle, "m_flRotation", m_flRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,21 +93,6 @@ void
|
||||||
func_platrot::Restore(string strKey, string strValue)
|
func_platrot::Restore(string strKey, string strValue)
|
||||||
{
|
{
|
||||||
switch (strKey) {
|
switch (strKey) {
|
||||||
case "m_iState":
|
|
||||||
m_iState = ReadInt(strValue);
|
|
||||||
break;
|
|
||||||
case "m_flSpeed":
|
|
||||||
m_flSpeed = ReadFloat(strValue);
|
|
||||||
break;
|
|
||||||
case "m_flHeight":
|
|
||||||
m_flHeight = ReadFloat(strValue);
|
|
||||||
break;
|
|
||||||
case "m_strNoise1":
|
|
||||||
m_strNoise1 = ReadString(strValue);
|
|
||||||
break;
|
|
||||||
case "m_strNoise2":
|
|
||||||
m_strNoise2 = ReadString(strValue);
|
|
||||||
break;
|
|
||||||
case "m_flRotation":
|
case "m_flRotation":
|
||||||
m_flRotation = ReadFloat(strValue);
|
m_flRotation = ReadFloat(strValue);
|
||||||
break;
|
break;
|
||||||
|
@ -127,18 +105,6 @@ void
|
||||||
func_platrot::SpawnKey(string strKey, string strValue)
|
func_platrot::SpawnKey(string strKey, string strValue)
|
||||||
{
|
{
|
||||||
switch (strKey) {
|
switch (strKey) {
|
||||||
case "height":
|
|
||||||
m_flHeight = stof(strValue);
|
|
||||||
break;
|
|
||||||
case "speed":
|
|
||||||
m_flSpeed = stof(strValue);
|
|
||||||
break;
|
|
||||||
case "noise1":
|
|
||||||
m_strNoise1 = strValue;
|
|
||||||
break;
|
|
||||||
case "noise2":
|
|
||||||
m_strNoise2 = strValue;
|
|
||||||
break;
|
|
||||||
case "rotation":
|
case "rotation":
|
||||||
m_flRotation = stof(strValue);
|
m_flRotation = stof(strValue);
|
||||||
break;
|
break;
|
||||||
|
@ -150,102 +116,39 @@ func_platrot::SpawnKey(string strKey, string strValue)
|
||||||
void
|
void
|
||||||
func_platrot::Respawn(void)
|
func_platrot::Respawn(void)
|
||||||
{
|
{
|
||||||
SetMovetype(MOVETYPE_PUSH);
|
super::Respawn();
|
||||||
SetSolid(SOLID_BSP);
|
|
||||||
SetModel(GetSpawnModel());
|
|
||||||
SetOrigin(GetSpawnOrigin());
|
|
||||||
SetAngles(GetSpawnAngles());
|
|
||||||
|
|
||||||
m_iState = PLATSTATE_RAISED;
|
SetMoverRotation2(GetSpawnAngles());
|
||||||
ReleaseThink();
|
SetMoverRotation1([0, m_flRotation, 0]);
|
||||||
|
|
||||||
|
if (HasTargetname() == false) {
|
||||||
|
SetAngles(GetMoverRotation2());
|
||||||
|
} else {
|
||||||
|
SetAngles(GetMoverRotation1());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
func_platrot::ArrivedUp(void)
|
func_platrot::PlatformReturn(void)
|
||||||
{
|
{
|
||||||
ClearVelocity();
|
MoveAndRotateToPosition(GetMoverPosition2(), GetMoverRotation2(), m_flSpeed);
|
||||||
m_iState = PLATSTATE_RAISED;
|
|
||||||
|
|
||||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
|
||||||
|
|
||||||
if (m_strNoise2)
|
|
||||||
sound(this, CHAN_WEAPON, m_strNoise2, 1.0f, ATTN_NORM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
func_platrot::ArrivedDown(void)
|
|
||||||
{
|
|
||||||
ClearVelocity();
|
|
||||||
m_iState = PLATSTATE_LOWERED;
|
|
||||||
|
|
||||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
|
||||||
|
|
||||||
if (m_strNoise2)
|
|
||||||
sound(this, CHAN_WEAPON, m_strNoise2, 1.0f, ATTN_NORM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
func_platrot::Move(vector vecDest, vector vecADest, void() vFunc)
|
|
||||||
{
|
|
||||||
vector vecDifference, vecADifference;
|
|
||||||
float flTravel, fTravelTime;
|
|
||||||
|
|
||||||
m_iState = PLATSTATE_DOWN;
|
|
||||||
vecDifference = (vecDest - origin);
|
|
||||||
vecADifference = vecADest - angles;
|
|
||||||
flTravel = vlen(vecDifference);
|
|
||||||
fTravelTime = (flTravel / m_flSpeed);
|
|
||||||
SetThink(vFunc);
|
|
||||||
|
|
||||||
if (fTravelTime < 0.1) {
|
|
||||||
ClearVelocity();
|
|
||||||
SetNextThink(0.1f);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SetAngularVelocity(vecADifference * (1.0f / fTravelTime));
|
|
||||||
SetVelocity(vecDifference * (1.0f / fTravelTime));
|
|
||||||
SetNextThink(ltime + fTravelTime);
|
|
||||||
|
|
||||||
if (m_strNoise1)
|
|
||||||
sound(this, CHAN_VOICE, m_strNoise1, 1.0f, ATTN_NORM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
func_platrot::MoveToggle(void)
|
|
||||||
{
|
|
||||||
if (m_iState == PLATSTATE_RAISED) {
|
|
||||||
Move(GetSpawnOrigin() - [0,0,m_flHeight], GetSpawnAngles() + [0, m_flRotation, 0], ArrivedDown);
|
|
||||||
} else if (m_iState == PLATSTATE_LOWERED) {
|
|
||||||
Move(GetSpawnOrigin(), GetSpawnAngles(), ArrivedUp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
func_platrot::Trigger(entity act, triggermode_t state)
|
func_platrot::Trigger(entity act, triggermode_t state)
|
||||||
{
|
{
|
||||||
if (HasSpawnFlags(FNCPLAT_TRIGGER))
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case TRIG_OFF:
|
case TRIG_OFF:
|
||||||
Move(GetSpawnOrigin() - [0,0,m_flHeight], GetSpawnAngles() + [0, m_flRotation, 0], ArrivedDown);
|
MoveAndRotateToPosition(GetMoverPosition1(), GetMoverRotation1(), m_flSpeed);
|
||||||
break;
|
break;
|
||||||
case TRIG_ON:
|
case TRIG_ON:
|
||||||
Move(GetSpawnOrigin(), GetSpawnAngles(), ArrivedUp);
|
MoveAndRotateToPosition(GetMoverPosition2(), GetMoverRotation2(), m_flSpeed);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
MoveToggle();
|
if ((GetMoverState() == MOVER_POS2) || (GetMoverState() == MOVER_1TO2)){
|
||||||
|
MoveAndRotateToPosition(GetMoverPosition1(), GetMoverRotation1(), m_flSpeed);
|
||||||
|
} else {
|
||||||
|
MoveAndRotateToPosition(GetMoverPosition2(), GetMoverRotation2(), m_flSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
func_platrot::Touch(entity eToucher)
|
|
||||||
{
|
|
||||||
if (eToucher.movetype != MOVETYPE_WALK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveToggle();
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue