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 .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
/*
Various utility objects and functions .
*/
# include "../idlib/precompiled.h"
# pragma hdrstop
# include "Game_local.h"
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idSpawnableEntity
A simple , spawnable entity with a model and no functionable ability of it ' s own .
For example , it can be used as a placeholder during development , for marking
locations on maps for script , or for simple placed models without any behavior
that can be bound to other entities . Should not be subclassed .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idSpawnableEntity )
END_CLASS
/*
= = = = = = = = = = = = = = = = = = = = = =
idSpawnableEntity : : Spawn
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSpawnableEntity : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
// this just holds dict information
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idPlayerStart
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_TeleportStage ( " <TeleportStage> " , " e " ) ;
CLASS_DECLARATION ( idEntity , idPlayerStart )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idPlayerStart : : Event_TeleportPlayer )
EVENT ( EV_TeleportStage , idPlayerStart : : Event_TeleportStage )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idPlayerStart : : idPlayerStart
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPlayerStart : : idPlayerStart ( )
{
2012-11-26 18:58:24 +00:00
teleportStage = 0 ;
}
/*
= = = = = = = = = = = = = = =
idPlayerStart : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlayerStart : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
teleportStage = 0 ;
}
/*
= = = = = = = = = = = = = = = =
idPlayerStart : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlayerStart : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( teleportStage ) ;
}
/*
= = = = = = = = = = = = = = = =
idPlayerStart : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlayerStart : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( teleportStage ) ;
}
/*
= = = = = = = = = = = = = = = =
idPlayerStart : : ClientReceiveEvent
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idPlayerStart : : ClientReceiveEvent ( int event , int time , const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
int entityNumber ;
2012-11-28 15:47:07 +00:00
switch ( event )
{
case EVENT_TELEPORTPLAYER :
{
2012-11-26 18:58:24 +00:00
entityNumber = msg . ReadBits ( GENTITYNUM_BITS ) ;
2012-11-28 15:47:07 +00:00
idPlayer * player = static_cast < idPlayer * > ( gameLocal . entities [ entityNumber ] ) ;
if ( player ! = NULL & & player - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
Event_TeleportPlayer ( player ) ;
}
return true ;
}
2012-11-28 15:47:07 +00:00
default :
{
2012-11-26 18:58:24 +00:00
return idEntity : : ClientReceiveEvent ( event , time , msg ) ;
}
}
}
/*
= = = = = = = = = = = = = = =
idPlayerStart : : Event_TeleportStage
FIXME : add functionality to fx system ( could be done with player scripting too )
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlayerStart : : Event_TeleportStage ( idEntity * _player )
{
idPlayer * player ;
if ( ! _player - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
common - > Warning ( " idPlayerStart::Event_TeleportStage: entity is not an idPlayer \n " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
player = static_cast < idPlayer * > ( _player ) ;
2012-11-26 18:58:24 +00:00
float teleportDelay = spawnArgs . GetFloat ( " teleportDelay " ) ;
2012-11-28 15:47:07 +00:00
switch ( teleportStage )
{
2012-11-26 18:58:24 +00:00
case 0 :
player - > playerView . Flash ( colorWhite , 125 ) ;
player - > SetInfluenceLevel ( INFLUENCE_LEVEL3 ) ;
player - > SetInfluenceView ( spawnArgs . GetString ( " mtr_teleportFx " ) , NULL , 0.0f , NULL ) ;
gameSoundWorld - > FadeSoundClasses ( 0 , - 20.0f , teleportDelay ) ;
player - > StartSound ( " snd_teleport_start " , SND_CHANNEL_BODY2 , 0 , false , NULL ) ;
teleportStage + + ;
PostEventSec ( & EV_TeleportStage , teleportDelay , player ) ;
break ;
case 1 :
gameSoundWorld - > FadeSoundClasses ( 0 , 0.0f , 0.25f ) ;
teleportStage + + ;
PostEventSec ( & EV_TeleportStage , 0.25f , player ) ;
break ;
case 2 :
player - > SetInfluenceView ( NULL , NULL , 0.0f , NULL ) ;
TeleportPlayer ( player ) ;
player - > StopSound ( SND_CHANNEL_BODY2 , false ) ;
player - > SetInfluenceLevel ( INFLUENCE_NONE ) ;
teleportStage = 0 ;
break ;
default :
break ;
}
}
/*
= = = = = = = = = = = = = = =
idPlayerStart : : TeleportPlayer
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlayerStart : : TeleportPlayer ( idPlayer * player )
{
2012-11-26 18:58:24 +00:00
float pushVel = spawnArgs . GetFloat ( " push " , " 300 " ) ;
float f = spawnArgs . GetFloat ( " visualEffect " , " 0 " ) ;
2012-11-28 15:47:07 +00:00
const char * viewName = spawnArgs . GetString ( " visualView " , " " ) ;
idEntity * ent = viewName ? gameLocal . FindEntity ( viewName ) : NULL ;
2012-11-26 18:58:24 +00:00
SetTimeState ts ( player - > timeGroup ) ;
2012-11-28 15:47:07 +00:00
if ( f & & ent ! = NULL )
{
2012-11-26 18:58:24 +00:00
// place in private camera view for some time
// the entity needs to teleport to where the camera view is to have the PVS right
player - > Teleport ( ent - > GetPhysics ( ) - > GetOrigin ( ) , ang_zero , this ) ;
player - > StartSound ( " snd_teleport_enter " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
2012-11-28 15:47:07 +00:00
player - > SetPrivateCameraView ( static_cast < idCamera * > ( ent ) ) ;
2012-11-26 18:58:24 +00:00
// the player entity knows where to spawn from the previous Teleport call
2012-11-28 15:47:07 +00:00
if ( ! common - > IsClient ( ) )
{
2012-11-26 18:58:24 +00:00
player - > PostEventSec ( & EV_Player_ExitTeleporter , f ) ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// direct to exit, Teleport will take care of the killbox
player - > Teleport ( GetPhysics ( ) - > GetOrigin ( ) , GetPhysics ( ) - > GetAxis ( ) . ToAngles ( ) , NULL ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// multiplayer hijacked this entity, so only push the player in multiplayer
2012-11-28 15:47:07 +00:00
if ( common - > IsMultiplayer ( ) )
{
2012-11-26 18:58:24 +00:00
player - > GetPhysics ( ) - > SetLinearVelocity ( GetPhysics ( ) - > GetAxis ( ) [ 0 ] * pushVel ) ;
}
}
}
/*
= = = = = = = = = = = = = = =
idPlayerStart : : Event_TeleportPlayer
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPlayerStart : : Event_TeleportPlayer ( idEntity * activator )
{
idPlayer * player ;
if ( activator - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
player = static_cast < idPlayer * > ( activator ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
player = gameLocal . GetLocalPlayer ( ) ;
}
2012-11-28 15:47:07 +00:00
if ( player )
{
if ( spawnArgs . GetBool ( " visualFx " ) )
{
2012-11-26 18:58:24 +00:00
teleportStage = 0 ;
Event_TeleportStage ( player ) ;
2012-11-28 15:47:07 +00:00
}
else
{
if ( common - > IsServer ( ) )
{
2012-11-26 18:58:24 +00:00
idBitMsg msg ;
byte msgBuf [ MAX_EVENT_PARAM_SIZE ] ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
msg . InitWrite ( msgBuf , sizeof ( msgBuf ) ) ;
msg . BeginWriting ( ) ;
msg . WriteBits ( player - > entityNumber , GENTITYNUM_BITS ) ;
ServerSendEvent ( EVENT_TELEPORTPLAYER , & msg , false ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
TeleportPlayer ( player ) ;
}
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idActivator
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idActivator )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idActivator : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idActivator : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idActivator : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( stay_on ) ;
}
/*
= = = = = = = = = = = = = = =
idActivator : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idActivator : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( stay_on ) ;
2012-11-28 15:47:07 +00:00
if ( stay_on )
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = =
idActivator : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idActivator : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
bool start_off ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetBool ( " stay_on " , " 0 " , stay_on ) ;
spawnArgs . GetBool ( " start_off " , " 0 " , start_off ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > SetClipBox ( idBounds ( vec3_origin ) . Expand ( 4 ) , 1.0f ) ;
GetPhysics ( ) - > SetContents ( 0 ) ;
2012-11-28 15:47:07 +00:00
if ( ! start_off )
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = =
idActivator : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idActivator : : Think ( )
{
2012-11-26 18:58:24 +00:00
RunPhysics ( ) ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_THINK )
{
if ( TouchTriggers ( ) )
{
if ( ! stay_on )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
}
}
}
Present ( ) ;
}
/*
= = = = = = = = = = = = = = =
idActivator : : Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idActivator : : Event_Activate ( idEntity * activator )
{
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idPathCorner
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idPathCorner )
2012-11-28 15:47:07 +00:00
EVENT ( AI_RandomPath , idPathCorner : : Event_RandomPath )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = = = = = = =
idPathCorner : : Spawn
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPathCorner : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = =
idPathCorner : : DrawDebugInfo
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPathCorner : : DrawDebugInfo ( )
{
idEntity * ent ;
2012-11-26 18:58:24 +00:00
idBounds bnds ( idVec3 ( - 4.0 , - 4.0f , - 8.0f ) , idVec3 ( 4.0 , 4.0f , 64.0f ) ) ;
2012-11-28 15:47:07 +00:00
for ( ent = gameLocal . spawnedEntities . Next ( ) ; ent ! = NULL ; ent = ent - > spawnNode . Next ( ) )
{
if ( ! ent - > IsType ( idPathCorner : : Type ) )
{
2012-11-26 18:58:24 +00:00
continue ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec3 org = ent - > GetPhysics ( ) - > GetOrigin ( ) ;
gameRenderWorld - > DebugBounds ( colorRed , bnds , org , 0 ) ;
}
}
/*
= = = = = = = = = = = =
idPathCorner : : RandomPath
= = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPathCorner * idPathCorner : : RandomPath ( const idEntity * source , const idEntity * ignore )
{
2012-11-26 18:58:24 +00:00
int i ;
int num ;
int which ;
2012-11-28 15:47:07 +00:00
idEntity * ent ;
idPathCorner * path [ MAX_GENTITIES ] ;
2012-11-26 18:58:24 +00:00
num = 0 ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < source - > targets . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
ent = source - > targets [ i ] . GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( ent ! = NULL & & ( ent ! = ignore ) & & ent - > IsType ( idPathCorner : : Type ) )
{
path [ num + + ] = static_cast < idPathCorner * > ( ent ) ;
if ( num > = MAX_GENTITIES )
{
2012-11-26 18:58:24 +00:00
break ;
}
}
}
2012-11-28 15:47:07 +00:00
if ( ! num )
{
2012-11-26 18:58:24 +00:00
return NULL ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
which = gameLocal . random . RandomInt ( num ) ;
return path [ which ] ;
}
/*
= = = = = = = = = = = = = = = = = = = = =
idPathCorner : : Event_RandomPath
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPathCorner : : Event_RandomPath ( )
{
idPathCorner * path ;
2012-11-26 18:58:24 +00:00
path = RandomPath ( this , NULL ) ;
idThread : : ReturnEntity ( path ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idDamagable
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_RestoreDamagable ( " <RestoreDamagable> " ) ;
CLASS_DECLARATION ( idEntity , idDamagable )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idDamagable : : Event_BecomeBroken )
EVENT ( EV_RestoreDamagable , idDamagable : : Event_RestoreDamagable )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idDamagable : : idDamagable
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idDamagable : : idDamagable ( )
{
2012-11-26 18:58:24 +00:00
count = 0 ;
nextTriggerTime = 0 ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( count ) ;
savefile - > WriteInt ( nextTriggerTime ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( count ) ;
savefile - > ReadInt ( nextTriggerTime ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idStr broken ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
health = spawnArgs . GetInt ( " health " , " 5 " ) ;
2012-11-28 15:47:07 +00:00
spawnArgs . GetInt ( " count " , " 1 " , count ) ;
2012-11-26 18:58:24 +00:00
nextTriggerTime = 0 ;
// make sure the model gets cached
spawnArgs . GetString ( " broken " , " " , broken ) ;
2012-11-28 15:47:07 +00:00
if ( broken . Length ( ) & & ! renderModelManager - > CheckModel ( broken ) )
{
gameLocal . Error ( " idDamagable '%s' at (%s): cannot load broken model '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , broken . c_str ( ) ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fl . takedamage = true ;
GetPhysics ( ) - > SetContents ( CONTENTS_SOLID ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : BecomeBroken
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : BecomeBroken ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
float forceState ;
int numStates ;
int cycle ;
float wait ;
2012-11-28 15:47:07 +00:00
if ( gameLocal . time < nextTriggerTime )
{
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
spawnArgs . GetFloat ( " wait " , " 0.1 " , wait ) ;
nextTriggerTime = gameLocal . time + SEC2MS ( wait ) ;
2012-11-28 15:47:07 +00:00
if ( count > 0 )
{
2012-11-26 18:58:24 +00:00
count - - ;
2012-11-28 15:47:07 +00:00
if ( ! count )
{
2012-11-26 18:58:24 +00:00
fl . takedamage = false ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
health = spawnArgs . GetInt ( " health " , " 5 " ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idStr broken ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetString ( " broken " , " " , broken ) ;
2012-11-28 15:47:07 +00:00
if ( broken . Length ( ) )
{
2012-11-26 18:58:24 +00:00
SetModel ( broken ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// offset the start time of the shader to sync it to the gameLocal time
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( gameLocal . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetInt ( " numstates " , " 1 " , numStates ) ;
spawnArgs . GetInt ( " cycle " , " 0 " , cycle ) ;
spawnArgs . GetFloat ( " forcestate " , " 0 " , forceState ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// set the state parm
2012-11-28 15:47:07 +00:00
if ( cycle )
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_MODE ] + + ;
2012-11-28 15:47:07 +00:00
if ( renderEntity . shaderParms [ SHADERPARM_MODE ] > numStates )
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_MODE ] = 0 ;
}
2012-11-28 15:47:07 +00:00
}
else if ( forceState )
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_MODE ] = forceState ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_MODE ] = gameLocal . random . RandomInt ( numStates ) + 1 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( gameLocal . time ) ;
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
if ( spawnArgs . GetBool ( " hideWhenBroken " ) )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
PostEventMS ( & EV_RestoreDamagable , nextTriggerTime - gameLocal . time ) ;
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Killed
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Killed ( idEntity * inflictor , idEntity * attacker , int damage , const idVec3 & dir , int location )
{
if ( gameLocal . time < nextTriggerTime )
{
2012-11-26 18:58:24 +00:00
health + = damage ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BecomeBroken ( attacker ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Hide
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Hide ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Hide ( ) ;
GetPhysics ( ) - > SetContents ( 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Show
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Show ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Show ( ) ;
GetPhysics ( ) - > SetContents ( CONTENTS_SOLID ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Event_BecomeBroken
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Event_BecomeBroken ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
BecomeBroken ( activator ) ;
}
/*
= = = = = = = = = = = = = = = =
idDamagable : : Event_RestoreDamagable
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idDamagable : : Event_RestoreDamagable ( )
{
2012-11-26 18:58:24 +00:00
health = spawnArgs . GetInt ( " health " , " 5 " ) ;
Show ( ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idExplodable
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idExplodable )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idExplodable : : Event_Explode )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idExplodable : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idExplodable : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idExplodable : : Event_Explode
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idExplodable : : Event_Explode ( idEntity * activator )
{
const char * temp ;
if ( spawnArgs . GetString ( " def_damage " , " damage_explosion " , & temp ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . RadiusDamage ( GetPhysics ( ) - > GetOrigin ( ) , activator , activator , this , this , temp ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
StartSound ( " snd_explode " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Show() calls UpdateVisuals, so we don't need to call it ourselves after setting the shaderParms
renderEntity . shaderParms [ SHADERPARM_RED ] = 1.0f ;
renderEntity . shaderParms [ SHADERPARM_GREEN ] = 1.0f ;
renderEntity . shaderParms [ SHADERPARM_BLUE ] = 1.0f ;
renderEntity . shaderParms [ SHADERPARM_ALPHA ] = 1.0f ;
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( gameLocal . time ) ;
renderEntity . shaderParms [ SHADERPARM_DIVERSITY ] = 0.0f ;
Show ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Remove , 2000 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ActivateTargets ( activator ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idSpring
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idSpring )
2012-11-28 15:47:07 +00:00
EVENT ( EV_PostSpawn , idSpring : : Event_LinkSpring )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idSpring : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSpring : : Think ( )
{
2012-11-26 18:58:24 +00:00
idVec3 start , end , origin ;
idMat3 axis ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// run physics
RunPhysics ( ) ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
// evaluate force
spring . Evaluate ( gameLocal . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
start = p1 ;
2012-11-28 15:47:07 +00:00
if ( ent1 - > GetPhysics ( ) )
{
2012-11-26 18:58:24 +00:00
axis = ent1 - > GetPhysics ( ) - > GetAxis ( ) ;
origin = ent1 - > GetPhysics ( ) - > GetOrigin ( ) ;
start = origin + start * axis ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
end = p2 ;
2012-11-28 15:47:07 +00:00
if ( ent2 - > GetPhysics ( ) )
{
2012-11-26 18:58:24 +00:00
axis = ent2 - > GetPhysics ( ) - > GetAxis ( ) ;
origin = ent2 - > GetPhysics ( ) - > GetOrigin ( ) ;
end = origin + p2 * axis ;
}
2012-11-28 15:47:07 +00:00
gameRenderWorld - > DebugLine ( idVec4 ( 1 , 1 , 0 , 1 ) , start , end , 0 , true ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Present ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idSpring : : Event_LinkSpring
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSpring : : Event_LinkSpring ( )
{
2012-11-26 18:58:24 +00:00
idStr name1 , name2 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetString ( " ent1 " , " " , name1 ) ;
spawnArgs . GetString ( " ent2 " , " " , name2 ) ;
2012-11-28 15:47:07 +00:00
if ( name1 . Length ( ) )
{
2012-11-26 18:58:24 +00:00
ent1 = gameLocal . FindEntity ( name1 ) ;
2012-11-28 15:47:07 +00:00
if ( ent1 = = NULL )
{
gameLocal . Error ( " idSpring '%s' at (%s): cannot find first entity '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , name1 . c_str ( ) ) ;
2012-11-26 18:58:24 +00:00
return ;
}
}
2012-11-28 15:47:07 +00:00
else
{
2012-11-26 18:58:24 +00:00
ent1 = gameLocal . entities [ ENTITYNUM_WORLD ] ;
}
2012-11-28 15:47:07 +00:00
if ( name2 . Length ( ) )
{
2012-11-26 18:58:24 +00:00
ent2 = gameLocal . FindEntity ( name2 ) ;
2012-11-28 15:47:07 +00:00
if ( ent2 = = NULL )
{
gameLocal . Error ( " idSpring '%s' at (%s): cannot find second entity '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , name2 . c_str ( ) ) ;
2012-11-26 18:58:24 +00:00
return ;
}
}
2012-11-28 15:47:07 +00:00
else
{
2012-11-26 18:58:24 +00:00
ent2 = gameLocal . entities [ ENTITYNUM_WORLD ] ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spring . SetPosition ( ent1 - > GetPhysics ( ) , id1 , p1 , ent2 - > GetPhysics ( ) , id2 , p2 ) ;
BecomeActive ( TH_THINK ) ;
}
/*
= = = = = = = = = = = = = = = =
idSpring : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idSpring : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
float Kstretch , damping , restLength ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetInt ( " id1 " , " 0 " , id1 ) ;
spawnArgs . GetInt ( " id2 " , " 0 " , id2 ) ;
spawnArgs . GetVector ( " point1 " , " 0 0 0 " , p1 ) ;
spawnArgs . GetVector ( " point2 " , " 0 0 0 " , p2 ) ;
spawnArgs . GetFloat ( " constant " , " 100.0f " , Kstretch ) ;
spawnArgs . GetFloat ( " damping " , " 10.0f " , damping ) ;
spawnArgs . GetFloat ( " restlength " , " 0.0f " , restLength ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spring . InitSpring ( Kstretch , 0.0f , damping , restLength ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ent1 = ent2 = NULL ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_PostSpawn , 0 ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idForceField
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_Toggle ( " Toggle " , NULL ) ;
CLASS_DECLARATION ( idEntity , idForceField )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idForceField : : Event_Activate )
EVENT ( EV_Toggle , idForceField : : Event_Toggle )
EVENT ( EV_FindTargets , idForceField : : Event_FindTargets )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idForceField : : Toggle
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Toggle ( )
{
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : ClientThink ( const int curTime , const float fraction , const bool predict )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
// evaluate force
forceField . Evaluate ( gameLocal . time ) ;
2012-11-26 18:58:24 +00:00
Present ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Think ( )
{
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
// evaluate force
forceField . Evaluate ( gameLocal . time ) ;
}
Present ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteStaticObject ( forceField ) ;
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadStaticObject ( forceField ) ;
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idVec3 uniform ;
float explosion , implosion , randomTorque ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetVector ( " uniform " , " 0 0 0 " , uniform ) )
{
2012-11-26 18:58:24 +00:00
forceField . Uniform ( uniform ) ;
2012-11-28 15:47:07 +00:00
}
else if ( spawnArgs . GetFloat ( " explosion " , " 0 " , explosion ) )
{
2012-11-26 18:58:24 +00:00
forceField . Explosion ( explosion ) ;
2012-11-28 15:47:07 +00:00
}
else if ( spawnArgs . GetFloat ( " implosion " , " 0 " , implosion ) )
{
2012-11-26 18:58:24 +00:00
forceField . Implosion ( implosion ) ;
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " randomTorque " , " 0 " , randomTorque ) )
{
2012-11-26 18:58:24 +00:00
forceField . RandomTorque ( randomTorque ) ;
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " applyForce " , " 0 " ) )
{
2012-11-26 18:58:24 +00:00
forceField . SetApplyType ( FORCEFIELD_APPLY_FORCE ) ;
2012-11-28 15:47:07 +00:00
}
else if ( spawnArgs . GetBool ( " applyImpulse " , " 0 " ) )
{
2012-11-26 18:58:24 +00:00
forceField . SetApplyType ( FORCEFIELD_APPLY_IMPULSE ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
forceField . SetApplyType ( FORCEFIELD_APPLY_VELOCITY ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
forceField . SetPlayerOnly ( spawnArgs . GetBool ( " playerOnly " , " 0 " ) ) ;
forceField . SetMonsterOnly ( spawnArgs . GetBool ( " monsterOnly " , " 0 " ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// set the collision model on the force field
2012-11-28 15:47:07 +00:00
forceField . SetClipModel ( new ( TAG_PHYSICS_CLIP_ENTITY ) idClipModel ( GetPhysics ( ) - > GetClipModel ( ) ) ) ;
2012-11-26 18:58:24 +00:00
// remove the collision model from the physics object
GetPhysics ( ) - > SetClipModel ( NULL , 1.0f ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " start_on " ) )
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = =
idForceField : : Event_Toggle
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Event_Toggle ( )
{
2012-11-26 18:58:24 +00:00
Toggle ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
float wait ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Toggle ( ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " wait " , " 0.01 " , wait ) )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Toggle , wait ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idForceField : : Event_FindTargets
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idForceField : : Event_FindTargets ( )
{
2012-11-26 18:58:24 +00:00
FindTargets ( ) ;
RemoveNullTargets ( ) ;
2012-11-28 15:47:07 +00:00
if ( targets . Num ( ) )
{
2012-11-26 18:58:24 +00:00
forceField . Uniform ( targets [ 0 ] . GetEntity ( ) - > GetPhysics ( ) - > GetOrigin ( ) - GetPhysics ( ) - > GetOrigin ( ) ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idAnimated
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_Animated_Start ( " <start> " ) ;
const idEventDef EV_LaunchMissiles ( " launchMissiles " , " ssssdf " ) ;
const idEventDef EV_LaunchMissilesUpdate ( " <launchMissiles> " , " dddd " ) ;
const idEventDef EV_AnimDone ( " <AnimDone> " , " d " ) ;
const idEventDef EV_StartRagdoll ( " startRagdoll " ) ;
const idEventDef EV_SetAnimation ( " setAnimation " , " s " ) ;
const idEventDef EV_GetAnimationLength ( " getAnimationLength " , NULL , ' f ' ) ;
CLASS_DECLARATION ( idAFEntity_Gibbable , idAnimated )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idAnimated : : Event_Activate )
EVENT ( EV_Animated_Start , idAnimated : : Event_Start )
EVENT ( EV_StartRagdoll , idAnimated : : Event_StartRagdoll )
EVENT ( EV_AnimDone , idAnimated : : Event_AnimDone )
EVENT ( EV_Footstep , idAnimated : : Event_Footstep )
EVENT ( EV_FootstepLeft , idAnimated : : Event_Footstep )
EVENT ( EV_FootstepRight , idAnimated : : Event_Footstep )
EVENT ( EV_LaunchMissiles , idAnimated : : Event_LaunchMissiles )
EVENT ( EV_LaunchMissilesUpdate , idAnimated : : Event_LaunchMissilesUpdate )
EVENT ( EV_SetAnimation , idAnimated : : Event_SetAnimation )
EVENT ( EV_GetAnimationLength , idAnimated : : Event_GetAnimationLength )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idAnimated : : idAnimated
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idAnimated : : idAnimated ( )
{
2012-11-26 18:58:24 +00:00
anim = 0 ;
blendFrames = 0 ;
soundJoint = INVALID_JOINT ;
activated = false ;
combatModel = NULL ;
activator = NULL ;
current_anim_index = 0 ;
num_anims = 0 ;
achievement = - 1 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idAnimated : : idAnimated
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idAnimated : : ~ idAnimated ( )
{
2012-11-26 18:58:24 +00:00
delete combatModel ;
combatModel = NULL ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( current_anim_index ) ;
savefile - > WriteInt ( num_anims ) ;
savefile - > WriteInt ( anim ) ;
savefile - > WriteInt ( blendFrames ) ;
savefile - > WriteJoint ( soundJoint ) ;
activator . Save ( savefile ) ;
savefile - > WriteBool ( activated ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( current_anim_index ) ;
savefile - > ReadInt ( num_anims ) ;
savefile - > ReadInt ( anim ) ;
savefile - > ReadInt ( blendFrames ) ;
savefile - > ReadJoint ( soundJoint ) ;
activator . Restore ( savefile ) ;
savefile - > ReadBool ( activated ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idStr animname ;
int anim2 ;
float wait ;
2012-11-28 15:47:07 +00:00
const char * joint ;
joint = spawnArgs . GetString ( " sound_bone " , " origin " ) ;
2012-11-26 18:58:24 +00:00
soundJoint = animator . GetJointHandle ( joint ) ;
2012-11-28 15:47:07 +00:00
if ( soundJoint = = INVALID_JOINT )
{
gameLocal . Warning ( " idAnimated '%s' at (%s): cannot find joint '%s' for sound playback " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , joint ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
LoadAF ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// allow bullets to collide with a combat model
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " combatModel " , " 0 " ) )
{
combatModel = new ( TAG_PHYSICS_CLIP_ENTITY ) idClipModel ( modelDefHandle ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// allow the entity to take damage
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " takeDamage " , " 0 " ) )
{
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
current_anim_index = 0 ;
spawnArgs . GetInt ( " num_anims " , " 0 " , num_anims ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
blendFrames = spawnArgs . GetInt ( " blend_in " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
animname = spawnArgs . GetString ( num_anims ? " anim1 " : " anim " ) ;
2012-11-28 15:47:07 +00:00
if ( ! animname . Length ( ) )
{
2012-11-26 18:58:24 +00:00
anim = 0 ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
anim = animator . GetAnim ( animname ) ;
2012-11-28 15:47:07 +00:00
if ( ! anim )
{
gameLocal . Error ( " idAnimated '%s' at (%s): cannot find anim '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , animname . c_str ( ) ) ;
2012-11-26 18:58:24 +00:00
}
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " hide " ) )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
2012-11-28 15:47:07 +00:00
if ( ! num_anims )
{
2012-11-26 18:58:24 +00:00
blendFrames = 0 ;
}
2012-11-28 15:47:07 +00:00
}
else if ( spawnArgs . GetString ( " start_anim " , " " , animname ) )
{
2012-11-26 18:58:24 +00:00
anim2 = animator . GetAnim ( animname ) ;
2012-11-28 15:47:07 +00:00
if ( ! anim2 )
{
gameLocal . Error ( " idAnimated '%s' at (%s): cannot find anim '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , animname . c_str ( ) ) ;
2012-11-26 18:58:24 +00:00
}
animator . CycleAnim ( ANIMCHANNEL_ALL , anim2 , gameLocal . time , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else if ( anim )
{
2012-11-26 18:58:24 +00:00
// init joints to the first frame of the animation
2012-11-28 15:47:07 +00:00
animator . SetFrame ( ANIMCHANNEL_ALL , anim , 1 , gameLocal . time , 0 ) ;
if ( ! num_anims )
{
2012-11-26 18:58:24 +00:00
blendFrames = 0 ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetFloat ( " wait " , " -1 " , wait ) ;
2012-11-28 15:47:07 +00:00
if ( wait > = 0 )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Activate , wait , this ) ;
}
}
/*
= = = = = = = = = = = = = = =
idAnimated : : LoadAF
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idAnimated : : LoadAF ( )
{
2012-11-26 18:58:24 +00:00
idStr fileName ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetString ( " ragdoll " , " *unknown* " , fileName ) )
{
2012-11-26 18:58:24 +00:00
return false ;
}
af . SetAnimator ( GetAnimator ( ) ) ;
return af . Load ( this , fileName ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : GetPhysicsToSoundTransform
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idAnimated : : GetPhysicsToSoundTransform ( idVec3 & origin , idMat3 & axis )
{
2012-11-26 18:58:24 +00:00
animator . GetJointTransform ( soundJoint , gameLocal . time , origin , axis ) ;
axis = renderEntity . axis ;
return true ;
}
/*
= = = = = = = = = = = = = = = =
idAnimated : : StartRagdoll
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
bool idAnimated : : StartRagdoll ( )
{
2012-11-26 18:58:24 +00:00
// if no AF loaded
2012-11-28 15:47:07 +00:00
if ( ! af . IsLoaded ( ) )
{
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
// if the AF is already active
2012-11-28 15:47:07 +00:00
if ( af . IsActive ( ) )
{
2012-11-26 18:58:24 +00:00
return true ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// disable any collision model used
GetPhysics ( ) - > DisableClip ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// start using the AF
af . StartFromCurrentPose ( spawnArgs . GetInt ( " velocityTime " , " 0 " ) ) ;
return true ;
}
/*
= = = = = = = = = = = = = = = = = = = = =
idAnimated : : PlayNextAnim
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : PlayNextAnim ( )
{
const char * animname ;
2012-11-26 18:58:24 +00:00
int len ;
int cycle ;
2012-11-28 15:47:07 +00:00
if ( current_anim_index > = num_anims )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " remove " ) )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Remove , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
current_anim_index = 0 ;
}
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Show ( ) ;
current_anim_index + + ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetString ( va ( " anim%d " , current_anim_index ) , NULL , & animname ) ;
2012-11-28 15:47:07 +00:00
if ( ! animname )
{
2012-11-26 18:58:24 +00:00
anim = 0 ;
animator . Clear ( ANIMCHANNEL_ALL , gameLocal . time , FRAME2MS ( blendFrames ) ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
anim = animator . GetAnim ( animname ) ;
2012-11-28 15:47:07 +00:00
if ( ! anim )
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " missing anim '%s' on %s " , animname , name . c_str ( ) ) ;
return ;
}
2012-11-28 15:47:07 +00:00
if ( g_debugCinematic . GetBool ( ) )
{
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' start anim '%s' \n " , gameLocal . framenum , GetName ( ) , animname ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . GetInt ( " cycle " , " 1 " , cycle ) ;
2012-11-28 15:47:07 +00:00
if ( ( current_anim_index = = num_anims ) & & spawnArgs . GetBool ( " loop_last_anim " ) )
{
2012-11-26 18:58:24 +00:00
cycle = - 1 ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
animator . CycleAnim ( ANIMCHANNEL_ALL , anim , gameLocal . time , FRAME2MS ( blendFrames ) ) ;
animator . CurrentAnim ( ANIMCHANNEL_ALL ) - > SetCycleCount ( cycle ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
len = animator . CurrentAnim ( ANIMCHANNEL_ALL ) - > PlayLength ( ) ;
2012-11-28 15:47:07 +00:00
if ( len > = 0 )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_AnimDone , len , current_anim_index ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// offset the start time of the shader to sync it to the game time
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( gameLocal . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
animator . ForceUpdate ( ) ;
UpdateAnimation ( ) ;
UpdateVisuals ( ) ;
Present ( ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Event_StartRagdoll
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_StartRagdoll ( )
{
2012-11-26 18:58:24 +00:00
StartRagdoll ( ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Event_AnimDone
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_AnimDone ( int animindex )
{
if ( g_debugCinematic . GetBool ( ) )
{
const idAnim * animPtr = animator . GetAnim ( anim ) ;
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' end anim '%s' \n " , gameLocal . framenum , GetName ( ) , animPtr ? animPtr - > Name ( ) : " " ) ;
}
2012-11-28 15:47:07 +00:00
if ( ( animindex > = num_anims ) & & spawnArgs . GetBool ( " remove " ) )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
PostEventMS ( & EV_Remove , 0 ) ;
2012-11-28 15:47:07 +00:00
}
else if ( spawnArgs . GetBool ( " auto_advance " ) )
{
2012-11-26 18:58:24 +00:00
PlayNextAnim ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
activated = false ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ActivateTargets ( activator . GetEntity ( ) ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_Activate ( idEntity * _activator )
{
if ( num_anims )
{
2012-11-26 18:58:24 +00:00
PlayNextAnim ( ) ;
activator = _activator ;
return ;
}
2012-11-28 15:47:07 +00:00
if ( activated )
{
2012-11-26 18:58:24 +00:00
// already activated
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// achievement associated with this entity (given on activation)
achievement = spawnArgs . GetInt ( " achievement " , " -1 " ) ;
2012-11-28 15:47:07 +00:00
if ( achievement ! = - 1 )
{
idPlayer * player = gameLocal . GetLocalPlayer ( ) ;
if ( player ! = NULL )
{
2012-11-26 18:58:24 +00:00
bool shouldCountAction = true ;
// only count unlocking lockers if we're in the base game
2012-11-28 15:47:07 +00:00
if ( achievement = = ACHIEVEMENT_OPEN_ALL_LOCKERS & & player - > GetExpansionType ( ) ! = GAME_BASE )
{
2012-11-26 18:58:24 +00:00
shouldCountAction = false ;
}
2012-11-28 15:47:07 +00:00
if ( shouldCountAction )
{
player - > GetAchievementManager ( ) . EventCompletesAchievement ( ( achievement_t ) achievement ) ;
2012-11-26 18:58:24 +00:00
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
activated = true ;
activator = _activator ;
ProcessEvent ( & EV_Animated_Start ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Event_Start
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_Start ( )
{
2012-11-26 18:58:24 +00:00
int cycle ;
int len ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
Show ( ) ;
2012-11-28 15:47:07 +00:00
if ( num_anims )
{
2012-11-26 18:58:24 +00:00
PlayNextAnim ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
if ( anim )
{
if ( g_debugCinematic . GetBool ( ) )
{
const idAnim * animPtr = animator . GetAnim ( anim ) ;
2012-11-26 18:58:24 +00:00
gameLocal . Printf ( " %d: '%s' start anim '%s' \n " , gameLocal . framenum , GetName ( ) , animPtr ? animPtr - > Name ( ) : " " ) ;
}
spawnArgs . GetInt ( " cycle " , " 1 " , cycle ) ;
animator . CycleAnim ( ANIMCHANNEL_ALL , anim , gameLocal . time , FRAME2MS ( blendFrames ) ) ;
animator . CurrentAnim ( ANIMCHANNEL_ALL ) - > SetCycleCount ( cycle ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
len = animator . CurrentAnim ( ANIMCHANNEL_ALL ) - > PlayLength ( ) ;
2012-11-28 15:47:07 +00:00
if ( len > = 0 )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_AnimDone , len , 1 ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// offset the start time of the shader to sync it to the game time
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( gameLocal . time ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
animator . ForceUpdate ( ) ;
UpdateAnimation ( ) ;
UpdateVisuals ( ) ;
Present ( ) ;
}
/*
= = = = = = = = = = = = = = =
idAnimated : : Event_Footstep
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_Footstep ( )
{
2012-11-26 18:58:24 +00:00
StartSound ( " snd_footstep " , SND_CHANNEL_BODY , 0 , false , NULL ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = =
idAnimated : : Event_LaunchMissilesUpdate
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_LaunchMissilesUpdate ( int launchjoint , int targetjoint , int numshots , int framedelay )
{
2012-11-26 18:58:24 +00:00
idVec3 launchPos ;
idVec3 targetPos ;
idMat3 axis ;
idVec3 dir ;
2012-11-28 15:47:07 +00:00
idEntity * ent ;
idProjectile * projectile ;
const idDict * projectileDef ;
const char * projectilename ;
2012-11-26 18:58:24 +00:00
projectilename = spawnArgs . GetString ( " projectilename " ) ;
projectileDef = gameLocal . FindEntityDefDict ( projectilename , false ) ;
2012-11-28 15:47:07 +00:00
if ( ! projectileDef )
{
gameLocal . Warning ( " idAnimated '%s' at (%s): 'launchMissiles' called with unknown projectile '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , projectilename ) ;
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
StartSound ( " snd_missile " , SND_CHANNEL_WEAPON , 0 , false , NULL ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
animator . GetJointTransform ( ( jointHandle_t ) launchjoint , gameLocal . time , launchPos , axis ) ;
launchPos = renderEntity . origin + launchPos * renderEntity . axis ;
animator . GetJointTransform ( ( jointHandle_t ) targetjoint , gameLocal . time , targetPos , axis ) ;
targetPos = renderEntity . origin + targetPos * renderEntity . axis ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dir = targetPos - launchPos ;
dir . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameLocal . SpawnEntityDef ( * projectileDef , & ent , false ) ;
2012-11-28 15:47:07 +00:00
if ( ent = = NULL | | ! ent - > IsType ( idProjectile : : Type ) )
{
gameLocal . Error ( " idAnimated '%s' at (%s): in 'launchMissiles' call '%s' is not an idProjectile " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , projectilename ) ;
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
projectile = ( idProjectile * ) ent ;
2012-11-26 18:58:24 +00:00
projectile - > Create ( this , launchPos , dir ) ;
projectile - > Launch ( launchPos , dir , vec3_origin ) ;
2012-11-28 15:47:07 +00:00
if ( numshots > 0 )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_LaunchMissilesUpdate , FRAME2MS ( framedelay ) , launchjoint , targetjoint , numshots - 1 , framedelay ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = =
idAnimated : : Event_LaunchMissiles
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_LaunchMissiles ( const char * projectilename , const char * sound , const char * launchjoint , const char * targetjoint , int numshots , int framedelay )
{
const idDict * projectileDef ;
2012-11-26 18:58:24 +00:00
jointHandle_t launch ;
jointHandle_t target ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
projectileDef = gameLocal . FindEntityDefDict ( projectilename , false ) ;
2012-11-28 15:47:07 +00:00
if ( ! projectileDef )
{
gameLocal . Warning ( " idAnimated '%s' at (%s): unknown projectile '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , projectilename ) ;
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
launch = animator . GetJointHandle ( launchjoint ) ;
2012-11-28 15:47:07 +00:00
if ( launch = = INVALID_JOINT )
{
gameLocal . Warning ( " idAnimated '%s' at (%s): unknown launch joint '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , launchjoint ) ;
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Unknown joint '%s' " , launchjoint ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
target = animator . GetJointHandle ( targetjoint ) ;
2012-11-28 15:47:07 +00:00
if ( target = = INVALID_JOINT )
{
gameLocal . Warning ( " idAnimated '%s' at (%s): unknown target joint '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , targetjoint ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnArgs . Set ( " projectilename " , projectilename ) ;
spawnArgs . Set ( " missilesound " , sound ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
CancelEvents ( & EV_LaunchMissilesUpdate ) ;
ProcessEvent ( & EV_LaunchMissilesUpdate , launch , target , numshots - 1 , framedelay ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = =
idAnimated : : Event_SetAnimation
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_SetAnimation ( const char * animName )
{
2012-11-26 18:58:24 +00:00
//BSM Nerve: Need to add some error checking so we don't change the animation
//in the middle of the existing animation
anim = animator . GetAnim ( animName ) ;
2012-11-28 15:47:07 +00:00
if ( ! anim )
{
gameLocal . Error ( " idAnimated '%s' at (%s): cannot find anim '%s' " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , animName ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = =
idAnimated : : Event_GetAnimationLength
= = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idAnimated : : Event_GetAnimationLength ( )
{
2012-11-26 18:58:24 +00:00
float length = 0 ;
2012-11-28 15:47:07 +00:00
if ( anim )
{
length = ( float ) ( animator . AnimLength ( anim ) ) / 1000.f ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
idThread : : ReturnFloat ( length ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idStaticEntity
Some static entities may be optimized into inline geometry by dmap
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idStaticEntity )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idStaticEntity : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idStaticEntity : : idStaticEntity
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idStaticEntity : : idStaticEntity ( )
{
2012-11-26 18:58:24 +00:00
spawnTime = 0 ;
active = false ;
fadeFrom . Set ( 1 , 1 , 1 , 1 ) ;
fadeTo . Set ( 1 , 1 , 1 , 1 ) ;
fadeStart = 0 ;
fadeEnd = 0 ;
runGui = false ;
}
/*
= = = = = = = = = = = = = = =
idStaticEntity : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( spawnTime ) ;
savefile - > WriteBool ( active ) ;
savefile - > WriteVec4 ( fadeFrom ) ;
savefile - > WriteVec4 ( fadeTo ) ;
savefile - > WriteInt ( fadeStart ) ;
savefile - > WriteInt ( fadeEnd ) ;
savefile - > WriteBool ( runGui ) ;
}
/*
= = = = = = = = = = = = = = =
idStaticEntity : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( spawnTime ) ;
savefile - > ReadBool ( active ) ;
savefile - > ReadVec4 ( fadeFrom ) ;
savefile - > ReadVec4 ( fadeTo ) ;
savefile - > ReadInt ( fadeStart ) ;
savefile - > ReadInt ( fadeEnd ) ;
savefile - > ReadBool ( runGui ) ;
}
/*
= = = = = = = = = = = = = = =
idStaticEntity : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
bool solid ;
bool hidden ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// an inline static model will not do anything at all
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " inline " ) | | gameLocal . world - > spawnArgs . GetBool ( " inlineAllStatics " ) )
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
solid = spawnArgs . GetBool ( " solid " ) ;
hidden = spawnArgs . GetBool ( " hide " ) ;
2012-11-28 15:47:07 +00:00
if ( solid & & ! hidden )
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > SetContents ( CONTENTS_SOLID ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > SetContents ( 0 ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnTime = gameLocal . time ;
active = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idStr model = spawnArgs . GetString ( " model " ) ;
2012-11-28 15:47:07 +00:00
if ( model . Find ( " .prt " ) > = 0 )
{
2012-11-26 18:58:24 +00:00
// we want the parametric particles out of sync with each other
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = gameLocal . random . RandomInt ( 32767 ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
fadeFrom . Set ( 1 , 1 , 1 , 1 ) ;
fadeTo . Set ( 1 , 1 , 1 , 1 ) ;
fadeStart = 0 ;
fadeEnd = 0 ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// NOTE: this should be used very rarely because it is expensive
runGui = spawnArgs . GetBool ( " runGui " ) ;
2012-11-28 15:47:07 +00:00
if ( runGui )
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : ShowEditingDialog
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : ShowEditingDialog ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Think ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Think ( ) ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_THINK )
{
if ( runGui & & renderEntity . gui [ 0 ] )
{
idPlayer * player = gameLocal . GetLocalPlayer ( ) ;
if ( player )
{
if ( ! player - > objectiveSystemOpen )
{
2012-11-26 18:58:24 +00:00
renderEntity . gui [ 0 ] - > StateChanged ( gameLocal . time , true ) ;
2012-11-28 15:47:07 +00:00
if ( renderEntity . gui [ 1 ] )
{
2012-11-26 18:58:24 +00:00
renderEntity . gui [ 1 ] - > StateChanged ( gameLocal . time , true ) ;
}
2012-11-28 15:47:07 +00:00
if ( renderEntity . gui [ 2 ] )
{
2012-11-26 18:58:24 +00:00
renderEntity . gui [ 2 ] - > StateChanged ( gameLocal . time , true ) ;
}
}
}
}
2012-11-28 15:47:07 +00:00
if ( fadeEnd > 0 )
{
2012-11-26 18:58:24 +00:00
idVec4 color ;
2012-11-28 15:47:07 +00:00
if ( gameLocal . time < fadeEnd )
{
2012-11-26 18:58:24 +00:00
color . Lerp ( fadeFrom , fadeTo , ( float ) ( gameLocal . time - fadeStart ) / ( float ) ( fadeEnd - fadeStart ) ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
color = fadeTo ;
fadeEnd = 0 ;
BecomeInactive ( TH_THINK ) ;
}
SetColor ( color ) ;
}
}
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : Fade
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Fade ( const idVec4 & to , float fadeTime )
{
2012-11-26 18:58:24 +00:00
GetColor ( fadeFrom ) ;
fadeTo = to ;
fadeStart = gameLocal . time ;
fadeEnd = gameLocal . time + SEC2MS ( fadeTime ) ;
BecomeActive ( TH_THINK ) ;
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : Hide
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Hide ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Hide ( ) ;
GetPhysics ( ) - > SetContents ( 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : Show
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Show ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Show ( ) ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " solid " ) )
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > SetContents ( CONTENTS_SOLID ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
idStr activateGui ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
spawnTime = gameLocal . time ;
active = ! active ;
2012-11-28 15:47:07 +00:00
const idKeyValue * kv = spawnArgs . FindKey ( " hide " ) ;
if ( kv )
{
if ( IsHidden ( ) )
{
2012-11-26 18:58:24 +00:00
Show ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
Hide ( ) ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( spawnTime ) ;
renderEntity . shaderParms [ 5 ] = active ;
2012-11-28 15:47:07 +00:00
// this change should be a good thing, it will automatically turn on
2012-11-26 18:58:24 +00:00
// lights etc.. when triggered so that does not have to be specifically done
// with trigger parms.. it MIGHT break things so need to keep an eye on it
renderEntity . shaderParms [ SHADERPARM_MODE ] = ( renderEntity . shaderParms [ SHADERPARM_MODE ] ) ? 0.0f : 1.0f ;
BecomeActive ( TH_UPDATEVISUALS ) ;
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > WriteToSnapshot ( msg ) ;
WriteBindToSnapshot ( msg ) ;
WriteColorToSnapshot ( msg ) ;
WriteGUIToSnapshot ( msg ) ;
2012-11-28 15:47:07 +00:00
msg . WriteBits ( IsHidden ( ) ? 1 : 0 , 1 ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idStaticEntity : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idStaticEntity : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
bool hidden ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > ReadFromSnapshot ( msg ) ;
ReadBindFromSnapshot ( msg ) ;
ReadColorFromSnapshot ( msg ) ;
ReadGUIFromSnapshot ( msg ) ;
hidden = msg . ReadBits ( 1 ) = = 1 ;
2012-11-28 15:47:07 +00:00
if ( hidden ! = IsHidden ( ) )
{
if ( hidden )
{
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 ( ) ;
}
}
2012-11-28 15:47:07 +00:00
if ( msg . HasChanged ( ) )
{
2012-11-26 18:58:24 +00:00
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncEmitter
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idStaticEntity , idFuncEmitter )
EVENT ( EV_Activate , idFuncEmitter : : Event_Activate )
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncEmitter : : idFuncEmitter
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncEmitter : : idFuncEmitter ( )
{
2012-11-26 18:58:24 +00:00
hidden = false ;
}
/*
= = = = = = = = = = = = = = =
idFuncEmitter : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncEmitter : : Spawn ( )
{
if ( spawnArgs . GetBool ( " start_off " ) )
{
2012-11-26 18:58:24 +00:00
hidden = true ;
renderEntity . shaderParms [ SHADERPARM_PARTICLE_STOPTIME ] = MS2SEC ( 1 ) ;
UpdateVisuals ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
hidden = false ;
}
}
/*
= = = = = = = = = = = = = = =
idFuncEmitter : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncEmitter : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( hidden ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncEmitter : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncEmitter : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( hidden ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncEmitter : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncEmitter : : Event_Activate ( idEntity * activator )
{
if ( hidden | | spawnArgs . GetBool ( " cycleTrigger " ) )
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_PARTICLE_STOPTIME ] = 0 ;
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = - MS2SEC ( gameLocal . time ) ;
hidden = false ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_PARTICLE_STOPTIME ] = MS2SEC ( gameLocal . time ) ;
hidden = true ;
}
UpdateVisuals ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncEmitter : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncEmitter : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
msg . WriteBits ( hidden ? 1 : 0 , 1 ) ;
msg . WriteFloat ( renderEntity . shaderParms [ SHADERPARM_PARTICLE_STOPTIME ] ) ;
msg . WriteFloat ( renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncEmitter : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncEmitter : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
hidden = msg . ReadBits ( 1 ) ! = 0 ;
renderEntity . shaderParms [ SHADERPARM_PARTICLE_STOPTIME ] = msg . ReadFloat ( ) ;
renderEntity . shaderParms [ SHADERPARM_TIMEOFFSET ] = msg . ReadFloat ( ) ;
2012-11-28 15:47:07 +00:00
if ( msg . HasChanged ( ) )
{
2012-11-26 18:58:24 +00:00
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncShootProjectile
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idStaticEntity , idFuncShootProjectile )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idFuncShootProjectile : : Event_Activate )
END_CLASS
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
/*
= = = = = = = = = = = = = = =
idFuncShootProjectile : : idFuncShootProjectile
= = = = = = = = = = = = = = =
*/
idFuncShootProjectile : : idFuncShootProjectile ( )
{
mRespawnDelay = 1000 ;
mRespawnTime = 0 ;
mShootSpeed = 1000 ;
mShootDir = idVec3 ( 0.0f , 0.0f , 1.0f ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idFuncShootProjectile : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idFuncShootProjectile : : Think
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : Think ( )
{
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
// time to spawn a new projectile?
2012-11-28 15:47:07 +00:00
if ( mRespawnTime > 0 & & mRespawnTime < = gameLocal . GetTime ( ) )
{
const idDict * dict = gameLocal . FindEntityDefDict ( mEntityDefName ) ;
idEntity * ent = NULL ;
2012-11-26 18:58:24 +00:00
gameLocal . SpawnEntityDef ( * dict , & ent ) ;
2012-11-28 15:47:07 +00:00
if ( ent ! = NULL )
{
idProjectile * proj = static_cast < idProjectile * > ( ent ) ;
2012-11-26 18:58:24 +00:00
idVec3 pushVel = mShootDir * mShootSpeed ;
proj - > Create ( this , GetPhysics ( ) - > GetOrigin ( ) , mShootDir ) ;
proj - > Launch ( GetPhysics ( ) - > GetOrigin ( ) , mShootDir , pushVel ) ;
2012-11-28 15:47:07 +00:00
if ( mShootSpeed = = 0.0f )
{
2012-11-26 18:58:24 +00:00
proj - > GetPhysics ( ) - > SetLinearVelocity ( vec3_zero ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
proj - > GetPhysics ( ) - > SetLinearVelocity ( pushVel ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mLastProjectile = proj ;
}
2012-11-28 15:47:07 +00:00
if ( mShootSpeed = = 0.0f )
{
2012-11-26 18:58:24 +00:00
mRespawnTime = 0 ; // stationary, respawn when triggered
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
mRespawnTime = gameLocal . GetTime ( ) + mRespawnDelay ; // moving, respawn after delay
}
}
}
}
/*
= = = = = = = = = = = = = = =
idFuncShootProjectile : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( mRespawnDelay ) ;
savefile - > WriteInt ( mRespawnTime ) ;
savefile - > WriteFloat ( mShootSpeed ) ;
savefile - > WriteVec3 ( mShootDir ) ;
savefile - > WriteString ( mEntityDefName ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncShootProjectile : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( mRespawnDelay ) ;
savefile - > ReadInt ( mRespawnTime ) ;
savefile - > ReadFloat ( mShootSpeed ) ;
savefile - > ReadVec3 ( mShootDir ) ;
savefile - > ReadString ( mEntityDefName ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncShootProjectile : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : Event_Activate ( idEntity * activator )
{
if ( ( thinkFlags & TH_THINK ) ! = 0 )
{
if ( mShootSpeed = = 0.0f & & mRespawnTime = = 0 )
{
2012-11-26 18:58:24 +00:00
mRespawnTime = gameLocal . GetTime ( ) ;
return ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mRespawnDelay = spawnArgs . GetInt ( " spawn_delay_ms " ) ;
mShootSpeed = spawnArgs . GetFloat ( " speed " ) ;
mEntityDefName = spawnArgs . GetString ( " def_projectile " ) ;
2012-11-28 15:47:07 +00:00
if ( targets . Num ( ) > 0 & & targets [ 0 ] . IsValid ( ) )
{
2012-11-26 18:58:24 +00:00
mShootDir = targets [ 0 ] - > GetPhysics ( ) - > GetOrigin ( ) - GetPhysics ( ) - > GetOrigin ( ) ;
mShootDir . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// stationary projectile, doesn't move and only respawns when triggered
mShootSpeed = 0.0f ;
mRespawnTime = 0 ;
}
2012-11-28 15:47:07 +00:00
if ( ( thinkFlags & TH_THINK ) ! = 0 )
{
2012-11-26 18:58:24 +00:00
// currently active, deactivate
BecomeInactive ( TH_THINK ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// currently inactive, activate
BecomeActive ( TH_THINK ) ;
mRespawnTime = gameLocal . GetTime ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idFuncShootProjectile : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
// msg.WriteBits( hidden ? 1 : 0, 1 );
// msg.WriteFloat( renderEntity.shaderParms[ SHADERPARM_PARTICLE_STOPTIME ] );
// msg.WriteFloat( renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] );
}
/*
= = = = = = = = = = = = = = = =
idFuncShootProjectile : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncShootProjectile : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
// hidden = msg.ReadBits( 1 ) != 0;
// renderEntity.shaderParms[ SHADERPARM_PARTICLE_STOPTIME ] = msg.ReadFloat();
// renderEntity.shaderParms[ SHADERPARM_TIMEOFFSET ] = msg.ReadFloat();
// if ( msg.HasChanged() ) {
// UpdateVisuals();
// }
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncSplat
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_Splat ( " <Splat> " ) ;
CLASS_DECLARATION ( idFuncEmitter , idFuncSplat )
EVENT ( EV_Activate , idFuncSplat : : Event_Activate )
EVENT ( EV_Splat , idFuncSplat : : Event_Splat )
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncSplat : : idFuncSplat
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncSplat : : idFuncSplat ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idFuncSplat : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSplat : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idFuncSplat : : Event_Splat
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSplat : : Event_Splat ( )
{
const char * splat = NULL ;
2012-11-26 18:58:24 +00:00
int count = spawnArgs . GetInt ( " splatCount " , " 1 " ) ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < count ; i + + )
{
2012-11-26 18:58:24 +00:00
splat = spawnArgs . RandomPrefix ( " mtr_splat " , gameLocal . random ) ;
2012-11-28 15:47:07 +00:00
if ( splat ! = NULL & & * splat ! = NULL )
{
2012-11-26 18:58:24 +00:00
float size = spawnArgs . GetFloat ( " splatSize " , " 128 " ) ;
float dist = spawnArgs . GetFloat ( " splatDistance " , " 128 " ) ;
float angle = spawnArgs . GetFloat ( " splatAngle " , " 0 " ) ;
gameLocal . ProjectDecal ( GetPhysics ( ) - > GetOrigin ( ) , GetPhysics ( ) - > GetAxis ( ) [ 2 ] , dist , true , size , splat , angle ) ;
}
}
StartSound ( " snd_splat " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncSplat : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSplat : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
idFuncEmitter : : Event_Activate ( activator ) ;
PostEventSec ( & EV_Splat , spawnArgs . GetFloat ( " splatDelay " , " 0.25 " ) ) ;
StartSound ( " snd_spurt " , SND_CHANNEL_ANY , 0 , false , NULL ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncSmoke
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idFuncSmoke )
EVENT ( EV_Activate , idFuncSmoke : : Event_Activate )
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncSmoke : : idFuncSmoke
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncSmoke : : idFuncSmoke ( )
{
2012-11-26 18:58:24 +00:00
smokeTime = 0 ;
smoke = NULL ;
restart = false ;
}
/*
= = = = = = = = = = = = = = =
idFuncSmoke : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSmoke : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( smokeTime ) ;
savefile - > WriteParticle ( smoke ) ;
savefile - > WriteBool ( restart ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncSmoke : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSmoke : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( smokeTime ) ;
savefile - > ReadParticle ( smoke ) ;
savefile - > ReadBool ( restart ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncSmoke : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSmoke : : Spawn ( )
{
const char * smokeName = spawnArgs . GetString ( " smoke " ) ;
if ( * smokeName ! = ' \0 ' )
{
smoke = static_cast < const idDeclParticle * > ( declManager - > FindType ( DECL_PARTICLE , smokeName ) ) ;
}
else
{
2012-11-26 18:58:24 +00:00
smoke = NULL ;
}
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetBool ( " start_off " ) )
{
2012-11-26 18:58:24 +00:00
smokeTime = 0 ;
restart = false ;
2012-11-28 15:47:07 +00:00
}
else if ( smoke )
{
2012-11-26 18:58:24 +00:00
smokeTime = gameLocal . time ;
BecomeActive ( TH_UPDATEPARTICLES ) ;
restart = true ;
}
GetPhysics ( ) - > SetContents ( 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncSmoke : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSmoke : : Event_Activate ( idEntity * activator )
{
if ( thinkFlags & TH_UPDATEPARTICLES )
{
2012-11-26 18:58:24 +00:00
restart = false ;
return ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_UPDATEPARTICLES ) ;
restart = true ;
smokeTime = gameLocal . time ;
}
}
/*
= = = = = = = = = = = = = = =
idFuncSmoke : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncSmoke : : 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 ( ) | | smoke = = NULL | | smokeTime = = - 1 )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ( thinkFlags & TH_UPDATEPARTICLES ) & & ! IsHidden ( ) )
{
if ( ! gameLocal . smokeParticles - > EmitSmoke ( smoke , smokeTime , gameLocal . random . CRandomFloat ( ) , GetPhysics ( ) - > GetOrigin ( ) , GetPhysics ( ) - > GetAxis ( ) , timeGroup /*_D3XP*/ ) )
{
if ( restart )
{
2012-11-26 18:58:24 +00:00
smokeTime = gameLocal . time ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
smokeTime = 0 ;
BecomeInactive ( TH_UPDATEPARTICLES ) ;
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idTextEntity
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idTextEntity )
END_CLASS
/*
= = = = = = = = = = = = = = = =
idTextEntity : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idTextEntity : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
// these are cached as the are used each frame
text = spawnArgs . GetString ( " text " ) ;
playerOriented = spawnArgs . GetBool ( " playerOriented " ) ;
bool force = spawnArgs . GetBool ( " force " ) ;
2012-11-28 15:47:07 +00:00
if ( developer . GetBool ( ) | | force )
{
BecomeActive ( TH_THINK ) ;
2012-11-26 18:58:24 +00:00
}
}
/*
= = = = = = = = = = = = = = = =
idTextEntity : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idTextEntity : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteString ( text ) ;
savefile - > WriteBool ( playerOriented ) ;
}
/*
= = = = = = = = = = = = = = = =
idTextEntity : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idTextEntity : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadString ( text ) ;
savefile - > ReadBool ( playerOriented ) ;
}
/*
= = = = = = = = = = = = = = = =
idTextEntity : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idTextEntity : : Think ( )
{
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
gameRenderWorld - > DrawText ( text , GetPhysics ( ) - > GetOrigin ( ) , 0.25 , colorWhite , playerOriented ? gameLocal . GetLocalPlayer ( ) - > viewAngles . ToMat3 ( ) : GetPhysics ( ) - > GetAxis ( ) . Transpose ( ) , 1 ) ;
2012-11-28 15:47:07 +00:00
for ( int i = 0 ; i < targets . Num ( ) ; i + + )
{
if ( targets [ i ] . GetEntity ( ) )
{
2012-11-26 18:58:24 +00:00
gameRenderWorld - > DebugArrow ( colorBlue , GetPhysics ( ) - > GetOrigin ( ) , targets [ i ] . GetEntity ( ) - > GetPhysics ( ) - > GetOrigin ( ) , 1 ) ;
}
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_ALL ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idVacuumSeperatorEntity
Can be triggered to let vacuum through a portal ( blown out window )
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idVacuumSeparatorEntity )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idVacuumSeparatorEntity : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idVacuumSeparatorEntity : : idVacuumSeparatorEntity
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idVacuumSeparatorEntity : : idVacuumSeparatorEntity ( )
{
2012-11-26 18:58:24 +00:00
portal = 0 ;
}
/*
= = = = = = = = = = = = = = = =
idVacuumSeparatorEntity : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idVacuumSeparatorEntity : : Save ( idSaveGame * savefile ) const
{
savefile - > WriteInt ( ( int ) portal ) ;
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( gameRenderWorld - > GetPortalState ( portal ) ) ;
}
/*
= = = = = = = = = = = = = = = =
idVacuumSeparatorEntity : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idVacuumSeparatorEntity : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
int state ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( ( int & ) portal ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( state ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameLocal . SetPortalState ( portal , state ) ;
}
/*
= = = = = = = = = = = = = = = =
idVacuumSeparatorEntity : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idVacuumSeparatorEntity : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idBounds b ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
b = idBounds ( spawnArgs . GetVector ( " origin " ) ) . Expand ( 16 ) ;
portal = gameRenderWorld - > FindPortal ( b ) ;
2012-11-28 15:47:07 +00:00
if ( ! portal )
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " VacuumSeparator '%s' didn't contact a portal " , spawnArgs . GetString ( " name " ) ) ;
return ;
}
gameLocal . SetPortalState ( portal , PS_BLOCK_AIR | PS_BLOCK_LOCATION ) ;
}
/*
= = = = = = = = = = = = = = = =
idVacuumSeparatorEntity : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idVacuumSeparatorEntity : : Event_Activate ( idEntity * activator )
{
if ( ! portal )
{
2012-11-26 18:58:24 +00:00
return ;
}
gameLocal . SetPortalState ( portal , PS_BLOCK_NONE ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idLocationSeparatorEntity
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idLocationSeparatorEntity )
END_CLASS
/*
= = = = = = = = = = = = = = = =
idLocationSeparatorEntity : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idLocationSeparatorEntity : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idBounds b ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
b = idBounds ( spawnArgs . GetVector ( " origin " ) ) . Expand ( 16 ) ;
qhandle_t portal = gameRenderWorld - > FindPortal ( b ) ;
2012-11-28 15:47:07 +00:00
if ( ! portal )
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " LocationSeparator '%s' didn't contact a portal " , spawnArgs . GetString ( " name " ) ) ;
}
gameLocal . SetPortalState ( portal , PS_BLOCK_LOCATION ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idVacuumEntity
Levels should only have a single vacuum entity .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idVacuumEntity )
END_CLASS
/*
= = = = = = = = = = = = = = = =
idVacuumEntity : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idVacuumEntity : : Spawn ( )
{
if ( gameLocal . vacuumAreaNum ! = - 1 )
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " idVacuumEntity::Spawn: multiple idVacuumEntity in level " ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec3 org = spawnArgs . GetVector ( " origin " ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameLocal . vacuumAreaNum = gameRenderWorld - > PointInArea ( org ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idLocationEntity
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idLocationEntity )
END_CLASS
/*
= = = = = = = = = = = = = = = = = = = = = =
idLocationEntity : : Spawn
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idLocationEntity : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
idStr realName ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// this just holds dict information
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// if "location" not already set, use the entity name.
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetString ( " location " , " " , realName ) )
{
2012-11-26 18:58:24 +00:00
spawnArgs . Set ( " location " , name ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = =
idLocationEntity : : GetLocation
= = = = = = = = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
const char * idLocationEntity : : GetLocation ( ) const
{
2012-11-26 18:58:24 +00:00
return spawnArgs . GetString ( " location " ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idBeam
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idBeam )
2012-11-28 15:47:07 +00:00
EVENT ( EV_PostSpawn , idBeam : : Event_MatchTarget )
EVENT ( EV_Activate , idBeam : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idBeam : : idBeam
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idBeam : : idBeam ( )
{
2012-11-26 18:58:24 +00:00
target = NULL ;
master = NULL ;
}
/*
= = = = = = = = = = = = = = =
idBeam : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
target . Save ( savefile ) ;
master . Save ( savefile ) ;
}
/*
= = = = = = = = = = = = = = =
idBeam : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
target . Restore ( savefile ) ;
master . Restore ( savefile ) ;
}
/*
= = = = = = = = = = = = = = =
idBeam : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
float width ;
2012-11-28 15:47:07 +00:00
if ( spawnArgs . GetFloat ( " width " , " 0 " , width ) )
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_BEAM_WIDTH ] = width ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
SetModel ( " _BEAM " ) ;
Hide ( ) ;
PostEventMS ( & EV_PostSpawn , 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idBeam : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Think ( )
{
idBeam * masterEnt ;
if ( ! IsHidden ( ) & & ! target . GetEntity ( ) )
{
2012-11-26 18:58:24 +00:00
// hide if our target is removed
Hide ( ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
RunPhysics ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
masterEnt = master . GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( masterEnt )
{
const idVec3 & origin = GetPhysics ( ) - > GetOrigin ( ) ;
2012-11-26 18:58:24 +00:00
masterEnt - > SetBeamTarget ( origin ) ;
}
Present ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idBeam : : SetMaster
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : SetMaster ( idBeam * masterbeam )
{
2012-11-26 18:58:24 +00:00
master = masterbeam ;
}
/*
= = = = = = = = = = = = = = = =
idBeam : : SetBeamTarget
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : SetBeamTarget ( const idVec3 & origin )
{
if ( ( renderEntity . shaderParms [ SHADERPARM_BEAM_END_X ] ! = origin . x ) | | ( renderEntity . shaderParms [ SHADERPARM_BEAM_END_Y ] ! = origin . y ) | | ( renderEntity . shaderParms [ SHADERPARM_BEAM_END_Z ] ! = origin . z ) )
{
2012-11-26 18:58:24 +00:00
renderEntity . shaderParms [ SHADERPARM_BEAM_END_X ] = origin . x ;
renderEntity . shaderParms [ SHADERPARM_BEAM_END_Y ] = origin . y ;
renderEntity . shaderParms [ SHADERPARM_BEAM_END_Z ] = origin . z ;
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idBeam : : Show
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Show ( )
{
idBeam * targetEnt ;
2012-11-26 18:58:24 +00:00
idEntity : : Show ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
targetEnt = target . GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( targetEnt )
{
const idVec3 & origin = targetEnt - > GetPhysics ( ) - > GetOrigin ( ) ;
2012-11-26 18:58:24 +00:00
SetBeamTarget ( origin ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idBeam : : Event_MatchTarget
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Event_MatchTarget ( )
{
2012-11-26 18:58:24 +00:00
int i ;
2012-11-28 15:47:07 +00:00
idEntity * targetEnt ;
idBeam * targetBeam ;
if ( ! targets . Num ( ) )
{
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
targetBeam = NULL ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < targets . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
targetEnt = targets [ i ] . GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( targetEnt ! = NULL & & targetEnt - > IsType ( idBeam : : Type ) )
{
targetBeam = static_cast < idBeam * > ( targetEnt ) ;
2012-11-26 18:58:24 +00:00
break ;
}
}
2012-11-28 15:47:07 +00:00
if ( targetBeam = = NULL )
{
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " Could not find valid beam target for '%s' " , name . c_str ( ) ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
target = targetBeam ;
targetBeam - > SetMaster ( this ) ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " start_off " ) )
{
2012-11-26 18:58:24 +00:00
Show ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idBeam : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : Event_Activate ( idEntity * activator )
{
if ( IsHidden ( ) )
{
2012-11-26 18:58:24 +00:00
Show ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
Hide ( ) ;
2012-11-26 18:58:24 +00:00
}
}
/*
= = = = = = = = = = = = = = = =
idBeam : : WriteToSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : WriteToSnapshot ( idBitMsg & msg ) const
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > WriteToSnapshot ( msg ) ;
WriteBindToSnapshot ( msg ) ;
WriteColorToSnapshot ( msg ) ;
msg . WriteFloat ( renderEntity . shaderParms [ SHADERPARM_BEAM_END_X ] ) ;
msg . WriteFloat ( renderEntity . shaderParms [ SHADERPARM_BEAM_END_Y ] ) ;
msg . WriteFloat ( renderEntity . shaderParms [ SHADERPARM_BEAM_END_Z ] ) ;
}
/*
= = = = = = = = = = = = = = = =
idBeam : : ReadFromSnapshot
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idBeam : : ReadFromSnapshot ( const idBitMsg & msg )
{
2012-11-26 18:58:24 +00:00
GetPhysics ( ) - > ReadFromSnapshot ( msg ) ;
ReadBindFromSnapshot ( msg ) ;
ReadColorFromSnapshot ( msg ) ;
renderEntity . shaderParms [ SHADERPARM_BEAM_END_X ] = msg . ReadFloat ( ) ;
renderEntity . shaderParms [ SHADERPARM_BEAM_END_Y ] = msg . ReadFloat ( ) ;
renderEntity . shaderParms [ SHADERPARM_BEAM_END_Z ] = msg . ReadFloat ( ) ;
2012-11-28 15:47:07 +00:00
if ( msg . HasChanged ( ) )
{
2012-11-26 18:58:24 +00:00
UpdateVisuals ( ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idLiquid
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idLiquid )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Touch , idLiquid : : Event_Touch )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = = =
idLiquid : : Save
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idLiquid : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
// Nothing to save
}
/*
= = = = = = = = = = = = = = = =
idLiquid : : Restore
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idLiquid : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
//FIXME: NO!
Spawn ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idLiquid : : Spawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idLiquid : : Spawn ( )
{
/*
model = dynamic_cast < idRenderModelLiquid * > ( renderEntity . hModel ) ;
if ( ! model ) {
gameLocal . Error ( " Entity '%s' must have liquid model " , name . c_str ( ) ) ;
}
model - > Reset ( ) ;
GetPhysics ( ) - > SetContents ( CONTENTS_TRIGGER ) ;
*/
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idLiquid : : Event_Touch
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idLiquid : : Event_Touch ( idEntity * other , trace_t * trace )
{
2012-11-26 18:58:24 +00:00
// FIXME: for QuakeCon
2012-11-28 15:47:07 +00:00
/*
if ( common - > IsClient ( ) ) {
return ;
}
idVec3 pos ;
pos = other - > GetPhysics ( ) - > GetOrigin ( ) - GetPhysics ( ) - > GetOrigin ( ) ;
model - > IntersectBounds ( other - > GetPhysics ( ) - > GetBounds ( ) . Translate ( pos ) , - 10.0f ) ;
*/
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idShaking
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idShaking )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idShaking : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idShaking : : idShaking
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idShaking : : idShaking ( )
{
2012-11-26 18:58:24 +00:00
active = false ;
}
/*
= = = = = = = = = = = = = = =
idShaking : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShaking : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( active ) ;
savefile - > WriteStaticObject ( physicsObj ) ;
}
/*
= = = = = = = = = = = = = = =
idShaking : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShaking : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( active ) ;
savefile - > ReadStaticObject ( physicsObj ) ;
RestorePhysics ( & physicsObj ) ;
}
/*
= = = = = = = = = = = = = = =
idShaking : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShaking : : 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_ENTITY ) 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 ) ;
SetPhysics ( & physicsObj ) ;
active = false ;
2012-11-28 15:47:07 +00:00
if ( ! spawnArgs . GetBool ( " start_off " ) )
{
2012-11-26 18:58:24 +00:00
BeginShaking ( ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idShaking : : BeginShaking
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShaking : : BeginShaking ( )
{
2012-11-26 18:58:24 +00:00
int phase ;
idAngles shake ;
int period ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
active = true ;
phase = gameLocal . random . RandomInt ( 1000 ) ;
shake = spawnArgs . GetAngles ( " shake " , " 0.5 0.5 0.5 " ) ;
period = spawnArgs . GetFloat ( " period " , " 0.05 " ) * 1000 ;
2012-11-28 15:47:07 +00:00
physicsObj . SetAngularExtrapolation ( extrapolation_t ( EXTRAPOLATION_DECELSINE | EXTRAPOLATION_NOSTOP ) , phase , period * 0.25f , GetPhysics ( ) - > GetAxis ( ) . ToAngles ( ) , shake , ang_zero ) ;
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = = =
idShaking : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShaking : : Event_Activate ( idEntity * activator )
{
if ( ! active )
{
2012-11-26 18:58:24 +00:00
BeginShaking ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
active = false ;
physicsObj . SetAngularExtrapolation ( EXTRAPOLATION_NONE , 0 , 0 , physicsObj . GetAxis ( ) . ToAngles ( ) , ang_zero , ang_zero ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idEarthQuake
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idEarthQuake )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idEarthQuake : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idEarthQuake : : idEarthQuake
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idEarthQuake : : idEarthQuake ( )
{
2012-11-26 18:58:24 +00:00
wait = 0.0f ;
random = 0.0f ;
nextTriggerTime = 0 ;
shakeStopTime = 0 ;
triggered = false ;
playerOriented = false ;
disabled = false ;
shakeTime = 0.0f ;
}
/*
= = = = = = = = = = = = = = =
idEarthQuake : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idEarthQuake : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( nextTriggerTime ) ;
savefile - > WriteInt ( shakeStopTime ) ;
savefile - > WriteFloat ( wait ) ;
savefile - > WriteFloat ( random ) ;
savefile - > WriteBool ( triggered ) ;
savefile - > WriteBool ( playerOriented ) ;
savefile - > WriteBool ( disabled ) ;
savefile - > WriteFloat ( shakeTime ) ;
}
/*
= = = = = = = = = = = = = = =
idEarthQuake : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idEarthQuake : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( nextTriggerTime ) ;
savefile - > ReadInt ( shakeStopTime ) ;
savefile - > ReadFloat ( wait ) ;
savefile - > ReadFloat ( random ) ;
savefile - > ReadBool ( triggered ) ;
savefile - > ReadBool ( playerOriented ) ;
savefile - > ReadBool ( disabled ) ;
savefile - > ReadFloat ( shakeTime ) ;
2012-11-28 15:47:07 +00:00
if ( shakeStopTime > gameLocal . time )
{
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = =
idEarthQuake : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idEarthQuake : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
nextTriggerTime = 0 ;
shakeStopTime = 0 ;
wait = spawnArgs . GetFloat ( " wait " , " 15 " ) ;
random = spawnArgs . GetFloat ( " random " , " 5 " ) ;
triggered = spawnArgs . GetBool ( " triggered " ) ;
playerOriented = spawnArgs . GetBool ( " playerOriented " ) ;
disabled = false ;
shakeTime = spawnArgs . GetFloat ( " shakeTime " , " 0 " ) ;
2012-11-28 15:47:07 +00:00
if ( ! triggered )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Activate , spawnArgs . GetFloat ( " wait " ) , this ) ;
}
BecomeInactive ( TH_THINK ) ;
}
/*
= = = = = = = = = = = = = = = =
idEarthQuake : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idEarthQuake : : Event_Activate ( idEntity * activator )
{
if ( nextTriggerTime > gameLocal . time )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( disabled & & activator = = this )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
idPlayer * player = gameLocal . GetLocalPlayer ( ) ;
if ( player = = NULL )
{
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
nextTriggerTime = 0 ;
2012-11-28 15:47:07 +00:00
if ( ! triggered & & activator ! = this )
{
2012-11-26 18:58:24 +00:00
// if we are not triggered ( i.e. random ), disable or enable
disabled ^ = 1 ;
2012-11-28 15:47:07 +00:00
if ( disabled )
{
2012-11-26 18:58:24 +00:00
return ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Activate , wait + random * gameLocal . random . CRandomFloat ( ) , this ) ;
}
}
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
const idSoundShader * shader = declManager - > FindSound ( spawnArgs . GetString ( " snd_quake " ) ) ;
if ( playerOriented )
{
2012-11-26 18:58:24 +00:00
player - > StartSoundShader ( shader , SND_CHANNEL_ANY , SSF_GLOBAL , false , NULL ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
StartSoundShader ( shader , SND_CHANNEL_ANY , SSF_GLOBAL , false , NULL ) ;
}
2012-11-28 15:47:07 +00:00
if ( shakeTime > 0.0f )
{
2012-11-26 18:58:24 +00:00
shakeStopTime = gameLocal . time + SEC2MS ( shakeTime ) ;
BecomeActive ( TH_THINK ) ;
}
2012-11-28 15:47:07 +00:00
if ( wait > 0.0f )
{
if ( ! triggered )
{
2012-11-26 18:58:24 +00:00
PostEventSec ( & EV_Activate , wait + random * gameLocal . random . CRandomFloat ( ) , this ) ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
nextTriggerTime = gameLocal . time + SEC2MS ( wait + random * gameLocal . random . CRandomFloat ( ) ) ;
}
2012-11-28 15:47:07 +00:00
}
else if ( shakeTime = = 0.0f )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Remove , 0 ) ;
}
}
/*
= = = = = = = = = = = = = = =
idEarthQuake : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idEarthQuake : : Think ( )
{
if ( thinkFlags & TH_THINK )
{
if ( gameLocal . time > shakeStopTime )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
2012-11-28 15:47:07 +00:00
if ( wait < = 0.0f )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_Remove , 0 ) ;
}
return ;
}
float shakeVolume = gameSoundWorld - > CurrentShakeAmplitude ( ) ;
gameLocal . RadiusPush ( GetPhysics ( ) - > GetOrigin ( ) , 256 , 1500 * shakeVolume , this , this , 1.0f , true ) ;
}
BecomeInactive ( TH_UPDATEVISUALS ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncPortal
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idFuncPortal )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idFuncPortal : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncPortal : : idFuncPortal
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncPortal : : idFuncPortal ( )
{
2012-11-26 18:58:24 +00:00
portal = 0 ;
state = false ;
}
/*
= = = = = = = = = = = = = = =
idFuncPortal : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncPortal : : Save ( idSaveGame * savefile ) const
{
savefile - > WriteInt ( ( int ) portal ) ;
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( state ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncPortal : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncPortal : : Restore ( idRestoreGame * savefile )
{
savefile - > ReadInt ( ( int & ) portal ) ;
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( state ) ;
gameLocal . SetPortalState ( portal , state ? PS_BLOCK_ALL : PS_BLOCK_NONE ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncPortal : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncPortal : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
portal = gameRenderWorld - > FindPortal ( GetPhysics ( ) - > GetAbsBounds ( ) . Expand ( 32.0f ) ) ;
2012-11-28 15:47:07 +00:00
if ( portal > 0 )
{
2012-11-26 18:58:24 +00:00
state = spawnArgs . GetBool ( " start_on " ) ;
gameLocal . SetPortalState ( portal , state ? PS_BLOCK_ALL : PS_BLOCK_NONE ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idFuncPortal : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncPortal : : Event_Activate ( idEntity * activator )
{
if ( portal > 0 )
{
2012-11-26 18:58:24 +00:00
state = ! state ;
gameLocal . SetPortalState ( portal , state ? PS_BLOCK_ALL : PS_BLOCK_NONE ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncAASPortal
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idFuncAASPortal )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idFuncAASPortal : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncAASPortal : : idFuncAASPortal
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncAASPortal : : idFuncAASPortal ( )
{
2012-11-26 18:58:24 +00:00
state = false ;
}
/*
= = = = = = = = = = = = = = =
idFuncAASPortal : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASPortal : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( state ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncAASPortal : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASPortal : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( state ) ;
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL , state ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncAASPortal : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASPortal : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
state = spawnArgs . GetBool ( " start_on " ) ;
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL , state ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncAASPortal : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASPortal : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
state ^ = 1 ;
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_CLUSTERPORTAL , state ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncAASObstacle
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idFuncAASObstacle )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idFuncAASObstacle : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncAASObstacle : : idFuncAASObstacle
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncAASObstacle : : idFuncAASObstacle ( )
{
2012-11-26 18:58:24 +00:00
state = false ;
}
/*
= = = = = = = = = = = = = = =
idFuncAASObstacle : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASObstacle : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( state ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncAASObstacle : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASObstacle : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( state ) ;
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_OBSTACLE , state ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncAASObstacle : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASObstacle : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
state = spawnArgs . GetBool ( " start_on " ) ;
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_OBSTACLE , state ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncAASObstacle : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncAASObstacle : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
state ^ = 1 ;
gameLocal . SetAASAreaState ( GetPhysics ( ) - > GetAbsBounds ( ) , AREACONTENTS_OBSTACLE , state ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncRadioChatter
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
const idEventDef EV_ResetRadioHud ( " <resetradiohud> " , " e " ) ;
CLASS_DECLARATION ( idEntity , idFuncRadioChatter )
EVENT ( EV_Activate , idFuncRadioChatter : : Event_Activate )
EVENT ( EV_ResetRadioHud , idFuncRadioChatter : : Event_ResetRadioHud )
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncRadioChatter : : idFuncRadioChatter
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncRadioChatter : : idFuncRadioChatter ( )
{
2012-11-26 18:58:24 +00:00
time = 0.0 ;
}
/*
= = = = = = = = = = = = = = =
idFuncRadioChatter : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncRadioChatter : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( time ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncRadioChatter : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncRadioChatter : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( time ) ;
}
/*
= = = = = = = = = = = = = = =
idFuncRadioChatter : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncRadioChatter : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
time = spawnArgs . GetFloat ( " time " , " 5.0 " ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncRadioChatter : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncRadioChatter : : Event_Activate ( idEntity * activator )
{
idPlayer * player = gameLocal . GetLocalPlayer ( ) ;
if ( player ! = NULL & & player - > hudManager )
{
2012-11-26 18:58:24 +00:00
player - > hudManager - > SetRadioMessage ( true ) ;
}
2012-11-28 15:47:07 +00:00
const char * sound = spawnArgs . GetString ( " snd_radiochatter " , " " ) ;
if ( sound ! = NULL & & * sound ! = NULL )
{
const idSoundShader * shader = declManager - > FindSound ( sound ) ;
2012-11-26 18:58:24 +00:00
int length = 0 ;
player - > StartSoundShader ( shader , SND_CHANNEL_RADIO , SSF_GLOBAL , false , & length ) ;
time = MS2SEC ( length + 150 ) ;
}
2012-11-28 15:47:07 +00:00
// we still put the hud up because this is used with no sound on
2012-11-26 18:58:24 +00:00
// certain frame commands when the chatter is triggered
PostEventSec ( & EV_ResetRadioHud , time , player ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncRadioChatter : : Event_ResetRadioHud
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncRadioChatter : : Event_ResetRadioHud ( idEntity * activator )
{
idPlayer * player = ( activator - > IsType ( idPlayer : : Type ) ) ? static_cast < idPlayer * > ( activator ) : gameLocal . GetLocalPlayer ( ) ;
if ( player ! = NULL & & player - > hudManager )
{
2012-11-26 18:58:24 +00:00
player - > hudManager - > SetRadioMessage ( false ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
ActivateTargets ( activator ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idPhantomObjects
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idPhantomObjects )
2012-11-28 15:47:07 +00:00
EVENT ( EV_Activate , idPhantomObjects : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idPhantomObjects : : idPhantomObjects
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPhantomObjects : : idPhantomObjects ( )
{
2012-11-26 18:58:24 +00:00
target = NULL ;
end_time = 0 ;
throw_time = 0.0f ;
shake_time = 0.0f ;
shake_ang . Zero ( ) ;
speed = 0.0f ;
min_wait = 0 ;
max_wait = 0 ;
fl . neverDormant = false ;
}
/*
= = = = = = = = = = = = = = =
idPhantomObjects : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPhantomObjects : : 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 - > WriteInt ( end_time ) ;
savefile - > WriteFloat ( throw_time ) ;
savefile - > WriteFloat ( shake_time ) ;
savefile - > WriteVec3 ( shake_ang ) ;
savefile - > WriteFloat ( speed ) ;
savefile - > WriteInt ( min_wait ) ;
savefile - > WriteInt ( max_wait ) ;
target . Save ( savefile ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( targetTime . Num ( ) ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < targetTime . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > WriteInt ( targetTime [ i ] ) ;
}
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < lastTargetPos . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > WriteVec3 ( lastTargetPos [ i ] ) ;
}
}
/*
= = = = = = = = = = = = = = =
idPhantomObjects : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPhantomObjects : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
int num ;
int i ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( end_time ) ;
savefile - > ReadFloat ( throw_time ) ;
savefile - > ReadFloat ( shake_time ) ;
savefile - > ReadVec3 ( shake_ang ) ;
savefile - > ReadFloat ( speed ) ;
savefile - > ReadInt ( min_wait ) ;
savefile - > ReadInt ( max_wait ) ;
target . Restore ( savefile ) ;
2012-11-28 15:47:07 +00:00
savefile - > ReadInt ( num ) ;
2012-11-26 18:58:24 +00:00
targetTime . SetGranularity ( 1 ) ;
targetTime . SetNum ( num ) ;
lastTargetPos . SetGranularity ( 1 ) ;
lastTargetPos . SetNum ( num ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < num ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadInt ( targetTime [ i ] ) ;
}
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < num ; i + + )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadVec3 ( lastTargetPos [ i ] ) ;
}
}
/*
= = = = = = = = = = = = = = =
idPhantomObjects : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPhantomObjects : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
throw_time = spawnArgs . GetFloat ( " time " , " 5 " ) ;
speed = spawnArgs . GetFloat ( " speed " , " 1200 " ) ;
shake_time = spawnArgs . GetFloat ( " shake_time " , " 1 " ) ;
throw_time - = shake_time ;
2012-11-28 15:47:07 +00:00
if ( throw_time < 0.0f )
{
2012-11-26 18:58:24 +00:00
throw_time = 0.0f ;
}
min_wait = SEC2MS ( spawnArgs . GetFloat ( " min_wait " , " 1 " ) ) ;
max_wait = SEC2MS ( spawnArgs . GetFloat ( " max_wait " , " 3 " ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
shake_ang = spawnArgs . GetVector ( " shake_ang " , " 65 65 65 " ) ;
Hide ( ) ;
GetPhysics ( ) - > SetContents ( 0 ) ;
}
/*
= = = = = = = = = = = = = = = =
idPhantomObjects : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPhantomObjects : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
int i ;
float time ;
float frac ;
float scale ;
2012-11-28 15:47:07 +00:00
if ( thinkFlags & TH_THINK )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
RemoveNullTargets ( ) ;
2012-11-28 15:47:07 +00:00
if ( ! targets . Num ( ) )
{
2012-11-26 18:58:24 +00:00
return ;
}
2012-11-28 15:47:07 +00:00
if ( ! activator | | ! activator - > IsType ( idActor : : Type ) )
{
2012-11-26 18:58:24 +00:00
target = gameLocal . GetLocalPlayer ( ) ;
2012-11-28 15:47:07 +00:00
}
else
{
target = static_cast < idActor * > ( activator ) ;
2012-11-26 18:58:24 +00:00
}
end_time = gameLocal . time + SEC2MS ( spawnArgs . GetFloat ( " end_time " , " 0 " ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
targetTime . SetNum ( targets . Num ( ) ) ;
lastTargetPos . SetNum ( targets . Num ( ) ) ;
2012-11-28 15:47:07 +00:00
const idVec3 & toPos = target . GetEntity ( ) - > GetEyePosition ( ) ;
// calculate the relative times of all the objects
2012-11-26 18:58:24 +00:00
time = 0.0f ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < targetTime . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
targetTime [ i ] = SEC2MS ( time ) ;
lastTargetPos [ i ] = toPos ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
frac = 1.0f - ( float ) i / ( float ) targetTime . Num ( ) ;
time + = ( gameLocal . random . RandomFloat ( ) + 1.0f ) * 0.5f * frac + 0.1f ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// scale up the times to fit within throw_time
scale = throw_time / time ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < targetTime . Num ( ) ; i + + )
{
targetTime [ i ] = gameLocal . time + SEC2MS ( shake_time ) + targetTime [ i ] * scale ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
/*
= = = = = = = = = = = = = = =
idPhantomObjects : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPhantomObjects : : Think ( )
{
2012-11-26 18:58:24 +00:00
int i ;
int num ;
float time ;
idVec3 vel ;
idVec3 ang ;
2012-11-28 15:47:07 +00:00
idEntity * ent ;
idActor * targetEnt ;
idPhysics * entPhys ;
2012-11-26 18:58:24 +00:00
trace_t tr ;
2012-11-28 15:47:07 +00:00
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
if ( ! ( thinkFlags & TH_THINK ) )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( thinkFlags & ~ TH_THINK ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
targetEnt = target . GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( targetEnt = = NULL | | ( targetEnt - > health < = 0 ) | | ( end_time & & ( gameLocal . time > end_time ) ) | | gameLocal . inCinematic )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
return ;
}
2012-11-28 15:47:07 +00:00
const idVec3 & toPos = targetEnt - > GetEyePosition ( ) ;
2012-11-26 18:58:24 +00:00
num = 0 ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < targets . Num ( ) ; i + + )
{
2012-11-26 18:58:24 +00:00
ent = targets [ i ] . GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( ! ent )
{
2012-11-26 18:58:24 +00:00
continue ;
}
2012-11-28 15:47:07 +00:00
if ( ent - > fl . hidden )
{
2012-11-26 18:58:24 +00:00
// don't throw hidden objects
continue ;
}
2012-11-28 15:47:07 +00:00
if ( ! targetTime [ i ] )
{
2012-11-26 18:58:24 +00:00
// already threw this object
continue ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
num + + ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
time = MS2SEC ( targetTime [ i ] - gameLocal . time ) ;
2012-11-28 15:47:07 +00:00
if ( time > shake_time )
{
2012-11-26 18:58:24 +00:00
continue ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
entPhys = ent - > GetPhysics ( ) ;
2012-11-28 15:47:07 +00:00
const idVec3 & entOrg = entPhys - > GetOrigin ( ) ;
2012-11-26 18:58:24 +00:00
gameLocal . clip . TracePoint ( tr , entOrg , toPos , MASK_OPAQUE , ent ) ;
2012-11-28 15:47:07 +00:00
if ( tr . fraction > = 1.0f | | ( gameLocal . GetTraceEntity ( tr ) = = targetEnt ) )
{
2012-11-26 18:58:24 +00:00
lastTargetPos [ i ] = toPos ;
}
2012-11-28 15:47:07 +00:00
if ( time < 0.0f )
{
idAI : : PredictTrajectory ( entPhys - > GetOrigin ( ) , lastTargetPos [ i ] , speed , entPhys - > GetGravity ( ) ,
entPhys - > GetClipModel ( ) , entPhys - > GetClipMask ( ) , 256.0f , ent , targetEnt , ai_debugTrajectory . GetBool ( ) ? 1 : 0 , vel ) ;
2012-11-26 18:58:24 +00:00
vel * = speed ;
entPhys - > SetLinearVelocity ( vel ) ;
2012-11-28 15:47:07 +00:00
if ( ! end_time )
{
2012-11-26 18:58:24 +00:00
targetTime [ i ] = 0 ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
targetTime [ i ] = gameLocal . time + gameLocal . random . RandomInt ( max_wait - min_wait ) + min_wait ;
}
2012-11-28 15:47:07 +00:00
if ( ent - > IsType ( idMoveable : : Type ) )
{
idMoveable * ment = static_cast < idMoveable * > ( ent ) ;
2012-11-26 18:58:24 +00:00
ment - > EnableDamage ( true , 2.5f ) ;
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// this is not the right way to set the angular velocity, but the effect is nice, so I'm keeping it. :)
ang . Set ( gameLocal . random . CRandomFloat ( ) * shake_ang . x , gameLocal . random . CRandomFloat ( ) * shake_ang . y , gameLocal . random . CRandomFloat ( ) * shake_ang . z ) ;
ang * = ( 1.0f - time / shake_time ) ;
entPhys - > SetAngularVelocity ( ang ) ;
}
}
2012-11-28 15:47:07 +00:00
if ( ! num )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idShockwave
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idShockwave )
EVENT ( EV_Activate , idShockwave : : Event_Activate )
END_CLASS
/*
= = = = = = = = = = = = = = =
idShockwave : : idShockwave
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idShockwave : : idShockwave ( )
{
2012-11-26 18:58:24 +00:00
isActive = false ;
startTime = 0 ;
duration = 0 ;
startSize = 0.f ;
endSize = 0.f ;
currentSize = 0.f ;
magnitude = 0.f ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
height = 0.0f ;
playerDamaged = false ;
playerDamageSize = 0.0f ;
}
/*
= = = = = = = = = = = = = = =
idShockwave : : ~ idShockwave
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idShockwave : : ~ idShockwave ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idShockwave : : Save
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShockwave : : Save ( idSaveGame * savefile ) const
{
2012-11-26 18:58:24 +00:00
savefile - > WriteBool ( isActive ) ;
savefile - > WriteInt ( startTime ) ;
savefile - > WriteInt ( duration ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( startSize ) ;
savefile - > WriteFloat ( endSize ) ;
savefile - > WriteFloat ( currentSize ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( magnitude ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > WriteFloat ( height ) ;
savefile - > WriteBool ( playerDamaged ) ;
savefile - > WriteFloat ( playerDamageSize ) ;
}
/*
= = = = = = = = = = = = = = =
idShockwave : : Restore
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShockwave : : Restore ( idRestoreGame * savefile )
{
2012-11-26 18:58:24 +00:00
savefile - > ReadBool ( isActive ) ;
savefile - > ReadInt ( startTime ) ;
savefile - > ReadInt ( duration ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( startSize ) ;
savefile - > ReadFloat ( endSize ) ;
savefile - > ReadFloat ( currentSize ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( magnitude ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
savefile - > ReadFloat ( height ) ;
savefile - > ReadBool ( playerDamaged ) ;
savefile - > ReadFloat ( playerDamageSize ) ;
}
/*
= = = = = = = = = = = = = = =
idShockwave : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShockwave : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
spawnArgs . GetInt ( " duration " , " 1000 " , duration ) ;
spawnArgs . GetFloat ( " startsize " , " 8 " , startSize ) ;
spawnArgs . GetFloat ( " endsize " , " 512 " , endSize ) ;
spawnArgs . GetFloat ( " magnitude " , " 100 " , magnitude ) ;
2012-11-28 15:47:07 +00:00
spawnArgs . GetFloat ( " height " , " 0 " , height ) ;
spawnArgs . GetFloat ( " player_damage_size " , " 20 " , playerDamageSize ) ;
if ( spawnArgs . GetBool ( " start_on " ) )
{
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_Activate , this ) ;
}
}
/*
= = = = = = = = = = = = = = =
idShockwave : : Think
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShockwave : : Think ( )
{
2012-11-26 18:58:24 +00:00
int endTime ;
2012-11-28 15:47:07 +00:00
if ( ! isActive )
{
2012-11-26 18:58:24 +00:00
BecomeInactive ( TH_THINK ) ;
return ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
endTime = startTime + duration ;
2012-11-28 15:47:07 +00:00
if ( gameLocal . time < endTime )
{
2012-11-26 18:58:24 +00:00
float u ;
float newSize ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Expand shockwave
2012-11-28 15:47:07 +00:00
u = ( float ) ( gameLocal . time - startTime ) / ( float ) duration ;
newSize = startSize + u * ( endSize - startSize ) ;
2012-11-26 18:58:24 +00:00
// Find all clipmodels between currentSize and newSize
idVec3 pos , end ;
2012-11-28 15:47:07 +00:00
idClipModel * clipModelList [ MAX_GENTITIES ] ;
idClipModel * clip ;
idEntity * ent ;
2012-11-26 18:58:24 +00:00
int i , listedClipModels ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Set bounds
pos = GetPhysics ( ) - > GetOrigin ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float zVal ;
2012-11-28 15:47:07 +00:00
if ( ! height )
{
2012-11-26 18:58:24 +00:00
zVal = newSize ;
}
2012-11-28 15:47:07 +00:00
else
{
zVal = height / 2.0f ;
}
2012-11-26 18:58:24 +00:00
//Expand in a sphere
end = pos + idVec3 ( newSize , newSize , zVal ) ;
idBounds bounds ( end ) ;
end = pos + idVec3 ( - newSize , - newSize , - zVal ) ;
bounds . AddPoint ( end ) ;
2012-11-28 15:47:07 +00:00
if ( g_debugShockwave . GetBool ( ) )
{
gameRenderWorld - > DebugBounds ( colorRed , bounds , vec3_origin ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
listedClipModels = gameLocal . clip . ClipModelsTouchingBounds ( bounds , - 1 , clipModelList , MAX_GENTITIES ) ;
2012-11-28 15:47:07 +00:00
for ( i = 0 ; i < listedClipModels ; i + + )
{
2012-11-26 18:58:24 +00:00
clip = clipModelList [ i ] ;
ent = clip - > GetEntity ( ) ;
2012-11-28 15:47:07 +00:00
if ( ent - > IsHidden ( ) )
{
2012-11-26 18:58:24 +00:00
continue ;
}
2012-11-28 15:47:07 +00:00
if ( ! ent - > IsType ( idMoveable : : Type ) & & ! ent - > IsType ( idAFEntity_Base : : Type ) & & ! ent - > IsType ( idPlayer : : Type ) )
{
2012-11-26 18:58:24 +00:00
continue ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idVec3 point = ent - > GetPhysics ( ) - > GetOrigin ( ) ;
idVec3 force = point - pos ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float dist = force . Normalize ( ) ;
2012-11-28 15:47:07 +00:00
if ( ent - > IsType ( idPlayer : : Type ) )
{
if ( ent - > GetPhysics ( ) - > GetAbsBounds ( ) . IntersectsBounds ( bounds ) )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
//For player damage we check the current radius and a specified player damage ring size
if ( dist < = newSize & & dist > newSize - playerDamageSize )
{
idStr damageDef = spawnArgs . GetString ( " def_player_damage " , " " ) ;
if ( damageDef . Length ( ) > 0 & & ! playerDamaged )
{
2012-11-26 18:58:24 +00:00
playerDamaged = true ; //Only damage once per shockwave
idPlayer * player = static_cast < idPlayer * > ( ent ) ;
idVec3 dir = ent - > GetPhysics ( ) - > GetOrigin ( ) - pos ;
dir . NormalizeFast ( ) ;
2012-11-28 15:47:07 +00:00
player - > Damage ( NULL , NULL , dir , damageDef , 1.0f , INVALID_JOINT ) ;
2012-11-26 18:58:24 +00:00
}
}
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// If the object is inside the current expansion...
2012-11-28 15:47:07 +00:00
if ( dist < = newSize & & dist > currentSize )
{
2012-11-26 18:58:24 +00:00
force . z + = 4.f ;
force . NormalizeFast ( ) ;
2012-11-28 15:47:07 +00:00
if ( ent - > IsType ( idAFEntity_Base : : Type ) )
{
force = force * ( ent - > GetPhysics ( ) - > GetMass ( ) * magnitude * 0.01f ) ;
}
else
{
2012-11-26 18:58:24 +00:00
force = force * ent - > GetPhysics ( ) - > GetMass ( ) * magnitude ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Kick it up, move force point off object origin
float rad = ent - > GetPhysics ( ) - > GetBounds ( ) . GetRadius ( ) ;
point . x + = gameLocal . random . CRandomFloat ( ) * rad ;
point . y + = gameLocal . random . CRandomFloat ( ) * rad ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
int j ;
2012-11-28 15:47:07 +00:00
for ( j = 0 ; j < ent - > GetPhysics ( ) - > GetNumClipModels ( ) ; j + + )
{
2012-11-26 18:58:24 +00:00
ent - > GetPhysics ( ) - > AddForce ( j , point , force ) ;
}
}
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Update currentSize for next frame
currentSize = newSize ;
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
// turn off
isActive = false ;
}
}
/*
= = = = = = = = = = = = = = =
idShockwave : : Event_Activate
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idShockwave : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
isActive = true ;
startTime = gameLocal . time ;
playerDamaged = false ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncMountedObject
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idFuncMountedObject )
EVENT ( EV_Touch , idFuncMountedObject : : Event_Touch )
EVENT ( EV_Activate , idFuncMountedObject : : Event_Activate )
END_CLASS
/*
= = = = = = = = = = = = = = =
idFuncMountedObject : : idFuncMountedObject
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncMountedObject : : idFuncMountedObject ( )
{
2012-11-26 18:58:24 +00:00
isMounted = false ;
scriptFunction = NULL ;
mountedPlayer = NULL ;
harc = 0 ;
varc = 0 ;
}
/*
= = = = = = = = = = = = = = =
idFuncMountedObject : : idFuncMountedObject
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idFuncMountedObject : : ~ idFuncMountedObject ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idFuncMountedObject : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncMountedObject : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
// Get viewOffset
spawnArgs . GetInt ( " harc " , " 45 " , harc ) ;
spawnArgs . GetInt ( " varc " , " 30 " , varc ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Get script function
idStr funcName = spawnArgs . GetString ( " call " , " " ) ;
2012-11-28 15:47:07 +00:00
if ( funcName . Length ( ) )
{
2012-11-26 18:58:24 +00:00
scriptFunction = gameLocal . program . FindFunction ( funcName ) ;
2012-11-28 15:47:07 +00:00
if ( scriptFunction = = NULL )
{
gameLocal . Warning ( " idFuncMountedObject '%s' at (%s) calls unknown function '%s' \n " , name . c_str ( ) , GetPhysics ( ) - > GetOrigin ( ) . ToString ( 0 ) , funcName . c_str ( ) ) ;
2012-11-26 18:58:24 +00:00
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
BecomeActive ( TH_THINK ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncMountedObject : : Think
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncMountedObject : : Think ( )
{
2012-11-26 18:58:24 +00:00
idEntity : : Think ( ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncMountedObject : : GetViewInfo
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncMountedObject : : GetAngleRestrictions ( int & yaw_min , int & yaw_max , int & pitch )
{
2012-11-26 18:58:24 +00:00
idMat3 axis ;
idAngles angs ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
axis = GetPhysics ( ) - > GetAxis ( ) ;
angs = axis . ToAngles ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
yaw_min = angs . yaw - harc ;
yaw_min = idMath : : AngleNormalize180 ( yaw_min ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
yaw_max = angs . yaw + harc ;
yaw_max = idMath : : AngleNormalize180 ( yaw_max ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
pitch = varc ;
}
/*
= = = = = = = = = = = = = = = =
idFuncMountedObject : : Event_Touch
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncMountedObject : : 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
2012-11-26 18:58:24 +00:00
ProcessEvent ( & EV_Activate , other ) ;
}
/*
= = = = = = = = = = = = = = = =
idFuncMountedObject : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idFuncMountedObject : : Event_Activate ( idEntity * activator )
{
if ( ! isMounted & & activator - > IsType ( idPlayer : : Type ) )
{
idPlayer * client = ( idPlayer * ) activator ;
2012-11-26 18:58:24 +00:00
mountedPlayer = client ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
/*
// Place player at path_corner targeted by mounted object
int i ;
idPathCorner * spot ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
for ( i = 0 ; i < targets . Num ( ) ; i + + ) {
if ( targets [ i ] - > IsType ( idPathCorner : : Type ) ) {
spot = ( idPathCorner * ) targets [ i ] ;
break ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mountedPlayer - > GetPhysics ( ) - > SetOrigin ( spot - > GetPhysics ( ) - > GetOrigin ( ) ) ;
mountedPlayer - > GetPhysics ( ) - > SetAxis ( spot - > GetPhysics ( ) - > GetAxis ( ) ) ;
*/
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mountedPlayer - > Bind ( this , true ) ;
mountedPlayer - > mountedObject = this ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Call a script function
2012-11-28 15:47:07 +00:00
idThread * mountthread ;
if ( scriptFunction )
{
2012-11-26 18:58:24 +00:00
mountthread = new idThread ( scriptFunction ) ;
mountthread - > DelayedStart ( 0 ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
isMounted = true ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idFuncMountedWeapon
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idFuncMountedObject , idFuncMountedWeapon )
EVENT ( EV_PostSpawn , idFuncMountedWeapon : : Event_PostSpawn )
END_CLASS
2012-11-28 15:47:07 +00:00
idFuncMountedWeapon : : idFuncMountedWeapon ( )
{
2012-11-26 18:58:24 +00:00
turret = NULL ;
weaponLastFireTime = 0 ;
weaponFireDelay = 0 ;
projectile = NULL ;
}
2012-11-28 15:47:07 +00:00
idFuncMountedWeapon : : ~ idFuncMountedWeapon ( )
{
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
void idFuncMountedWeapon : : Spawn ( )
{
2012-11-26 18:58:24 +00:00
// Get projectile info
projectile = gameLocal . FindEntityDefDict ( spawnArgs . GetString ( " def_projectile " ) , false ) ;
2012-11-28 15:47:07 +00:00
if ( ! projectile )
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " Invalid projectile on func_mountedweapon. " ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
float firerate ;
spawnArgs . GetFloat ( " firerate " , " 3 " , firerate ) ;
weaponFireDelay = 1000.f / firerate ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Get the firing sound
idStr fireSound ;
spawnArgs . GetString ( " snd_fire " , " " , fireSound ) ;
soundFireWeapon = declManager - > FindSound ( fireSound ) ;
2012-11-28 15:47:07 +00:00
PostEventMS ( & EV_PostSpawn , 0 ) ;
2012-11-26 18:58:24 +00:00
}
2012-11-28 15:47:07 +00:00
void idFuncMountedWeapon : : Think ( )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( isMounted & & turret )
{
2012-11-26 18:58:24 +00:00
idVec3 vec = mountedPlayer - > viewAngles . ToForward ( ) ;
idAngles ang = mountedPlayer - > GetLocalVector ( vec ) . ToAngles ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
turret - > GetPhysics ( ) - > SetAxis ( ang . ToMat3 ( ) ) ;
turret - > UpdateVisuals ( ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
// Check for firing
2012-11-28 15:47:07 +00:00
if ( mountedPlayer - > usercmd . buttons & BUTTON_ATTACK & & ( gameLocal . time > weaponLastFireTime + weaponFireDelay ) )
{
2012-11-26 18:58:24 +00:00
// FIRE!
2012-11-28 15:47:07 +00:00
idEntity * ent ;
idProjectile * proj ;
2012-11-26 18:58:24 +00:00
idBounds projBounds ;
idVec3 dir ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
gameLocal . SpawnEntityDef ( * projectile , & ent ) ;
2012-11-28 15:47:07 +00:00
if ( ! ent | | ! ent - > IsType ( idProjectile : : Type ) )
{
const char * projectileName = spawnArgs . GetString ( " def_projectile " ) ;
2012-11-26 18:58:24 +00:00
gameLocal . Error ( " '%s' is not an idProjectile " , projectileName ) ;
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
mountedPlayer - > GetViewPos ( muzzleOrigin , muzzleAxis ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
muzzleOrigin + = ( muzzleAxis [ 0 ] * 128 ) ;
muzzleOrigin - = ( muzzleAxis [ 2 ] * 20 ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
dir = muzzleAxis [ 0 ] ;
2012-11-28 15:47:07 +00:00
proj = static_cast < idProjectile * > ( ent ) ;
2012-11-26 18:58:24 +00:00
proj - > Create ( this , muzzleOrigin , dir ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
projBounds = proj - > GetPhysics ( ) - > GetBounds ( ) . Rotate ( proj - > GetPhysics ( ) - > GetAxis ( ) ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
proj - > Launch ( muzzleOrigin , dir , vec3_origin ) ;
StartSoundShader ( soundFireWeapon , SND_CHANNEL_WEAPON , SSF_GLOBAL , false , NULL ) ;
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
weaponLastFireTime = gameLocal . time ;
}
}
2012-11-28 15:47:07 +00:00
2012-11-26 18:58:24 +00:00
idFuncMountedObject : : Think ( ) ;
}
2012-11-28 15:47:07 +00:00
void idFuncMountedWeapon : : Event_PostSpawn ( )
{
2012-11-26 18:58:24 +00:00
2012-11-28 15:47:07 +00:00
if ( targets . Num ( ) > = 1 )
{
for ( int i = 0 ; i < targets . Num ( ) ; i + + )
{
if ( targets [ i ] . GetEntity ( ) - > IsType ( idStaticEntity : : Type ) )
{
2012-11-26 18:58:24 +00:00
turret = targets [ i ] . GetEntity ( ) ;
break ;
}
}
2012-11-28 15:47:07 +00:00
}
else
{
2012-11-26 18:58:24 +00:00
gameLocal . Warning ( " idFuncMountedWeapon::Spawn: Please target one model for a turret \n " ) ;
}
}
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
idPortalSky
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
CLASS_DECLARATION ( idEntity , idPortalSky )
2012-11-28 15:47:07 +00:00
EVENT ( EV_PostSpawn , idPortalSky : : Event_PostSpawn )
EVENT ( EV_Activate , idPortalSky : : Event_Activate )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
= = = = = = = = = = = = = = =
idPortalSky : : idPortalSky
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPortalSky : : idPortalSky ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idPortalSky : : ~ idPortalSky
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
idPortalSky : : ~ idPortalSky ( )
{
2012-11-26 18:58:24 +00:00
}
/*
= = = = = = = = = = = = = = =
idPortalSky : : Spawn
= = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPortalSky : : Spawn ( )
{
if ( ! spawnArgs . GetBool ( " triggered " ) )
{
2012-11-26 18:58:24 +00:00
PostEventMS ( & EV_PostSpawn , 1 ) ;
}
}
/*
= = = = = = = = = = = = = = = =
idPortalSky : : Event_PostSpawn
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPortalSky : : Event_PostSpawn ( )
{
2012-11-26 18:58:24 +00:00
gameLocal . SetPortalSkyEnt ( this ) ;
}
/*
= = = = = = = = = = = = = = = =
idPortalSky : : Event_Activate
= = = = = = = = = = = = = = = =
*/
2012-11-28 15:47:07 +00:00
void idPortalSky : : Event_Activate ( idEntity * activator )
{
2012-11-26 18:58:24 +00:00
gameLocal . SetPortalSkyEnt ( this ) ;
}