NSMoverEntity: Improvements so transformation and rotation is easier at the same time.
This commit is contained in:
parent
f92de15ca5
commit
495b661b47
10 changed files with 166 additions and 158 deletions
BIN
platform/base_scripts.pk3dir/sound/common/null.wav
Normal file
BIN
platform/base_scripts.pk3dir/sound/common/null.wav
Normal file
Binary file not shown.
BIN
platform/base_scripts.pk3dir/sound/misc/null.wav
Normal file
BIN
platform/base_scripts.pk3dir/sound/misc/null.wav
Normal file
Binary file not shown.
|
@ -276,8 +276,8 @@ func_button::Respawn(void)
|
|||
SetHealth(GetSpawnHealth());
|
||||
|
||||
RestoreAngles();
|
||||
SetPosition1(GetSpawnOrigin());
|
||||
SetPosition2(GetDirectionalPosition(GetSpawnAngles(), m_flLip));
|
||||
SetMoverPosition1(GetSpawnOrigin());
|
||||
SetMoverPosition2(GetDirectionalPosition(GetSpawnAngles(), m_flLip));
|
||||
ClearAngles();
|
||||
|
||||
if (health > 0) {
|
||||
|
@ -290,7 +290,7 @@ func_button::Respawn(void)
|
|||
}
|
||||
|
||||
if (HasSpawnFlags(SF_BTT_NOMOVE)) {
|
||||
SetPosition2(GetPosition1());
|
||||
SetMoverPosition2(GetMoverPosition1());
|
||||
}
|
||||
|
||||
m_iValue = 0;
|
||||
|
@ -300,7 +300,7 @@ void
|
|||
func_button::MoverFinishesMoving(void)
|
||||
{
|
||||
static void MoveBack(void) {
|
||||
MoveToPosition(GetPosition1(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition1(), m_flSpeed);
|
||||
}
|
||||
|
||||
if (GetMoverState() == MOVER_POS1) {
|
||||
|
@ -349,7 +349,7 @@ func_button::Trigger(entity act, triggermode_t state)
|
|||
|
||||
if ((m_moverState == MOVER_1TO2) || (m_moverState == MOVER_POS2)){
|
||||
if (m_flWait != -1) {
|
||||
MoveToPosition(GetPosition1(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition1(), m_flSpeed);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ func_button::Trigger(entity act, triggermode_t state)
|
|||
if (m_strSndPressed)
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndPressed);
|
||||
|
||||
MoveToPosition(GetPosition2(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition2(), m_flSpeed);
|
||||
UseOutput(act, m_strOnPressed);
|
||||
UseTargets(act, TRIG_TOGGLE, m_flDelay);
|
||||
|
||||
|
|
|
@ -314,8 +314,8 @@ func_door::Respawn(void)
|
|||
ReleaseThink();
|
||||
|
||||
RestoreAngles();
|
||||
SetPosition1(GetSpawnOrigin());
|
||||
SetPosition2(GetDirectionalPosition(GetSpawnAngles(), m_flLip));
|
||||
SetMoverPosition1(GetSpawnOrigin());
|
||||
SetMoverPosition2(GetDirectionalPosition(GetSpawnAngles(), m_flLip));
|
||||
ClearAngles();
|
||||
|
||||
/* FIXME: Is this correct? */
|
||||
|
@ -340,8 +340,8 @@ func_door::Respawn(void)
|
|||
|
||||
if (HasSpawnFlags(SF_MOV_OPEN)) {
|
||||
SetOrigin(m_vecPos2);
|
||||
SetPosition2(GetPosition1());
|
||||
SetPosition1(GetOrigin());
|
||||
SetMoverPosition2(GetMoverPosition1());
|
||||
SetMoverPosition1(GetOrigin());
|
||||
|
||||
m_iValue = 1;
|
||||
_PortalOpen();
|
||||
|
@ -386,7 +386,7 @@ void
|
|||
func_door::MoverFinishesMoving(void)
|
||||
{
|
||||
static void MoveBack(void) {
|
||||
MoveToPosition(GetPosition1(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition1(), m_flSpeed);
|
||||
}
|
||||
|
||||
/* we arrived at our starting position within the map */
|
||||
|
@ -400,23 +400,23 @@ func_door::MoverFinishesMoving(void)
|
|||
}
|
||||
|
||||
if (m_strSndStop) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndStop);
|
||||
StartSoundDef(m_strSndStop, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
|
||||
if (m_strSndMove)
|
||||
sound(this, CHAN_WEAPON, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_WEAPON, 0, true);
|
||||
|
||||
} else if (GetMoverState() == MOVER_POS2) {
|
||||
if (m_strSndStop) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndStop);
|
||||
StartSoundDef(m_strSndStop, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
|
||||
if (m_strSndMove)
|
||||
sound(this, CHAN_WEAPON, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_WEAPON, 0, true);
|
||||
|
||||
if ((m_flWait < 0.0f) || HasSpawnFlags(SF_MOV_TOGGLE) == true)
|
||||
return;
|
||||
|
@ -430,25 +430,25 @@ func_door::MoverStartsMoving(void)
|
|||
{
|
||||
if (GetMoverState() == MOVER_1TO2) {
|
||||
if (m_strSndOpen) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndOpen);
|
||||
StartSoundDef(m_strSndOpen, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
|
||||
if (m_strSndMove)
|
||||
Sound_Play(this, CHAN_WEAPON, m_strSndMove);
|
||||
StartSoundDef(m_strSndMove, CHAN_WEAPON, true);
|
||||
|
||||
m_iValue = 1;
|
||||
} else if (GetMoverState() == MOVER_2TO1) {
|
||||
|
||||
if (m_strSndClose) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndClose);
|
||||
StartSoundDef(m_strSndClose, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
|
||||
if (m_strSndMove)
|
||||
Sound_Play(this, CHAN_WEAPON, m_strSndMove);
|
||||
StartSoundDef(m_strSndMove, CHAN_WEAPON, true);
|
||||
|
||||
m_iValue = 0;
|
||||
}
|
||||
|
@ -473,9 +473,9 @@ func_door::Trigger(entity act, triggermode_t triggerstate)
|
|||
}
|
||||
|
||||
if (triggerstate == TRIG_OFF) {
|
||||
MoveToPosition(GetPosition1(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition1(), m_flSpeed);
|
||||
} else if (triggerstate == TRIG_ON) {
|
||||
MoveToPosition(GetPosition2(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition2(), m_flSpeed);
|
||||
} else {
|
||||
MoveToReverse(m_flSpeed);
|
||||
}
|
||||
|
|
|
@ -260,20 +260,20 @@ func_door_rotating::Respawn(void)
|
|||
PlayerUse = __NULL__;
|
||||
}
|
||||
|
||||
SetPosition1(GetSpawnAngles());
|
||||
SetMoverRotation1(GetSpawnAngles());
|
||||
|
||||
RestoreAngles();
|
||||
if (HasSpawnFlags(SF_ROT_BACKWARDS)) {
|
||||
SetPosition2(GetDirectionalRotation(m_vecTurnDir, -m_flDistance));
|
||||
SetMoverRotation2(GetDirectionalRotation(m_vecTurnDir, -m_flDistance));
|
||||
} else {
|
||||
SetPosition2(GetDirectionalRotation(m_vecTurnDir, m_flDistance));
|
||||
SetMoverRotation2(GetDirectionalRotation(m_vecTurnDir, m_flDistance));
|
||||
}
|
||||
ClearAngles();
|
||||
|
||||
if (HasSpawnFlags(SF_ROT_OPEN)) {
|
||||
vector vTemp = GetPosition2();
|
||||
SetPosition2(GetPosition1());
|
||||
SetPosition1(vTemp);
|
||||
vector vTemp = GetMoverRotation2();
|
||||
SetMoverRotation2(GetMoverRotation1());
|
||||
SetMoverRotation1(vTemp);
|
||||
}
|
||||
|
||||
if (HasSpawnFlags(SF_ROT_PASSABLE)) {
|
||||
|
@ -284,7 +284,7 @@ func_door_rotating::Respawn(void)
|
|||
m_iLocked = TRUE;
|
||||
}
|
||||
|
||||
SetAngles(GetPosition1());
|
||||
SetAngles(GetMoverRotation1());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -355,14 +355,14 @@ void
|
|||
func_door_rotating::MoverFinishesMoving(void)
|
||||
{
|
||||
static void RotateBack(void) {
|
||||
RotateToPosition(GetPosition1(), m_flSpeed);
|
||||
RotateToPosition(GetMoverRotation1(), m_flSpeed);
|
||||
}
|
||||
|
||||
if (GetMoverState() == MOVER_POS1) {
|
||||
if (m_strSndStop) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndStop);
|
||||
StartSoundDef(m_strSndStop, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
|
||||
if (targetClose)
|
||||
|
@ -374,9 +374,9 @@ func_door_rotating::MoverFinishesMoving(void)
|
|||
}
|
||||
} else if (GetMoverState() == MOVER_POS2) {
|
||||
if (m_strSndStop) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndStop);
|
||||
StartSoundDef(m_strSndStop, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
|
||||
if ((m_flWait < 0.0f) || HasSpawnFlags(SF_ROT_TOGGLE) == true)
|
||||
|
@ -392,17 +392,17 @@ func_door_rotating::MoverStartsMoving(void)
|
|||
if (GetMoverState() == MOVER_2TO1) {
|
||||
if (!HasSpawnFlags(SF_DOOR_SILENT)) {
|
||||
if (m_strSndClose) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndClose);
|
||||
StartSoundDef(m_strSndClose, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
}
|
||||
} else if (GetMoverState() == MOVER_1TO2) {
|
||||
if (!HasSpawnFlags(SF_DOOR_SILENT)) {
|
||||
if (m_strSndOpen) {
|
||||
Sound_Play(this, CHAN_VOICE, m_strSndOpen);
|
||||
StartSoundDef(m_strSndOpen, CHAN_VOICE, true);
|
||||
} else {
|
||||
sound(this, CHAN_VOICE, "common/null.wav", 1.0f, ATTN_NORM);
|
||||
StartSound("common/null.wav", CHAN_VOICE, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -431,21 +431,21 @@ func_door_rotating::Trigger(entity act, triggermode_t state)
|
|||
flDirection = -1.0f;
|
||||
}
|
||||
|
||||
SetPosition2(GetDirectionalRotation(m_vecTurnDir, m_flDistance * flDirection));
|
||||
SetMoverRotation2(GetDirectionalRotation(m_vecTurnDir, m_flDistance * flDirection));
|
||||
}
|
||||
}
|
||||
|
||||
if (state == TRIG_TOGGLE) {
|
||||
if ((GetMoverState() == MOVER_1TO2) || (GetMoverState() == MOVER_POS2)) {
|
||||
RotateToPosition(GetPosition1(), m_flSpeed);
|
||||
RotateToPosition(GetMoverRotation1(), m_flSpeed);
|
||||
return;
|
||||
} else {
|
||||
RotateToPosition(GetPosition2(), m_flSpeed);
|
||||
RotateToPosition(GetMoverRotation2(), m_flSpeed);
|
||||
}
|
||||
} else if (state == TRIG_OFF) {
|
||||
RotateToPosition(GetPosition1(), m_flSpeed);
|
||||
RotateToPosition(GetMoverRotation1(), m_flSpeed);
|
||||
} else if (state == TRIG_ON) {
|
||||
RotateToPosition(GetPosition2(), m_flSpeed);
|
||||
RotateToPosition(GetMoverRotation2(), m_flSpeed);
|
||||
}
|
||||
|
||||
UseTargets(act, TRIG_TOGGLE, m_flDelay);
|
||||
|
|
|
@ -177,7 +177,7 @@ void
|
|||
func_plat::MoverFinishesMoving(void)
|
||||
{
|
||||
static void MoveDown(void) {
|
||||
MoveToPosition(GetPosition2(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition2(), m_flSpeed);
|
||||
}
|
||||
|
||||
/* cancel out any moving sfx */
|
||||
|
@ -206,8 +206,8 @@ func_plat::Respawn(void)
|
|||
m_flHeight = size[2] + 8;
|
||||
}
|
||||
|
||||
SetPosition1(GetOrigin());
|
||||
SetPosition2(GetOrigin() - [0, 0, m_flHeight]);
|
||||
SetMoverPosition1(GetOrigin());
|
||||
SetMoverPosition2(GetOrigin() - [0, 0, m_flHeight]);
|
||||
|
||||
ClearAngles();
|
||||
ReleaseThink();
|
||||
|
@ -220,7 +220,7 @@ func_plat::Respawn(void)
|
|||
m_handler.SetTargetPlatform(this);
|
||||
}
|
||||
|
||||
SetOrigin(GetPosition2());
|
||||
SetOrigin(GetMoverPosition2());
|
||||
SetMoverState(MOVER_POS2);
|
||||
}
|
||||
|
||||
|
@ -229,10 +229,10 @@ func_plat::Trigger(entity act, triggermode_t state)
|
|||
{
|
||||
switch (state) {
|
||||
case TRIG_OFF:
|
||||
MoveToPosition(GetPosition1(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition1(), m_flSpeed);
|
||||
break;
|
||||
case TRIG_ON:
|
||||
MoveToPosition(GetPosition2(), m_flSpeed);
|
||||
MoveToPosition(GetMoverPosition2(), m_flSpeed);
|
||||
break;
|
||||
default:
|
||||
MoveToReverse(m_flSpeed);
|
||||
|
@ -274,8 +274,8 @@ func_plat_helper::SetTargetPlatform(entity targ)
|
|||
|
||||
m_eTargetPlat = targ;
|
||||
|
||||
vecPos1 = targetPlat.GetPosition1();
|
||||
vecPos2 = targetPlat.GetPosition2();
|
||||
vecPos1 = targetPlat.GetMoverPosition1();
|
||||
vecPos2 = targetPlat.GetMoverPosition2();
|
||||
vecMins = targetPlat.GetMins() + [25, 25, 0];
|
||||
vecMaxs = targetPlat.GetMaxs() - [25, 25, -8];
|
||||
vecMins[2] = vecMaxs[2] - (vecPos1[2] - vecPos2[2] + 8);
|
||||
|
@ -301,7 +301,7 @@ func_plat_helper::Touch(entity eToucher)
|
|||
return;
|
||||
|
||||
if (targetPlat.GetMoverState() == MOVER_POS2)
|
||||
targetPlat.MoveToPosition(targetPlat.GetPosition1(), targetPlat.m_flSpeed);
|
||||
targetPlat.MoveToPosition(targetPlat.GetMoverPosition1(), targetPlat.m_flSpeed);
|
||||
else
|
||||
targetPlat.SetNextThink(1.0);
|
||||
}
|
|
@ -127,7 +127,7 @@ trigger_auto::Processing(void)
|
|||
}
|
||||
|
||||
UseTargets(this, m_iTriggerState, m_flDelay);
|
||||
print(sprintf("%S %d %f %f\n", target, m_iTriggerState, m_flDelay, time));
|
||||
//print(sprintf("%S %d %f %f\n", target, m_iTriggerState, m_flDelay, time));
|
||||
|
||||
if (HasSpawnFlags(1)) {
|
||||
NSLog("^2trigger_auto::^3Processing^7: %s triggerer removed self", target);
|
||||
|
|
|
@ -396,6 +396,10 @@ initents(void)
|
|||
precache_sound("debris/concrete2.wav");
|
||||
precache_sound("debris/concrete3.wav");
|
||||
|
||||
/** compat... */
|
||||
precache_sound("misc/null.wav");
|
||||
precache_sound("common/null.wav");
|
||||
|
||||
precache_sound("player/pl_fallpain3.wav");
|
||||
precache_sound("items/9mmclip1.wav");
|
||||
precache_sound("items/gunpickup2.wav");
|
||||
|
@ -403,7 +407,6 @@ initents(void)
|
|||
precache_sound("common/wpn_denyselect.wav");
|
||||
precache_sound("player/sprayer.wav");
|
||||
precache_sound("items/flashlight1.wav");
|
||||
precache_sound("common/null.wav");
|
||||
|
||||
Sound_Precache("player.gasplight");
|
||||
Sound_Precache("player.gaspheavy");
|
||||
|
|
|
@ -26,8 +26,8 @@ typedef enum
|
|||
/** The movement type of the NSMoverEntity. */
|
||||
typedef enum
|
||||
{
|
||||
MOVERTYPE_TRANSFORM, /**< Moves in a linear fashion. */
|
||||
MOVERTYPE_ROTATE, /**< Rotates in a linear fashion. */
|
||||
MOVERTYPE_LINEAR, /**< Moves in a linear fashion. */
|
||||
MOVERTYPE_ACCELERATED, /**< Moved in an accelerated fashion. */
|
||||
} moverType_t;
|
||||
|
||||
|
||||
|
@ -61,19 +61,31 @@ public:
|
|||
nonvirtual moverType_t GetMoverType(void);
|
||||
|
||||
/** Sets the initial starting position. */
|
||||
nonvirtual void SetPosition1(vector);
|
||||
nonvirtual void SetMoverPosition1(vector);
|
||||
/** Returns the starting position. */
|
||||
nonvirtual vector GetPosition1(void);
|
||||
nonvirtual vector GetMoverPosition1(void);
|
||||
|
||||
/** Sets the final destination. */
|
||||
nonvirtual void SetPosition2(vector);
|
||||
nonvirtual void SetMoverPosition2(vector);
|
||||
/** Returns the final destination. */
|
||||
nonvirtual vector GetPosition2(void);
|
||||
nonvirtual vector GetMoverPosition2(void);
|
||||
|
||||
/** Sets the initial starting angle. */
|
||||
nonvirtual void SetMoverRotation1(vector);
|
||||
/** Returns the starting angle. */
|
||||
nonvirtual vector GetMoverRotation1(void);
|
||||
|
||||
/** Sets the final destination angle. */
|
||||
nonvirtual void SetMoverRotation2(vector);
|
||||
/** Returns the final destination angle. */
|
||||
nonvirtual vector GetMoverRotation2(void);
|
||||
|
||||
/** Moves this entity to the specified position. */
|
||||
nonvirtual void MoveToPosition(vector, float);
|
||||
/** Rotates this entity to the desired angle. */
|
||||
nonvirtual void RotateToPosition(vector, float);
|
||||
/** Moves and rotates this entity to a desired location. */
|
||||
nonvirtual void MoveAndRotateToPosition(vector, vector, float);
|
||||
|
||||
/** Moves to the reverse state. If a mover is at pos1, it'll go to pos2, etc. */
|
||||
nonvirtual void MoveToReverse(float);
|
||||
|
@ -96,15 +108,15 @@ public:
|
|||
private:
|
||||
vector m_vecPos1;
|
||||
vector m_vecPos2;
|
||||
vector m_vecPos3;
|
||||
vector m_vecPos4;
|
||||
moverState_t m_moverState;
|
||||
moverType_t m_moverType;
|
||||
int m_iPortalState;
|
||||
|
||||
nonvirtual void _PortalOpen(void);
|
||||
nonvirtual void _PortalClose(void);
|
||||
nonvirtual void _ArrivedAtPosition1(void);
|
||||
nonvirtual void _ArrivedAtPosition2(void);
|
||||
nonvirtual void _RotatedToPosition1(void);
|
||||
nonvirtual void _RotatedToPosition2(void);
|
||||
nonvirtual void _ArrivedAtRotPosition1(void);
|
||||
nonvirtual void _ArrivedAtRotPosition2(void);
|
||||
nonvirtual void _BeginMoving(void);
|
||||
};
|
|
@ -3,8 +3,10 @@ NSMoverEntity::NSMoverEntity(void)
|
|||
{
|
||||
m_vecPos1 = g_vec_null;
|
||||
m_vecPos2 = g_vec_null;
|
||||
m_vecPos3 = g_vec_null;
|
||||
m_vecPos4 = g_vec_null;
|
||||
m_moverState = MOVER_POS1;
|
||||
m_moverType = MOVERTYPE_TRANSFORM;
|
||||
m_moverType = MOVERTYPE_LINEAR;
|
||||
m_iPortalState = 0i;
|
||||
}
|
||||
|
||||
|
@ -16,6 +18,8 @@ NSMoverEntity::Save(float handle)
|
|||
|
||||
SaveVector(handle, "m_vecPos1", m_vecPos1);
|
||||
SaveVector(handle, "m_vecPos2", m_vecPos2);
|
||||
SaveVector(handle, "m_vecPos3", m_vecPos3);
|
||||
SaveVector(handle, "m_vecPos4", m_vecPos4);
|
||||
SaveFloat(handle, "m_moverState", m_moverState);
|
||||
SaveFloat(handle, "m_moverType", m_moverType);
|
||||
SaveInt(handle, "m_iPortalState", m_iPortalState);
|
||||
|
@ -31,6 +35,12 @@ NSMoverEntity::Restore(string strKey, string strValue)
|
|||
case "m_vecPos2":
|
||||
m_vecPos2 = ReadVector(strValue);
|
||||
break;
|
||||
case "m_vecPos3":
|
||||
m_vecPos3 = ReadVector(strValue);
|
||||
break;
|
||||
case "m_vecPos4":
|
||||
m_vecPos4 = ReadVector(strValue);
|
||||
break;
|
||||
case "m_moverState":
|
||||
m_moverState = ReadFloat(strValue);
|
||||
break;
|
||||
|
@ -100,55 +110,88 @@ NSMoverEntity::GetMoverType(void)
|
|||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::SetPosition1(vector val)
|
||||
NSMoverEntity::SetMoverPosition1(vector val)
|
||||
{
|
||||
m_vecPos1 = val;
|
||||
}
|
||||
|
||||
vector
|
||||
NSMoverEntity::GetPosition1(void)
|
||||
NSMoverEntity::GetMoverPosition1(void)
|
||||
{
|
||||
return m_vecPos1;
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::SetPosition2(vector val)
|
||||
NSMoverEntity::SetMoverPosition2(vector val)
|
||||
{
|
||||
m_vecPos2 = val;
|
||||
}
|
||||
|
||||
vector
|
||||
NSMoverEntity::GetPosition2(void)
|
||||
NSMoverEntity::GetMoverPosition2(void)
|
||||
{
|
||||
return m_vecPos2;
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::SetMoverRotation1(vector val)
|
||||
{
|
||||
m_vecPos3 = val;
|
||||
}
|
||||
|
||||
vector
|
||||
NSMoverEntity::GetMoverRotation1(void)
|
||||
{
|
||||
return m_vecPos3;
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::SetMoverRotation2(vector val)
|
||||
{
|
||||
m_vecPos4 = val;
|
||||
}
|
||||
|
||||
vector
|
||||
NSMoverEntity::GetMoverRotation2(void)
|
||||
{
|
||||
return m_vecPos4;
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::MoveToPosition(vector vecDest, float flSpeed)
|
||||
{
|
||||
MoveAndRotateToPosition(vecDest, GetAngles(), flSpeed);
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::MoveAndRotateToPosition(vector vecDest, vector vecAngle, float flSpeed)
|
||||
{
|
||||
vector vecDifference;
|
||||
vector vecAngleDifference;
|
||||
float flTravel;
|
||||
float fTravelTime;
|
||||
|
||||
/* selects which end method to trigger based on state. */
|
||||
static void MoveToPosition_Done(float travelTime) {
|
||||
static void MoveToRotPosition_Done(float travelTime) {
|
||||
if (m_moverState == MOVER_1TO2) {
|
||||
ScheduleThink(_ArrivedAtPosition2, travelTime);
|
||||
ScheduleThink(_ArrivedAtRotPosition2, travelTime);
|
||||
} else if (m_moverState == MOVER_2TO1) {
|
||||
ScheduleThink(_ArrivedAtPosition1, travelTime);
|
||||
ScheduleThink(_ArrivedAtRotPosition1, travelTime);
|
||||
}
|
||||
MoverStartsMoving();
|
||||
_PortalOpen();
|
||||
}
|
||||
|
||||
/* selects which end positition to set based on state */
|
||||
static void MoveToPosition_SetDest(vector vecDest) {
|
||||
static void MoveToRotPosition_SetDest(vector vecDest, vector vecAngle) {
|
||||
if (m_moverState == MOVER_POS2) {
|
||||
m_vecPos1 = vecDest;
|
||||
m_vecPos3 = vecAngle;
|
||||
m_moverState = MOVER_2TO1;
|
||||
} else {
|
||||
m_moverState = MOVER_1TO2;
|
||||
m_vecPos2 = vecDest;
|
||||
m_vecPos4 = vecAngle;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,92 +202,60 @@ NSMoverEntity::MoveToPosition(vector vecDest, float flSpeed)
|
|||
}
|
||||
|
||||
/* set the appropriate attribute */
|
||||
MoveToPosition_SetDest(vecDest);
|
||||
|
||||
/* if we're already there, don't bother and trigger it right now. */
|
||||
if (vecDest == GetOrigin()) {
|
||||
MoveToPosition_Done(0.0f);
|
||||
ClearVelocity();
|
||||
return;
|
||||
}
|
||||
MoveToRotPosition_SetDest(vecDest, vecAngle);
|
||||
|
||||
/* calculate travel distance and time */
|
||||
vecDifference = (vecDest - GetOrigin());
|
||||
vecAngleDifference = (vecAngle - GetAngles());
|
||||
flTravel = vlen(vecDifference);
|
||||
fTravelTime = (flTravel / flSpeed);
|
||||
|
||||
/* if we won't move far enough, we may rotate? */
|
||||
if (!flTravel) {
|
||||
flTravel = vlen(vecAngleDifference);
|
||||
fTravelTime = (flTravel / flSpeed);
|
||||
}
|
||||
|
||||
/* if we're already there, don't bother and trigger it right now. */
|
||||
if (fTravelTime <= 0.0) {
|
||||
|
||||
if (m_moverState == MOVER_1TO2) {
|
||||
_ArrivedAtRotPosition2();
|
||||
} else if (m_moverState == MOVER_2TO1) {
|
||||
_ArrivedAtRotPosition1();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* schedule the movement and proceed to trigger the end after a certain time */
|
||||
MoveToPosition_Done(fTravelTime);
|
||||
MoveToRotPosition_Done(fTravelTime);
|
||||
SetVelocity(vecDifference * (1.0f / fTravelTime));
|
||||
SetAngularVelocity((vecAngleDifference * (1.0 / fTravelTime)));
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::MoveToReverse(float flSpeed)
|
||||
{
|
||||
if ((GetMoverState() == MOVER_POS2) || (GetMoverState() == MOVER_1TO2)){
|
||||
MoveToPosition(GetPosition1(), flSpeed);
|
||||
MoveToPosition(GetMoverPosition1(), flSpeed);
|
||||
} else {
|
||||
MoveToPosition(GetPosition2(), flSpeed);
|
||||
MoveToPosition(GetMoverPosition2(), flSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::RotateToPosition(vector vDestAngle, float flSpeed)
|
||||
NSMoverEntity::RotateToPosition(vector vecAngle, float flSpeed)
|
||||
{
|
||||
vector vecAngleDifference;
|
||||
float flTravelLength, flTravelTime;
|
||||
|
||||
static void RotateToPosition_Done(float travelTime) {
|
||||
if (m_moverState == MOVER_1TO2) {
|
||||
ScheduleThink(_RotatedToPosition2, travelTime);
|
||||
} else if (m_moverState == MOVER_2TO1) {
|
||||
ScheduleThink(_RotatedToPosition1, travelTime);
|
||||
}
|
||||
MoverStartsMoving();
|
||||
_PortalOpen();
|
||||
}
|
||||
|
||||
static void RotateToPosition_SetDest(vector vecDest) {
|
||||
if (m_moverState == MOVER_POS2) {
|
||||
m_vecPos1 = vecDest;
|
||||
m_moverState = MOVER_2TO1;
|
||||
} else {
|
||||
m_moverState = MOVER_1TO2;
|
||||
m_vecPos2 = vecDest;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flSpeed) {
|
||||
NSLog("NSMoverEntity::RotateToPosition: No speed defined!");
|
||||
Respawn();
|
||||
return;
|
||||
}
|
||||
|
||||
RotateToPosition_SetDest(vDestAngle);
|
||||
vecAngleDifference = (vDestAngle - angles);
|
||||
flTravelLength = vlen(vecAngleDifference);
|
||||
flTravelTime = (flTravelLength / flSpeed);
|
||||
|
||||
/* Avoid NAN hack */
|
||||
if (flTravelTime <= 0.0f) {
|
||||
if (m_moverState == MOVER_1TO2) {
|
||||
_RotatedToPosition2();
|
||||
} else if (m_moverState == MOVER_2TO1) {
|
||||
_RotatedToPosition1();
|
||||
}
|
||||
} else {
|
||||
SetAngularVelocity((vecAngleDifference * (1 / flTravelTime)));
|
||||
RotateToPosition_Done(flTravelTime);
|
||||
}
|
||||
MoveAndRotateToPosition(GetOrigin(), vecAngle, flSpeed);
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::RotateToReverse(float flSpeed)
|
||||
{
|
||||
if ((GetMoverState() == MOVER_POS2) || (GetMoverState() == MOVER_1TO2)){
|
||||
RotateToPosition(GetPosition1(), flSpeed);
|
||||
RotateToPosition(GetMoverRotation1(), flSpeed);
|
||||
} else {
|
||||
RotateToPosition(GetPosition2(), flSpeed);
|
||||
RotateToPosition(GetMoverRotation2(), flSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,10 +294,12 @@ NSMoverEntity::_PortalClose(void)
|
|||
openportal(this, AREAPORTAL_CLOSED);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NSMoverEntity::_ArrivedAtPosition1(void)
|
||||
NSMoverEntity::_ArrivedAtRotPosition1(void)
|
||||
{
|
||||
SetOrigin(m_vecPos1);
|
||||
SetAngles(m_vecPos3);
|
||||
ClearVelocity();
|
||||
ReleaseThink();
|
||||
m_moverState = MOVER_POS1;
|
||||
|
@ -295,30 +308,10 @@ NSMoverEntity::_ArrivedAtPosition1(void)
|
|||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::_ArrivedAtPosition2(void)
|
||||
NSMoverEntity::_ArrivedAtRotPosition2(void)
|
||||
{
|
||||
SetOrigin(m_vecPos2);
|
||||
ClearVelocity();
|
||||
ReleaseThink();
|
||||
m_moverState = MOVER_POS2;
|
||||
MoverFinishesMoving();
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::_RotatedToPosition1(void)
|
||||
{
|
||||
SetAngles(m_vecPos1);
|
||||
ClearVelocity();
|
||||
ReleaseThink();
|
||||
m_moverState = MOVER_POS1;
|
||||
_PortalClose();
|
||||
MoverFinishesMoving();
|
||||
}
|
||||
|
||||
void
|
||||
NSMoverEntity::_RotatedToPosition2(void)
|
||||
{
|
||||
SetAngles(m_vecPos2);
|
||||
SetAngles(m_vecPos4);
|
||||
ClearVelocity();
|
||||
ReleaseThink();
|
||||
m_moverState = MOVER_POS2;
|
||||
|
|
Loading…
Reference in a new issue