2012-11-26 18:58:24 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Doom 3 BFG Edition GPL Source Code
2012-11-28 15:47:07 +00:00
Copyright ( C ) 1993 - 2012 id Software LLC , a ZeniMax Media company .
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
This file is part of the Doom 3 BFG Edition GPL Source Code ( " Doom 3 BFG Edition Source Code " ) .
2012-11-26 18:58:24 +00:00
Doom 3 BFG Edition Source Code is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with Doom 3 BFG Edition Source Code . If not , see < http : //www.gnu.org/licenses/>.
In addition , the Doom 3 BFG Edition Source Code is also subject to certain additional terms . You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code . If not , please request a copy in writing from id Software at the address below .
If you have questions concerning this license or the applicable additional terms , you may contact in writing id Software LLC , c / o ZeniMax Media Inc . , Suite 120 , Rockville , Maryland 20850 USA .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-12-22 15:18:19 +00:00
# include "precompiled.h"
2012-11-26 18:58:24 +00:00
# pragma hdrstop
# include "Game_local.h"
// _D3XP : rename all gameLocal.time to gameLocal.slow.time for merge!
2012-11-28 15:47:07 +00:00
// a mover will update any gui entities in it's target list with
2012-11-26 18:58:24 +00:00
// a key/val pair of "mover" "state" from below.. guis can represent
// realtime info like this
// binary only
2012-11-28 15:47:07 +00:00
static const char * guiBinaryMoverStates [ ] =
{
2012-11-26 18:58:24 +00:00
" 1 " , // pos 1
" 2 " , // pos 2
" 3 " , // moving 1 to 2
" 4 " // moving 2 to 1
} ;
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idMover
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_FindGuiTargets ( " <FindGuiTargets> " , NULL ) ;
const idEventDef EV_TeamBlocked ( " <teamblocked> " , " ee " ) ;
const idEventDef EV_PartBlocked ( " <partblocked> " , " e " ) ;
const idEventDef EV_ReachedPos ( " <reachedpos> " , NULL ) ;
const idEventDef EV_ReachedAng ( " <reachedang> " , NULL ) ;
const idEventDef EV_PostRestore ( " <postrestore> " , " ddddd " ) ;
const idEventDef EV_StopMoving ( " stopMoving " , NULL ) ;
const idEventDef EV_StopRotating ( " stopRotating " , NULL ) ;
const idEventDef EV_Speed ( " speed " , " f " ) ;
const idEventDef EV_Time ( " time " , " f " ) ;
const idEventDef EV_AccelTime ( " accelTime " , " f " ) ;
const idEventDef EV_DecelTime ( " decelTime " , " f " ) ;
const idEventDef EV_MoveTo ( " moveTo " , " e " ) ;
const idEventDef EV_MoveToPos ( " moveToPos " , " v " ) ;
const idEventDef EV_Move ( " move " , " ff " ) ;
const idEventDef EV_MoveAccelerateTo ( " accelTo " , " ff " ) ;
const idEventDef EV_MoveDecelerateTo ( " decelTo " , " ff " ) ;
const idEventDef EV_RotateDownTo ( " rotateDownTo " , " df " ) ;
const idEventDef EV_RotateUpTo ( " rotateUpTo " , " df " ) ;
const idEventDef EV_RotateTo ( " rotateTo " , " v " ) ;
const idEventDef EV_Rotate ( " rotate " , " v " ) ;
const idEventDef EV_RotateOnce ( " rotateOnce " , " v " ) ;
const idEventDef EV_Bob ( " bob " , " ffv " ) ;
const idEventDef EV_Sway ( " sway " , " ffv " ) ;
const idEventDef EV_Mover_OpenPortal ( " openPortal " ) ;
const idEventDef EV_Mover_ClosePortal ( " closePortal " ) ;
const idEventDef EV_AccelSound ( " accelSound " , " s " ) ;
const idEventDef EV_DecelSound ( " decelSound " , " s " ) ;
const idEventDef EV_MoveSound ( " moveSound " , " s " ) ;
const idEventDef EV_Mover_InitGuiTargets ( " <initguitargets> " , NULL ) ;
const idEventDef EV_EnableSplineAngles ( " enableSplineAngles " , NULL ) ;
const idEventDef EV_DisableSplineAngles ( " disableSplineAngles " , NULL ) ;
const idEventDef EV_RemoveInitialSplineAngles ( " removeInitialSplineAngles " , NULL ) ;
const idEventDef EV_StartSpline ( " startSpline " , " e " ) ;
const idEventDef EV_StopSpline ( " stopSpline " , NULL ) ;
const idEventDef EV_IsMoving ( " isMoving " , NULL , ' d ' ) ;
const idEventDef EV_IsRotating ( " isRotating " , NULL , ' d ' ) ;
CLASS_DECLARATION ( idEntity , idMover )
2012-11-28 15:47:07 +00:00
EVENT ( EV_FindGuiTargets , idMover : : Event_FindGuiTargets )
EVENT ( EV_Thread_SetCallback , idMover : : Event_SetCallback )
EVENT ( EV_TeamBlocked , idMover : : Event_TeamBlocked )
EVENT ( EV_PartBlocked , idMover : : Event_PartBlocked )
EVENT ( EV_ReachedPos , idMover : : Event_UpdateMove )
EVENT ( EV_ReachedAng , idMover : : Event_UpdateRotation )
EVENT ( EV_PostRestore , idMover : : Event_PostRestore )
EVENT ( EV_StopMoving , idMover : : Event_StopMoving )
EVENT ( EV_StopRotating , idMover : : Event_StopRotating )
EVENT ( EV_Speed , idMover : : Event_SetMoveSpeed )
EVENT ( EV_Time , idMover : : Event_SetMoveTime )
EVENT ( EV_AccelTime , idMover : : Event_SetAccellerationTime )
EVENT ( EV_DecelTime , idMover : : Event_SetDecelerationTime )
EVENT ( EV_MoveTo , idMover : : Event_MoveTo )
EVENT ( EV_MoveToPos , idMover : : Event_MoveToPos )
EVENT ( EV_Move , idMover : : Event_MoveDir )
EVENT ( EV_MoveAccelerateTo , idMover : : Event_MoveAccelerateTo )
EVENT ( EV_MoveDecelerateTo , idMover : : Event_MoveDecelerateTo )
EVENT ( EV_RotateDownTo , idMover : : Event_RotateDownTo )
EVENT ( EV_RotateUpTo , idMover : : Event_RotateUpTo )
EVENT ( EV_RotateTo , idMover : : Event_RotateTo )
EVENT ( EV_Rotate , idMover : : Event_Rotate )
EVENT ( EV_RotateOnce , idMover : : Event_RotateOnce )
EVENT ( EV_Bob , idMover : : Event_Bob )
EVENT ( EV_Sway , idMover : : Event_Sway )
EVENT ( EV_Mover_OpenPortal , idMover : : Event_OpenPortal )
EVENT ( EV_Mover_ClosePortal , idMover : : Event_ClosePortal )
EVENT ( EV_AccelSound , idMover : : Event_SetAccelSound )
EVENT ( EV_DecelSound , idMover : : Event_SetDecelSound )
EVENT ( EV_MoveSound , idMover : : Event_SetMoveSound )
EVENT ( EV_Mover_InitGuiTargets , idMover : : Event_InitGuiTargets )
EVENT ( EV_EnableSplineAngles , idMover : : Event_EnableSplineAngles )
EVENT ( EV_DisableSplineAngles , idMover : : Event_DisableSplineAngles )
EVENT ( EV_RemoveInitialSplineAngles , idMover : : Event_RemoveInitialSplineAngles )
EVENT ( EV_StartSpline , idMover : : Event_StartSpline )
EVENT ( EV_StopSpline , idMover : : Event_StopSpline )
EVENT ( EV_Activate , idMover : : Event_Activate )
EVENT ( EV_IsMoving , idMover : : Event_IsMoving )
EVENT ( EV_IsRotating , idMover : : Event_IsRotating )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idMover : : idMover
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idMover : : idMover ( )
{
2012-11-26 18:58:24 +00:00
memset ( & move , 0 , sizeof ( move ) ) ;
memset ( & rot , 0 , sizeof ( rot ) ) ;
move_thread = 0 ;
rotate_thread = 0 ;
dest_angles . Zero ( ) ;
angle_delta . Zero ( ) ;
dest_position . Zero ( ) ;
move_delta . Zero ( ) ;
move_speed = 0.0f ;
move_time = 0 ;
deceltime = 0 ;
acceltime = 0 ;
stopRotation = false ;
useSplineAngles = true ;
lastCommand = MOVER_NONE ;
damage = 0.0f ;
areaPortal = 0 ;
fl . networkSync = true ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteStaticObject ( physicsObj ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( move . stage ) ;
savefile - > WriteInt ( move . acceleration ) ;
savefile - > WriteInt ( move . movetime ) ;
savefile - > WriteInt ( move . deceleration ) ;
savefile - > WriteVec3 ( move . dir ) ;
savefile - > WriteInt ( rot . stage ) ;
savefile - > WriteInt ( rot . acceleration ) ;
savefile - > WriteInt ( rot . movetime ) ;
savefile - > WriteInt ( rot . deceleration ) ;
savefile - > WriteFloat ( rot . rot . pitch ) ;
savefile - > WriteFloat ( rot . rot . yaw ) ;
savefile - > WriteFloat ( rot . rot . roll ) ;
savefile - > WriteInt ( move_thread ) ;
savefile - > WriteInt ( rotate_thread ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteAngles ( dest_angles ) ;
savefile - > WriteAngles ( angle_delta ) ;
savefile - > WriteVec3 ( dest_position ) ;
savefile - > WriteVec3 ( move_delta ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( move_speed ) ;
savefile - > WriteInt ( move_time ) ;
savefile - > WriteInt ( deceltime ) ;
savefile - > WriteInt ( acceltime ) ;
savefile - > WriteBool ( stopRotation ) ;
savefile - > WriteBool ( useSplineAngles ) ;
savefile - > WriteInt ( lastCommand ) ;
savefile - > WriteFloat ( damage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( areaPortal ) ;
2012-11-28 15:47:07 +00:00
if ( areaPortal > 0 )
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( gameRenderWorld - > GetPortalState ( areaPortal ) ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( guiTargets . Num ( ) ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < guiTargets . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
guiTargets [ i ] . Save ( savefile ) ;
}
2012-11-28 15:47:07 +00:00
if ( splineEnt . GetEntity ( ) & & splineEnt . GetEntity ( ) - > GetSpline ( ) )
{
idCurve_Spline < idVec3 > * spline = physicsObj . GetSpline ( ) ;
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( true ) ;
splineEnt . Save ( savefile ) ;
savefile - > WriteInt ( spline - > GetTime ( 0 ) ) ;
savefile - > WriteInt ( spline - > GetTime ( spline - > GetNumValues ( ) - 1 ) - spline - > GetTime ( 0 ) ) ;
savefile - > WriteInt ( physicsObj . GetSplineAcceleration ( ) ) ;
savefile - > WriteInt ( physicsObj . GetSplineDeceleration ( ) ) ;
2012-11-28 15:47:07 +00:00
savefile - > WriteInt ( ( int ) physicsObj . UsingSplineAngles ( ) ) ;
}
else
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( false ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
int i , num ;
bool hasSpline = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadStaticObject ( physicsObj ) ;
RestorePhysics ( & physicsObj ) ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( ( int & ) move . stage ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( move . acceleration ) ;
savefile - > ReadInt ( move . movetime ) ;
savefile - > ReadInt ( move . deceleration ) ;
savefile - > ReadVec3 ( move . dir ) ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( ( int & ) rot . stage ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( rot . acceleration ) ;
savefile - > ReadInt ( rot . movetime ) ;
savefile - > ReadInt ( rot . deceleration ) ;
savefile - > ReadFloat ( rot . rot . pitch ) ;
savefile - > ReadFloat ( rot . rot . yaw ) ;
savefile - > ReadFloat ( rot . rot . roll ) ;
savefile - > ReadInt ( move_thread ) ;
savefile - > ReadInt ( rotate_thread ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadAngles ( dest_angles ) ;
savefile - > ReadAngles ( angle_delta ) ;
savefile - > ReadVec3 ( dest_position ) ;
savefile - > ReadVec3 ( move_delta ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( move_speed ) ;
savefile - > ReadInt ( move_time ) ;
savefile - > ReadInt ( deceltime ) ;
savefile - > ReadInt ( acceltime ) ;
savefile - > ReadBool ( stopRotation ) ;
savefile - > ReadBool ( useSplineAngles ) ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( ( int & ) lastCommand ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( damage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( areaPortal ) ;
2012-11-28 15:47:07 +00:00
if ( areaPortal > 0 )
{
2012-11-26 18:58:24 +00:00
int portalState = 0 ;
savefile - > ReadInt ( portalState ) ;
gameLocal . SetPortalState ( areaPortal , portalState ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
guiTargets . Clear ( ) ;
savefile - > ReadInt ( num ) ;
guiTargets . SetNum ( num ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < num ; i + + )
{
2012-11-26 18:58:24 +00:00
guiTargets [ i ] . Restore ( savefile ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( hasSpline ) ;
2012-11-28 15:47:07 +00:00
if ( hasSpline )
{
2012-11-26 18:58:24 +00:00
int starttime ;
int totaltime ;
int accel ;
int decel ;
int useAngles ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
splineEnt . Restore ( savefile ) ;
savefile - > ReadInt ( starttime ) ;
savefile - > ReadInt ( totaltime ) ;
savefile - > ReadInt ( accel ) ;
savefile - > ReadInt ( decel ) ;
savefile - > ReadInt ( useAngles ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_PostRestore , 0 , starttime , totaltime , accel , decel , useAngles ) ;
2012-11-28 15:47:07 +00:00
}
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_PostRestore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_PostRestore ( int start , int total , int accel , int decel , int useSplineAng )
{
idCurve_Spline < idVec3 > * spline ;
idEntity * splineEntity = splineEnt . GetEntity ( ) ;
if ( ! splineEntity )
{
2012-11-26 18:58:24 +00:00
// We should never get this event if splineEnt is invalid
common - > Warning ( " Invalid spline entity during restore \n " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spline = splineEntity - > GetSpline ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spline - > MakeUniform ( total ) ;
spline - > ShiftTime ( start - spline - > GetTime ( 0 ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetSpline ( spline , accel , decel , ( useSplineAng ! = 0 ) ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_position , vec3_origin , vec3_origin ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
move_thread = 0 ;
rotate_thread = 0 ;
stopRotation = false ;
lastCommand = MOVER_NONE ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
acceltime = 1000.0f * spawnArgs . GetFloat ( " accel_time " , " 0 " ) ;
deceltime = 1000.0f * spawnArgs . GetFloat ( " decel_time " , " 0 " ) ;
move_time = 1000.0f * spawnArgs . GetFloat ( " move_time " , " 1 " ) ; // safe default value
move_speed = spawnArgs . GetFloat ( " move_speed " , " 0 " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " damage " , " 0 " , damage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dest_position = GetPhysics ( ) - > GetOrigin ( ) ;
dest_angles = GetPhysics ( ) - > GetAxis ( ) . ToAngles ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetSelf ( this ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetClipModel ( new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) , 1.0f ) ;
2012-11-26 18:58:24 +00:00
physicsObj . SetOrigin ( GetPhysics ( ) - > GetOrigin ( ) ) ;
physicsObj . SetAxis ( GetPhysics ( ) - > GetAxis ( ) ) ;
physicsObj . SetClipMask ( MASK_SOLID ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " solid " , " 1 " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetContents ( 0 ) ;
}
2012-11-28 15:47:07 +00:00
if ( ! renderEntity . hModel | | ! spawnArgs . GetBool ( " nopush " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetPusher ( 0 ) ;
}
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_position , vec3_origin , vec3_origin ) ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_angles , ang_zero , ang_zero ) ;
SetPhysics ( & physicsObj ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// see if we are on an areaportal
areaPortal = gameRenderWorld - > FindPortal ( GetPhysics ( ) - > GetAbsBounds ( ) ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . MatchPrefix ( " guiTarget " ) )
{
if ( gameLocal . GameState ( ) = = GAMESTATE_STARTUP )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_FindGuiTargets , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// not during spawn, so it's ok to get the targets
FindGuiTargets ( ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
health = spawnArgs . GetInt ( " health " ) ;
2012-11-28 15:47:07 +00:00
if ( health )
{
2012-11-26 18:58:24 +00:00
fl . takedamage = true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idMover : : Hide
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Hide ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Hide ( ) ;
physicsObj . SetContents ( 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Show
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Show ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Show ( ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " solid " , " 1 " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetContents ( CONTENTS_SOLID ) ;
}
SetPhysics ( & physicsObj ) ;
}
/*
= = = = = = = = = = = =
idMover : : Killed
= = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Killed ( idEntity * inflictor , idEntity * attacker , int damage , const idVec3 & dir , int location )
{
2012-11-26 18:58:24 +00:00
fl . takedamage = false ;
ActivateTargets ( this ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetCallback
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetCallback ( )
{
if ( ( lastCommand = = MOVER_ROTATING ) & & ! rotate_thread )
{
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_NONE ;
rotate_thread = idThread : : CurrentThreadNum ( ) ;
idThread : : ReturnInt ( true ) ;
2012-11-28 15:47:07 +00:00
}
else if ( ( lastCommand = = MOVER_MOVING | | lastCommand = = MOVER_SPLINE ) & & ! move_thread )
{
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_NONE ;
move_thread = idThread : : CurrentThreadNum ( ) ;
idThread : : ReturnInt ( true ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idThread : : ReturnInt ( false ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : VectorForDir
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : VectorForDir ( float angle , idVec3 & vec )
{
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
switch ( ( int ) angle )
{
case DIR_UP :
vec . Set ( 0 , 0 , 1 ) ;
break ;
case DIR_DOWN :
vec . Set ( 0 , 0 , - 1 ) ;
break ;
case DIR_LEFT :
physicsObj . GetLocalAngles ( ang ) ;
ang . pitch = 0 ;
ang . roll = 0 ;
ang . yaw + = 90 ;
vec = ang . ToForward ( ) ;
break ;
case DIR_RIGHT :
physicsObj . GetLocalAngles ( ang ) ;
ang . pitch = 0 ;
ang . roll = 0 ;
ang . yaw - = 90 ;
vec = ang . ToForward ( ) ;
break ;
case DIR_FORWARD :
physicsObj . GetLocalAngles ( ang ) ;
ang . pitch = 0 ;
ang . roll = 0 ;
vec = ang . ToForward ( ) ;
break ;
case DIR_BACK :
physicsObj . GetLocalAngles ( ang ) ;
ang . pitch = 0 ;
ang . roll = 0 ;
ang . yaw + = 180 ;
vec = ang . ToForward ( ) ;
break ;
case DIR_REL_UP :
vec . Set ( 0 , 0 , 1 ) ;
break ;
case DIR_REL_DOWN :
vec . Set ( 0 , 0 , - 1 ) ;
break ;
case DIR_REL_LEFT :
physicsObj . GetLocalAngles ( ang ) ;
ang . ToVectors ( NULL , & vec ) ;
vec * = - 1 ;
break ;
case DIR_REL_RIGHT :
physicsObj . GetLocalAngles ( ang ) ;
ang . ToVectors ( NULL , & vec ) ;
break ;
case DIR_REL_FORWARD :
physicsObj . GetLocalAngles ( ang ) ;
vec = ang . ToForward ( ) ;
break ;
case DIR_REL_BACK :
physicsObj . GetLocalAngles ( ang ) ;
vec = ang . ToForward ( ) * - 1 ;
break ;
default :
ang . Set ( 0 , angle , 0 ) ;
vec = GetWorldVector ( ang . ToForward ( ) ) ;
break ;
2012-11-26 18:58:24 +00:00
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : FindGuiTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : FindGuiTargets ( )
{
gameLocal . GetTargets ( spawnArgs , guiTargets , " guiTarget " ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idMover : : ClientThink
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : ClientThink ( const int curTime , const float fraction , const bool predict )
{
2012-11-26 18:58:24 +00:00
// HACK. because I'm not sure all the other stuff this will screw up.
// There was a reason we weren't fully interpolating movers ( Which would evaluate bound objects ).
// I just cant remember what it was.
2012-11-28 15:47:07 +00:00
// Evaluating the Team will update the parts that bound to the entity.
2012-11-26 18:58:24 +00:00
// but because we interpolate the master, we don't want to run evaluate on the mover itself.
// sending in true to the interpolatePhysicsOnly will run the TeamChain Evaluate, but only on
// Objects bound to the entity.
2012-11-28 15:47:07 +00:00
if ( this - > name = = " blueshotty_door " | | this - > name = = " redshotty_door " | |
this - > name = = " Red_blastshield_mover " | | this - > name = = " Blue_blastshield_mover " )
{
2012-11-26 18:58:24 +00:00
InterpolatePhysicsOnly ( fraction , true ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
InterpolatePhysicsOnly ( fraction ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Present ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idMover : : SetGuiState
key / val will be set to any renderEntity - > gui ' s on the list
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : SetGuiState ( const char * key , const char * val ) const
{
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " Setting %s to %s \n " , key , val ) ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < guiTargets . Num ( ) ; i + + )
{
idEntity * ent = guiTargets [ i ] . GetEntity ( ) ;
if ( ent )
{
for ( int j = 0 ; j < MAX_RENDERENTITY_GUI ; j + + )
{
if ( ent - > GetRenderEntity ( ) & & ent - > GetRenderEntity ( ) - > gui [ j ] )
{
2012-11-26 18:58:24 +00:00
ent - > GetRenderEntity ( ) - > gui [ j ] - > SetStateString ( key , val ) ;
ent - > GetRenderEntity ( ) - > gui [ j ] - > StateChanged ( gameLocal . slow . time , true ) ;
}
}
ent - > UpdateVisuals ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_InitGuiTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_FindGuiTargets ( )
{
2012-11-26 18:58:24 +00:00
FindGuiTargets ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : SetGuiStates
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : SetGuiStates ( const char * state )
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
if ( guiTargets . Num ( ) )
{
2012-11-26 18:58:24 +00:00
SetGuiState ( " movestate " , state ) ;
}
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < MAX_RENDERENTITY_GUI ; i + + )
{
if ( renderEntity . gui [ i ] )
{
2012-11-26 18:58:24 +00:00
renderEntity . gui [ i ] - > SetStateString ( " movestate " , state ) ;
renderEntity . gui [ i ] - > StateChanged ( gameLocal . slow . time , true ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_InitGuiTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_InitGuiTargets ( )
{
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_POS1 ] ) ;
}
/***********************************************************************
Translation control functions
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
= = = = = = = = = = = = = = = =
idMover : : Event_StopMoving
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_StopMoving ( )
{
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( dest_position ) ;
DoneMoving ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : DoneMoving
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : DoneMoving ( )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( lastCommand ! = MOVER_SPLINE )
{
2012-11-26 18:58:24 +00:00
// set our final position so that we get rid of any numerical inaccuracy
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_position , vec3_origin , vec3_origin ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_NONE ;
idThread : : ObjectMoveDone ( move_thread , this ) ;
move_thread = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StopSound ( SND_CHANNEL_BODY , false ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : UpdateMoveSound
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : UpdateMoveSound ( moveStage_t stage )
{
switch ( stage )
{
case ACCELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_accel " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
StartSound ( " snd_move " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case LINEAR_STAGE :
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_move " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case DECELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
StopSound ( SND_CHANNEL_BODY , false ) ;
StartSound ( " snd_decel " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case FINISHED_STAGE :
{
2012-11-26 18:58:24 +00:00
StopSound ( SND_CHANNEL_BODY , false ) ;
break ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_UpdateMove
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_UpdateMove ( )
{
2012-11-26 18:58:24 +00:00
idVec3 org ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( org ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
UpdateMoveSound ( move . stage ) ;
2012-11-28 15:47:07 +00:00
switch ( move . stage )
{
case ACCELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_ACCELLINEAR , gameLocal . slow . time , move . acceleration , org , move . dir , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
if ( move . movetime > 0 )
{
2012-11-26 18:58:24 +00:00
move . stage = LINEAR_STAGE ;
2012-11-28 15:47:07 +00:00
}
else if ( move . deceleration > 0 )
{
2012-11-26 18:58:24 +00:00
move . stage = DECELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
move . stage = FINISHED_STAGE ;
}
break ;
}
2012-11-28 15:47:07 +00:00
case LINEAR_STAGE :
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_LINEAR , gameLocal . slow . time , move . movetime , org , move . dir , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
if ( move . deceleration )
{
2012-11-26 18:58:24 +00:00
move . stage = DECELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
move . stage = FINISHED_STAGE ;
}
break ;
}
2012-11-28 15:47:07 +00:00
case DECELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_DECELLINEAR , gameLocal . slow . time , move . deceleration , org , move . dir , vec3_origin ) ;
move . stage = FINISHED_STAGE ;
break ;
}
2012-11-28 15:47:07 +00:00
case FINISHED_STAGE :
{
if ( g_debugMover . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' move done \n " , gameLocal . slow . time , name . c_str ( ) ) ;
}
DoneMoving ( ) ;
break ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : BeginMove
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : BeginMove ( idThread * thread )
{
2012-11-26 18:58:24 +00:00
moveStage_t stage ;
idVec3 org ;
float dist ;
float acceldist ;
int totalacceltime ;
int at ;
int dt ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_MOVING ;
move_thread = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( org ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
move_delta = dest_position - org ;
2012-11-28 15:47:07 +00:00
if ( move_delta . Compare ( vec3_zero ) )
{
2012-11-26 18:58:24 +00:00
DoneMoving ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// scale times up to whole physics frames
at = idPhysics : : SnapTimeToPhysicsFrame ( acceltime ) ;
move_time + = at - acceltime ;
acceltime = at ;
dt = idPhysics : : SnapTimeToPhysicsFrame ( deceltime ) ;
move_time + = dt - deceltime ;
deceltime = dt ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if we're moving at a specific speed, we need to calculate the move time
2012-11-28 15:47:07 +00:00
if ( move_speed )
{
2012-11-26 18:58:24 +00:00
dist = move_delta . Length ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
totalacceltime = acceltime + deceltime ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// calculate the distance we'll move during acceleration and deceleration
acceldist = totalacceltime * 0.5f * 0.001f * move_speed ;
2012-11-28 15:47:07 +00:00
if ( acceldist > = dist )
{
2012-11-26 18:58:24 +00:00
// going too slow for this distance to move at a constant speed
move_time = totalacceltime ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// calculate move time taking acceleration into account
move_time = totalacceltime + 1000.0f * ( dist - acceldist ) / move_speed ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// scale time up to a whole physics frames
move_time = idPhysics : : SnapTimeToPhysicsFrame ( move_time ) ;
2012-11-28 15:47:07 +00:00
if ( acceltime )
{
2012-11-26 18:58:24 +00:00
stage = ACCELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else if ( move_time < = deceltime )
{
2012-11-26 18:58:24 +00:00
stage = DECELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
stage = LINEAR_STAGE ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
at = acceltime ;
dt = deceltime ;
2012-11-28 15:47:07 +00:00
if ( at + dt > move_time )
{
2012-11-26 18:58:24 +00:00
// there's no real correct way to handle this, so we just scale
// the times to fit into the move time in the same proportions
at = idPhysics : : SnapTimeToPhysicsFrame ( at * move_time / ( at + dt ) ) ;
dt = move_time - at ;
}
2012-11-28 15:47:07 +00:00
move_delta = move_delta * ( 1000.0f / ( ( float ) move_time - ( at + dt ) * 0.5f ) ) ;
2012-11-26 18:58:24 +00:00
move . stage = stage ;
move . acceleration = at ;
move . movetime = move_time - at - dt ;
move . deceleration = dt ;
move . dir = move_delta ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_ReachedPos ) ;
}
/***********************************************************************
Rotation control functions
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
= = = = = = = = = = = = = = = =
idMover : : Event_StopRotating
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_StopRotating ( )
{
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( dest_angles ) ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_angles , ang_zero , ang_zero ) ;
DoneRotating ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : DoneRotating
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : DoneRotating ( )
{
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_NONE ;
idThread : : ObjectMoveDone ( rotate_thread , this ) ;
rotate_thread = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StopSound ( SND_CHANNEL_BODY , false ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : UpdateRotationSound
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : UpdateRotationSound ( moveStage_t stage )
{
switch ( stage )
{
case ACCELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_accel " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
StartSound ( " snd_move " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case LINEAR_STAGE :
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_move " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case DECELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
StopSound ( SND_CHANNEL_BODY , false ) ;
StartSound ( " snd_decel " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case FINISHED_STAGE :
{
2012-11-26 18:58:24 +00:00
StopSound ( SND_CHANNEL_BODY , false ) ;
break ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_UpdateRotation
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_UpdateRotation ( )
{
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
UpdateRotationSound ( rot . stage ) ;
2012-11-28 15:47:07 +00:00
switch ( rot . stage )
{
case ACCELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_ACCELLINEAR , gameLocal . slow . time , rot . acceleration , ang , rot . rot , ang_zero ) ;
2012-11-28 15:47:07 +00:00
if ( rot . movetime > 0 )
{
2012-11-26 18:58:24 +00:00
rot . stage = LINEAR_STAGE ;
2012-11-28 15:47:07 +00:00
}
else if ( rot . deceleration > 0 )
{
2012-11-26 18:58:24 +00:00
rot . stage = DECELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
rot . stage = FINISHED_STAGE ;
}
break ;
}
2012-11-28 15:47:07 +00:00
case LINEAR_STAGE :
{
if ( ! stopRotation & & ! rot . deceleration )
{
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_LINEAR | EXTRAPOLATION_NOSTOP ) , gameLocal . slow . time , rot . movetime , ang , rot . rot , ang_zero ) ;
}
else
{
2012-11-26 18:58:24 +00:00
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_LINEAR , gameLocal . slow . time , rot . movetime , ang , rot . rot , ang_zero ) ;
}
2012-11-28 15:47:07 +00:00
if ( rot . deceleration )
{
2012-11-26 18:58:24 +00:00
rot . stage = DECELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
rot . stage = FINISHED_STAGE ;
}
break ;
}
2012-11-28 15:47:07 +00:00
case DECELERATION_STAGE :
{
2012-11-26 18:58:24 +00:00
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_DECELLINEAR , gameLocal . slow . time , rot . deceleration , ang , rot . rot , ang_zero ) ;
rot . stage = FINISHED_STAGE ;
break ;
}
2012-11-28 15:47:07 +00:00
case FINISHED_STAGE :
{
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_NONE ;
2012-11-28 15:47:07 +00:00
if ( stopRotation )
{
2012-11-26 18:58:24 +00:00
// set our final angles so that we get rid of any numerical inaccuracy
dest_angles . Normalize360 ( ) ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_angles , ang_zero , ang_zero ) ;
stopRotation = false ;
2012-11-28 15:47:07 +00:00
}
else if ( physicsObj . GetAngularExtrapolationType ( ) = = EXTRAPOLATION_ACCELLINEAR )
{
2012-11-26 18:58:24 +00:00
// keep our angular velocity constant
2012-11-28 15:47:07 +00:00
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_LINEAR | EXTRAPOLATION_NOSTOP ) , gameLocal . slow . time , 0 , ang , rot . rot , ang_zero ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
if ( g_debugMover . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' rotation done \n " , gameLocal . slow . time , name . c_str ( ) ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
DoneRotating ( ) ;
break ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : BeginRotation
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : BeginRotation ( idThread * thread , bool stopwhendone )
{
2012-11-26 18:58:24 +00:00
moveStage_t stage ;
idAngles ang ;
int at ;
int dt ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_ROTATING ;
rotate_thread = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// rotation always uses move_time so that if a move was started before the rotation,
// the rotation will take the same amount of time as the move. If no move has been
// started and no time is set, the rotation takes 1 second.
2012-11-28 15:47:07 +00:00
if ( ! move_time )
{
2012-11-26 18:58:24 +00:00
move_time = 1 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
angle_delta = dest_angles - ang ;
2012-11-28 15:47:07 +00:00
if ( angle_delta = = ang_zero )
{
2012-11-26 18:58:24 +00:00
// set our final angles so that we get rid of any numerical inaccuracy
dest_angles . Normalize360 ( ) ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_angles , ang_zero , ang_zero ) ;
stopRotation = false ;
DoneRotating ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// scale times up to whole physics frames
at = idPhysics : : SnapTimeToPhysicsFrame ( acceltime ) ;
move_time + = at - acceltime ;
acceltime = at ;
dt = idPhysics : : SnapTimeToPhysicsFrame ( deceltime ) ;
move_time + = dt - deceltime ;
deceltime = dt ;
move_time = idPhysics : : SnapTimeToPhysicsFrame ( move_time ) ;
2012-11-28 15:47:07 +00:00
if ( acceltime )
{
2012-11-26 18:58:24 +00:00
stage = ACCELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else if ( move_time < = deceltime )
{
2012-11-26 18:58:24 +00:00
stage = DECELERATION_STAGE ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
stage = LINEAR_STAGE ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
at = acceltime ;
dt = deceltime ;
2012-11-28 15:47:07 +00:00
if ( at + dt > move_time )
{
2012-11-26 18:58:24 +00:00
// there's no real correct way to handle this, so we just scale
// the times to fit into the move time in the same proportions
at = idPhysics : : SnapTimeToPhysicsFrame ( at * move_time / ( at + dt ) ) ;
dt = move_time - at ;
}
2012-11-28 15:47:07 +00:00
angle_delta = angle_delta * ( 1000.0f / ( ( float ) move_time - ( at + dt ) * 0.5f ) ) ;
2012-11-26 18:58:24 +00:00
stopRotation = stopwhendone | | ( dt ! = 0 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
rot . stage = stage ;
rot . acceleration = at ;
rot . movetime = move_time - at - dt ;
rot . deceleration = dt ;
rot . rot = angle_delta ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_ReachedAng ) ;
}
/***********************************************************************
2012-11-28 15:47:07 +00:00
Script callable routines
2012-11-26 18:58:24 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
= = = = = = = = = = = = = = =
idMover : : Event_TeamBlocked
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_TeamBlocked ( idEntity * blockedEntity , idEntity * blockingEntity )
{
if ( g_debugMover . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' stopped due to team member '%s' blocked by '%s' \n " , gameLocal . slow . time , name . c_str ( ) , blockedEntity - > name . c_str ( ) , blockingEntity - > name . c_str ( ) ) ;
}
}
/*
= = = = = = = = = = = = = = =
idMover : : Event_PartBlocked
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_PartBlocked ( idEntity * blockingEntity )
{
if ( damage > 0.0f )
{
2012-11-26 18:58:24 +00:00
blockingEntity - > Damage ( this , this , vec3_origin , " damage_moverCrush " , damage , INVALID_JOINT ) ;
}
2012-11-28 15:47:07 +00:00
if ( g_debugMover . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' blocked by '%s' \n " , gameLocal . slow . time , name . c_str ( ) , blockingEntity - > name . c_str ( ) ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetMoveSpeed
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetMoveSpeed ( float speed )
{
if ( speed < = 0 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Cannot set speed less than or equal to 0. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
move_speed = speed ;
move_time = 0 ; // move_time is calculated for each move when move_speed is non-0
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetMoveTime
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetMoveTime ( float time )
{
if ( time < = 0 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Cannot set time less than or equal to 0. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
move_speed = 0 ;
move_time = SEC2MS ( time ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetAccellerationTime
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetAccellerationTime ( float time )
{
if ( time < 0 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Cannot set acceleration time less than 0. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
acceltime = SEC2MS ( time ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetDecelerationTime
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetDecelerationTime ( float time )
{
if ( time < 0 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Cannot set deceleration time less than 0. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
deceltime = SEC2MS ( time ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_MoveTo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_MoveTo ( idEntity * ent )
{
if ( ent = = NULL )
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " Entity not found " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dest_position = GetLocalCoordinates ( ent - > GetPhysics ( ) - > GetOrigin ( ) ) ;
BeginMove ( idThread : : CurrentThread ( ) ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : MoveToPos
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : MoveToPos ( const idVec3 & pos )
{
2012-11-26 18:58:24 +00:00
dest_position = GetLocalCoordinates ( pos ) ;
BeginMove ( NULL ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_MoveToPos
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_MoveToPos ( idVec3 & pos )
{
2012-11-26 18:58:24 +00:00
MoveToPos ( pos ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_MoveDir
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_MoveDir ( float angle , float distance )
{
2012-11-26 18:58:24 +00:00
idVec3 dir ;
idVec3 org ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( org ) ;
VectorForDir ( angle , dir ) ;
dest_position = org + dir * distance ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BeginMove ( idThread : : CurrentThread ( ) ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_MoveAccelerateTo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_MoveAccelerateTo ( float speed , float time )
{
2012-11-26 18:58:24 +00:00
float v ;
idVec3 org , dir ;
int at ;
2012-11-28 15:47:07 +00:00
if ( time < 0 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " idMover::Event_MoveAccelerateTo: cannot set acceleration time less than 0. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dir = physicsObj . GetLinearVelocity ( ) ;
v = dir . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if not moving already
2012-11-28 15:47:07 +00:00
if ( v = = 0.0f )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " idMover::Event_MoveAccelerateTo: not moving. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if already moving faster than the desired speed
2012-11-28 15:47:07 +00:00
if ( v > = speed )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
at = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( time ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_MOVING ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( org ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
move . stage = ACCELERATION_STAGE ;
move . acceleration = at ;
move . movetime = 0 ;
move . deceleration = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StartSound ( " snd_accel " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
StartSound ( " snd_move " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_ACCELLINEAR , gameLocal . slow . time , move . acceleration , org , dir * ( speed - v ) , dir * v ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_MoveDecelerateTo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_MoveDecelerateTo ( float speed , float time )
{
2012-11-26 18:58:24 +00:00
float v ;
idVec3 org , dir ;
int dt ;
2012-11-28 15:47:07 +00:00
if ( time < 0 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " idMover::Event_MoveDecelerateTo: cannot set deceleration time less than 0. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dir = physicsObj . GetLinearVelocity ( ) ;
v = dir . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if not moving already
2012-11-28 15:47:07 +00:00
if ( v = = 0.0f )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " idMover::Event_MoveDecelerateTo: not moving. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if already moving slower than the desired speed
2012-11-28 15:47:07 +00:00
if ( v < = speed )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dt = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( time ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_MOVING ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( org ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
move . stage = DECELERATION_STAGE ;
move . acceleration = 0 ;
move . movetime = 0 ;
move . deceleration = dt ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StartSound ( " snd_decel " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
StartSound ( " snd_move " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_DECELLINEAR , gameLocal . slow . time , move . deceleration , org , dir * ( v - speed ) , dir * speed ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_RotateDownTo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_RotateDownTo ( int axis , float angle )
{
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
if ( ( axis < 0 ) | | ( axis > 2 ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Invalid axis " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dest_angles [ axis ] = angle ;
2012-11-28 15:47:07 +00:00
if ( dest_angles [ axis ] > ang [ axis ] )
{
2012-11-26 18:58:24 +00:00
dest_angles [ axis ] - = 360 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BeginRotation ( idThread : : CurrentThread ( ) , true ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_RotateUpTo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_RotateUpTo ( int axis , float angle )
{
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
if ( ( axis < 0 ) | | ( axis > 2 ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Invalid axis " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dest_angles [ axis ] = angle ;
2012-11-28 15:47:07 +00:00
if ( dest_angles [ axis ] < ang [ axis ] )
{
2012-11-26 18:58:24 +00:00
dest_angles [ axis ] + = 360 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BeginRotation ( idThread : : CurrentThread ( ) , true ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_RotateTo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_RotateTo ( idAngles & angles )
{
2012-11-26 18:58:24 +00:00
dest_angles = angles ;
BeginRotation ( idThread : : CurrentThread ( ) , true ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_Rotate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_Rotate ( idAngles & angles )
{
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
if ( rotate_thread )
{
2012-11-26 18:58:24 +00:00
DoneRotating ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
dest_angles = ang + angles * ( move_time - ( acceltime + deceltime ) / 2 ) * 0.001f ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BeginRotation ( idThread : : CurrentThread ( ) , false ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_RotateOnce
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_RotateOnce ( idAngles & angles )
{
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
if ( rotate_thread )
{
2012-11-26 18:58:24 +00:00
DoneRotating ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
dest_angles = ang + angles ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BeginRotation ( idThread : : CurrentThread ( ) , true ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_Bob
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_Bob ( float speed , float phase , idVec3 & depth )
{
2012-11-26 18:58:24 +00:00
idVec3 org ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalOrigin ( org ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetLinearExtrapolation ( extrapolation_t ( EXTRAPOLATION_DECELSINE | EXTRAPOLATION_NOSTOP ) , speed * 1000 * phase , speed * 500 , org , depth * 2.0f , vec3_origin ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_Sway
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_Sway ( float speed , float phase , idAngles & depth )
{
2012-11-26 18:58:24 +00:00
idAngles ang , angSpeed ;
float duration ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . GetLocalAngles ( ang ) ;
2012-11-28 15:47:07 +00:00
assert ( speed > 0.0f ) ;
2012-11-26 18:58:24 +00:00
duration = idMath : : Sqrt ( depth [ 0 ] * depth [ 0 ] + depth [ 1 ] * depth [ 1 ] + depth [ 2 ] * depth [ 2 ] ) / speed ;
angSpeed = depth / ( duration * idMath : : SQRT_1OVER2 ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_DECELSINE | EXTRAPOLATION_NOSTOP ) , duration * 1000.0f * phase , duration * 1000.0f , ang , angSpeed , ang_zero ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_OpenPortal
Sets the portal associtated with this mover to be open
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_OpenPortal ( )
{
if ( areaPortal )
{
2012-11-26 18:58:24 +00:00
SetPortalState ( true ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_ClosePortal
Sets the portal associtated with this mover to be closed
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_ClosePortal ( )
{
if ( areaPortal )
{
2012-11-26 18:58:24 +00:00
SetPortalState ( false ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetAccelSound
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetAccelSound ( const char * sound )
{
2012-11-26 18:58:24 +00:00
// refSound.SetSound( "accel", sound );
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetDecelSound
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetDecelSound ( const char * sound )
{
2012-11-26 18:58:24 +00:00
// refSound.SetSound( "decel", sound );
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_SetMoveSound
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_SetMoveSound ( const char * sound )
{
2012-11-26 18:58:24 +00:00
// refSound.SetSound( "move", sound );
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_EnableSplineAngles
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_EnableSplineAngles ( )
{
2012-11-26 18:58:24 +00:00
useSplineAngles = true ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_DisableSplineAngles
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_DisableSplineAngles ( )
{
2012-11-26 18:58:24 +00:00
useSplineAngles = false ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_RemoveInitialSplineAngles
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_RemoveInitialSplineAngles ( )
{
idCurve_Spline < idVec3 > * spline ;
2012-11-26 18:58:24 +00:00
idAngles ang ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spline = physicsObj . GetSpline ( ) ;
2012-11-28 15:47:07 +00:00
if ( ! spline )
{
2012-11-26 18:58:24 +00:00
return ;
}
ang = spline - > GetCurrentFirstDerivative ( 0 ) . ToAngles ( ) ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , - ang , ang_zero , ang_zero ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_StartSpline
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_StartSpline ( idEntity * splineEntity )
{
idCurve_Spline < idVec3 > * spline ;
if ( ! splineEntity )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Needed for savegames
splineEnt = splineEntity ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spline = splineEntity - > GetSpline ( ) ;
2012-11-28 15:47:07 +00:00
if ( ! spline )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastCommand = MOVER_SPLINE ;
move_thread = 0 ;
2012-11-28 15:47:07 +00:00
if ( acceltime + deceltime > move_time )
{
2012-11-26 18:58:24 +00:00
acceltime = move_time / 2 ;
deceltime = move_time - acceltime ;
}
move . stage = FINISHED_STAGE ;
move . acceleration = acceltime ;
move . movetime = move_time ;
move . deceleration = deceltime ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spline - > MakeUniform ( move_time ) ;
spline - > ShiftTime ( gameLocal . slow . time - spline - > GetTime ( 0 ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetSpline ( spline , move . acceleration , move . deceleration , useSplineAngles ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , dest_position , vec3_origin , vec3_origin ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_StopSpline
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_StopSpline ( )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetSpline ( NULL , 0 , 0 , useSplineAngles ) ;
splineEnt = NULL ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
Show ( ) ;
Event_StartSpline ( this ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_IsMoving
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_IsMoving ( )
{
if ( physicsObj . GetLinearExtrapolationType ( ) = = EXTRAPOLATION_NONE )
{
2012-11-26 18:58:24 +00:00
idThread : : ReturnInt ( false ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idThread : : ReturnInt ( true ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : Event_IsRotating
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : Event_IsRotating ( )
{
if ( physicsObj . GetAngularExtrapolationType ( ) = = EXTRAPOLATION_NONE )
{
2012-11-26 18:58:24 +00:00
idThread : : ReturnInt ( false ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idThread : : ReturnInt ( true ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
physicsObj . WriteToSnapshot ( msg ) ;
msg . WriteBits ( move . stage , 3 ) ;
msg . WriteBits ( rot . stage , 3 ) ;
WriteBindToSnapshot ( msg ) ;
WriteGUIToSnapshot ( msg ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
moveStage_t oldMoveStage = move . stage ;
moveStage_t oldRotStage = rot . stage ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . ReadFromSnapshot ( msg ) ;
2012-11-28 15:47:07 +00:00
move . stage = ( moveStage_t ) msg . ReadBits ( 3 ) ;
rot . stage = ( moveStage_t ) msg . ReadBits ( 3 ) ;
2012-11-26 18:58:24 +00:00
ReadBindFromSnapshot ( msg ) ;
ReadGUIFromSnapshot ( msg ) ;
2012-11-28 15:47:07 +00:00
if ( msg . HasChanged ( ) )
{
if ( move . stage ! = oldMoveStage )
{
2012-11-26 18:58:24 +00:00
UpdateMoveSound ( oldMoveStage ) ;
}
2012-11-28 15:47:07 +00:00
if ( rot . stage ! = oldRotStage )
{
2012-11-26 18:58:24 +00:00
UpdateRotationSound ( oldRotStage ) ;
}
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover : : SetPortalState
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover : : SetPortalState ( bool open )
{
2012-11-26 18:58:24 +00:00
assert ( areaPortal ) ;
gameLocal . SetPortalState ( areaPortal , open ? PS_BLOCK_NONE : PS_BLOCK_ALL ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idSplinePath , holds a spline path to be used by an idMover
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idSplinePath )
END_CLASS
/*
= = = = = = = = = = = = = = = =
idSplinePath : : idSplinePath
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idSplinePath : : idSplinePath ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idSplinePath : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSplinePath : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idElevator
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_PostArrival ( " postArrival " , NULL ) ;
const idEventDef EV_GotoFloor ( " gotoFloor " , " d " ) ;
const idEventDef EV_SetGuiStates ( " setGuiStates " ) ;
CLASS_DECLARATION ( idMover , idElevator )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idElevator : : Event_Activate )
EVENT ( EV_TeamBlocked , idElevator : : Event_TeamBlocked )
EVENT ( EV_PartBlocked , idElevator : : Event_PartBlocked )
EVENT ( EV_PostArrival , idElevator : : Event_PostFloorArrival )
EVENT ( EV_GotoFloor , idElevator : : Event_GotoFloor )
EVENT ( EV_Touch , idElevator : : Event_Touch )
EVENT ( EV_SetGuiStates , idElevator : : Event_SetGuiStates )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idElevator : : idElevator
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idElevator : : idElevator ( )
{
2012-11-26 18:58:24 +00:00
state = INIT ;
floorInfo . Clear ( ) ;
currentFloor = 0 ;
pendingFloor = 0 ;
lastFloor = 0 ;
controlsDisabled = false ;
lastTouchTime = 0 ;
returnFloor = 0 ;
returnTime = 0 ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
savefile - > WriteInt ( ( int ) state ) ;
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( floorInfo . Num ( ) ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > WriteVec3 ( floorInfo [ i ] . pos ) ;
savefile - > WriteString ( floorInfo [ i ] . door ) ;
savefile - > WriteInt ( floorInfo [ i ] . floor ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( currentFloor ) ;
savefile - > WriteInt ( pendingFloor ) ;
savefile - > WriteInt ( lastFloor ) ;
savefile - > WriteBool ( controlsDisabled ) ;
savefile - > WriteFloat ( returnTime ) ;
savefile - > WriteInt ( returnFloor ) ;
savefile - > WriteInt ( lastTouchTime ) ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
int i , num ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( ( int & ) state ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( num ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < num ; i + + )
{
2012-11-26 18:58:24 +00:00
floorInfo_s floor ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadVec3 ( floor . pos ) ;
savefile - > ReadString ( floor . door ) ;
savefile - > ReadInt ( floor . floor ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
floorInfo . Append ( floor ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( currentFloor ) ;
savefile - > ReadInt ( pendingFloor ) ;
savefile - > ReadInt ( lastFloor ) ;
savefile - > ReadBool ( controlsDisabled ) ;
savefile - > ReadFloat ( returnTime ) ;
savefile - > ReadInt ( returnFloor ) ;
savefile - > ReadInt ( lastTouchTime ) ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idStr str ;
int len1 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastFloor = 0 ;
currentFloor = 0 ;
pendingFloor = spawnArgs . GetInt ( " floor " , " 1 " ) ;
2012-11-28 15:47:07 +00:00
SetGuiStates ( ( pendingFloor = = 1 ) ? guiBinaryMoverStates [ 0 ] : guiBinaryMoverStates [ 1 ] ) ;
2012-11-26 18:58:24 +00:00
returnTime = spawnArgs . GetFloat ( " returnTime " ) ;
returnFloor = spawnArgs . GetInt ( " returnFloor " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
len1 = strlen ( " floorPos_ " ) ;
2012-11-28 15:47:07 +00:00
const idKeyValue * kv = spawnArgs . MatchPrefix ( " floorPos_ " , NULL ) ;
while ( kv )
{
2012-11-26 18:58:24 +00:00
str = kv - > GetKey ( ) . Right ( kv - > GetKey ( ) . Length ( ) - len1 ) ;
floorInfo_s fi ;
fi . floor = atoi ( str ) ;
fi . door = spawnArgs . GetString ( va ( " floorDoor_%i " , fi . floor ) ) ;
fi . pos = spawnArgs . GetVector ( kv - > GetKey ( ) ) ;
floorInfo . Append ( fi ) ;
kv = spawnArgs . MatchPrefix ( " floorPos_ " , kv ) ;
}
lastTouchTime = 0 ;
state = INIT ;
BecomeActive ( TH_THINK | TH_PHYSICS ) ;
PostEventMS ( & EV_Mover_InitGuiTargets , 0 ) ;
controlsDisabled = false ;
}
/*
= = = = = = = = = = = = = =
idElevator : : Event_Touch
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Event_Touch ( idEntity * other , trace_t * trace )
{
if ( common - > IsClient ( ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( gameLocal . slow . time < lastTouchTime + 2000 )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! other - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
lastTouchTime = gameLocal . slow . time ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_PHYSICS )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int triggerFloor = spawnArgs . GetInt ( " triggerFloor " ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " trigger " ) & & triggerFloor ! = currentFloor )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_GotoFloor , 0.25f , triggerFloor ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Think ( )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin ;
idMat3 masterAxis ;
2012-11-28 15:47:07 +00:00
idDoor * doorent = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( state = = INIT )
{
2012-11-26 18:58:24 +00:00
state = IDLE ;
2012-11-28 15:47:07 +00:00
if ( doorent )
{
2012-11-26 18:58:24 +00:00
doorent - > BindTeam ( this ) ;
doorent - > spawnArgs . Set ( " snd_open " , " " ) ;
doorent - > spawnArgs . Set ( " snd_close " , " " ) ;
doorent - > spawnArgs . Set ( " snd_opened " , " " ) ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
idDoor * door = GetDoor ( floorInfo [ i ] . door ) ;
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > SetCompanion ( doorent ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Event_GotoFloor ( pendingFloor ) ;
DisableAllDoors ( ) ;
SetGuiStates ( ( pendingFloor = = 1 ) ? guiBinaryMoverStates [ 0 ] : guiBinaryMoverStates [ 1 ] ) ;
2012-11-28 15:47:07 +00:00
}
else if ( state = = WAITING_ON_DOORS )
{
2012-11-26 18:58:24 +00:00
state = IDLE ;
2012-11-28 15:47:07 +00:00
if ( doorent ! = NULL & & doorent - > IsOpen ( ) )
{
2012-11-26 18:58:24 +00:00
state = WAITING_ON_DOORS ;
2012-11-28 15:47:07 +00:00
}
else
{
for ( int i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
idDoor * door = GetDoor ( floorInfo [ i ] . door ) ;
if ( door ! = NULL & & door - > IsOpen ( ) )
{
state = WAITING_ON_DOORS ;
2012-11-26 18:58:24 +00:00
break ;
}
}
}
2012-11-28 15:47:07 +00:00
if ( state = = IDLE )
{
2012-11-26 18:58:24 +00:00
lastFloor = currentFloor ;
currentFloor = pendingFloor ;
2012-11-28 15:47:07 +00:00
floorInfo_s * fi = GetFloorInfo ( currentFloor ) ;
if ( fi )
{
2012-11-26 18:58:24 +00:00
MoveToPos ( fi - > pos ) ;
}
}
2012-11-28 15:47:07 +00:00
}
2012-11-26 18:58:24 +00:00
RunPhysics ( ) ;
Present ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
int triggerFloor = spawnArgs . GetInt ( " triggerFloor " ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " trigger " ) & & triggerFloor ! = currentFloor )
{
2012-11-26 18:58:24 +00:00
Event_GotoFloor ( triggerFloor ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Event_TeamBlocked
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Event_TeamBlocked ( idEntity * blockedEntity , idEntity * blockingEntity )
{
if ( blockedEntity = = this )
{
2012-11-26 18:58:24 +00:00
Event_GotoFloor ( lastFloor ) ;
2012-11-28 15:47:07 +00:00
}
else if ( blockedEntity & & blockedEntity - > IsType ( idDoor : : Type ) )
{
2012-11-26 18:58:24 +00:00
// open the inner doors if one is blocked
2012-11-28 15:47:07 +00:00
idDoor * blocked = static_cast < idDoor * > ( blockedEntity ) ;
idDoor * door = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( door ! = NULL & & blocked - > GetMoveMaster ( ) = = door - > GetMoveMaster ( ) )
{
door - > SetBlocked ( true ) ;
2012-11-26 18:58:24 +00:00
OpenInnerDoor ( ) ;
OpenFloorDoor ( currentFloor ) ;
}
}
}
/*
= = = = = = = = = = = = = = =
idElevator : : HandleSingleGuiCommand
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idElevator : : HandleSingleGuiCommand ( idEntity * entityGui , idLexer * src )
{
2012-11-26 18:58:24 +00:00
idToken token ;
2012-11-28 15:47:07 +00:00
if ( controlsDisabled )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
if ( ! src - > ReadToken ( & token ) )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
if ( token = = " ; " )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
if ( token . Icmp ( " changefloor " ) = = 0 )
{
if ( src - > ReadToken ( & token ) )
{
2012-11-26 18:58:24 +00:00
int newFloor = atoi ( token ) ;
2012-11-28 15:47:07 +00:00
if ( newFloor = = currentFloor )
{
2012-11-26 18:58:24 +00:00
// open currentFloor and interior doors
OpenInnerDoor ( ) ;
OpenFloorDoor ( currentFloor ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_GotoFloor , newFloor ) ;
}
return true ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
src - > UnreadToken ( & token ) ;
return false ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : OpenFloorDoor
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : OpenFloorDoor ( int floor )
{
floorInfo_s * fi = GetFloorInfo ( floor ) ;
if ( fi )
{
idDoor * door = GetDoor ( fi - > door ) ;
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Open ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : OpenInnerDoor
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : OpenInnerDoor ( )
{
idDoor * door = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Open ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : GetFloorInfo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
floorInfo_s * idElevator : : GetFloorInfo ( int floor )
{
for ( int i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
if ( floorInfo [ i ] . floor = = floor )
{
2012-11-26 18:58:24 +00:00
return & floorInfo [ i ] ;
}
}
return NULL ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Event_GotoFloor
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Event_GotoFloor ( int floor )
{
floorInfo_s * fi = GetFloorInfo ( floor ) ;
if ( fi )
{
2012-11-26 18:58:24 +00:00
DisableAllDoors ( ) ;
CloseAllDoors ( ) ;
state = WAITING_ON_DOORS ;
pendingFloor = floor ;
}
// If the inner door is blocked, repost this event
2012-11-28 15:47:07 +00:00
idDoor * door = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( door )
{
if ( door - > IsBlocked ( ) | | door - > IsOpen ( ) )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_GotoFloor , 0.5f , floor ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : BeginMove
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : BeginMove ( idThread * thread )
{
2012-11-26 18:58:24 +00:00
controlsDisabled = true ;
CloseAllDoors ( ) ;
DisableAllDoors ( ) ;
2012-11-28 15:47:07 +00:00
const idKeyValue * kv = spawnArgs . MatchPrefix ( " statusGui " ) ;
while ( kv )
{
idEntity * ent = gameLocal . FindEntity ( kv - > GetValue ( ) ) ;
if ( ent )
{
for ( int j = 0 ; j < MAX_RENDERENTITY_GUI ; j + + )
{
if ( ent - > GetRenderEntity ( ) & & ent - > GetRenderEntity ( ) - > gui [ j ] )
{
2012-11-26 18:58:24 +00:00
ent - > GetRenderEntity ( ) - > gui [ j ] - > SetStateString ( " floor " , " " ) ;
ent - > GetRenderEntity ( ) - > gui [ j ] - > StateChanged ( gameLocal . slow . time , true ) ;
}
}
ent - > UpdateVisuals ( ) ;
}
kv = spawnArgs . MatchPrefix ( " statusGui " , kv ) ;
}
SetGuiStates ( ( pendingFloor = = 1 ) ? guiBinaryMoverStates [ 3 ] : guiBinaryMoverStates [ 2 ] ) ;
idMover : : BeginMove ( thread ) ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : GetDoor
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idDoor * idElevator : : GetDoor ( const char * name )
{
idEntity * ent ;
idEntity * master ;
idDoor * doorEnt ;
2012-11-26 18:58:24 +00:00
doorEnt = NULL ;
2012-11-28 15:47:07 +00:00
if ( name & & * name )
{
2012-11-26 18:58:24 +00:00
ent = gameLocal . FindEntity ( name ) ;
2012-11-28 15:47:07 +00:00
if ( ent & & ent - > IsType ( idDoor : : Type ) )
{
2012-11-26 18:58:24 +00:00
doorEnt = static_cast < idDoor * > ( ent ) ;
master = doorEnt - > GetMoveMaster ( ) ;
2012-11-28 15:47:07 +00:00
if ( master ! = doorEnt )
{
if ( master - > IsType ( idDoor : : Type ) )
{
2012-11-26 18:58:24 +00:00
doorEnt = static_cast < idDoor * > ( master ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
doorEnt = NULL ;
}
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return doorEnt ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : Event_PostFloorArrival
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : Event_PostFloorArrival ( )
{
2012-11-26 18:58:24 +00:00
OpenFloorDoor ( currentFloor ) ;
OpenInnerDoor ( ) ;
SetGuiStates ( ( currentFloor = = 1 ) ? guiBinaryMoverStates [ 0 ] : guiBinaryMoverStates [ 1 ] ) ;
controlsDisabled = false ;
2012-11-28 15:47:07 +00:00
if ( returnTime > 0.0f & & returnFloor ! = currentFloor )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_GotoFloor , returnTime , returnFloor ) ;
}
}
2012-11-28 15:47:07 +00:00
void idElevator : : Event_SetGuiStates ( )
{
2012-11-26 18:58:24 +00:00
SetGuiStates ( ( currentFloor = = 1 ) ? guiBinaryMoverStates [ 0 ] : guiBinaryMoverStates [ 1 ] ) ;
}
/*
= = = = = = = = = = = = = = = =
idElevator : : DoneMoving
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : DoneMoving ( )
{
2012-11-26 18:58:24 +00:00
idMover : : DoneMoving ( ) ;
EnableProperDoors ( ) ;
2012-11-28 15:47:07 +00:00
const idKeyValue * kv = spawnArgs . MatchPrefix ( " statusGui " ) ;
while ( kv )
{
idEntity * ent = gameLocal . FindEntity ( kv - > GetValue ( ) ) ;
if ( ent )
{
for ( int j = 0 ; j < MAX_RENDERENTITY_GUI ; j + + )
{
if ( ent - > GetRenderEntity ( ) & & ent - > GetRenderEntity ( ) - > gui [ j ] )
{
2012-11-26 18:58:24 +00:00
ent - > GetRenderEntity ( ) - > gui [ j ] - > SetStateString ( " floor " , va ( " %i " , currentFloor ) ) ;
ent - > GetRenderEntity ( ) - > gui [ j ] - > StateChanged ( gameLocal . slow . time , true ) ;
}
}
ent - > UpdateVisuals ( ) ;
}
kv = spawnArgs . MatchPrefix ( " statusGui " , kv ) ;
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetInt ( " pauseOnFloor " , " -1 " ) = = currentFloor )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_PostArrival , spawnArgs . GetFloat ( " pauseTime " ) ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
Event_PostFloorArrival ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : CloseAllDoors
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : CloseAllDoors ( )
{
idDoor * door = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Close ( ) ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
door = GetDoor ( floorInfo [ i ] . door ) ;
2012-11-28 15:47:07 +00:00
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Close ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : DisableAllDoors
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : DisableAllDoors ( )
{
idDoor * door = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Enable ( false ) ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
door = GetDoor ( floorInfo [ i ] . door ) ;
2012-11-28 15:47:07 +00:00
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Enable ( false ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idElevator : : EnableProperDoors
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idElevator : : EnableProperDoors ( )
{
idDoor * door = GetDoor ( spawnArgs . GetString ( " innerdoor " ) ) ;
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Enable ( true ) ;
}
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < floorInfo . Num ( ) ; i + + )
{
if ( floorInfo [ i ] . floor = = currentFloor )
{
2012-11-26 18:58:24 +00:00
door = GetDoor ( floorInfo [ i ] . door ) ;
2012-11-28 15:47:07 +00:00
if ( door )
{
2012-11-26 18:58:24 +00:00
door - > Enable ( true ) ;
break ;
}
}
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idMover_Binary
Doors , plats , and buttons are all binary ( two position ) movers
Pos1 is " at rest " , pos2 is " activated "
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_Mover_ReturnToPos1 ( " <returntopos1> " , NULL ) ;
const idEventDef EV_Mover_MatchTeam ( " <matchteam> " , " dd " ) ;
const idEventDef EV_Mover_Enable ( " enable " , NULL ) ;
const idEventDef EV_Mover_Disable ( " disable " , NULL ) ;
CLASS_DECLARATION ( idEntity , idMover_Binary )
2012-11-28 15:47:07 +00:00
EVENT ( EV_FindGuiTargets , idMover_Binary : : Event_FindGuiTargets )
EVENT ( EV_Thread_SetCallback , idMover_Binary : : Event_SetCallback )
EVENT ( EV_Mover_ReturnToPos1 , idMover_Binary : : Event_ReturnToPos1 )
EVENT ( EV_Activate , idMover_Binary : : Event_Use_BinaryMover )
EVENT ( EV_ReachedPos , idMover_Binary : : Event_Reached_BinaryMover )
EVENT ( EV_Mover_MatchTeam , idMover_Binary : : Event_MatchActivateTeam )
EVENT ( EV_Mover_Enable , idMover_Binary : : Event_Enable )
EVENT ( EV_Mover_Disable , idMover_Binary : : Event_Disable )
EVENT ( EV_Mover_OpenPortal , idMover_Binary : : Event_OpenPortal )
EVENT ( EV_Mover_ClosePortal , idMover_Binary : : Event_ClosePortal )
EVENT ( EV_Mover_InitGuiTargets , idMover_Binary : : Event_InitGuiTargets )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : idMover_Binary ( )
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idMover_Binary : : idMover_Binary ( )
{
2012-11-26 18:58:24 +00:00
pos1 . Zero ( ) ;
pos2 . Zero ( ) ;
moverState = MOVER_POS1 ;
moveMaster = NULL ;
activateChain = NULL ;
soundPos1 = 0 ;
sound1to2 = 0 ;
sound2to1 = 0 ;
soundPos2 = 0 ;
soundLoop = 0 ;
wait = 0.0f ;
damage = 0.0f ;
duration = 0 ;
accelTime = 0 ;
decelTime = 0 ;
activatedBy = this ;
stateStartTime = 0 ;
team . Clear ( ) ;
enabled = false ;
move_thread = 0 ;
updateStatus = 0 ;
areaPortal = 0 ;
blocked = false ;
playerOnly = false ;
fl . networkSync = true ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : ~ idMover_Binary
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idMover_Binary : : ~ idMover_Binary ( )
{
idMover_Binary * mover ;
2012-11-26 18:58:24 +00:00
// if this is the mover master
2012-11-28 15:47:07 +00:00
if ( this = = moveMaster )
{
2012-11-26 18:58:24 +00:00
// make the next mover in the chain the move master
2012-11-28 15:47:07 +00:00
for ( mover = moveMaster ; mover ; mover = mover - > activateChain )
{
2012-11-26 18:58:24 +00:00
mover - > moveMaster = this - > activateChain ;
}
}
2012-11-28 15:47:07 +00:00
else
{
2012-11-26 18:58:24 +00:00
// remove mover from the activate chain
2012-11-28 15:47:07 +00:00
for ( mover = moveMaster ; mover ; mover = mover - > activateChain )
{
if ( mover - > activateChain = = this )
{
2012-11-26 18:58:24 +00:00
mover - > activateChain = this - > activateChain ;
break ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteVec3 ( pos1 ) ;
savefile - > WriteVec3 ( pos2 ) ;
2012-11-28 15:47:07 +00:00
savefile - > WriteInt ( ( moverState_t ) moverState ) ;
2012-11-26 18:58:24 +00:00
savefile - > WriteObject ( moveMaster ) ;
savefile - > WriteObject ( activateChain ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( soundPos1 ) ;
savefile - > WriteInt ( sound1to2 ) ;
savefile - > WriteInt ( sound2to1 ) ;
savefile - > WriteInt ( soundPos2 ) ;
savefile - > WriteInt ( soundLoop ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( wait ) ;
savefile - > WriteFloat ( damage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( duration ) ;
savefile - > WriteInt ( accelTime ) ;
savefile - > WriteInt ( decelTime ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
activatedBy . Save ( savefile ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( stateStartTime ) ;
savefile - > WriteString ( team ) ;
savefile - > WriteBool ( enabled ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( move_thread ) ;
savefile - > WriteInt ( updateStatus ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( buddies . Num ( ) ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < buddies . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > WriteString ( buddies [ i ] ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteStaticObject ( physicsObj ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( areaPortal ) ;
2012-11-28 15:47:07 +00:00
if ( areaPortal )
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( gameRenderWorld - > GetPortalState ( areaPortal ) ) ;
}
savefile - > WriteBool ( blocked ) ;
savefile - > WriteBool ( playerOnly ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( guiTargets . Num ( ) ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < guiTargets . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
guiTargets [ i ] . Save ( savefile ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
int i , num , portalState ;
idStr temp ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadVec3 ( pos1 ) ;
savefile - > ReadVec3 ( pos2 ) ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( ( int & ) moverState ) ;
savefile - > ReadObject ( reinterpret_cast < idClass * & > ( moveMaster ) ) ;
savefile - > ReadObject ( reinterpret_cast < idClass * & > ( activateChain ) ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( soundPos1 ) ;
savefile - > ReadInt ( sound1to2 ) ;
savefile - > ReadInt ( sound2to1 ) ;
savefile - > ReadInt ( soundPos2 ) ;
savefile - > ReadInt ( soundLoop ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( wait ) ;
savefile - > ReadFloat ( damage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( duration ) ;
savefile - > ReadInt ( accelTime ) ;
savefile - > ReadInt ( decelTime ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
activatedBy . Restore ( savefile ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( stateStartTime ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadString ( team ) ;
savefile - > ReadBool ( enabled ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( move_thread ) ;
savefile - > ReadInt ( updateStatus ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( num ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < num ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadString ( temp ) ;
buddies . Append ( temp ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadStaticObject ( physicsObj ) ;
RestorePhysics ( & physicsObj ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( areaPortal ) ;
2012-11-28 15:47:07 +00:00
if ( areaPortal )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( portalState ) ;
gameLocal . SetPortalState ( areaPortal , portalState ) ;
}
savefile - > ReadBool ( blocked ) ;
savefile - > ReadBool ( playerOnly ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
guiTargets . Clear ( ) ;
savefile - > ReadInt ( num ) ;
guiTargets . SetNum ( num ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < num ; i + + )
{
2012-11-26 18:58:24 +00:00
guiTargets [ i ] . Restore ( savefile ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Spawn
Base class for all movers .
" wait " wait before returning ( 3 default , - 1 = never return )
" speed " movement speed
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Spawn ( )
{
idEntity * ent ;
const char * temp ;
2012-11-26 18:58:24 +00:00
move_thread = 0 ;
enabled = true ;
areaPortal = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
activateChain = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " wait " , " 0 " , wait ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetInt ( " updateStatus " , " 0 " , updateStatus ) ;
2012-11-28 15:47:07 +00:00
const idKeyValue * kv = spawnArgs . MatchPrefix ( " buddy " , NULL ) ;
while ( kv )
{
2012-11-26 18:58:24 +00:00
buddies . Append ( kv - > GetValue ( ) ) ;
kv = spawnArgs . MatchPrefix ( " buddy " , kv ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetString ( " team " , " " , & temp ) ;
team = temp ;
2012-11-28 15:47:07 +00:00
if ( ! team . Length ( ) )
{
2012-11-26 18:58:24 +00:00
ent = this ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// find the first entity spawned on this team (which could be us)
2012-11-28 15:47:07 +00:00
for ( ent = gameLocal . spawnedEntities . Next ( ) ; ent ! = NULL ; ent = ent - > spawnNode . Next ( ) )
{
if ( ent - > IsType ( idMover_Binary : : Type ) & & ! idStr : : Icmp ( static_cast < idMover_Binary * > ( ent ) - > team . c_str ( ) , temp ) )
{
2012-11-26 18:58:24 +00:00
break ;
}
}
2012-11-28 15:47:07 +00:00
if ( ! ent )
{
2012-11-26 18:58:24 +00:00
ent = this ;
}
}
2012-11-28 15:47:07 +00:00
moveMaster = static_cast < idMover_Binary * > ( ent ) ;
2012-11-26 18:58:24 +00:00
// create a physics team for the binary mover parts
2012-11-28 15:47:07 +00:00
if ( ent ! = this )
{
2012-11-26 18:58:24 +00:00
JoinTeam ( ent ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetSelf ( this ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetClipModel ( new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) , 1.0f ) ;
2012-11-26 18:58:24 +00:00
physicsObj . SetOrigin ( GetPhysics ( ) - > GetOrigin ( ) ) ;
physicsObj . SetAxis ( GetPhysics ( ) - > GetAxis ( ) ) ;
physicsObj . SetClipMask ( MASK_SOLID ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " solid " , " 1 " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetContents ( 0 ) ;
}
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " nopush " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetPusher ( 0 ) ;
}
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , GetPhysics ( ) - > GetOrigin ( ) , vec3_origin , vec3_origin ) ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , GetPhysics ( ) - > GetAxis ( ) . ToAngles ( ) , ang_zero , ang_zero ) ;
SetPhysics ( & physicsObj ) ;
2012-11-28 15:47:07 +00:00
if ( moveMaster ! = this )
{
2012-11-26 18:58:24 +00:00
JoinActivateTeam ( moveMaster ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idBounds soundOrigin ;
2012-11-28 15:47:07 +00:00
idMover_Binary * slave ;
2012-11-26 18:58:24 +00:00
soundOrigin . Clear ( ) ;
2012-11-28 15:47:07 +00:00
for ( slave = moveMaster ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
soundOrigin + = slave - > GetPhysics ( ) - > GetAbsBounds ( ) ;
}
moveMaster - > refSound . origin = soundOrigin . GetCenter ( ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . MatchPrefix ( " guiTarget " ) )
{
if ( gameLocal . GameState ( ) = = GAMESTATE_STARTUP )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_FindGuiTargets , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// not during spawn, so it's ok to get the targets
FindGuiTargets ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = =
idMover_Binary : : GetMovedir
The editor only specifies a single value for angles ( yaw ) ,
but we have special constants to generate an up or down direction .
Angles will be cleared , because it is being used to represent a direction
instead of an orientation .
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : GetMovedir ( float angle , idVec3 & movedir )
{
if ( angle = = - 1 )
{
2012-11-26 18:58:24 +00:00
movedir . Set ( 0 , 0 , 1 ) ;
2012-11-28 15:47:07 +00:00
}
else if ( angle = = - 2 )
{
2012-11-26 18:58:24 +00:00
movedir . Set ( 0 , 0 , - 1 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
movedir = idAngles ( 0 , angle , 0 ) . ToForward ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_SetCallback
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_SetCallback ( )
{
if ( ( moverState = = MOVER_1TO2 ) | | ( moverState = = MOVER_2TO1 ) )
{
2012-11-26 18:58:24 +00:00
move_thread = idThread : : CurrentThreadNum ( ) ;
idThread : : ReturnInt ( true ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
idThread : : ReturnInt ( false ) ;
}
}
/*
= = = = = = = = = = = = = = =
idMover_Binary : : UpdateMoverSound
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : UpdateMoverSound ( moverState_t state )
{
if ( moveMaster = = this )
{
switch ( state )
{
2012-11-26 18:58:24 +00:00
case MOVER_POS1 :
break ;
case MOVER_POS2 :
break ;
case MOVER_1TO2 :
StartSound ( " snd_open " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
break ;
case MOVER_2TO1 :
StartSound ( " snd_close " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
break ;
}
}
}
/*
= = = = = = = = = = = = = = =
idMover_Binary : : SetMoverState
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : SetMoverState ( moverState_t newstate , int time )
{
2012-11-26 18:58:24 +00:00
idVec3 delta ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
moverState = newstate ;
move_thread = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
UpdateMoverSound ( newstate ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
stateStartTime = time ;
2012-11-28 15:47:07 +00:00
switch ( moverState )
{
case MOVER_POS1 :
{
2012-11-26 18:58:24 +00:00
Signal ( SIG_MOVER_POS1 ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , time , 0 , pos1 , vec3_origin , vec3_origin ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case MOVER_POS2 :
{
2012-11-26 18:58:24 +00:00
Signal ( SIG_MOVER_POS2 ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , time , 0 , pos2 , vec3_origin , vec3_origin ) ;
break ;
}
2012-11-28 15:47:07 +00:00
case MOVER_1TO2 :
{
2012-11-26 18:58:24 +00:00
Signal ( SIG_MOVER_1TO2 ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_LINEAR , time , duration , pos1 , ( pos2 - pos1 ) * 1000.0f / duration , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
if ( accelTime ! = 0 | | decelTime ! = 0 )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearInterpolation ( time , accelTime , decelTime , duration , pos1 , pos2 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearInterpolation ( 0 , 0 , 0 , 0 , pos1 , pos2 ) ;
}
break ;
}
2012-11-28 15:47:07 +00:00
case MOVER_2TO1 :
{
2012-11-26 18:58:24 +00:00
Signal ( SIG_MOVER_2TO1 ) ;
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_LINEAR , time , duration , pos2 , ( pos1 - pos2 ) * 1000.0f / duration , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
if ( accelTime ! = 0 | | decelTime ! = 0 )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearInterpolation ( time , accelTime , decelTime , duration , pos2 , pos1 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearInterpolation ( 0 , 0 , 0 , 0 , pos1 , pos2 ) ;
}
break ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : MatchActivateTeam
All entities in a mover team will move from pos1 to pos2
in the same amount of time
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : MatchActivateTeam ( moverState_t newstate , int time )
{
idMover_Binary * slave ;
for ( slave = this ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > SetMoverState ( newstate , time ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Enable
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Enable ( bool b )
{
2012-11-26 18:58:24 +00:00
enabled = b ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_MatchActivateTeam
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_MatchActivateTeam ( moverState_t newstate , int time )
{
2012-11-26 18:58:24 +00:00
MatchActivateTeam ( newstate , time ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : BindTeam
2012-11-28 15:47:07 +00:00
All entities in a mover team will be bound
2012-11-26 18:58:24 +00:00
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : BindTeam ( idEntity * bindTo )
{
idMover_Binary * slave ;
for ( slave = this ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > Bind ( bindTo , true ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : JoinActivateTeam
Set all entities in a mover team to be enabled
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : JoinActivateTeam ( idMover_Binary * master )
{
2012-11-26 18:58:24 +00:00
this - > activateChain = master - > activateChain ;
master - > activateChain = this ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_Enable
Set all entities in a mover team to be enabled
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_Enable ( )
{
idMover_Binary * slave ;
for ( slave = moveMaster ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > Enable ( false ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_Disable
Set all entities in a mover team to be disabled
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_Disable ( )
{
idMover_Binary * slave ;
for ( slave = moveMaster ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > Enable ( false ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_OpenPortal
Sets the portal associtated with this mover to be open
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_OpenPortal ( )
{
idMover_Binary * slave ;
for ( slave = moveMaster ; slave ! = NULL ; slave = slave - > activateChain )
{
if ( slave - > areaPortal )
{
2012-11-26 18:58:24 +00:00
slave - > SetPortalState ( true ) ;
}
2012-11-28 15:47:07 +00:00
if ( slave - > playerOnly )
{
2012-11-26 18:58:24 +00:00
gameLocal . SetAASAreaState ( slave - > GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL , false ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_ClosePortal
Sets the portal associtated with this mover to be closed
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_ClosePortal ( )
{
idMover_Binary * slave ;
for ( slave = moveMaster ; slave ! = NULL ; slave = slave - > activateChain )
{
if ( ! slave - > IsHidden ( ) )
{
if ( slave - > areaPortal )
{
2012-11-26 18:58:24 +00:00
slave - > SetPortalState ( false ) ;
}
2012-11-28 15:47:07 +00:00
if ( slave - > playerOnly )
{
2012-11-26 18:58:24 +00:00
gameLocal . SetAASAreaState ( slave - > GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL , true ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_ReturnToPos1
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_ReturnToPos1 ( )
{
2012-11-26 18:58:24 +00:00
MatchActivateTeam ( MOVER_2TO1 , gameLocal . slow . time ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_Reached_BinaryMover
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_Reached_BinaryMover ( )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_1TO2 )
{
2012-11-26 18:58:24 +00:00
// reached pos2
idThread : : ObjectMoveDone ( move_thread , this ) ;
move_thread = 0 ;
2012-11-28 15:47:07 +00:00
if ( moveMaster = = this )
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_opened " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetMoverState ( MOVER_POS2 , gameLocal . slow . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_POS2 ] ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
UpdateBuddies ( 1 ) ;
2012-11-28 15:47:07 +00:00
if ( enabled & & wait > = 0 & & ! spawnArgs . GetBool ( " toggle " ) )
{
2012-11-26 18:58:24 +00:00
// return to pos1 after a delay
PostEventSec ( & EV_Mover_ReturnToPos1 , wait ) ;
}
// fire targets
ActivateTargets ( moveMaster - > GetActivator ( ) ) ;
2012-11-28 15:47:07 +00:00
SetBlocked ( false ) ;
}
else if ( moverState = = MOVER_2TO1 )
{
2012-11-26 18:58:24 +00:00
// reached pos1
idThread : : ObjectMoveDone ( move_thread , this ) ;
move_thread = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetMoverState ( MOVER_POS1 , gameLocal . slow . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_POS1 ] ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
UpdateBuddies ( 0 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// close areaportals
2012-11-28 15:47:07 +00:00
if ( moveMaster = = this )
{
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_Mover_ClosePortal ) ;
}
2012-11-28 15:47:07 +00:00
if ( enabled & & wait > = 0 & & spawnArgs . GetBool ( " continuous " ) )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Activate , wait , this ) ;
}
2012-11-28 15:47:07 +00:00
SetBlocked ( false ) ;
}
else
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Event_Reached_BinaryMover: bad moverState " ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : GotoPosition1
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : GotoPosition1 ( )
{
idMover_Binary * slave ;
2012-11-26 18:58:24 +00:00
int partial ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// only the master should control this
2012-11-28 15:47:07 +00:00
if ( moveMaster ! = this )
{
2012-11-26 18:58:24 +00:00
moveMaster - > GotoPosition1 ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_2TO1 ] ) ;
2012-11-28 15:47:07 +00:00
if ( ( moverState = = MOVER_POS1 ) | | ( moverState = = MOVER_2TO1 ) )
{
2012-11-26 18:58:24 +00:00
// already there, or on the way
return ;
}
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_POS2 )
{
for ( slave = this ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > CancelEvents ( & EV_Mover_ReturnToPos1 ) ;
}
ProcessEvent ( & EV_Mover_ReturnToPos1 ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// only partway up before reversing
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_1TO2 )
{
2012-11-26 18:58:24 +00:00
// use the physics times because this might be executed during the physics simulation
partial = physicsObj . GetLinearEndTime ( ) - physicsObj . GetTime ( ) ;
assert ( partial > = 0 ) ;
2012-11-28 15:47:07 +00:00
if ( partial < 0 )
{
2012-11-26 18:58:24 +00:00
partial = 0 ;
}
MatchActivateTeam ( MOVER_2TO1 , physicsObj . GetTime ( ) - partial ) ;
// if already at at position 1 (partial == duration) execute the reached event
2012-11-28 15:47:07 +00:00
if ( partial > = duration )
{
2012-11-26 18:58:24 +00:00
Event_Reached_BinaryMover ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : GotoPosition2
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : GotoPosition2 ( )
{
2012-11-26 18:58:24 +00:00
int partial ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// only the master should control this
2012-11-28 15:47:07 +00:00
if ( moveMaster ! = this )
{
2012-11-26 18:58:24 +00:00
moveMaster - > GotoPosition2 ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_1TO2 ] ) ;
2012-11-28 15:47:07 +00:00
if ( ( moverState = = MOVER_POS2 ) | | ( moverState = = MOVER_1TO2 ) )
{
2012-11-26 18:58:24 +00:00
// already there, or on the way
return ;
}
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_POS1 )
{
2012-11-26 18:58:24 +00:00
MatchActivateTeam ( MOVER_1TO2 , gameLocal . slow . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// open areaportal
ProcessEvent ( & EV_Mover_OpenPortal ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// only partway up before reversing
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_2TO1 )
{
2012-11-26 18:58:24 +00:00
// use the physics times because this might be executed during the physics simulation
partial = physicsObj . GetLinearEndTime ( ) - physicsObj . GetTime ( ) ;
assert ( partial > = 0 ) ;
2012-11-28 15:47:07 +00:00
if ( partial < 0 )
{
2012-11-26 18:58:24 +00:00
partial = 0 ;
}
MatchActivateTeam ( MOVER_1TO2 , physicsObj . GetTime ( ) - partial ) ;
// if already at at position 2 (partial == duration) execute the reached event
2012-11-28 15:47:07 +00:00
if ( partial > = duration )
{
2012-11-26 18:58:24 +00:00
Event_Reached_BinaryMover ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : UpdateBuddies
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : UpdateBuddies ( int val )
{
2012-11-26 18:58:24 +00:00
int i , c ;
2012-11-28 15:47:07 +00:00
if ( updateStatus = = 2 )
{
c = buddies . Num ( ) ;
for ( i = 0 ; i < c ; i + + )
{
idEntity * buddy = gameLocal . FindEntity ( buddies [ i ] ) ;
if ( buddy )
{
2012-11-26 18:58:24 +00:00
buddy - > SetShaderParm ( SHADERPARM_MODE , val ) ;
buddy - > UpdateVisuals ( ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : SetGuiStates
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : SetGuiStates ( const char * state )
{
if ( guiTargets . Num ( ) )
{
2012-11-26 18:58:24 +00:00
SetGuiState ( " movestate " , state ) ;
}
2012-11-28 15:47:07 +00:00
idMover_Binary * mb = activateChain ;
while ( mb )
{
if ( mb - > guiTargets . Num ( ) )
{
2012-11-26 18:58:24 +00:00
mb - > SetGuiState ( " movestate " , state ) ;
}
mb = mb - > activateChain ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Use_BinaryMover
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Use_BinaryMover ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
// only the master should be used
2012-11-28 15:47:07 +00:00
if ( moveMaster ! = this )
{
2012-11-26 18:58:24 +00:00
moveMaster - > Use_BinaryMover ( activator ) ;
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! enabled )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
activatedBy = activator ;
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_POS1 )
{
2012-11-26 18:58:24 +00:00
// FIXME: start moving 1 ms later, because if this was player
// triggered, gameLocal.time hasn't been advanced yet
MatchActivateTeam ( MOVER_1TO2 , gameLocal . slow . time + 1 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_1TO2 ] ) ;
// open areaportal
ProcessEvent ( & EV_Mover_OpenPortal ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if all the way up, just delay before coming down
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_POS2 )
{
idMover_Binary * slave ;
if ( wait = = - 1 )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetGuiStates ( guiBinaryMoverStates [ MOVER_2TO1 ] ) ;
2012-11-28 15:47:07 +00:00
for ( slave = this ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > CancelEvents ( & EV_Mover_ReturnToPos1 ) ;
slave - > PostEventSec ( & EV_Mover_ReturnToPos1 , spawnArgs . GetBool ( " toggle " ) ? 0 : wait ) ;
}
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// only partway down before reversing
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_2TO1 )
{
2012-11-26 18:58:24 +00:00
GotoPosition2 ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// only partway up before reversing
2012-11-28 15:47:07 +00:00
if ( moverState = = MOVER_1TO2 )
{
2012-11-26 18:58:24 +00:00
GotoPosition1 ( ) ;
return ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_Use_BinaryMover
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_Use_BinaryMover ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
Use_BinaryMover ( activator ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : PreBind
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : PreBind ( )
{
2012-11-26 18:58:24 +00:00
pos1 = GetWorldCoordinates ( pos1 ) ;
pos2 = GetWorldCoordinates ( pos2 ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : PostBind
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : PostBind ( )
{
2012-11-26 18:58:24 +00:00
pos1 = GetLocalCoordinates ( pos1 ) ;
pos2 = GetLocalCoordinates ( pos2 ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : FindGuiTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : FindGuiTargets ( )
{
gameLocal . GetTargets ( spawnArgs , guiTargets , " guiTarget " ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idMover_Binary : : SetGuiState
key / val will be set to any renderEntity - > gui ' s on the list
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : SetGuiState ( const char * key , const char * val ) const
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < guiTargets . Num ( ) ; i + + )
{
idEntity * ent = guiTargets [ i ] . GetEntity ( ) ;
if ( ent )
{
for ( int j = 0 ; j < MAX_RENDERENTITY_GUI ; j + + )
{
if ( ent - > GetRenderEntity ( ) & & ent - > GetRenderEntity ( ) - > gui [ j ] )
{
2012-11-26 18:58:24 +00:00
ent - > GetRenderEntity ( ) - > gui [ j ] - > SetStateString ( key , val ) ;
ent - > GetRenderEntity ( ) - > gui [ j ] - > StateChanged ( gameLocal . slow . time , true ) ;
}
}
ent - > UpdateVisuals ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_InitGuiTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_FindGuiTargets ( )
{
2012-11-26 18:58:24 +00:00
FindGuiTargets ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : Event_InitGuiTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : Event_InitGuiTargets ( )
{
if ( guiTargets . Num ( ) )
{
2012-11-26 18:58:24 +00:00
SetGuiState ( " movestate " , guiBinaryMoverStates [ MOVER_POS1 ] ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : InitSpeed
pos1 , pos2 , and speed are passed in so the movement delta can be calculated
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : InitSpeed ( idVec3 & mpos1 , idVec3 & mpos2 , float mspeed , float maccelTime , float mdecelTime )
{
2012-11-26 18:58:24 +00:00
idVec3 move ;
float distance ;
float speed ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
pos1 = mpos1 ;
pos2 = mpos2 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
accelTime = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( maccelTime ) ) ;
decelTime = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( mdecelTime ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
speed = mspeed ? mspeed : 100 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// calculate time to reach second position from speed
move = pos2 - pos1 ;
distance = move . Length ( ) ;
duration = idPhysics : : SnapTimeToPhysicsFrame ( distance * 1000 / speed ) ;
2012-11-28 15:47:07 +00:00
if ( duration < = 0 )
{
2012-11-26 18:58:24 +00:00
duration = 1 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
moverState = MOVER_POS1 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , pos1 , vec3_origin , vec3_origin ) ;
physicsObj . SetLinearInterpolation ( 0 , 0 , 0 , 0 , vec3_origin , vec3_origin ) ;
SetOrigin ( pos1 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Mover_InitGuiTargets , 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : InitTime
pos1 , pos2 , and time are passed in so the movement delta can be calculated
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : InitTime ( idVec3 & mpos1 , idVec3 & mpos2 , float mtime , float maccelTime , float mdecelTime )
{
2012-11-26 18:58:24 +00:00
pos1 = mpos1 ;
pos2 = mpos2 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
accelTime = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( maccelTime ) ) ;
decelTime = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( mdecelTime ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
duration = idPhysics : : SnapTimeToPhysicsFrame ( SEC2MS ( mtime ) ) ;
2012-11-28 15:47:07 +00:00
if ( duration < = 0 )
{
2012-11-26 18:58:24 +00:00
duration = 1 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
moverState = MOVER_POS1 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , pos1 , vec3_origin , vec3_origin ) ;
physicsObj . SetLinearInterpolation ( 0 , 0 , 0 , 0 , vec3_origin , vec3_origin ) ;
SetOrigin ( pos1 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Mover_InitGuiTargets , 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : SetBlocked
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : SetBlocked ( bool b )
{
for ( idMover_Binary * slave = moveMaster ; slave ! = NULL ; slave = slave - > activateChain )
{
2012-11-26 18:58:24 +00:00
slave - > blocked = b ;
2012-11-28 15:47:07 +00:00
if ( b )
{
const idKeyValue * kv = slave - > spawnArgs . MatchPrefix ( " triggerBlocked " ) ;
while ( kv )
{
idEntity * ent = gameLocal . FindEntity ( kv - > GetValue ( ) ) ;
if ( ent )
{
2012-11-26 18:58:24 +00:00
ent - > PostEventMS ( & EV_Activate , 0 , moveMaster - > GetActivator ( ) ) ;
}
kv = slave - > spawnArgs . MatchPrefix ( " triggerBlocked " , kv ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : IsBlocked
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idMover_Binary : : IsBlocked ( )
{
2012-11-26 18:58:24 +00:00
return blocked ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : GetActivator
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idEntity * idMover_Binary : : GetActivator ( ) const
{
2012-11-26 18:58:24 +00:00
return activatedBy . GetEntity ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
physicsObj . WriteToSnapshot ( msg ) ;
msg . WriteBits ( moverState , 3 ) ;
WriteBindToSnapshot ( msg ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
moverState_t oldMoverState = moverState ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . ReadFromSnapshot ( msg ) ;
2012-11-28 15:47:07 +00:00
moverState = ( moverState_t ) msg . ReadBits ( 3 ) ;
2012-11-26 18:58:24 +00:00
ReadBindFromSnapshot ( msg ) ;
2012-11-28 15:47:07 +00:00
if ( msg . HasChanged ( ) )
{
if ( moverState ! = oldMoverState )
{
2012-11-26 18:58:24 +00:00
UpdateMoverSound ( moverState ) ;
MatchActivateTeam ( moverState , gameLocal . slow . time ) ;
}
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Binary : : SetPortalState
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Binary : : SetPortalState ( bool open )
{
2012-11-26 18:58:24 +00:00
assert ( areaPortal ) ;
gameLocal . SetPortalState ( areaPortal , open ? PS_BLOCK_NONE : PS_BLOCK_ALL ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idDoor
A use can be triggered either by a touch function , by being shot , or by being
targeted by another entity .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_Door_StartOpen ( " <startOpen> " , NULL ) ;
const idEventDef EV_Door_SpawnDoorTrigger ( " <spawnDoorTrigger> " , NULL ) ;
const idEventDef EV_Door_SpawnSoundTrigger ( " <spawnSoundTrigger> " , NULL ) ;
const idEventDef EV_Door_Open ( " open " , NULL ) ;
const idEventDef EV_Door_Close ( " close " , NULL ) ;
const idEventDef EV_Door_Lock ( " lock " , " d " ) ;
const idEventDef EV_Door_IsOpen ( " isOpen " , NULL , ' f ' ) ;
const idEventDef EV_Door_IsLocked ( " isLocked " , NULL , ' f ' ) ;
CLASS_DECLARATION ( idMover_Binary , idDoor )
2012-11-28 15:47:07 +00:00
EVENT ( EV_TeamBlocked , idDoor : : Event_TeamBlocked )
EVENT ( EV_PartBlocked , idDoor : : Event_PartBlocked )
EVENT ( EV_Touch , idDoor : : Event_Touch )
EVENT ( EV_Activate , idDoor : : Event_Activate )
EVENT ( EV_Door_StartOpen , idDoor : : Event_StartOpen )
EVENT ( EV_Door_SpawnDoorTrigger , idDoor : : Event_SpawnDoorTrigger )
EVENT ( EV_Door_SpawnSoundTrigger , idDoor : : Event_SpawnSoundTrigger )
EVENT ( EV_Door_Open , idDoor : : Event_Open )
EVENT ( EV_Door_Close , idDoor : : Event_Close )
EVENT ( EV_Door_Lock , idDoor : : Event_Lock )
EVENT ( EV_Door_IsOpen , idDoor : : Event_IsOpen )
EVENT ( EV_Door_IsLocked , idDoor : : Event_Locked )
EVENT ( EV_ReachedPos , idDoor : : Event_Reached_BinaryMover )
EVENT ( EV_SpectatorTouch , idDoor : : Event_SpectatorTouch )
EVENT ( EV_Mover_OpenPortal , idDoor : : Event_OpenPortal )
EVENT ( EV_Mover_ClosePortal , idDoor : : Event_ClosePortal )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idDoor : : idDoor
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idDoor : : idDoor ( )
{
2012-11-26 18:58:24 +00:00
triggersize = 1.0f ;
crusher = false ;
noTouch = false ;
aas_area_closed = false ;
buddyStr . Clear ( ) ;
trigger = NULL ;
sndTrigger = NULL ;
nextSndTriggerTime = 0 ;
localTriggerOrigin . Zero ( ) ;
localTriggerAxis . Identity ( ) ;
requires . Clear ( ) ;
removeItem = 0 ;
syncLock . Clear ( ) ;
companionDoor = NULL ;
normalAxisIndex = 0 ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : ~ idDoor
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idDoor : : ~ idDoor ( )
{
if ( trigger )
{
2012-11-26 18:58:24 +00:00
delete trigger ;
}
2012-11-28 15:47:07 +00:00
if ( sndTrigger )
{
2012-11-26 18:58:24 +00:00
delete sndTrigger ;
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( triggersize ) ;
savefile - > WriteBool ( crusher ) ;
savefile - > WriteBool ( noTouch ) ;
savefile - > WriteBool ( aas_area_closed ) ;
savefile - > WriteString ( buddyStr ) ;
savefile - > WriteInt ( nextSndTriggerTime ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteVec3 ( localTriggerOrigin ) ;
savefile - > WriteMat3 ( localTriggerAxis ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteString ( requires ) ;
savefile - > WriteInt ( removeItem ) ;
savefile - > WriteString ( syncLock ) ;
savefile - > WriteInt ( normalAxisIndex ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteClipModel ( trigger ) ;
savefile - > WriteClipModel ( sndTrigger ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteObject ( companionDoor ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( triggersize ) ;
savefile - > ReadBool ( crusher ) ;
savefile - > ReadBool ( noTouch ) ;
savefile - > ReadBool ( aas_area_closed ) ;
SetAASAreaState ( aas_area_closed ) ;
savefile - > ReadString ( buddyStr ) ;
savefile - > ReadInt ( nextSndTriggerTime ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadVec3 ( localTriggerOrigin ) ;
savefile - > ReadMat3 ( localTriggerAxis ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadString ( requires ) ;
savefile - > ReadInt ( removeItem ) ;
savefile - > ReadString ( syncLock ) ;
savefile - > ReadInt ( normalAxisIndex ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadClipModel ( trigger ) ;
savefile - > ReadClipModel ( sndTrigger ) ;
2012-11-28 15:47:07 +00:00
savefile - > ReadObject ( reinterpret_cast < idClass * & > ( companionDoor ) ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idVec3 abs_movedir ;
float distance ;
idVec3 size ;
idVec3 movedir ;
float dir ;
float lip ;
bool start_open ;
float time ;
float speed ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// get the direction to move
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetFloat ( " movedir " , " 0 " , dir ) )
{
2012-11-26 18:58:24 +00:00
// no movedir, so angle defines movement direction and not orientation,
// a la oldschool Quake
SetAngles ( ang_zero ) ;
spawnArgs . GetFloat ( " angle " , " 0 " , dir ) ;
}
GetMovedir ( dir , movedir ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// default speed of 400
spawnArgs . GetFloat ( " speed " , " 400 " , speed ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// default wait of 2 seconds
spawnArgs . GetFloat ( " wait " , " 3 " , wait ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// default lip of 8 units
spawnArgs . GetFloat ( " lip " , " 8 " , lip ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// by default no damage
spawnArgs . GetFloat ( " damage " , " 0 " , damage ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// trigger size
spawnArgs . GetFloat ( " triggersize " , " 120 " , triggersize ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetBool ( " crusher " , " 0 " , crusher ) ;
spawnArgs . GetBool ( " start_open " , " 0 " , start_open ) ;
spawnArgs . GetBool ( " no_touch " , " 0 " , noTouch ) ;
spawnArgs . GetBool ( " player_only " , " 0 " , playerOnly ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// expects syncLock to be a door that must be closed before this door will open
spawnArgs . GetString ( " syncLock " , " " , syncLock ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetString ( " buddy " , " " , buddyStr ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetString ( " requires " , " " , requires ) ;
spawnArgs . GetInt ( " removeItem " , " 0 " , removeItem ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// ever separate piece of a door is considered solid when other team mates push entities
fl . solidForTeam = true ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// first position at start
pos1 = GetPhysics ( ) - > GetOrigin ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// calculate second position
abs_movedir [ 0 ] = idMath : : Fabs ( movedir [ 0 ] ) ;
abs_movedir [ 1 ] = idMath : : Fabs ( movedir [ 1 ] ) ;
abs_movedir [ 2 ] = idMath : : Fabs ( movedir [ 2 ] ) ;
size = GetPhysics ( ) - > GetAbsBounds ( ) [ 1 ] - GetPhysics ( ) - > GetAbsBounds ( ) [ 0 ] ;
distance = ( abs_movedir * size ) - lip ;
pos2 = pos1 + distance * movedir ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if "start_open", reverse position 1 and 2
2012-11-28 15:47:07 +00:00
if ( start_open )
{
2012-11-26 18:58:24 +00:00
// post it after EV_SpawnBind
2012-11-28 15:47:07 +00:00
PostEventMS ( & EV_Door_StartOpen , 1 ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " time " , " 1 " , time ) )
{
2012-11-26 18:58:24 +00:00
InitTime ( pos1 , pos2 , time , 0 , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
InitSpeed ( pos1 , pos2 , speed , 0 , 0 ) ;
}
2012-11-28 15:47:07 +00:00
if ( moveMaster = = this )
{
if ( health )
{
2012-11-26 18:58:24 +00:00
fl . takedamage = true ;
}
2012-11-28 15:47:07 +00:00
if ( noTouch | | health )
{
2012-11-26 18:58:24 +00:00
// non touch/shoot doors
PostEventMS ( & EV_Mover_MatchTeam , 0 , moverState , gameLocal . slow . time ) ;
2012-11-28 15:47:07 +00:00
const char * sndtemp = spawnArgs . GetString ( " snd_locked " ) ;
if ( spawnArgs . GetInt ( " locked " ) & & sndtemp & & * sndtemp )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Door_SpawnSoundTrigger , 0 ) ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// spawn trigger
PostEventMS ( & EV_Door_SpawnDoorTrigger , 0 ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// see if we are on an areaportal
areaPortal = gameRenderWorld - > FindPortal ( GetPhysics ( ) - > GetAbsBounds ( ) ) ;
2012-11-28 15:47:07 +00:00
if ( ! start_open )
{
2012-11-26 18:58:24 +00:00
// start closed
ProcessEvent ( & EV_Mover_ClosePortal ) ;
2012-11-28 15:47:07 +00:00
if ( playerOnly )
{
2012-11-26 18:58:24 +00:00
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL , true ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int locked = spawnArgs . GetInt ( " locked " ) ;
2012-11-28 15:47:07 +00:00
if ( locked )
{
2012-11-26 18:58:24 +00:00
// make sure all members of the team get locked
PostEventMS ( & EV_Door_Lock , 0 , locked ) ;
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " continuous " ) )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Activate , spawnArgs . GetFloat ( " delay " ) , this ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// sounds have a habit of stuttering when portals close, so make them unoccluded
refSound . parms . soundShaderFlags | = SSF_NO_OCCLUSION ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
companionDoor = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
enabled = true ;
blocked = false ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : ClientThink ( const int curTime , const float fraction , const bool predict )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin ;
idMat3 masterAxis ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idMover_Binary : : ClientThink ( curTime , fraction , predict ) ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_PHYSICS )
{
2012-11-26 18:58:24 +00:00
// update trigger position
2012-11-28 15:47:07 +00:00
if ( GetMasterPosition ( masterOrigin , masterAxis ) )
{
if ( trigger )
{
2012-11-26 18:58:24 +00:00
trigger - > Link ( gameLocal . clip , this , 0 , masterOrigin + localTriggerOrigin * masterAxis , localTriggerAxis * masterAxis ) ;
}
2012-11-28 15:47:07 +00:00
if ( sndTrigger )
{
2012-11-26 18:58:24 +00:00
sndTrigger - > Link ( gameLocal . clip , this , 0 , masterOrigin + localTriggerOrigin * masterAxis , localTriggerAxis * masterAxis ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Think ( )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin ;
idMat3 masterAxis ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idMover_Binary : : Think ( ) ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_PHYSICS )
{
2012-11-26 18:58:24 +00:00
// update trigger position
2012-11-28 15:47:07 +00:00
if ( GetMasterPosition ( masterOrigin , masterAxis ) )
{
if ( trigger )
{
2012-11-26 18:58:24 +00:00
trigger - > Link ( gameLocal . clip , this , 0 , masterOrigin + localTriggerOrigin * masterAxis , localTriggerAxis * masterAxis ) ;
}
2012-11-28 15:47:07 +00:00
if ( sndTrigger )
{
2012-11-26 18:58:24 +00:00
sndTrigger - > Link ( gameLocal . clip , this , 0 , masterOrigin + localTriggerOrigin * masterAxis , localTriggerAxis * masterAxis ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : PreBind
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : PreBind ( )
{
2012-11-26 18:58:24 +00:00
idMover_Binary : : PreBind ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : PostBind
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : PostBind ( )
{
2012-11-26 18:58:24 +00:00
idMover_Binary : : PostBind ( ) ;
GetLocalTriggerPosition ( trigger ? trigger : sndTrigger ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : SetAASAreaState
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : SetAASAreaState ( bool closed )
{
2012-11-26 18:58:24 +00:00
aas_area_closed = closed ;
2012-11-28 15:47:07 +00:00
gameLocal . SetAASAreaState ( physicsObj . GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL | AREACONTENTS_OBSTACLE , closed ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Hide
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Hide ( )
{
idMover_Binary * slave ;
idMover_Binary * master ;
idDoor * slaveDoor ;
idDoor * companion ;
2012-11-26 18:58:24 +00:00
master = GetMoveMaster ( ) ;
2012-11-28 15:47:07 +00:00
if ( this ! = master )
{
2012-11-26 18:58:24 +00:00
master - > Hide ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
for ( slave = this ; slave ! = NULL ; slave = slave - > GetActivateChain ( ) )
{
if ( slave - > IsType ( idDoor : : Type ) )
{
slaveDoor = static_cast < idDoor * > ( slave ) ;
2012-11-26 18:58:24 +00:00
companion = slaveDoor - > companionDoor ;
2012-11-28 15:47:07 +00:00
if ( companion & & ( companion ! = master ) & & ( companion - > GetMoveMaster ( ) ! = master ) )
{
2012-11-26 18:58:24 +00:00
companion - > Hide ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( slaveDoor - > trigger )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > trigger - > Disable ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( slaveDoor - > sndTrigger )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > sndTrigger - > Disable ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( slaveDoor - > areaPortal )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > SetPortalState ( true ) ;
}
slaveDoor - > SetAASAreaState ( false ) ;
}
slave - > GetPhysics ( ) - > GetClipModel ( ) - > Disable ( ) ;
slave - > idMover_Binary : : Hide ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Show
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Show ( )
{
idMover_Binary * slave ;
idMover_Binary * master ;
idDoor * slaveDoor ;
idDoor * companion ;
2012-11-26 18:58:24 +00:00
master = GetMoveMaster ( ) ;
2012-11-28 15:47:07 +00:00
if ( this ! = master )
{
2012-11-26 18:58:24 +00:00
master - > Show ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
for ( slave = this ; slave ! = NULL ; slave = slave - > GetActivateChain ( ) )
{
if ( slave - > IsType ( idDoor : : Type ) )
{
slaveDoor = static_cast < idDoor * > ( slave ) ;
2012-11-26 18:58:24 +00:00
companion = slaveDoor - > companionDoor ;
2012-11-28 15:47:07 +00:00
if ( companion & & ( companion ! = master ) & & ( companion - > GetMoveMaster ( ) ! = master ) )
{
2012-11-26 18:58:24 +00:00
companion - > Show ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( slaveDoor - > trigger )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > trigger - > Enable ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( slaveDoor - > sndTrigger )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > sndTrigger - > Enable ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( slaveDoor - > areaPortal & & ( slaveDoor - > moverState = = MOVER_POS1 ) )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > SetPortalState ( false ) ;
}
slaveDoor - > SetAASAreaState ( IsLocked ( ) | | IsNoTouch ( ) ) ;
}
slave - > GetPhysics ( ) - > GetClipModel ( ) - > Enable ( ) ;
slave - > idMover_Binary : : Show ( ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : GetLocalTriggerPosition
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : GetLocalTriggerPosition ( const idClipModel * trigger )
{
2012-11-26 18:58:24 +00:00
idVec3 origin ;
idMat3 axis ;
2012-11-28 15:47:07 +00:00
if ( ! trigger )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
GetMasterPosition ( origin , axis ) ;
localTriggerOrigin = ( trigger - > GetOrigin ( ) - origin ) * axis . Transpose ( ) ;
localTriggerAxis = trigger - > GetAxis ( ) * axis . Transpose ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Use
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Use ( idEntity * other , idEntity * activator )
{
if ( gameLocal . RequirementMet ( activator , requires , removeItem ) )
{
if ( syncLock . Length ( ) )
{
idEntity * sync = gameLocal . FindEntity ( syncLock ) ;
if ( sync ! = NULL & & sync - > IsType ( idDoor : : Type ) )
{
if ( static_cast < idDoor * > ( sync ) - > IsOpen ( ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
}
}
ActivateTargets ( activator ) ;
Use_BinaryMover ( activator ) ;
2012-11-28 15:47:07 +00:00
}
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Open
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Open ( )
{
2012-11-26 18:58:24 +00:00
GotoPosition2 ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Close
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Close ( )
{
2012-11-26 18:58:24 +00:00
GotoPosition1 ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Lock
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Lock ( int f )
{
idMover_Binary * other ;
2012-11-26 18:58:24 +00:00
// lock all the doors on the team
2012-11-28 15:47:07 +00:00
for ( other = moveMaster ; other ! = NULL ; other = other - > GetActivateChain ( ) )
{
if ( other - > IsType ( idDoor : : Type ) )
{
idDoor * door = static_cast < idDoor * > ( other ) ;
if ( other = = moveMaster )
{
if ( door - > sndTrigger = = NULL )
{
2012-11-26 18:58:24 +00:00
// in this case the sound trigger never got spawned
2012-11-28 15:47:07 +00:00
const char * sndtemp = door - > spawnArgs . GetString ( " snd_locked " ) ;
2012-12-11 22:48:55 +00:00
if ( sndtemp ! = NULL & & * sndtemp ! = ' \0 ' )
2012-11-28 15:47:07 +00:00
{
2012-11-26 18:58:24 +00:00
door - > PostEventMS ( & EV_Door_SpawnSoundTrigger , 0 ) ;
}
}
2012-11-28 15:47:07 +00:00
if ( ! f & & ( door - > spawnArgs . GetInt ( " locked " ) ! = 0 ) )
{
2012-11-26 18:58:24 +00:00
door - > StartSound ( " snd_unlocked " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
}
}
door - > spawnArgs . SetInt ( " locked " , f ) ;
2012-11-28 15:47:07 +00:00
if ( ( f = = 0 ) | | ( ! IsHidden ( ) & & ( door - > moverState = = MOVER_POS1 ) ) )
{
2012-11-26 18:58:24 +00:00
door - > SetAASAreaState ( f ! = 0 ) ;
}
}
}
2012-11-28 15:47:07 +00:00
if ( f )
{
2012-11-26 18:58:24 +00:00
Close ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : IsLocked
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
int idDoor : : IsLocked ( )
{
2012-11-26 18:58:24 +00:00
return spawnArgs . GetInt ( " locked " ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : IsOpen
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idDoor : : IsOpen ( )
{
2012-11-26 18:58:24 +00:00
return ( moverState ! = MOVER_POS1 ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : IsNoTouch
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idDoor : : IsNoTouch ( )
{
2012-11-26 18:58:24 +00:00
return noTouch ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : AllowPlayerOnly
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idDoor : : AllowPlayerOnly ( idEntity * ent )
{
if ( playerOnly & & ! ent - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
return false ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
return true ;
}
/*
= = = = = = = = = = = = = = = = = = = = = =
idDoor : : CalcTriggerBounds
Calcs bounds for a trigger .
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : CalcTriggerBounds ( float size , idBounds & bounds )
{
idMover_Binary * other ;
2012-11-26 18:58:24 +00:00
int i ;
int best ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// find the bounds of everything on the team
bounds = GetPhysics ( ) - > GetAbsBounds ( ) ;
fl . takedamage = true ;
2012-11-28 15:47:07 +00:00
for ( other = activateChain ; other ! = NULL ; other = other - > GetActivateChain ( ) )
{
if ( other - > IsType ( idDoor : : Type ) )
{
2012-11-26 18:58:24 +00:00
// find the bounds of everything on the team
bounds . AddBounds ( other - > GetPhysics ( ) - > GetAbsBounds ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// set all of the slaves as shootable
other - > fl . takedamage = true ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// find the thinnest axis, which will be the one we expand
best = 0 ;
2012-11-28 15:47:07 +00:00
for ( i = 1 ; i < 3 ; i + + )
{
if ( bounds [ 1 ] [ i ] - bounds [ 0 ] [ i ] < bounds [ 1 ] [ best ] - bounds [ 0 ] [ best ] )
{
2012-11-26 18:58:24 +00:00
best = i ;
}
}
normalAxisIndex = best ;
bounds [ 0 ] [ best ] - = size ;
bounds [ 1 ] [ best ] + = size ;
bounds [ 0 ] - = GetPhysics ( ) - > GetOrigin ( ) ;
bounds [ 1 ] - = GetPhysics ( ) - > GetOrigin ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = =
idDoor : : Event_StartOpen
if " start_open " , reverse position 1 and 2
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_StartOpen ( )
{
2012-11-26 18:58:24 +00:00
float time ;
float speed ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if "start_open", reverse position 1 and 2
pos1 = pos2 ;
pos2 = GetPhysics ( ) - > GetOrigin ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " speed " , " 400 " , speed ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " time " , " 1 " , time ) )
{
2012-11-26 18:58:24 +00:00
InitTime ( pos1 , pos2 , time , 0 , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
InitSpeed ( pos1 , pos2 , speed , 0 , 0 ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = =
idDoor : : Event_SpawnDoorTrigger
All of the parts of a door have been spawned , so create
a trigger that encloses all of them .
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_SpawnDoorTrigger ( )
{
2012-11-26 18:58:24 +00:00
idBounds bounds ;
2012-11-28 15:47:07 +00:00
idMover_Binary * other ;
2012-11-26 18:58:24 +00:00
bool toggle ;
2012-11-28 15:47:07 +00:00
if ( trigger )
{
2012-11-26 18:58:24 +00:00
// already have a trigger, so don't spawn a new one.
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check if any of the doors are marked as toggled
toggle = false ;
2012-11-28 15:47:07 +00:00
for ( other = moveMaster ; other ! = NULL ; other = other - > GetActivateChain ( ) )
{
if ( other - > IsType ( idDoor : : Type ) & & other - > spawnArgs . GetBool ( " toggle " ) )
{
2012-11-26 18:58:24 +00:00
toggle = true ;
break ;
}
}
2012-11-28 15:47:07 +00:00
if ( toggle )
{
2012-11-26 18:58:24 +00:00
// mark them all as toggled
2012-11-28 15:47:07 +00:00
for ( other = moveMaster ; other ! = NULL ; other = other - > GetActivateChain ( ) )
{
if ( other - > IsType ( idDoor : : Type ) )
{
2012-11-26 18:58:24 +00:00
other - > spawnArgs . Set ( " toggle " , " 1 " ) ;
}
}
// don't spawn trigger
return ;
}
2012-11-28 15:47:07 +00:00
const char * sndtemp = spawnArgs . GetString ( " snd_locked " ) ;
2012-12-11 22:48:55 +00:00
if ( spawnArgs . GetInt ( " locked " ) & & sndtemp ! = NULL & & * sndtemp ! = ' \0 ' )
2012-11-28 15:47:07 +00:00
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Door_SpawnSoundTrigger , 0 ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
CalcTriggerBounds ( triggersize , bounds ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// create a trigger clip model
2012-11-28 15:47:07 +00:00
trigger = new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( idTraceModel ( bounds ) ) ;
2012-11-26 18:58:24 +00:00
trigger - > Link ( gameLocal . clip , this , 255 , GetPhysics ( ) - > GetOrigin ( ) , mat3_identity ) ;
trigger - > SetContents ( CONTENTS_TRIGGER ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
GetLocalTriggerPosition ( trigger ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
MatchActivateTeam ( moverState , gameLocal . slow . time ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = =
idDoor : : Event_SpawnSoundTrigger
Spawn a sound trigger to activate locked sound if it exists .
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_SpawnSoundTrigger ( )
{
2012-11-26 18:58:24 +00:00
idBounds bounds ;
2012-11-28 15:47:07 +00:00
if ( sndTrigger )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
CalcTriggerBounds ( triggersize * 0.5f , bounds ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// create a trigger clip model
2012-11-28 15:47:07 +00:00
sndTrigger = new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( idTraceModel ( bounds ) ) ;
2012-11-26 18:58:24 +00:00
sndTrigger - > Link ( gameLocal . clip , this , 254 , GetPhysics ( ) - > GetOrigin ( ) , mat3_identity ) ;
sndTrigger - > SetContents ( CONTENTS_TRIGGER ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
GetLocalTriggerPosition ( sndTrigger ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Reached_BinaryMover
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Reached_BinaryMover ( )
{
if ( moverState = = MOVER_2TO1 )
{
2012-11-26 18:58:24 +00:00
SetBlocked ( false ) ;
2012-11-28 15:47:07 +00:00
const idKeyValue * kv = spawnArgs . MatchPrefix ( " triggerClosed " ) ;
while ( kv )
{
idEntity * ent = gameLocal . FindEntity ( kv - > GetValue ( ) ) ;
if ( ent )
{
2012-11-26 18:58:24 +00:00
ent - > PostEventMS ( & EV_Activate , 0 , moveMaster - > GetActivator ( ) ) ;
}
kv = spawnArgs . MatchPrefix ( " triggerClosed " , kv ) ;
}
2012-11-28 15:47:07 +00:00
}
else if ( moverState = = MOVER_1TO2 )
{
const idKeyValue * kv = spawnArgs . MatchPrefix ( " triggerOpened " ) ;
while ( kv )
{
idEntity * ent = gameLocal . FindEntity ( kv - > GetValue ( ) ) ;
if ( ent )
{
2012-11-26 18:58:24 +00:00
ent - > PostEventMS ( & EV_Activate , 0 , moveMaster - > GetActivator ( ) ) ;
}
kv = spawnArgs . MatchPrefix ( " triggerOpened " , kv ) ;
}
}
idMover_Binary : : Event_Reached_BinaryMover ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Blocked_Door
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_TeamBlocked ( idEntity * blockedEntity , idEntity * blockingEntity )
{
2012-11-26 18:58:24 +00:00
SetBlocked ( true ) ;
2012-11-28 15:47:07 +00:00
if ( crusher )
{
2012-11-26 18:58:24 +00:00
return ; // crushers don't reverse
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// reverse direction
Use_BinaryMover ( moveMaster - > GetActivator ( ) ) ;
2012-11-28 15:47:07 +00:00
if ( companionDoor )
{
2012-11-26 18:58:24 +00:00
companionDoor - > ProcessEvent ( & EV_TeamBlocked , blockedEntity , blockingEntity ) ;
}
}
/*
= = = = = = = = = = = = = = =
idDoor : : SetCompanion
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : SetCompanion ( idDoor * door )
{
2012-11-26 18:58:24 +00:00
companionDoor = door ;
}
/*
= = = = = = = = = = = = = = =
idDoor : : Event_PartBlocked
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_PartBlocked ( idEntity * blockingEntity )
{
if ( damage > 0.0f )
{
2012-11-26 18:58:24 +00:00
blockingEntity - > Damage ( this , this , vec3_origin , " damage_moverCrush " , damage , INVALID_JOINT ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Touch
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Touch ( idEntity * other , trace_t * trace )
{
2012-11-26 18:58:24 +00:00
idVec3 contact , translate ;
idVec3 planeaxis1 , planeaxis2 , normal ;
idBounds bounds ;
2012-11-28 15:47:07 +00:00
if ( common - > IsClient ( ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! enabled )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( trigger & & trace - > c . id = = trigger - > GetId ( ) )
{
if ( ! IsNoTouch ( ) & & ! IsLocked ( ) & & GetMoverState ( ) ! = MOVER_1TO2 )
{
if ( AllowPlayerOnly ( other ) )
{
2012-11-26 18:58:24 +00:00
Use ( this , other ) ;
}
}
2012-11-28 15:47:07 +00:00
}
else if ( sndTrigger & & trace - > c . id = = sndTrigger - > GetId ( ) )
{
if ( other & & other - > IsType ( idPlayer : : Type ) & & IsLocked ( ) & & gameLocal . slow . time > nextSndTriggerTime )
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_locked " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
nextSndTriggerTime = gameLocal . slow . time + 10000 ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_SpectatorTouch
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_SpectatorTouch ( idEntity * other , trace_t * trace )
{
2012-11-26 18:58:24 +00:00
idVec3 contact , translate , normal ;
idBounds bounds ;
2012-11-28 15:47:07 +00:00
idPlayer * p ;
assert ( other & & other - > IsType ( idPlayer : : Type ) & & static_cast < idPlayer * > ( other ) - > spectating ) ;
p = static_cast < idPlayer * > ( other ) ;
2012-11-26 18:58:24 +00:00
// avoid flicker when stopping right at clip box boundaries
2012-11-28 15:47:07 +00:00
if ( p - > lastSpectateTeleport > gameLocal . slow . time - 1000 )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( trigger & & ! IsOpen ( ) )
{
2012-11-26 18:58:24 +00:00
// teleport to the other side, center to the middle of the trigger brush
bounds = trigger - > GetAbsBounds ( ) ;
contact = trace - > endpos - bounds . GetCenter ( ) ;
translate = bounds . GetCenter ( ) ;
normal . Zero ( ) ;
normal [ normalAxisIndex ] = 1.0f ;
2012-11-28 15:47:07 +00:00
if ( normal * contact > 0 )
{
2012-11-26 18:58:24 +00:00
translate [ normalAxisIndex ] + = ( bounds [ 0 ] [ normalAxisIndex ] - translate [ normalAxisIndex ] ) * 0.5f ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
translate [ normalAxisIndex ] + = ( bounds [ 1 ] [ normalAxisIndex ] - translate [ normalAxisIndex ] ) * 0.5f ;
}
p - > SetOrigin ( translate ) ;
p - > lastSpectateTeleport = gameLocal . slow . time ;
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
int old_lock ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetInt ( " locked " ) )
{
if ( ! trigger )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Door_SpawnDoorTrigger , 0 ) ;
}
2012-11-28 15:47:07 +00:00
if ( buddyStr . Length ( ) )
{
idEntity * buddy = gameLocal . FindEntity ( buddyStr ) ;
if ( buddy )
{
2012-11-26 18:58:24 +00:00
buddy - > SetShaderParm ( SHADERPARM_MODE , 1 ) ;
buddy - > UpdateVisuals ( ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
old_lock = spawnArgs . GetInt ( " locked " ) ;
Lock ( 0 ) ;
2012-11-28 15:47:07 +00:00
if ( old_lock = = 2 )
{
2012-11-26 18:58:24 +00:00
return ;
}
}
2012-11-28 15:47:07 +00:00
if ( syncLock . Length ( ) )
{
idEntity * sync = gameLocal . FindEntity ( syncLock ) ;
if ( sync ! = NULL & & sync - > IsType ( idDoor : : Type ) )
{
if ( static_cast < idDoor * > ( sync ) - > IsOpen ( ) )
{
return ;
}
}
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ActivateTargets ( activator ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_MODE ] = 1 ;
UpdateVisuals ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Use_BinaryMover ( activator ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Open
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Open ( )
{
2012-11-26 18:58:24 +00:00
Open ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Close
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Close ( )
{
2012-11-26 18:58:24 +00:00
Close ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Lock
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Lock ( int f )
{
2012-11-26 18:58:24 +00:00
Lock ( f ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_IsOpen
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_IsOpen ( )
{
2012-11-26 18:58:24 +00:00
bool state ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
state = IsOpen ( ) ;
idThread : : ReturnFloat ( state ) ;
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_Locked
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_Locked ( )
{
idThread : : ReturnFloat ( spawnArgs . GetInt ( " locked " ) ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_OpenPortal
Sets the portal associtated with this door to be open
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_OpenPortal ( )
{
idMover_Binary * slave ;
idDoor * slaveDoor ;
for ( slave = this ; slave ! = NULL ; slave = slave - > GetActivateChain ( ) )
{
if ( slave - > IsType ( idDoor : : Type ) )
{
slaveDoor = static_cast < idDoor * > ( slave ) ;
if ( slaveDoor - > areaPortal )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > SetPortalState ( true ) ;
}
slaveDoor - > SetAASAreaState ( false ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idDoor : : Event_ClosePortal
Sets the portal associtated with this door to be closed
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDoor : : Event_ClosePortal ( )
{
idMover_Binary * slave ;
idDoor * slaveDoor ;
for ( slave = this ; slave ! = NULL ; slave = slave - > GetActivateChain ( ) )
{
if ( ! slave - > IsHidden ( ) )
{
if ( slave - > IsType ( idDoor : : Type ) )
{
slaveDoor = static_cast < idDoor * > ( slave ) ;
if ( slaveDoor - > areaPortal )
{
2012-11-26 18:58:24 +00:00
slaveDoor - > SetPortalState ( false ) ;
}
slaveDoor - > SetAASAreaState ( IsLocked ( ) | | IsNoTouch ( ) ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idPlat
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idMover_Binary , idPlat )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Touch , idPlat : : Event_Touch )
EVENT ( EV_TeamBlocked , idPlat : : Event_TeamBlocked )
EVENT ( EV_PartBlocked , idPlat : : Event_PartBlocked )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idPlat : : idPlat
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPlat : : idPlat ( )
{
2012-11-26 18:58:24 +00:00
trigger = NULL ;
localTriggerOrigin . Zero ( ) ;
localTriggerAxis . Identity ( ) ;
}
/*
= = = = = = = = = = = = = = =
idPlat : : ~ idPlat
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPlat : : ~ idPlat ( )
{
if ( trigger )
{
2012-11-26 18:58:24 +00:00
delete trigger ;
}
}
/*
= = = = = = = = = = = = = = =
idPlat : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteClipModel ( trigger ) ;
savefile - > WriteVec3 ( localTriggerOrigin ) ;
savefile - > WriteMat3 ( localTriggerAxis ) ;
}
/*
= = = = = = = = = = = = = = =
idPlat : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadClipModel ( trigger ) ;
savefile - > ReadVec3 ( localTriggerOrigin ) ;
savefile - > ReadMat3 ( localTriggerAxis ) ;
}
/*
= = = = = = = = = = = = = = =
idPlat : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
float lip ;
float height ;
float time ;
float speed ;
float accel ;
float decel ;
bool noTouch ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " speed " , " 100 " , speed ) ;
spawnArgs . GetFloat ( " damage " , " 0 " , damage ) ;
spawnArgs . GetFloat ( " wait " , " 1 " , wait ) ;
spawnArgs . GetFloat ( " lip " , " 8 " , lip ) ;
spawnArgs . GetFloat ( " accel_time " , " 0.25 " , accel ) ;
spawnArgs . GetFloat ( " decel_time " , " 0.25 " , decel ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// create second position
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetFloat ( " height " , " 0 " , height ) )
{
2012-11-26 18:58:24 +00:00
height = ( GetPhysics ( ) - > GetBounds ( ) [ 1 ] [ 2 ] - GetPhysics ( ) - > GetBounds ( ) [ 0 ] [ 2 ] ) - lip ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetBool ( " no_touch " , " 0 " , noTouch ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// pos1 is the rest (bottom) position, pos2 is the top
pos2 = GetPhysics ( ) - > GetOrigin ( ) ;
pos1 = pos2 ;
pos1 [ 2 ] - = height ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " time " , " 1 " , time ) )
{
2012-11-26 18:58:24 +00:00
InitTime ( pos1 , pos2 , time , accel , decel ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
InitSpeed ( pos1 , pos2 , speed , accel , decel ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetMoverState ( MOVER_POS1 , gameLocal . slow . time ) ;
UpdateVisuals ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// spawn the trigger if one hasn't been custom made
2012-11-28 15:47:07 +00:00
if ( ! noTouch )
{
2012-11-26 18:58:24 +00:00
// spawn trigger
SpawnPlatTrigger ( pos1 ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idPlat : : RunPhysics_NoBlocking
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : RunPhysics_NoBlocking ( )
{
2012-11-26 18:58:24 +00:00
int i , startTime , endTime ;
2012-11-28 15:47:07 +00:00
idEntity * part = NULL , * blockedPart = NULL , * blockingEntity = NULL ;
2012-11-26 18:58:24 +00:00
trace_t results ;
bool moved ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// don't run physics if not enabled
2012-11-28 15:47:07 +00:00
if ( ! ( thinkFlags & TH_PHYSICS ) )
{
2012-11-26 18:58:24 +00:00
// however do update any animation controllers
2012-11-28 15:47:07 +00:00
if ( UpdateAnimationControllers ( ) )
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_ANIMATE ) ;
}
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
/*
// if this entity is a team slave don't do anything because the team master will handle everything
if ( teamMaster & & teamMaster ! = this ) {
return false ;
}
*/
startTime = gameLocal . previousTime ;
endTime = gameLocal . time ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameLocal . push . InitSavingPushedEntityPositions ( ) ;
blockedPart = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// save the physics state of the whole team and disable the team for collision detection
2012-11-28 15:47:07 +00:00
for ( part = this ; part ! = NULL ; part = part - > GetTeamChain ( ) )
{
if ( part - > GetPhysics ( ) )
{
if ( ! part - > fl . solidForTeam )
{
2012-11-26 18:58:24 +00:00
part - > GetPhysics ( ) - > DisableClip ( ) ;
}
part - > GetPhysics ( ) - > SaveState ( ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// move the whole team
2012-11-28 15:47:07 +00:00
for ( part = this ; part ! = NULL ; part = part - > GetTeamChain ( ) )
{
if ( part - > GetPhysics ( ) )
{
2012-11-26 18:58:24 +00:00
// run physics
moved = part - > GetPhysics ( ) - > Evaluate ( endTime - startTime , endTime ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// check if the object is blocked
blockingEntity = part - > GetPhysics ( ) - > GetBlockingEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( blockingEntity )
{
2012-11-26 18:58:24 +00:00
blockedPart = part ;
break ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if moved or forced to update the visual position and orientation from the physics
2012-11-28 15:47:07 +00:00
if ( moved | | part - > fl . forcePhysicsUpdate )
{
2012-11-26 18:58:24 +00:00
part - > UpdateVisuals ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// update any animation controllers here so an entity bound
// to a joint of this entity gets the correct position
2012-11-28 15:47:07 +00:00
if ( part - > UpdateAnimationControllers ( ) )
{
2012-11-26 18:58:24 +00:00
part - > BecomeActive ( TH_ANIMATE ) ;
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// enable the whole team for collision detection
2012-11-28 15:47:07 +00:00
for ( part = this ; part ! = NULL ; part = part - > GetTeamChain ( ) )
{
if ( part - > GetPhysics ( ) )
{
if ( ! part - > fl . solidForTeam )
{
2012-11-26 18:58:24 +00:00
part - > GetPhysics ( ) - > EnableClip ( ) ;
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// set pushed
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < gameLocal . push . GetNumPushedEntities ( ) ; i + + )
{
idEntity * ent = gameLocal . push . GetPushedEntity ( i ) ;
2012-11-26 18:58:24 +00:00
ent - > GetPhysics ( ) - > SetPushed ( endTime - startTime ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idPlat : : ClientThink
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : ClientThink ( const int curTime , const float fraction , const bool predict )
{
2012-11-26 18:58:24 +00:00
InterpolatePhysicsOnly ( fraction ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Present ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
//idMover_Binary::ClientThink( curTime, fraction, predict );
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
/*
idVec3 masterOrigin ;
idMat3 masterAxis ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Dont bother with blocking entities on clients.. host tells us our move state.
RunPhysics_NoBlocking ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Present ( ) ;
if ( thinkFlags & TH_PHYSICS ) {
// update trigger position
if ( GetMasterPosition ( masterOrigin , masterAxis ) ) {
if ( trigger ) {
trigger - > Link ( gameLocal . clip , this , 0 , masterOrigin + localTriggerOrigin * masterAxis , localTriggerAxis * masterAxis ) ;
}
}
}
*/
}
/*
= = = = = = = = = = = = = = = =
idPlat : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Think ( )
{
2012-11-26 18:58:24 +00:00
idVec3 masterOrigin ;
idMat3 masterAxis ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idMover_Binary : : Think ( ) ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_PHYSICS )
{
2012-11-26 18:58:24 +00:00
// update trigger position
2012-11-28 15:47:07 +00:00
if ( GetMasterPosition ( masterOrigin , masterAxis ) )
{
if ( trigger )
{
2012-11-26 18:58:24 +00:00
trigger - > Link ( gameLocal . clip , this , 0 , masterOrigin + localTriggerOrigin * masterAxis , localTriggerAxis * masterAxis ) ;
}
}
}
}
/*
= = = = = = = = = = = = = = = =
idPlat : : PreBind
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : PreBind ( )
{
2012-11-26 18:58:24 +00:00
idMover_Binary : : PreBind ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idPlat : : PostBind
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : PostBind ( )
{
2012-11-26 18:58:24 +00:00
idMover_Binary : : PostBind ( ) ;
GetLocalTriggerPosition ( trigger ) ;
}
/*
= = = = = = = = = = = = = = = =
idPlat : : GetLocalTriggerPosition
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : GetLocalTriggerPosition ( const idClipModel * trigger )
{
2012-11-26 18:58:24 +00:00
idVec3 origin ;
idMat3 axis ;
2012-11-28 15:47:07 +00:00
if ( ! trigger )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
GetMasterPosition ( origin , axis ) ;
localTriggerOrigin = ( trigger - > GetOrigin ( ) - origin ) * axis . Transpose ( ) ;
localTriggerAxis = trigger - > GetAxis ( ) * axis . Transpose ( ) ;
}
/*
= = = = = = = = = = = = = =
idPlat : : SpawnPlatTrigger
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : SpawnPlatTrigger ( idVec3 & pos )
{
2012-11-26 18:58:24 +00:00
idBounds bounds ;
idVec3 tmin ;
idVec3 tmax ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// the middle trigger will be a thin trigger just
// above the starting position
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
bounds = GetPhysics ( ) - > GetBounds ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
tmin [ 0 ] = bounds [ 0 ] [ 0 ] + 33 ;
tmin [ 1 ] = bounds [ 0 ] [ 1 ] + 33 ;
tmin [ 2 ] = bounds [ 0 ] [ 2 ] ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
tmax [ 0 ] = bounds [ 1 ] [ 0 ] - 33 ;
tmax [ 1 ] = bounds [ 1 ] [ 1 ] - 33 ;
tmax [ 2 ] = bounds [ 1 ] [ 2 ] + 8 ;
2012-11-28 15:47:07 +00:00
if ( tmax [ 0 ] < = tmin [ 0 ] )
{
2012-11-26 18:58:24 +00:00
tmin [ 0 ] = ( bounds [ 0 ] [ 0 ] + bounds [ 1 ] [ 0 ] ) * 0.5f ;
tmax [ 0 ] = tmin [ 0 ] + 1 ;
}
2012-11-28 15:47:07 +00:00
if ( tmax [ 1 ] < = tmin [ 1 ] )
{
2012-11-26 18:58:24 +00:00
tmin [ 1 ] = ( bounds [ 0 ] [ 1 ] + bounds [ 1 ] [ 1 ] ) * 0.5f ;
tmax [ 1 ] = tmin [ 1 ] + 1 ;
}
2012-11-28 15:47:07 +00:00
trigger = new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( idTraceModel ( idBounds ( tmin , tmax ) ) ) ;
2012-11-26 18:58:24 +00:00
trigger - > Link ( gameLocal . clip , this , 255 , GetPhysics ( ) - > GetOrigin ( ) , mat3_identity ) ;
trigger - > SetContents ( CONTENTS_TRIGGER ) ;
}
/*
= = = = = = = = = = = = = =
idPlat : : Event_Touch
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Event_Touch ( idEntity * other , trace_t * trace )
{
if ( common - > IsClient ( ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! other - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ( GetMoverState ( ) = = MOVER_POS1 ) & & trigger & & ( trace - > c . id = = trigger - > GetId ( ) ) & & ( other - > health > 0 ) )
{
2012-11-26 18:58:24 +00:00
Use_BinaryMover ( other ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idPlat : : Event_TeamBlocked
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Event_TeamBlocked ( idEntity * blockedEntity , idEntity * blockingEntity )
{
2012-11-26 18:58:24 +00:00
// reverse direction
Use_BinaryMover ( activatedBy . GetEntity ( ) ) ;
}
/*
= = = = = = = = = = = = = = =
idPlat : : Event_PartBlocked
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlat : : Event_PartBlocked ( idEntity * blockingEntity )
{
if ( damage > 0.0f )
{
2012-11-26 18:58:24 +00:00
blockingEntity - > Damage ( this , this , vec3_origin , " damage_moverCrush " , damage , INVALID_JOINT ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idMover_Periodic
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idMover_Periodic )
2012-11-28 15:47:07 +00:00
EVENT ( EV_TeamBlocked , idMover_Periodic : : Event_TeamBlocked )
EVENT ( EV_PartBlocked , idMover_Periodic : : Event_PartBlocked )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idMover_Periodic : : idMover_Periodic
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idMover_Periodic : : idMover_Periodic ( )
{
2012-11-26 18:58:24 +00:00
damage = 0.0f ;
fl . neverDormant = false ;
}
/*
= = = = = = = = = = = = = = =
idMover_Periodic : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " damage " , " 0 " , damage ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " solid " , " 1 " ) )
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > SetContents ( 0 ) ;
}
}
/*
= = = = = = = = = = = = = = =
idMover_Periodic : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( damage ) ;
savefile - > WriteStaticObject ( physicsObj ) ;
}
/*
= = = = = = = = = = = = = = =
idMover_Periodic : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( damage ) ;
savefile - > ReadStaticObject ( physicsObj ) ;
RestorePhysics ( & physicsObj ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Periodic : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : Think ( )
{
2012-11-26 18:58:24 +00:00
// if we are completely closed off from the player, don't do anything at all
2012-11-28 15:47:07 +00:00
if ( CheckDormant ( ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
RunPhysics ( ) ;
Present ( ) ;
}
/*
= = = = = = = = = = = = = = =
idMover_Periodic : : Event_TeamBlocked
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : Event_TeamBlocked ( idEntity * blockedEntity , idEntity * blockingEntity )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idMover_Periodic : : Event_PartBlocked
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : Event_PartBlocked ( idEntity * blockingEntity )
{
if ( damage > 0.0f )
{
2012-11-26 18:58:24 +00:00
blockingEntity - > Damage ( this , this , vec3_origin , " damage_moverCrush " , damage , INVALID_JOINT ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idMover_Periodic : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
physicsObj . WriteToSnapshot ( msg ) ;
WriteBindToSnapshot ( msg ) ;
}
/*
= = = = = = = = = = = = = = = =
idMover_Periodic : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idMover_Periodic : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
physicsObj . ReadFromSnapshot ( msg ) ;
ReadBindFromSnapshot ( msg ) ;
2012-11-28 15:47:07 +00:00
if ( msg . HasChanged ( ) )
{
2012-11-26 18:58:24 +00:00
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idRotater
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idMover_Periodic , idRotater )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idRotater : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idRotater : : idRotater
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idRotater : : idRotater ( )
{
2012-11-26 18:58:24 +00:00
activatedBy = this ;
}
/*
= = = = = = = = = = = = = = =
idRotater : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idRotater : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetSelf ( this ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetClipModel ( new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) , 1.0f ) ;
2012-11-26 18:58:24 +00:00
physicsObj . SetOrigin ( GetPhysics ( ) - > GetOrigin ( ) ) ;
physicsObj . SetAxis ( GetPhysics ( ) - > GetAxis ( ) ) ;
physicsObj . SetClipMask ( MASK_SOLID ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " nopush " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetPusher ( 0 ) ;
}
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , gameLocal . slow . time , 0 , GetPhysics ( ) - > GetOrigin ( ) , vec3_origin , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_LINEAR | EXTRAPOLATION_NOSTOP ) , gameLocal . slow . time , 0 , GetPhysics ( ) - > GetAxis ( ) . ToAngles ( ) , ang_zero , ang_zero ) ;
2012-11-26 18:58:24 +00:00
SetPhysics ( & physicsObj ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " start_on " ) )
{
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_Activate , this ) ;
}
}
/*
= = = = = = = = = = = = = = =
idRotater : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idRotater : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
activatedBy . Save ( savefile ) ;
}
/*
= = = = = = = = = = = = = = =
idRotater : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idRotater : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
activatedBy . Restore ( savefile ) ;
}
/*
= = = = = = = = = = = = = = =
idRotater : : Event_Activate
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idRotater : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
float speed ;
bool x_axis ;
bool y_axis ;
idAngles delta ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
activatedBy = activator ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
delta . Zero ( ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " rotate " ) )
{
2012-11-26 18:58:24 +00:00
spawnArgs . Set ( " rotate " , " 1 " ) ;
spawnArgs . GetFloat ( " speed " , " 100 " , speed ) ;
spawnArgs . GetBool ( " x_axis " , " 0 " , x_axis ) ;
spawnArgs . GetBool ( " y_axis " , " 0 " , y_axis ) ;
// set the axis of rotation
2012-11-28 15:47:07 +00:00
if ( x_axis )
{
2012-11-26 18:58:24 +00:00
delta [ 2 ] = speed ;
2012-11-28 15:47:07 +00:00
}
else if ( y_axis )
{
2012-11-26 18:58:24 +00:00
delta [ 0 ] = speed ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
delta [ 1 ] = speed ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
spawnArgs . Set ( " rotate " , " 0 " ) ;
}
2012-11-28 15:47:07 +00:00
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_LINEAR | EXTRAPOLATION_NOSTOP ) , gameLocal . slow . time , 0 , physicsObj . GetAxis ( ) . ToAngles ( ) , delta , ang_zero ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idBobber
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idMover_Periodic , idBobber )
END_CLASS
/*
= = = = = = = = = = = = = = =
idBobber : : idBobber
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idBobber : : idBobber ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idBobber : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBobber : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
float speed ;
float height ;
float phase ;
bool x_axis ;
bool y_axis ;
idVec3 delta ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " speed " , " 4 " , speed ) ;
spawnArgs . GetFloat ( " height " , " 32 " , height ) ;
spawnArgs . GetFloat ( " phase " , " 0 " , phase ) ;
spawnArgs . GetBool ( " x_axis " , " 0 " , x_axis ) ;
spawnArgs . GetBool ( " y_axis " , " 0 " , y_axis ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// set the axis of bobbing
delta = vec3_origin ;
2012-11-28 15:47:07 +00:00
if ( x_axis )
{
2012-11-26 18:58:24 +00:00
delta [ 0 ] = height ;
2012-11-28 15:47:07 +00:00
}
else if ( y_axis )
{
2012-11-26 18:58:24 +00:00
delta [ 1 ] = height ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
delta [ 2 ] = height ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetSelf ( this ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetClipModel ( new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) , 1.0f ) ;
2012-11-26 18:58:24 +00:00
physicsObj . SetOrigin ( GetPhysics ( ) - > GetOrigin ( ) ) ;
physicsObj . SetAxis ( GetPhysics ( ) - > GetAxis ( ) ) ;
physicsObj . SetClipMask ( MASK_SOLID ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " nopush " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetPusher ( 0 ) ;
}
2012-11-28 15:47:07 +00:00
physicsObj . SetLinearExtrapolation ( extrapolation_t ( EXTRAPOLATION_DECELSINE | EXTRAPOLATION_NOSTOP ) , phase * 1000 , speed * 500 , GetPhysics ( ) - > GetOrigin ( ) , delta * 2.0f , vec3_origin ) ;
2012-11-26 18:58:24 +00:00
SetPhysics ( & physicsObj ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idPendulum
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idMover_Periodic , idPendulum )
END_CLASS
/*
= = = = = = = = = = = = = = =
idPendulum : : idPendulum
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPendulum : : idPendulum ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idPendulum : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPendulum : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
float speed ;
float freq ;
float length ;
float phase ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " speed " , " 30 " , speed ) ;
spawnArgs . GetFloat ( " phase " , " 0 " , phase ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " freq " , " " , freq ) )
{
if ( freq < = 0.0f )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Invalid frequency on entity '%s' " , GetName ( ) ) ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// find pendulum length
length = idMath : : Fabs ( GetPhysics ( ) - > GetBounds ( ) [ 0 ] [ 2 ] ) ;
2012-11-28 15:47:07 +00:00
if ( length < 8 )
{
2012-11-26 18:58:24 +00:00
length = 8 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
freq = 1 / ( idMath : : TWO_PI ) * idMath : : Sqrt ( g_gravity . GetFloat ( ) / ( 3 * length ) ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetSelf ( this ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetClipModel ( new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) , 1.0f ) ;
2012-11-26 18:58:24 +00:00
physicsObj . SetOrigin ( GetPhysics ( ) - > GetOrigin ( ) ) ;
physicsObj . SetAxis ( GetPhysics ( ) - > GetAxis ( ) ) ;
physicsObj . SetClipMask ( MASK_SOLID ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " nopush " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetPusher ( 0 ) ;
}
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , GetPhysics ( ) - > GetOrigin ( ) , vec3_origin , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_DECELSINE | EXTRAPOLATION_NOSTOP ) , phase * 1000 , 500 / freq , GetPhysics ( ) - > GetAxis ( ) . ToAngles ( ) , idAngles ( 0 , 0 , speed * 2.0f ) , ang_zero ) ;
2012-11-26 18:58:24 +00:00
SetPhysics ( & physicsObj ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idBobber
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idMover_Periodic , idRiser )
EVENT ( EV_Activate , idRiser : : Event_Activate )
END_CLASS
/*
= = = = = = = = = = = = = = =
idRiser : : idRiser
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idRiser : : idRiser ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idRiser : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idRiser : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetSelf ( this ) ;
2012-11-28 15:47:07 +00:00
physicsObj . SetClipModel ( new ( TAG_PHYSICS_CLIP_MOVER ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) , 1.0f ) ;
2012-11-26 18:58:24 +00:00
physicsObj . SetOrigin ( GetPhysics ( ) - > GetOrigin ( ) ) ;
physicsObj . SetAxis ( GetPhysics ( ) - > GetAxis ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetClipMask ( MASK_SOLID ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " solid " , " 1 " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetContents ( 0 ) ;
}
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " nopush " ) )
{
2012-11-26 18:58:24 +00:00
physicsObj . SetPusher ( 0 ) ;
}
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , GetPhysics ( ) - > GetOrigin ( ) , vec3_origin , vec3_origin ) ;
SetPhysics ( & physicsObj ) ;
}
/*
= = = = = = = = = = = = = = = =
idRiser : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idRiser : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( ! IsHidden ( ) & & spawnArgs . GetBool ( " hide " ) )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
Show ( ) ;
float time ;
float height ;
idVec3 delta ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " time " , " 4 " , time ) ;
spawnArgs . GetFloat ( " height " , " 32 " , height ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
delta = vec3_origin ;
delta [ 2 ] = height ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
physicsObj . SetLinearExtrapolation ( EXTRAPOLATION_LINEAR , gameLocal . slow . time , time * 1000 , physicsObj . GetOrigin ( ) , delta , vec3_origin ) ;
}
}