2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
#include "Game_local.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idMultiModelAF
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idEntity, idMultiModelAF )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiModelAF::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiModelAF::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
physicsObj.SetSelf( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiModelAF::~idMultiModelAF
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idMultiModelAF::~idMultiModelAF()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < modelDefHandles.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( modelDefHandles[i] != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->FreeEntityDef( modelDefHandles[i] );
|
|
|
|
modelDefHandles[i] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiModelAF::SetModelForId
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiModelAF::SetModelForId( int id, const idStr& modelName )
|
|
|
|
{
|
|
|
|
modelHandles.AssureSize( id + 1, NULL );
|
|
|
|
modelDefHandles.AssureSize( id + 1, -1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
modelHandles[id] = renderModelManager->FindModel( modelName );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiModelAF::Present
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiModelAF::Present()
|
|
|
|
{
|
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
|
|
|
// don't present to the renderer if the entity hasn't changed
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !( thinkFlags & TH_UPDATEVISUALS ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
BecomeInactive( TH_UPDATEVISUALS );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < modelHandles.Num(); i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !modelHandles[i] )
|
|
|
|
{
|
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
|
|
|
renderEntity.origin = physicsObj.GetOrigin( i );
|
|
|
|
renderEntity.axis = physicsObj.GetAxis( i );
|
|
|
|
renderEntity.hModel = modelHandles[i];
|
|
|
|
renderEntity.bodyId = i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// add to refresh list
|
2012-11-28 15:47:07 +00:00
|
|
|
if( modelDefHandles[i] == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
modelDefHandles[i] = gameRenderWorld->AddEntityDef( &renderEntity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->UpdateEntityDef( modelDefHandles[i], &renderEntity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idMultiModelAF::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idMultiModelAF::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RunPhysics();
|
|
|
|
Present();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idChain
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idMultiModelAF, idChain )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idChain::BuildChain
|
|
|
|
|
|
|
|
builds a chain hanging down from the ceiling
|
|
|
|
the highest link is a child of the link below it etc.
|
|
|
|
this allows an object to be attached to multiple chains while keeping a single tree structure
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idChain::BuildChain( const idStr& name, const idVec3& origin, float linkLength, float linkWidth, float density, int numLinks, bool bindToWorld )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
float halfLinkLength = linkLength * 0.5f;
|
|
|
|
idTraceModel trm;
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* clip;
|
|
|
|
idAFBody* body, *lastBody;
|
|
|
|
idAFConstraint_BallAndSocketJoint* bsj;
|
|
|
|
idAFConstraint_UniversalJoint* uj;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 org;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// create a trace model
|
|
|
|
trm = idTraceModel( linkLength, linkWidth );
|
|
|
|
trm.Translate( -trm.offset );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
org = origin - idVec3( 0, 0, halfLinkLength );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastBody = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < numLinks; i++ )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// add body
|
2012-11-28 15:47:07 +00:00
|
|
|
clip = new( TAG_PHYSICS_CLIP_AF ) idClipModel( trm );
|
2012-11-26 18:58:24 +00:00
|
|
|
clip->SetContents( CONTENTS_SOLID );
|
|
|
|
clip->Link( gameLocal.clip, this, 0, org, mat3_identity );
|
2012-11-28 15:47:07 +00:00
|
|
|
body = new( TAG_PHYSICS_AF ) idAFBody( name + idStr( i ), clip, density );
|
2012-11-26 18:58:24 +00:00
|
|
|
physicsObj.AddBody( body );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// visual model for body
|
|
|
|
SetModelForId( physicsObj.GetBodyId( body ), spawnArgs.GetString( "model" ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// add constraint
|
2012-11-28 15:47:07 +00:00
|
|
|
if( bindToWorld )
|
|
|
|
{
|
|
|
|
if( !lastBody )
|
|
|
|
{
|
|
|
|
uj = new( TAG_PHYSICS_AF ) idAFConstraint_UniversalJoint( name + idStr( i ), body, lastBody );
|
2012-11-26 18:58:24 +00:00
|
|
|
uj->SetShafts( idVec3( 0, 0, -1 ), idVec3( 0, 0, 1 ) );
|
|
|
|
//uj->SetConeLimit( idVec3( 0, 0, -1 ), 30.0f );
|
|
|
|
//uj->SetPyramidLimit( idVec3( 0, 0, -1 ), idVec3( 1, 0, 0 ), 90.0f, 30.0f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
uj = new( TAG_PHYSICS_AF ) idAFConstraint_UniversalJoint( name + idStr( i ), lastBody, body );
|
2012-11-26 18:58:24 +00:00
|
|
|
uj->SetShafts( idVec3( 0, 0, 1 ), idVec3( 0, 0, -1 ) );
|
|
|
|
//uj->SetConeLimit( idVec3( 0, 0, 1 ), 30.0f );
|
|
|
|
}
|
|
|
|
uj->SetAnchor( org + idVec3( 0, 0, halfLinkLength ) );
|
|
|
|
uj->SetFriction( 0.9f );
|
|
|
|
physicsObj.AddConstraint( uj );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( lastBody )
|
|
|
|
{
|
|
|
|
bsj = new( TAG_PHYSICS_AF ) idAFConstraint_BallAndSocketJoint( "joint" + idStr( i ), lastBody, body );
|
2012-11-26 18:58:24 +00:00
|
|
|
bsj->SetAnchor( org + idVec3( 0, 0, halfLinkLength ) );
|
|
|
|
bsj->SetConeLimit( idVec3( 0, 0, 1 ), 60.0f, idVec3( 0, 0, 1 ) );
|
|
|
|
physicsObj.AddConstraint( bsj );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
org[2] -= linkLength;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastBody = body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idChain::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idChain::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int numLinks;
|
|
|
|
float length, linkLength, linkWidth, density;
|
|
|
|
bool drop;
|
|
|
|
idVec3 origin;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnArgs.GetBool( "drop", "0", drop );
|
|
|
|
spawnArgs.GetInt( "links", "3", numLinks );
|
|
|
|
spawnArgs.GetFloat( "length", idStr( numLinks * 32.0f ), length );
|
|
|
|
spawnArgs.GetFloat( "width", "8", linkWidth );
|
|
|
|
spawnArgs.GetFloat( "density", "0.2", density );
|
|
|
|
linkLength = length / numLinks;
|
|
|
|
origin = GetPhysics()->GetOrigin();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// initialize physics
|
|
|
|
physicsObj.SetSelf( this );
|
|
|
|
physicsObj.SetGravity( gameLocal.GetGravity() );
|
|
|
|
physicsObj.SetClipMask( MASK_SOLID | CONTENTS_BODY );
|
|
|
|
SetPhysics( &physicsObj );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
BuildChain( "link", origin, linkLength, linkWidth, density, numLinks, !drop );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFAttachment
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAnimatedEntity, idAFAttachment )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFAttachment::idAFAttachment
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFAttachment::idAFAttachment()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
body = NULL;
|
|
|
|
combatModel = NULL;
|
|
|
|
idleAnim = 0;
|
|
|
|
attachJoint = INVALID_JOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFAttachment::~idAFAttachment
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFAttachment::~idAFAttachment()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
StopSound( SND_CHANNEL_ANY, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delete combatModel;
|
|
|
|
combatModel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFAttachment::Spawn
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idleAnim = animator.GetAnim( "idle" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFAttachment::SetBody
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::SetBody( idEntity* bodyEnt, const char* model, jointHandle_t attachJoint )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool bleed;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
body = bodyEnt;
|
|
|
|
this->attachJoint = attachJoint;
|
|
|
|
SetModel( model );
|
|
|
|
fl.takedamage = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bleed = body->spawnArgs.GetBool( "bleed" );
|
|
|
|
spawnArgs.SetBool( "bleed", bleed );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFAttachment::ClearBody
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::ClearBody()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
body = NULL;
|
|
|
|
attachJoint = INVALID_JOINT;
|
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFAttachment::GetBody
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* idAFAttachment::GetBody() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::Save
|
|
|
|
|
|
|
|
archive object for savegame file
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteObject( body );
|
|
|
|
savefile->WriteInt( idleAnim );
|
|
|
|
savefile->WriteJoint( attachJoint );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::Restore
|
|
|
|
|
|
|
|
unarchives object from save game file
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
|
|
|
savefile->ReadObject( reinterpret_cast<idClass*&>( body ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadInt( idleAnim );
|
|
|
|
savefile->ReadJoint( attachJoint );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetCombatModel();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::Hide
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Hide()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::Hide();
|
|
|
|
UnlinkCombat();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::Show
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Show()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::Show();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAFAttachment::Damage
|
|
|
|
|
|
|
|
Pass damage to body at the bindjoint
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Damage( idEntity* inflictor, idEntity* attacker, const idVec3& dir,
|
|
|
|
const char* damageDefName, const float damageScale, const int location )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( body )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
body->Damage( inflictor, attacker, dir, damageDefName, damageScale, attachJoint );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::AddDamageEffect
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::AddDamageEffect( const trace_t& collision, const idVec3& velocity, const char* damageDefName )
|
|
|
|
{
|
|
|
|
if( body )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
trace_t c = collision;
|
|
|
|
c.c.id = JOINT_HANDLE_TO_CLIPMODEL_ID( attachJoint );
|
|
|
|
body->AddDamageEffect( c, velocity, damageDefName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::GetImpactInfo
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::GetImpactInfo( idEntity* ent, int id, const idVec3& point, impactInfo_t* info )
|
|
|
|
{
|
|
|
|
if( body )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
body->GetImpactInfo( ent, JOINT_HANDLE_TO_CLIPMODEL_ID( attachJoint ), point, info );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::GetImpactInfo( ent, id, point, info );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::ApplyImpulse
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::ApplyImpulse( idEntity* ent, int id, const idVec3& point, const idVec3& impulse )
|
|
|
|
{
|
|
|
|
if( body )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
body->ApplyImpulse( ent, JOINT_HANDLE_TO_CLIPMODEL_ID( attachJoint ), point, impulse );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::ApplyImpulse( ent, id, point, impulse );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::AddForce
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::AddForce( idEntity* ent, int id, const idVec3& point, const idVec3& force )
|
|
|
|
{
|
|
|
|
if( body )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
body->AddForce( ent, JOINT_HANDLE_TO_CLIPMODEL_ID( attachJoint ), point, force );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::AddForce( ent, id, point, force );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::PlayIdleAnim
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::PlayIdleAnim( int blendTime )
|
|
|
|
{
|
|
|
|
if( idleAnim && ( idleAnim != animator.CurrentAnim( ANIMCHANNEL_ALL )->AnimNum() ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
animator.CycleAnim( ANIMCHANNEL_ALL, idleAnim, gameLocal.time, blendTime );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAfAttachment::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idAnimatedEntity::Think();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( thinkFlags & TH_UPDATEPARTICLES )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateDamageEffects();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::SetCombatModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::SetCombatModel()
|
|
|
|
{
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Unlink();
|
|
|
|
combatModel->LoadModel( modelDefHandle );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combatModel = new( TAG_PHYSICS_CLIP_AF ) idClipModel( modelDefHandle );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
combatModel->SetOwner( body );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::GetCombatModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* idAFAttachment::GetCombatModel() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return combatModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::LinkCombat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::LinkCombat()
|
|
|
|
{
|
|
|
|
if( fl.hidden )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Link( gameLocal.clip, this, 0, renderEntity.origin, renderEntity.axis, modelDefHandle );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFAttachment::UnlinkCombat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFAttachment::UnlinkCombat()
|
|
|
|
{
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Unlink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_Base
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
const idEventDef EV_SetConstraintPosition( "SetConstraintPosition", "sv" );
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAnimatedEntity, idAFEntity_Base )
|
2012-11-28 15:47:07 +00:00
|
|
|
EVENT( EV_SetConstraintPosition, idAFEntity_Base::Event_SetConstraintPosition )
|
2012-11-26 18:58:24 +00:00
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
static const float BOUNCE_SOUND_MIN_VELOCITY = 80.0f;
|
|
|
|
static const float BOUNCE_SOUND_MAX_VELOCITY = 200.0f;
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::idAFEntity_Base
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Base::idAFEntity_Base()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel = NULL;
|
|
|
|
combatModelContents = 0;
|
|
|
|
nextSoundTime = 0;
|
|
|
|
spawnOrigin.Zero();
|
|
|
|
spawnAxis.Identity();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::~idAFEntity_Base
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Base::~idAFEntity_Base()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete combatModel;
|
|
|
|
combatModel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteInt( combatModelContents );
|
|
|
|
savefile->WriteClipModel( combatModel );
|
|
|
|
savefile->WriteVec3( spawnOrigin );
|
|
|
|
savefile->WriteMat3( spawnAxis );
|
|
|
|
savefile->WriteInt( nextSoundTime );
|
|
|
|
af.Save( savefile );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadInt( combatModelContents );
|
|
|
|
savefile->ReadClipModel( combatModel );
|
|
|
|
savefile->ReadVec3( spawnOrigin );
|
|
|
|
savefile->ReadMat3( spawnAxis );
|
|
|
|
savefile->ReadInt( nextSoundTime );
|
|
|
|
LinkCombat();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.Restore( savefile );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnOrigin = GetPhysics()->GetOrigin();
|
|
|
|
spawnAxis = GetPhysics()->GetAxis();
|
|
|
|
nextSoundTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::LoadAF
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAFEntity_Base::LoadAF()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr fileName;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !spawnArgs.GetString( "articulatedFigure", "*unknown*", fileName ) )
|
|
|
|
{
|
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
|
|
|
af.SetAnimator( GetAnimator() );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !af.Load( this, fileName ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_Base::LoadAF: Couldn't load af file '%s' on entity '%s'", fileName.c_str(), name.c_str() );
|
|
|
|
}
|
|
|
|
float mass = spawnArgs.GetFloat( "mass", "-1" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( mass > 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetMass( mass );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.Start();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->Rotate( spawnAxis.ToRotation() );
|
|
|
|
af.GetPhysics()->Translate( spawnOrigin );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
LoadState( spawnArgs );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.UpdateAnimation();
|
|
|
|
animator.CreateFrame( gameLocal.time, true );
|
|
|
|
UpdateVisuals();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
RunPhysics();
|
|
|
|
UpdateAnimation();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( thinkFlags & TH_UPDATEVISUALS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Present();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::BodyForClipModelId
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idAFEntity_Base::BodyForClipModelId( int id ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return af.BodyForClipModelId( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::SaveState
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::SaveState( idDict& args ) const
|
|
|
|
{
|
|
|
|
const idKeyValue* kv;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// save the ragdoll pose
|
|
|
|
af.SaveState( args );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// save all the bind constraints
|
|
|
|
kv = spawnArgs.MatchPrefix( "bindConstraint ", NULL );
|
2012-11-28 15:47:07 +00:00
|
|
|
while( kv )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( kv->GetKey(), kv->GetValue() );
|
|
|
|
kv = spawnArgs.MatchPrefix( "bindConstraint ", kv );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// save the bind if it exists
|
|
|
|
kv = spawnArgs.FindKey( "bind" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( kv )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( kv->GetKey(), kv->GetValue() );
|
|
|
|
}
|
|
|
|
kv = spawnArgs.FindKey( "bindToJoint" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( kv )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( kv->GetKey(), kv->GetValue() );
|
|
|
|
}
|
|
|
|
kv = spawnArgs.FindKey( "bindToBody" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( kv )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( kv->GetKey(), kv->GetValue() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::LoadState
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::LoadState( const idDict& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.LoadState( args );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::AddBindConstraints
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::AddBindConstraints()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.AddBindConstraints();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::RemoveBindConstraints
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::RemoveBindConstraints()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.RemoveBindConstraints();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::AddDamageEffect
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::AddDamageEffect( const trace_t& collision, const idVec3& velocity, const char* damageDefName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idAnimatedEntity::AddDamageEffect( collision, velocity, damageDefName );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::GetImpactInfo
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::GetImpactInfo( idEntity* ent, int id, const idVec3& point, impactInfo_t* info )
|
|
|
|
{
|
|
|
|
if( af.IsActive() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetImpactInfo( ent, id, point, info );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::GetImpactInfo( ent, id, point, info );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::ApplyImpulse
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::ApplyImpulse( idEntity* ent, int id, const idVec3& point, const idVec3& impulse )
|
|
|
|
{
|
|
|
|
if( af.IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.ApplyImpulse( ent, id, point, impulse );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !af.IsActive() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::ApplyImpulse( ent, id, point, impulse );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::AddForce
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::AddForce( idEntity* ent, int id, const idVec3& point, const idVec3& force )
|
|
|
|
{
|
|
|
|
if( af.IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.AddForce( ent, id, point, force );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !af.IsActive() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::AddForce( ent, id, point, force );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::Collide
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAFEntity_Base::Collide( const trace_t& collision, const idVec3& velocity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
float v, f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( af.IsActive() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
v = -( velocity * collision.c.normal );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( v > BOUNCE_SOUND_MIN_VELOCITY && gameLocal.time > nextSoundTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
f = v > BOUNCE_SOUND_MAX_VELOCITY ? 1.0f : idMath::Sqrt( v - BOUNCE_SOUND_MIN_VELOCITY ) * ( 1.0f / idMath::Sqrt( BOUNCE_SOUND_MAX_VELOCITY - BOUNCE_SOUND_MIN_VELOCITY ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( StartSound( "snd_bounce", SND_CHANNEL_ANY, 0, false, NULL ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// don't set the volume unless there is a bounce sound as it overrides the entire channel
|
|
|
|
// which causes footsteps on ai's to not honor their shader parms
|
|
|
|
SetSoundVolume( f );
|
|
|
|
}
|
|
|
|
nextSoundTime = gameLocal.time + 500;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::GetPhysicsToVisualTransform
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAFEntity_Base::GetPhysicsToVisualTransform( idVec3& origin, idMat3& axis )
|
|
|
|
{
|
|
|
|
if( af.IsActive() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysicsToVisualTransform( origin, axis );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return idEntity::GetPhysicsToVisualTransform( origin, axis );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::UpdateAnimationControllers
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAFEntity_Base::UpdateAnimationControllers()
|
|
|
|
{
|
|
|
|
if( af.IsActive() )
|
|
|
|
{
|
|
|
|
if( af.UpdateAnimation() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::SetCombatModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::SetCombatModel()
|
|
|
|
{
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Unlink();
|
|
|
|
combatModel->LoadModel( modelDefHandle );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combatModel = new( TAG_PHYSICS_CLIP_AF ) idClipModel( modelDefHandle );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::GetCombatModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idClipModel* idAFEntity_Base::GetCombatModel() const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return combatModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::SetCombatContents
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::SetCombatContents( bool enable )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( combatModel );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( enable && combatModelContents )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !combatModel->GetContents() );
|
|
|
|
combatModel->SetContents( combatModelContents );
|
|
|
|
combatModelContents = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( !enable && combatModel->GetContents() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !combatModelContents );
|
|
|
|
combatModelContents = combatModel->GetContents();
|
|
|
|
combatModel->SetContents( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::LinkCombat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::LinkCombat()
|
|
|
|
{
|
|
|
|
if( fl.hidden )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Link( gameLocal.clip, this, 0, renderEntity.origin, renderEntity.axis, modelDefHandle );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::UnlinkCombat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::UnlinkCombat()
|
|
|
|
{
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Unlink();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::FreeModelDef
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::FreeModelDef()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
UnlinkCombat();
|
|
|
|
idEntity::FreeModelDef();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
idAFEntity_Base::ShowEditingDialog
|
|
|
|
===============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::ShowEditingDialog()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::DropAFs
|
|
|
|
|
|
|
|
The entity should have the following key/value pairs set:
|
|
|
|
"def_drop<type>AF" "af def"
|
|
|
|
"drop<type>Skin" "skin name"
|
|
|
|
To drop multiple articulated figures the following key/value pairs can be used:
|
|
|
|
"def_drop<type>AF*" "af def"
|
|
|
|
where * is an aribtrary string.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::DropAFs( idEntity* ent, const char* type, idList<idEntity*>* list )
|
|
|
|
{
|
|
|
|
const idKeyValue* kv;
|
|
|
|
const char* skinName;
|
|
|
|
idEntity* newEnt;
|
|
|
|
idAFEntity_Base* af;
|
2012-11-26 18:58:24 +00:00
|
|
|
idDict args;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idDeclSkin* skin;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// drop the articulated figures
|
|
|
|
kv = ent->spawnArgs.MatchPrefix( va( "def_drop%sAF", type ), NULL );
|
2012-11-28 15:47:07 +00:00
|
|
|
while( kv )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( "classname", kv->GetValue() );
|
|
|
|
gameLocal.SpawnEntityDef( args, &newEnt );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( newEnt && newEnt->IsType( idAFEntity_Base::Type ) )
|
|
|
|
{
|
|
|
|
af = static_cast<idAFEntity_Base*>( newEnt );
|
2012-11-26 18:58:24 +00:00
|
|
|
af->GetPhysics()->SetOrigin( ent->GetPhysics()->GetOrigin() );
|
|
|
|
af->GetPhysics()->SetAxis( ent->GetPhysics()->GetAxis() );
|
|
|
|
af->af.SetupPose( ent, gameLocal.time );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( list )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
list->Append( af );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
kv = ent->spawnArgs.MatchPrefix( va( "def_drop%sAF", type ), kv );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// change the skin to hide all the dropped articulated figures
|
|
|
|
skinName = ent->spawnArgs.GetString( va( "skin_drop%s", type ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( skinName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
skin = declManager->FindSkin( skinName );
|
|
|
|
ent->SetSkin( skin );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Base::Event_SetConstraintPosition
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Base::Event_SetConstraintPosition( const char* name, const idVec3& pos )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.SetConstraintPosition( name, pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_Gibbable
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
const idEventDef EV_Gib( "gib", "s" );
|
|
|
|
const idEventDef EV_Gibbed( "<gibbed>" );
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Base, idAFEntity_Gibbable )
|
2012-11-28 15:47:07 +00:00
|
|
|
EVENT( EV_Gib, idAFEntity_Gibbable::Event_Gib )
|
|
|
|
EVENT( EV_Gibbed, idAFEntity_Base::Event_Remove )
|
2012-11-26 18:58:24 +00:00
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::idAFEntity_Gibbable
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Gibbable::idAFEntity_Gibbable()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
skeletonModel = NULL;
|
|
|
|
skeletonModelDefHandle = -1;
|
|
|
|
gibbed = false;
|
|
|
|
wasThrown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::~idAFEntity_Gibbable
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Gibbable::~idAFEntity_Gibbable()
|
|
|
|
{
|
|
|
|
if( skeletonModelDefHandle != -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->FreeEntityDef( skeletonModelDefHandle );
|
|
|
|
skeletonModelDefHandle = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteBool( gibbed );
|
|
|
|
savefile->WriteBool( combatModel != NULL );
|
|
|
|
savefile->WriteBool( wasThrown );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool hasCombatModel;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadBool( gibbed );
|
|
|
|
savefile->ReadBool( hasCombatModel );
|
|
|
|
savefile->ReadBool( wasThrown );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
InitSkeletonModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( hasCombatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetCombatModel();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
InitSkeletonModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gibbed = false;
|
|
|
|
wasThrown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::InitSkeletonModel
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::InitSkeletonModel()
|
|
|
|
{
|
|
|
|
const char* modelName;
|
|
|
|
const idDeclModelDef* modelDef;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
skeletonModel = NULL;
|
|
|
|
skeletonModelDefHandle = -1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
modelName = spawnArgs.GetString( "model_gib" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
modelDef = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( modelName[0] != '\0' )
|
|
|
|
{
|
|
|
|
modelDef = static_cast<const idDeclModelDef*>( declManager->FindType( DECL_MODELDEF, modelName, false ) );
|
|
|
|
if( modelDef )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
skeletonModel = modelDef->ModelHandle();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
skeletonModel = renderModelManager->FindModel( modelName );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( skeletonModel != NULL && renderEntity.hModel != NULL )
|
|
|
|
{
|
|
|
|
if( skeletonModel->NumJoints() != renderEntity.hModel->NumJoints() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "gib model '%s' has different number of joints than model '%s'",
|
2012-11-28 15:47:07 +00:00
|
|
|
skeletonModel->Name(), renderEntity.hModel->Name() );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::Present
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Present()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
renderEntity_t skeleton;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !gameLocal.isNewFrame )
|
|
|
|
{
|
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
|
|
|
// don't present to the renderer if the entity hasn't changed
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !( thinkFlags & TH_UPDATEVISUALS ) )
|
|
|
|
{
|
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
|
|
|
// update skeleton model
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gibbed && !IsHidden() && skeletonModel != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
skeleton = renderEntity;
|
|
|
|
skeleton.hModel = skeletonModel;
|
|
|
|
// add to refresh list
|
2012-11-28 15:47:07 +00:00
|
|
|
if( skeletonModelDefHandle == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
skeletonModelDefHandle = gameRenderWorld->AddEntityDef( &skeleton );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->UpdateEntityDef( skeletonModelDefHandle, &skeleton );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity::Present();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Gibbable::Damage
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Damage( idEntity* inflictor, idEntity* attacker, const idVec3& dir, const char* damageDefName, const float damageScale, const int location )
|
|
|
|
{
|
|
|
|
if( !fl.takedamage )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
idAFEntity_Base::Damage( inflictor, attacker, dir, damageDefName, damageScale, location );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( health < -20 && spawnArgs.GetBool( "gib" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Gib( dir, damageDefName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFEntity_Gibbable::SetThrown
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::SetThrown( bool isThrown )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( isThrown )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, num = af.GetPhysics()->GetNumBodies();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < num; i++ )
|
|
|
|
{
|
|
|
|
idAFBody* body;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
body = af.GetPhysics()->GetBody( i );
|
|
|
|
body->SetClipMask( MASK_MONSTERSOLID );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
wasThrown = isThrown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFEntity_Gibbable::Collide
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAFEntity_Gibbable::Collide( const trace_t& collision, const idVec3& velocity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !gibbed && wasThrown )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Everything gibs (if possible)
|
2012-11-28 15:47:07 +00:00
|
|
|
if( spawnArgs.GetBool( "gib" ) )
|
|
|
|
{
|
|
|
|
idEntity* ent;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ent = gameLocal.entities[ collision.c.entityNum ];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ent->fl.takedamage )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->Damage( this, gameLocal.GetLocalPlayer(), collision.c.normal, "damage_thrown_ragdoll", 1.f, CLIPMODEL_ID_TO_JOINT_HANDLE( collision.c.id ) );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 vel = velocity;
|
|
|
|
vel.NormalizeFast();
|
|
|
|
Gib( vel, "damage_gib" );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return idAFEntity_Base::Collide( collision, velocity );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
idAFEntity_Gibbable::SpawnGibs
|
|
|
|
=====================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::SpawnGibs( const idVec3& dir, const char* damageDefName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
bool gibNonSolid;
|
|
|
|
idVec3 entityCenter, velocity;
|
2012-11-28 15:47:07 +00:00
|
|
|
idList<idEntity*> list;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
assert( !common->IsClient() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const idDict* damageDef = gameLocal.FindEntityDefDict( damageDefName );
|
|
|
|
if( damageDef == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "Unknown damageDef '%s'", damageDefName );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// spawn gib articulated figures
|
|
|
|
idAFEntity_Base::DropAFs( this, "gib", &list );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// spawn gib items
|
|
|
|
idMoveableItem::DropItems( this, "gib", &list );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// blow out the gibs in the given direction away from the center of the entity
|
|
|
|
entityCenter = GetPhysics()->GetAbsBounds().GetCenter();
|
|
|
|
gibNonSolid = damageDef->GetBool( "gibNonSolid" );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < list.Num(); i++ )
|
|
|
|
{
|
|
|
|
if( gibNonSolid )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
list[i]->GetPhysics()->SetContents( 0 );
|
|
|
|
list[i]->GetPhysics()->SetClipMask( 0 );
|
|
|
|
list[i]->GetPhysics()->UnlinkClip();
|
|
|
|
list[i]->GetPhysics()->PutToRest();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
list[i]->GetPhysics()->SetContents( 0 );
|
|
|
|
list[i]->GetPhysics()->SetClipMask( CONTENTS_SOLID );
|
|
|
|
velocity = list[i]->GetPhysics()->GetAbsBounds().GetCenter() - entityCenter;
|
|
|
|
velocity.NormalizeFast();
|
|
|
|
velocity += ( i & 1 ) ? dir : -dir;
|
|
|
|
list[i]->GetPhysics()->SetLinearVelocity( velocity * 75.0f );
|
|
|
|
}
|
|
|
|
// Don't allow grabber to pick up temporary gibs
|
|
|
|
list[i]->noGrab = true;
|
|
|
|
list[i]->GetRenderEntity()->noShadow = true;
|
|
|
|
list[i]->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = gameLocal.time * 0.001f;
|
|
|
|
list[i]->PostEventSec( &EV_Remove, 4.0f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAFEntity_Gibbable::Gib
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Gib( const idVec3& dir, const char* damageDefName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// only gib once
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gibbed )
|
|
|
|
{
|
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
|
|
|
// Don't grab this ent after it's been gibbed (and now invisible!)
|
|
|
|
noGrab = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const idDict* damageDef = gameLocal.FindEntityDefDict( damageDefName );
|
|
|
|
if( damageDef == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "Unknown damageDef '%s'", damageDefName );
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( damageDef->GetBool( "gibNonSolid" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetAFPhysics()->SetContents( 0 );
|
|
|
|
GetAFPhysics()->SetClipMask( 0 );
|
|
|
|
GetAFPhysics()->UnlinkClip();
|
|
|
|
GetAFPhysics()->PutToRest();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
GetAFPhysics()->SetContents( CONTENTS_CORPSE );
|
|
|
|
GetAFPhysics()->SetClipMask( CONTENTS_SOLID );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UnlinkCombat();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( g_bloodEffects.GetBool() )
|
|
|
|
{
|
|
|
|
if( gameLocal.time > gameLocal.GetGibTime() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.SetGibTime( gameLocal.time + GIB_DELAY );
|
|
|
|
SpawnGibs( dir, damageDefName );
|
|
|
|
renderEntity.noShadow = true;
|
|
|
|
renderEntity.shaderParms[ SHADERPARM_TIME_OF_DEATH ] = gameLocal.time * 0.001f;
|
|
|
|
StartSound( "snd_gibbed", SND_CHANNEL_ANY, 0, false, NULL );
|
|
|
|
gibbed = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gibbed = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventSec( &EV_Gibbed, 4.0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAFEntity_Gibbable::Event_Gib
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Gibbable::Event_Gib( const char* damageDefName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Gib( idVec3( 0, 0, 1 ), damageDefName );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_Generic
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Gibbable, idAFEntity_Generic )
|
2012-11-28 15:47:07 +00:00
|
|
|
EVENT( EV_Activate, idAFEntity_Generic::Event_Activate )
|
2012-11-26 18:58:24 +00:00
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::idAFEntity_Generic
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Generic::idAFEntity_Generic()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
keepRunningPhysics = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::~idAFEntity_Generic
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Generic::~idAFEntity_Generic()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Generic::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteBool( keepRunningPhysics );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Generic::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadBool( keepRunningPhysics );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Generic::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idAFEntity_Base::Think();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( keepRunningPhysics )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
BecomeActive( TH_PHYSICS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Generic::Spawn()
|
|
|
|
{
|
|
|
|
if( !LoadAF() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "Couldn't load af file on entity '%s'", name.c_str() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetCombatModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetPhysics( af.GetPhysics() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->PutToRest();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !spawnArgs.GetBool( "nodrop", "0" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->Activate();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fl.takedamage = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Generic::Event_Activate
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Generic::Event_Activate( idEntity* activator )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
float delay;
|
|
|
|
idVec3 init_velocity, init_avelocity;
|
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
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->EnableImpact();
|
|
|
|
af.GetPhysics()->Activate();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnArgs.GetVector( "init_velocity", "0 0 0", init_velocity );
|
|
|
|
spawnArgs.GetVector( "init_avelocity", "0 0 0", init_avelocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delay = spawnArgs.GetFloat( "init_velocityDelay", "0" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( delay == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetLinearVelocity( init_velocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventSec( &EV_SetLinearVelocity, delay, init_velocity );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delay = spawnArgs.GetFloat( "init_avelocityDelay", "0" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( delay == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetAngularVelocity( init_avelocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventSec( &EV_SetAngularVelocity, delay, init_avelocity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_WithAttachedHead
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Gibbable, idAFEntity_WithAttachedHead )
|
2012-11-28 15:47:07 +00:00
|
|
|
EVENT( EV_Gib, idAFEntity_WithAttachedHead::Event_Gib )
|
|
|
|
EVENT( EV_Activate, idAFEntity_WithAttachedHead::Event_Activate )
|
2012-11-26 18:58:24 +00:00
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::idAFEntity_WithAttachedHead
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_WithAttachedHead::idAFEntity_WithAttachedHead()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::~idAFEntity_WithAttachedHead
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_WithAttachedHead::~idAFEntity_WithAttachedHead()
|
|
|
|
{
|
|
|
|
if( head.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.GetEntity()->ClearBody();
|
|
|
|
head.GetEntity()->PostEventMS( &EV_Remove, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SetupHead();
|
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
|
|
|
SetCombatModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetPhysics( af.GetPhysics() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->PutToRest();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !spawnArgs.GetBool( "nodrop", "0" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->Activate();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fl.takedamage = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( head.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int anim = head.GetEntity()->GetAnimator()->GetAnim( "dead" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( anim )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.GetEntity()->GetAnimator()->SetFrame( ANIMCHANNEL_ALL, anim, 0, gameLocal.time, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.Save( savefile );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.Restore( savefile );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::SetupHead
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::SetupHead()
|
|
|
|
{
|
|
|
|
idAFAttachment* headEnt;
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr jointName;
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* headModel;
|
2012-11-26 18:58:24 +00:00
|
|
|
jointHandle_t joint;
|
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
headModel = spawnArgs.GetString( "def_head", "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( headModel[ 0 ] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
jointName = spawnArgs.GetString( "head_joint" );
|
|
|
|
joint = animator.GetJointHandle( jointName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( joint == INVALID_JOINT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "Joint '%s' not found for 'head_joint' on '%s'", jointName.c_str(), name.c_str() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
headEnt = static_cast<idAFAttachment*>( gameLocal.SpawnEntityType( idAFAttachment::Type, NULL ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
headEnt->SetName( va( "%s_head", name.c_str() ) );
|
|
|
|
headEnt->SetBody( this, headModel, joint );
|
|
|
|
headEnt->SetCombatModel();
|
|
|
|
head = headEnt;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr xSkin;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( spawnArgs.GetString( "skin_head_xray", "", xSkin ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
headEnt->xraySkin = declManager->FindSkin( xSkin.c_str() );
|
|
|
|
headEnt->UpdateModel();
|
|
|
|
}
|
|
|
|
animator.GetJointTransform( joint, gameLocal.time, origin, axis );
|
|
|
|
origin = renderEntity.origin + origin * renderEntity.axis;
|
|
|
|
headEnt->SetOrigin( origin );
|
|
|
|
headEnt->SetAxis( renderEntity.axis );
|
|
|
|
headEnt->BindToJoint( this, joint, true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idAFEntity_Base::Think();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::LinkCombat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::LinkCombat()
|
|
|
|
{
|
|
|
|
idAFAttachment* headEnt;
|
|
|
|
|
|
|
|
if( fl.hidden )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Link( gameLocal.clip, this, 0, renderEntity.origin, renderEntity.axis, modelDefHandle );
|
|
|
|
}
|
|
|
|
headEnt = head.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( headEnt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
headEnt->LinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::UnlinkCombat
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::UnlinkCombat()
|
|
|
|
{
|
|
|
|
idAFAttachment* headEnt;
|
|
|
|
|
|
|
|
if( combatModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
combatModel->Unlink();
|
|
|
|
}
|
|
|
|
headEnt = head.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( headEnt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
headEnt->UnlinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Hide
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Hide()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idAFEntity_Base::Hide();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( head.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.GetEntity()->Hide();
|
|
|
|
}
|
|
|
|
UnlinkCombat();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Show
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Show()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idAFEntity_Base::Show();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( head.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.GetEntity()->Show();
|
|
|
|
}
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::ProjectOverlay
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::ProjectOverlay( const idVec3& origin, const idVec3& dir, float size, const char* material )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idEntity::ProjectOverlay( origin, dir, size, material );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( head.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.GetEntity()->ProjectOverlay( origin, dir, size, material );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAFEntity_WithAttachedHead::Gib
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Gib( const idVec3& dir, const char* damageDefName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// only gib once
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gibbed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
idAFEntity_Gibbable::Gib( dir, damageDefName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( head.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
head.GetEntity()->Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAFEntity_WithAttachedHead::Event_Gib
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Event_Gib( const char* damageDefName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Gib( idVec3( 0, 0, 1 ), damageDefName );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_WithAttachedHead::Event_Activate
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_WithAttachedHead::Event_Activate( idEntity* activator )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
float delay;
|
|
|
|
idVec3 init_velocity, init_avelocity;
|
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
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->EnableImpact();
|
|
|
|
af.GetPhysics()->Activate();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnArgs.GetVector( "init_velocity", "0 0 0", init_velocity );
|
|
|
|
spawnArgs.GetVector( "init_avelocity", "0 0 0", init_avelocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delay = spawnArgs.GetFloat( "init_velocityDelay", "0" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( delay == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetLinearVelocity( init_velocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventSec( &EV_SetLinearVelocity, delay, init_velocity );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
delay = spawnArgs.GetFloat( "init_avelocityDelay", "0" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( delay == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetAngularVelocity( init_avelocity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventSec( &EV_SetAngularVelocity, delay, init_avelocity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_Vehicle
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Base, idAFEntity_Vehicle )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Vehicle::idAFEntity_Vehicle
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Vehicle::idAFEntity_Vehicle()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player = NULL;
|
|
|
|
eyesJoint = INVALID_JOINT;
|
|
|
|
steeringWheelJoint = INVALID_JOINT;
|
|
|
|
wheelRadius = 0.0f;
|
|
|
|
steerAngle = 0.0f;
|
|
|
|
steerSpeed = 0.0f;
|
|
|
|
dustSmoke = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Vehicle::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Vehicle::Spawn()
|
|
|
|
{
|
|
|
|
const char* eyesJointName = spawnArgs.GetString( "eyesJoint", "eyes" );
|
|
|
|
const char* steeringWheelJointName = spawnArgs.GetString( "steeringWheelJoint", "steeringWheel" );
|
|
|
|
|
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
|
|
|
SetCombatModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetPhysics( af.GetPhysics() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fl.takedamage = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !eyesJointName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_Vehicle '%s' no eyes joint specified", name.c_str() );
|
|
|
|
}
|
|
|
|
eyesJoint = animator.GetJointHandle( eyesJointName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !steeringWheelJointName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_Vehicle '%s' no steering wheel joint specified", name.c_str() );
|
|
|
|
}
|
|
|
|
steeringWheelJoint = animator.GetJointHandle( steeringWheelJointName );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnArgs.GetFloat( "wheelRadius", "20", wheelRadius );
|
2012-11-28 15:47:07 +00:00
|
|
|
spawnArgs.GetFloat( "steerSpeed", "5", steerSpeed );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player = NULL;
|
|
|
|
steerAngle = 0.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const char* smokeName = spawnArgs.GetString( "smoke_vehicle_dust", "muzzlesmoke" );
|
|
|
|
if( *smokeName != '\0' )
|
|
|
|
{
|
|
|
|
dustSmoke = static_cast<const idDeclParticle*>( declManager->FindType( DECL_PARTICLE, smokeName ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Vehicle::Use
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Vehicle::Use( idPlayer* other )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( player )
|
|
|
|
{
|
|
|
|
if( player == other )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
other->Unbind();
|
|
|
|
player = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetComeToRest( true );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
player = other;
|
|
|
|
animator.GetJointTransform( eyesJoint, gameLocal.time, origin, axis );
|
|
|
|
origin = renderEntity.origin + origin * renderEntity.axis;
|
|
|
|
player->GetPhysics()->SetOrigin( origin );
|
|
|
|
player->BindToBody( this, 0, true );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->SetComeToRest( false );
|
|
|
|
af.GetPhysics()->Activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Vehicle::GetSteerAngle
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
float idAFEntity_Vehicle::GetSteerAngle()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
float idealSteerAngle, angleDelta;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idealSteerAngle = player->usercmd.rightmove * ( 30.0f / 128.0f );
|
|
|
|
angleDelta = idealSteerAngle - steerAngle;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( angleDelta > steerSpeed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steerAngle += steerSpeed;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( angleDelta < -steerSpeed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steerAngle -= steerSpeed;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steerAngle = idealSteerAngle;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return steerAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_VehicleSimple
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Vehicle, idAFEntity_VehicleSimple )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleSimple::idAFEntity_VehicleSimple
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_VehicleSimple::idAFEntity_VehicleSimple()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleSimple::~idAFEntity_VehicleSimple
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_VehicleSimple::~idAFEntity_VehicleSimple()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete wheelModel;
|
|
|
|
wheelModel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleSimple::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleSimple::Spawn()
|
|
|
|
{
|
|
|
|
static const char* wheelJointKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"wheelJointFrontLeft",
|
|
|
|
"wheelJointFrontRight",
|
|
|
|
"wheelJointRearLeft",
|
|
|
|
"wheelJointRearRight"
|
|
|
|
};
|
|
|
|
static idVec3 wheelPoly[4] = { idVec3( 2, 2, 0 ), idVec3( 2, -2, 0 ), idVec3( -2, -2, 0 ), idVec3( -2, 2, 0 ) };
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
|
|
|
idTraceModel trm;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
trm.SetupPolygon( wheelPoly, 4 );
|
|
|
|
trm.Translate( idVec3( 0, 0, -wheelRadius ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
wheelModel = new( TAG_PHYSICS_CLIP_AF ) idClipModel( trm );
|
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
const char* wheelJointName = spawnArgs.GetString( wheelJointKeys[i], "" );
|
|
|
|
if( !wheelJointName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSimple '%s' no '%s' specified", name.c_str(), wheelJointKeys[i] );
|
|
|
|
}
|
|
|
|
wheelJoints[i] = animator.GetJointHandle( wheelJointName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( wheelJoints[i] == INVALID_JOINT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSimple '%s' can't find wheel joint '%s'", name.c_str(), wheelJointName );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
GetAnimator()->GetJointTransform( wheelJoints[i], 0, origin, axis );
|
|
|
|
origin = renderEntity.origin + origin * renderEntity.axis;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
suspension[i] = new( TAG_PHYSICS_AF ) idAFConstraint_Suspension();
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[i]->Setup( va( "suspension%d", i ), af.GetPhysics()->GetBody( 0 ), origin, af.GetPhysics()->GetAxis( 0 ), wheelModel );
|
|
|
|
suspension[i]->SetSuspension( g_vehicleSuspensionUp.GetFloat(),
|
|
|
|
g_vehicleSuspensionDown.GetFloat(),
|
|
|
|
g_vehicleSuspensionKCompress.GetFloat(),
|
|
|
|
g_vehicleSuspensionDamping.GetFloat(),
|
|
|
|
g_vehicleTireFriction.GetFloat() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->AddConstraint( suspension[i] );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( wheelAngles, 0, sizeof( wheelAngles ) );
|
|
|
|
BecomeActive( TH_THINK );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleSimple::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleSimple::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
float force = 0.0f, velocity = 0.0f, steerAngle = 0.0f;
|
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
|
|
|
idRotation wheelRotation, steerRotation;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( thinkFlags & TH_THINK )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// capture the input from a player
|
|
|
|
velocity = g_vehicleVelocity.GetFloat();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player->usercmd.forwardmove < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = -velocity;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
force = idMath::Fabs( player->usercmd.forwardmove * g_vehicleForce.GetFloat() ) * ( 1.0f / 128.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
steerAngle = GetSteerAngle();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the wheel motor force and steering
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// front wheel drive
|
2012-11-28 15:47:07 +00:00
|
|
|
if( velocity != 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[i]->EnableMotor( true );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[i]->EnableMotor( false );
|
|
|
|
}
|
|
|
|
suspension[i]->SetMotorVelocity( velocity );
|
|
|
|
suspension[i]->SetMotorForce( force );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the wheel steering
|
|
|
|
suspension[i]->SetSteerAngle( steerAngle );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// adjust wheel velocity for better steering because there are no differentials between the wheels
|
2012-11-28 15:47:07 +00:00
|
|
|
if( steerAngle < 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[0]->SetMotorVelocity( velocity * 0.5f );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else if( steerAngle > 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[1]->SetMotorVelocity( velocity * 0.5f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update suspension with latest cvar settings
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
suspension[i]->SetSuspension( g_vehicleSuspensionUp.GetFloat(),
|
|
|
|
g_vehicleSuspensionDown.GetFloat(),
|
|
|
|
g_vehicleSuspensionKCompress.GetFloat(),
|
|
|
|
g_vehicleSuspensionDamping.GetFloat(),
|
|
|
|
g_vehicleTireFriction.GetFloat() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// run the physics
|
|
|
|
RunPhysics();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// move and rotate the wheels visually
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
idAFBody* body = af.GetPhysics()->GetBody( 0 );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
origin = suspension[i]->GetWheelOrigin();
|
|
|
|
velocity = body->GetPointVelocity( origin ) * body->GetWorldAxis()[0];
|
|
|
|
wheelAngles[i] += velocity * MS2SEC( gameLocal.time - gameLocal.previousTime ) / wheelRadius;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// additional rotation about the wheel axis
|
|
|
|
wheelRotation.SetAngle( RAD2DEG( wheelAngles[i] ) );
|
|
|
|
wheelRotation.SetVec( 0, -1, 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( i < 2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// rotate the wheel for steering
|
|
|
|
steerRotation.SetAngle( steerAngle );
|
|
|
|
steerRotation.SetVec( 0, 0, 1 );
|
|
|
|
// set wheel rotation
|
|
|
|
animator.SetJointAxis( wheelJoints[i], JOINTMOD_WORLD, wheelRotation.ToMat3() * steerRotation.ToMat3() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// set wheel rotation
|
|
|
|
animator.SetJointAxis( wheelJoints[i], JOINTMOD_WORLD, wheelRotation.ToMat3() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// set wheel position for suspension
|
|
|
|
origin = ( origin - renderEntity.origin ) * renderEntity.axis.Transpose();
|
|
|
|
GetAnimator()->SetJointPos( wheelJoints[i], JOINTMOD_WORLD_OVERRIDE, origin );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
/*
|
|
|
|
// spawn dust particle effects
|
|
|
|
if ( force != 0.0f && !( gameLocal.framenum & 7 ) ) {
|
|
|
|
int numContacts;
|
|
|
|
idAFConstraint_Contact *contacts[2];
|
|
|
|
for ( i = 0; i < 4; i++ ) {
|
|
|
|
numContacts = af.GetPhysics()->GetBodyContactConstraints( wheels[i]->GetClipModel()->GetId(), contacts, 2 );
|
|
|
|
for ( int j = 0; j < numContacts; j++ ) {
|
|
|
|
gameLocal.smokeParticles->EmitSmoke( dustSmoke, gameLocal.time, gameLocal.random.RandomFloat(), contacts[j]->GetContact().point, contacts[j]->GetContact().normal.ToMat3() );
|
|
|
|
}
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
*/
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateAnimation();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( thinkFlags & TH_UPDATEVISUALS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Present();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_VehicleFourWheels
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Vehicle, idAFEntity_VehicleFourWheels )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleFourWheels::idAFEntity_VehicleFourWheels
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_VehicleFourWheels::idAFEntity_VehicleFourWheels()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheels[i] = NULL;
|
|
|
|
wheelJoints[i] = INVALID_JOINT;
|
|
|
|
wheelAngles[i] = 0.0f;
|
|
|
|
}
|
|
|
|
steering[0] = NULL;
|
|
|
|
steering[1] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleFourWheels::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleFourWheels::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* wheelBodyKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"wheelBodyFrontLeft",
|
|
|
|
"wheelBodyFrontRight",
|
|
|
|
"wheelBodyRearLeft",
|
|
|
|
"wheelBodyRearRight"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* wheelJointKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"wheelJointFrontLeft",
|
|
|
|
"wheelJointFrontRight",
|
|
|
|
"wheelJointRearLeft",
|
|
|
|
"wheelJointRearRight"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* steeringHingeKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"steeringHingeFrontLeft",
|
|
|
|
"steeringHingeFrontRight",
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const char* wheelBodyName, *wheelJointName, *steeringHingeName;
|
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheelBodyName = spawnArgs.GetString( wheelBodyKeys[i], "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wheelBodyName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleFourWheels '%s' no '%s' specified", name.c_str(), wheelBodyKeys[i] );
|
|
|
|
}
|
|
|
|
wheels[i] = af.GetPhysics()->GetBody( wheelBodyName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wheels[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleFourWheels '%s' can't find wheel body '%s'", name.c_str(), wheelBodyName );
|
|
|
|
}
|
|
|
|
wheelJointName = spawnArgs.GetString( wheelJointKeys[i], "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wheelJointName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleFourWheels '%s' no '%s' specified", name.c_str(), wheelJointKeys[i] );
|
|
|
|
}
|
|
|
|
wheelJoints[i] = animator.GetJointHandle( wheelJointName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( wheelJoints[i] == INVALID_JOINT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleFourWheels '%s' can't find wheel joint '%s'", name.c_str(), wheelJointName );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steeringHingeName = spawnArgs.GetString( steeringHingeKeys[i], "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !steeringHingeName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleFourWheels '%s' no '%s' specified", name.c_str(), steeringHingeKeys[i] );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
steering[i] = static_cast<idAFConstraint_Hinge*>( af.GetPhysics()->GetConstraint( steeringHingeName ) );
|
|
|
|
if( !steering[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleFourWheels '%s': can't find steering hinge '%s'", name.c_str(), steeringHingeName );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( wheelAngles, 0, sizeof( wheelAngles ) );
|
|
|
|
BecomeActive( TH_THINK );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleFourWheels::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleFourWheels::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
float force = 0.0f, velocity = 0.0f, steerAngle = 0.0f;
|
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
|
|
|
idRotation rotation;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( thinkFlags & TH_THINK )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// capture the input from a player
|
|
|
|
velocity = g_vehicleVelocity.GetFloat();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player->usercmd.forwardmove < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = -velocity;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
force = idMath::Fabs( player->usercmd.forwardmove * g_vehicleForce.GetFloat() ) * ( 1.0f / 128.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
steerAngle = GetSteerAngle();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the wheel motor force
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
wheels[2 + i]->SetContactMotorVelocity( velocity );
|
|
|
|
wheels[2 + i]->SetContactMotorForce( force );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// adjust wheel velocity for better steering because there are no differentials between the wheels
|
2012-11-28 15:47:07 +00:00
|
|
|
if( steerAngle < 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheels[2]->SetContactMotorVelocity( velocity * 0.5f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else if( steerAngle > 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheels[3]->SetContactMotorVelocity( velocity * 0.5f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the wheel steering
|
|
|
|
steering[0]->SetSteerAngle( steerAngle );
|
|
|
|
steering[1]->SetSteerAngle( steerAngle );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 2; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steering[i]->SetSteerSpeed( 3.0f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the steering wheel
|
|
|
|
animator.GetJointTransform( steeringWheelJoint, gameLocal.time, origin, axis );
|
|
|
|
rotation.SetVec( axis[2] );
|
|
|
|
rotation.SetAngle( -steerAngle );
|
|
|
|
animator.SetJointAxis( steeringWheelJoint, JOINTMOD_WORLD, rotation.ToMat3() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// run the physics
|
|
|
|
RunPhysics();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// rotate the wheels visually
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
if( force == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = wheels[i]->GetLinearVelocity() * wheels[i]->GetWorldAxis()[0];
|
|
|
|
}
|
|
|
|
wheelAngles[i] += velocity * MS2SEC( gameLocal.time - gameLocal.previousTime ) / wheelRadius;
|
|
|
|
// give the wheel joint an additional rotation about the wheel axis
|
|
|
|
rotation.SetAngle( RAD2DEG( wheelAngles[i] ) );
|
|
|
|
axis = af.GetPhysics()->GetAxis( 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
rotation.SetVec( ( wheels[i]->GetWorldAxis() * axis.Transpose() )[2] );
|
2012-11-26 18:58:24 +00:00
|
|
|
animator.SetJointAxis( wheelJoints[i], JOINTMOD_WORLD, rotation.ToMat3() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// spawn dust particle effects
|
2012-11-28 15:47:07 +00:00
|
|
|
if( force != 0.0f && !( gameLocal.framenum & 7 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int numContacts;
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFConstraint_Contact* contacts[2];
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numContacts = af.GetPhysics()->GetBodyContactConstraints( wheels[i]->GetClipModel()->GetId(), contacts, 2 );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 0; j < numContacts; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.smokeParticles->EmitSmoke( dustSmoke, gameLocal.time, gameLocal.random.RandomFloat(), contacts[j]->GetContact().point, contacts[j]->GetContact().normal.ToMat3(), timeGroup /* D3XP */ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateAnimation();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( thinkFlags & TH_UPDATEVISUALS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Present();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_VehicleSixWheels
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Vehicle, idAFEntity_VehicleSixWheels )
|
|
|
|
END_CLASS
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
/*
|
2012-11-26 18:58:24 +00:00
|
|
|
================
|
|
|
|
idAFEntity_VehicleSixWheels::idAFEntity_VehicleSixWheels
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_VehicleSixWheels::idAFEntity_VehicleSixWheels()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 6; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheels[i] = NULL;
|
|
|
|
wheelJoints[i] = INVALID_JOINT;
|
|
|
|
wheelAngles[i] = 0.0f;
|
|
|
|
}
|
|
|
|
steering[0] = NULL;
|
|
|
|
steering[1] = NULL;
|
|
|
|
steering[2] = NULL;
|
|
|
|
steering[3] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleSixWheels::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleSixWheels::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* wheelBodyKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"wheelBodyFrontLeft",
|
|
|
|
"wheelBodyFrontRight",
|
|
|
|
"wheelBodyMiddleLeft",
|
|
|
|
"wheelBodyMiddleRight",
|
|
|
|
"wheelBodyRearLeft",
|
|
|
|
"wheelBodyRearRight"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* wheelJointKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"wheelJointFrontLeft",
|
|
|
|
"wheelJointFrontRight",
|
|
|
|
"wheelJointMiddleLeft",
|
|
|
|
"wheelJointMiddleRight",
|
|
|
|
"wheelJointRearLeft",
|
|
|
|
"wheelJointRearRight"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* steeringHingeKeys[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"steeringHingeFrontLeft",
|
|
|
|
"steeringHingeFrontRight",
|
|
|
|
"steeringHingeRearLeft",
|
|
|
|
"steeringHingeRearRight"
|
|
|
|
};
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const char* wheelBodyName, *wheelJointName, *steeringHingeName;
|
|
|
|
|
|
|
|
for( i = 0; i < 6; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheelBodyName = spawnArgs.GetString( wheelBodyKeys[i], "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wheelBodyName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSixWheels '%s' no '%s' specified", name.c_str(), wheelBodyKeys[i] );
|
|
|
|
}
|
|
|
|
wheels[i] = af.GetPhysics()->GetBody( wheelBodyName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wheels[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSixWheels '%s' can't find wheel body '%s'", name.c_str(), wheelBodyName );
|
|
|
|
}
|
|
|
|
wheelJointName = spawnArgs.GetString( wheelJointKeys[i], "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !wheelJointName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSixWheels '%s' no '%s' specified", name.c_str(), wheelJointKeys[i] );
|
|
|
|
}
|
|
|
|
wheelJoints[i] = animator.GetJointHandle( wheelJointName );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( wheelJoints[i] == INVALID_JOINT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSixWheels '%s' can't find wheel joint '%s'", name.c_str(), wheelJointName );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steeringHingeName = spawnArgs.GetString( steeringHingeKeys[i], "" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !steeringHingeName[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSixWheels '%s' no '%s' specified", name.c_str(), steeringHingeKeys[i] );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
steering[i] = static_cast<idAFConstraint_Hinge*>( af.GetPhysics()->GetConstraint( steeringHingeName ) );
|
|
|
|
if( !steering[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idAFEntity_VehicleSixWheels '%s': can't find steering hinge '%s'", name.c_str(), steeringHingeName );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( wheelAngles, 0, sizeof( wheelAngles ) );
|
|
|
|
BecomeActive( TH_THINK );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleSixWheels::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleSixWheels::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
|
|
|
idVec3 origin;
|
|
|
|
idMat3 axis;
|
|
|
|
idRotation rotation;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( thinkFlags & TH_THINK )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( player )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// capture the input from a player
|
|
|
|
velocity = g_vehicleVelocity.GetFloat();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( player->usercmd.forwardmove < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = -velocity;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
force = idMath::Fabs( player->usercmd.forwardmove * g_vehicleForce.GetFloat() ) * ( 1.0f / 128.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
steerAngle = GetSteerAngle();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the wheel motor force
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 6; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wheels[i]->SetContactMotorVelocity( velocity );
|
|
|
|
wheels[i]->SetContactMotorForce( force );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// adjust wheel velocity for better steering because there are no differentials between the wheels
|
2012-11-28 15:47:07 +00:00
|
|
|
if( steerAngle < 0.0f )
|
|
|
|
{
|
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
wheels[( i << 1 )]->SetContactMotorVelocity( velocity * 0.5f );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else if( steerAngle > 0.0f )
|
|
|
|
{
|
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
{
|
|
|
|
wheels[1 + ( i << 1 )]->SetContactMotorVelocity( velocity * 0.5f );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the wheel steering
|
|
|
|
steering[0]->SetSteerAngle( steerAngle );
|
|
|
|
steering[1]->SetSteerAngle( steerAngle );
|
|
|
|
steering[2]->SetSteerAngle( -steerAngle );
|
|
|
|
steering[3]->SetSteerAngle( -steerAngle );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steering[i]->SetSteerSpeed( 3.0f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// update the steering wheel
|
|
|
|
animator.GetJointTransform( steeringWheelJoint, gameLocal.time, origin, axis );
|
|
|
|
rotation.SetVec( axis[2] );
|
|
|
|
rotation.SetAngle( -steerAngle );
|
|
|
|
animator.SetJointAxis( steeringWheelJoint, JOINTMOD_WORLD, rotation.ToMat3() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// run the physics
|
|
|
|
RunPhysics();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// rotate the wheels visually
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < 6; i++ )
|
|
|
|
{
|
|
|
|
if( force == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = wheels[i]->GetLinearVelocity() * wheels[i]->GetWorldAxis()[0];
|
|
|
|
}
|
|
|
|
wheelAngles[i] += velocity * MS2SEC( gameLocal.time - gameLocal.previousTime ) / wheelRadius;
|
|
|
|
// give the wheel joint an additional rotation about the wheel axis
|
|
|
|
rotation.SetAngle( RAD2DEG( wheelAngles[i] ) );
|
|
|
|
axis = af.GetPhysics()->GetAxis( 0 );
|
2012-11-28 15:47:07 +00:00
|
|
|
rotation.SetVec( ( wheels[i]->GetWorldAxis() * axis.Transpose() )[2] );
|
2012-11-26 18:58:24 +00:00
|
|
|
animator.SetJointAxis( wheelJoints[i], JOINTMOD_WORLD, rotation.ToMat3() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// spawn dust particle effects
|
2012-11-28 15:47:07 +00:00
|
|
|
if( force != 0.0f && !( gameLocal.framenum & 7 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int numContacts;
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFConstraint_Contact* contacts[2];
|
|
|
|
for( i = 0; i < 6; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numContacts = af.GetPhysics()->GetBodyContactConstraints( wheels[i]->GetClipModel()->GetId(), contacts, 2 );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 0; j < numContacts; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.smokeParticles->EmitSmoke( dustSmoke, gameLocal.time, gameLocal.random.RandomFloat(), contacts[j]->GetContact().point, contacts[j]->GetContact().normal.ToMat3(), timeGroup /* D3XP */ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
UpdateAnimation();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( thinkFlags & TH_UPDATEVISUALS )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Present();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_VehicleAutomated
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
const idEventDef EV_Vehicle_setVelocity( "setVelocity", "f" );
|
|
|
|
const idEventDef EV_Vehicle_setTorque( "setTorque", "f" );
|
|
|
|
const idEventDef EV_Vehicle_setSteeringSpeed( "setSteeringSpeed", "f" );
|
|
|
|
const idEventDef EV_Vehicle_setWaypoint( "setWaypoint", "e" );
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_VehicleSixWheels, idAFEntity_VehicleAutomated )
|
|
|
|
EVENT( EV_PostSpawn, idAFEntity_VehicleAutomated::PostSpawn )
|
|
|
|
EVENT( EV_Vehicle_setVelocity, idAFEntity_VehicleAutomated::Event_SetVelocity )
|
|
|
|
EVENT( EV_Vehicle_setTorque, idAFEntity_VehicleAutomated::Event_SetTorque )
|
|
|
|
EVENT( EV_Vehicle_setSteeringSpeed, idAFEntity_VehicleAutomated::Event_SetSteeringSpeed )
|
|
|
|
EVENT( EV_Vehicle_setWaypoint, idAFEntity_VehicleAutomated::Event_SetWayPoint )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
velocity = force = steerAngle = 0.f;
|
|
|
|
currentSteering = steeringSpeed = 0.f;
|
|
|
|
originHeight = 0.f;
|
|
|
|
waypoint = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnArgs.GetFloat( "velocity", "150", velocity );
|
|
|
|
spawnArgs.GetFloat( "torque", "200000", force );
|
|
|
|
spawnArgs.GetFloat( "steeringSpeed", "1", steeringSpeed );
|
|
|
|
spawnArgs.GetFloat( "originHeight", "0", originHeight );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventMS( &EV_PostSpawn, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::PostSpawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::PostSpawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( targets.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
waypoint = targets[0].GetEntity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::Event_SetVelocity
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::Event_SetVelocity( float _velocity )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = _velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::Event_SetTorque
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::Event_SetTorque( float _torque )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
force = _torque;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::Event_SetSteeringSpeed
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::Event_SetSteeringSpeed( float _steeringSpeed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steeringSpeed = _steeringSpeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::Event_SetWayPoint
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::Event_SetWayPoint( idEntity* _waypoint )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
waypoint = _waypoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_VehicleAutomated::Think
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
#define HIT_WAYPOINT_THRESHOLD 80.f
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_VehicleAutomated::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
// If we don't have a waypoint, coast to a stop
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !waypoint )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
velocity = force = steerAngle = 0.f;
|
|
|
|
idAFEntity_VehicleSixWheels::Think();
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 waypoint_origin, vehicle_origin;
|
|
|
|
idVec3 travel_vector;
|
|
|
|
float distance_from_waypoint;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Set up the vector from the vehicle origin, to the waypoint
|
|
|
|
vehicle_origin = GetPhysics()->GetOrigin();
|
|
|
|
vehicle_origin.z -= originHeight;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
waypoint_origin = waypoint->GetPhysics()->GetOrigin();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
travel_vector = waypoint_origin - vehicle_origin;
|
|
|
|
distance_from_waypoint = travel_vector.Length();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Check if we've hit the waypoint (within a certain threshold)
|
2012-11-28 15:47:07 +00:00
|
|
|
if( distance_from_waypoint < HIT_WAYPOINT_THRESHOLD )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr callfunc;
|
2012-11-28 15:47:07 +00:00
|
|
|
const function_t* func;
|
|
|
|
idThread* thread;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Waypoints can call script functions
|
|
|
|
waypoint->spawnArgs.GetString( "call", "", callfunc );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( callfunc.Length() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
func = gameLocal.program.FindFunction( callfunc );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( func != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
thread = new idThread( func );
|
|
|
|
thread->DelayedStart( 0 );
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Get next waypoint
|
2012-11-28 15:47:07 +00:00
|
|
|
if( waypoint->targets.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
waypoint = waypoint->targets[0].GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
waypoint = NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// We are switching waypoints, adjust steering next frame
|
|
|
|
idAFEntity_VehicleSixWheels::Think();
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idAngles vehicle_angles, travel_angles;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Get the angles we need to steer towards
|
|
|
|
travel_angles = travel_vector.ToAngles().Normalize360();
|
|
|
|
vehicle_angles = this->GetPhysics()->GetAxis().ToAngles().Normalize360();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float delta_yaw;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Get the shortest steering angle towards the travel angles
|
|
|
|
delta_yaw = vehicle_angles.yaw - travel_angles.yaw;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idMath::Fabs( delta_yaw ) > 180.f )
|
|
|
|
{
|
|
|
|
if( delta_yaw > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delta_yaw = delta_yaw - 360;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delta_yaw = delta_yaw + 360;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Maximum steering angle is 35 degrees
|
|
|
|
delta_yaw = idMath::ClampFloat( -35.f, 35.f, delta_yaw );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idealSteering = delta_yaw;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Adjust steering incrementally so it doesn't snap to the ideal angle
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idMath::Fabs( ( idealSteering - currentSteering ) ) > steeringSpeed )
|
|
|
|
{
|
|
|
|
if( idealSteering > currentSteering )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentSteering += steeringSpeed;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentSteering -= steeringSpeed;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentSteering = idealSteering;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// DEBUG
|
2012-11-28 15:47:07 +00:00
|
|
|
if( g_vehicleDebug.GetBool() )
|
|
|
|
{
|
|
|
|
gameRenderWorld->DebugBounds( colorRed, idBounds( idVec3( -4, -4, -4 ), idVec3( 4, 4, 4 ) ), vehicle_origin );
|
|
|
|
gameRenderWorld->DebugBounds( colorRed, idBounds( idVec3( -4, -4, -4 ), idVec3( 4, 4, 4 ) ), waypoint_origin );
|
|
|
|
gameRenderWorld->DrawText( waypoint->name.c_str(), waypoint_origin + idVec3( 0, 0, 16 ), 0.25f, colorYellow, gameLocal.GetLocalPlayer()->viewAxis );
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->DebugArrow( colorWhite, vehicle_origin, waypoint_origin, 12.f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Set the final steerAngle for the vehicle
|
|
|
|
steerAngle = currentSteering;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idAFEntity_VehicleSixWheels::Think();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_SteamPipe
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Base, idAFEntity_SteamPipe )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::idAFEntity_SteamPipe
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_SteamPipe::idAFEntity_SteamPipe()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamBody = 0;
|
|
|
|
steamForce = 0.0f;
|
|
|
|
steamUpForce = 0.0f;
|
|
|
|
steamModelDefHandle = -1;
|
|
|
|
memset( &steamRenderEntity, 0, sizeof( steamRenderEntity ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::~idAFEntity_SteamPipe
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_SteamPipe::~idAFEntity_SteamPipe()
|
|
|
|
{
|
|
|
|
if( steamModelDefHandle >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameRenderWorld->FreeEntityDef( steamModelDefHandle );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_SteamPipe::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_SteamPipe::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Spawn();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_SteamPipe::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 steamDir;
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* steamBodyName;
|
|
|
|
|
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
|
|
|
SetCombatModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetPhysics( af.GetPhysics() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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
|
|
|
steamBodyName = spawnArgs.GetString( "steamBody", "" );
|
|
|
|
steamForce = spawnArgs.GetFloat( "steamForce", "2000" );
|
|
|
|
steamUpForce = spawnArgs.GetFloat( "steamUpForce", "10" );
|
|
|
|
steamDir = af.GetPhysics()->GetAxis( steamBody )[2];
|
|
|
|
steamBody = af.GetPhysics()->GetBodyId( steamBodyName );
|
|
|
|
force.SetPosition( af.GetPhysics(), steamBody, af.GetPhysics()->GetOrigin( steamBody ) );
|
|
|
|
force.SetForce( steamDir * -steamForce );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
InitSteamRenderEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
BecomeActive( TH_THINK );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::InitSteamRenderEntity
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_SteamPipe::InitSteamRenderEntity()
|
|
|
|
{
|
|
|
|
const char* temp;
|
|
|
|
const idDeclModelDef* modelDef;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( &steamRenderEntity, 0, sizeof( steamRenderEntity ) );
|
|
|
|
steamRenderEntity.shaderParms[ SHADERPARM_RED ] = 1.0f;
|
|
|
|
steamRenderEntity.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
|
|
|
|
steamRenderEntity.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
|
|
|
|
modelDef = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
temp = spawnArgs.GetString( "model_steam" );
|
|
|
|
if( *temp != '\0' )
|
|
|
|
{
|
|
|
|
if( !strstr( temp, "." ) )
|
|
|
|
{
|
|
|
|
modelDef = static_cast<const idDeclModelDef*>( declManager->FindType( DECL_MODELDEF, temp, false ) );
|
|
|
|
if( modelDef )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamRenderEntity.hModel = modelDef->ModelHandle();
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !steamRenderEntity.hModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamRenderEntity.hModel = renderModelManager->FindModel( temp );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( steamRenderEntity.hModel )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamRenderEntity.bounds = steamRenderEntity.hModel->Bounds( &steamRenderEntity );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamRenderEntity.bounds.Zero();
|
|
|
|
}
|
|
|
|
steamRenderEntity.origin = af.GetPhysics()->GetOrigin( steamBody );
|
|
|
|
steamRenderEntity.axis = af.GetPhysics()->GetAxis( steamBody );
|
|
|
|
steamModelDefHandle = gameRenderWorld->AddEntityDef( &steamRenderEntity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_SteamPipe::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_SteamPipe::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 steamDir;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( thinkFlags & TH_THINK )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamDir.x = gameLocal.random.CRandomFloat() * steamForce;
|
|
|
|
steamDir.y = gameLocal.random.CRandomFloat() * steamForce;
|
|
|
|
steamDir.z = steamUpForce;
|
|
|
|
force.SetForce( steamDir );
|
|
|
|
force.Evaluate( gameLocal.time );
|
|
|
|
//gameRenderWorld->DebugArrow( colorWhite, af.GetPhysics()->GetOrigin( steamBody ), af.GetPhysics()->GetOrigin( steamBody ) - 10.0f * steamDir, 4 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( steamModelDefHandle >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
steamRenderEntity.origin = af.GetPhysics()->GetOrigin( steamBody );
|
|
|
|
steamRenderEntity.axis = af.GetPhysics()->GetAxis( steamBody );
|
|
|
|
gameRenderWorld->UpdateEntityDef( steamModelDefHandle, &steamRenderEntity );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idAFEntity_Base::Think();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_ClawFourFingers
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
const idEventDef EV_SetFingerAngle( "setFingerAngle", "f" );
|
|
|
|
const idEventDef EV_StopFingers( "stopFingers" );
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_Base, idAFEntity_ClawFourFingers )
|
2012-11-28 15:47:07 +00:00
|
|
|
EVENT( EV_SetFingerAngle, idAFEntity_ClawFourFingers::Event_SetFingerAngle )
|
|
|
|
EVENT( EV_StopFingers, idAFEntity_ClawFourFingers::Event_StopFingers )
|
2012-11-26 18:58:24 +00:00
|
|
|
END_CLASS
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* clawConstraintNames[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"claw1", "claw2", "claw3", "claw4"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_ClawFourFingers::idAFEntity_ClawFourFingers
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_ClawFourFingers::idAFEntity_ClawFourFingers()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fingers[0] = NULL;
|
|
|
|
fingers[1] = NULL;
|
|
|
|
fingers[2] = NULL;
|
|
|
|
fingers[3] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_ClawFourFingers::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_ClawFourFingers::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fingers[i]->Save( savefile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_ClawFourFingers::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_ClawFourFingers::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
fingers[i] = static_cast<idAFConstraint_Hinge*>( af.GetPhysics()->GetConstraint( clawConstraintNames[i] ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
fingers[i]->Restore( savefile );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetCombatModel();
|
|
|
|
LinkCombat();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_ClawFourFingers::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_ClawFourFingers::Spawn()
|
|
|
|
{
|
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
|
|
|
LoadAF();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SetCombatModel();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
af.GetPhysics()->LockWorldConstraints( true );
|
|
|
|
af.GetPhysics()->SetForcePushable( true );
|
|
|
|
SetPhysics( af.GetPhysics() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
fl.takedamage = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
fingers[i] = static_cast<idAFConstraint_Hinge*>( af.GetPhysics()->GetConstraint( clawConstraintNames[i] ) );
|
|
|
|
if( !fingers[i] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.Error( "idClaw_FourFingers '%s': can't find claw constraint '%s'", name.c_str(), clawConstraintNames[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_ClawFourFingers::Event_SetFingerAngle
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_ClawFourFingers::Event_SetFingerAngle( float angle )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fingers[i]->SetSteerAngle( angle );
|
|
|
|
fingers[i]->SetSteerSpeed( 0.5f );
|
|
|
|
}
|
|
|
|
af.GetPhysics()->Activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_ClawFourFingers::Event_StopFingers
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_ClawFourFingers::Event_StopFingers()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fingers[i]->SetSteerAngle( fingers[i]->GetAngle() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
editor support routines
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idGameEdit::AF_SpawnEntity
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idGameEdit::AF_SpawnEntity( const char* fileName )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idDict args;
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* player;
|
|
|
|
idAFEntity_Generic* ent;
|
|
|
|
const idDeclAF* af;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 org;
|
|
|
|
float yaw;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player = gameLocal.GetLocalPlayer();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !player || !gameLocal.CheatsOk( false ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
af = static_cast<const idDeclAF*>( declManager->FindType( DECL_AF, fileName ) );
|
|
|
|
if( !af )
|
|
|
|
{
|
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
|
|
|
yaw = player->viewAngles.yaw;
|
|
|
|
args.Set( "angle", va( "%f", yaw + 180 ) );
|
|
|
|
org = player->GetPhysics()->GetOrigin() + idAngles( 0, yaw, 0 ).ToForward() * 80 + idVec3( 0, 0, 1 );
|
|
|
|
args.Set( "origin", org.ToString() );
|
|
|
|
args.Set( "spawnclass", "idAFEntity_Generic" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( af->model[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( "model", af->model.c_str() );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( "model", fileName );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( af->skin[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
args.Set( "skin", af->skin.c_str() );
|
|
|
|
}
|
|
|
|
args.Set( "articulatedFigure", fileName );
|
|
|
|
args.Set( "nodrop", "1" );
|
2012-11-28 15:47:07 +00:00
|
|
|
ent = static_cast<idAFEntity_Generic*>( gameLocal.SpawnEntityType( idAFEntity_Generic::Type, &args ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// always update this entity
|
|
|
|
ent->BecomeActive( TH_THINK );
|
|
|
|
ent->KeepRunningPhysics();
|
|
|
|
ent->fl.forcePhysicsUpdate = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player->dragEntity.SetSelected( ent );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idGameEdit::AF_UpdateEntities
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameEdit::AF_UpdateEntities( const char* fileName )
|
|
|
|
{
|
|
|
|
idEntity* ent;
|
|
|
|
idAFEntity_Base* af;
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr name;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
name = fileName;
|
|
|
|
name.StripFileExtension();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// reload any idAFEntity_Generic which uses the given articulated figure file
|
2012-11-28 15:47:07 +00:00
|
|
|
for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() )
|
|
|
|
{
|
|
|
|
if( ent->IsType( idAFEntity_Base::Type ) )
|
|
|
|
{
|
|
|
|
af = static_cast<idAFEntity_Base*>( ent );
|
|
|
|
if( name.Icmp( af->GetAFName() ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af->LoadAF();
|
|
|
|
af->GetAFPhysics()->PutToRest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idGameEdit::AF_UndoChanges
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameEdit::AF_UndoChanges()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, c;
|
2012-11-28 15:47:07 +00:00
|
|
|
idEntity* ent;
|
|
|
|
idAFEntity_Base* af;
|
|
|
|
idDeclAF* decl;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
c = declManager->GetNumDecls( DECL_AF );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < c; i++ )
|
|
|
|
{
|
|
|
|
decl = static_cast<idDeclAF*>( const_cast<idDecl*>( declManager->DeclByIndex( DECL_AF, i, false ) ) );
|
|
|
|
if( !decl->modified )
|
|
|
|
{
|
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
|
|
|
decl->Invalidate();
|
|
|
|
declManager->FindType( DECL_AF, decl->GetName() );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// reload all AF entities using the file
|
2012-11-28 15:47:07 +00:00
|
|
|
for( ent = gameLocal.spawnedEntities.Next(); ent != NULL; ent = ent->spawnNode.Next() )
|
|
|
|
{
|
|
|
|
if( ent->IsType( idAFEntity_Base::Type ) )
|
|
|
|
{
|
|
|
|
af = static_cast<idAFEntity_Base*>( ent );
|
|
|
|
if( idStr::Icmp( decl->GetName(), af->GetAFName() ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
af->LoadAF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GetJointTransform
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
renderEntity_t* ent;
|
|
|
|
const idMD5Joint* joints;
|
2012-11-26 18:58:24 +00:00
|
|
|
} jointTransformData_t;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
static bool GetJointTransform( void* model, const idJointMat* frame, const char* jointName, idVec3& origin, idMat3& axis )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i;
|
2012-11-28 15:47:07 +00:00
|
|
|
jointTransformData_t* data = reinterpret_cast<jointTransformData_t*>( model );
|
|
|
|
|
|
|
|
for( i = 0; i < data->ent->numJoints; i++ )
|
|
|
|
{
|
|
|
|
if( data->joints[i].name.Icmp( jointName ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( i >= data->ent->numJoints )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
origin = frame[i].ToVec3();
|
|
|
|
axis = frame[i].ToMat3();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
GetArgString
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
static const char* GetArgString( const idDict& args, const idDict* defArgs, const char* key )
|
|
|
|
{
|
|
|
|
const char* s;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
s = args.GetString( key );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !s[0] && defArgs )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
s = defArgs->GetString( key );
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idGameEdit::AF_CreateMesh
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idRenderModel* idGameEdit::AF_CreateMesh( const idDict& args, idVec3& meshOrigin, idMat3& meshAxis, bool& poseIsSet )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, jointNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idDeclAF* af = NULL;
|
|
|
|
const idDeclAF_Body* fb = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
renderEntity_t ent;
|
|
|
|
idVec3 origin, *bodyOrigin = NULL, *newBodyOrigin = NULL, *modifiedOrigin = NULL;
|
|
|
|
idMat3 axis, *bodyAxis = NULL, *newBodyAxis = NULL, *modifiedAxis = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
declAFJointMod_t* jointMod = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idAngles angles;
|
2012-11-28 15:47:07 +00:00
|
|
|
const idDict* defArgs = NULL;
|
|
|
|
const idKeyValue* arg = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr name;
|
|
|
|
jointTransformData_t data;
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* classname = NULL, *afName = NULL, *modelName = NULL;
|
|
|
|
idRenderModel* md5 = NULL;
|
|
|
|
const idDeclModelDef* modelDef = NULL;
|
|
|
|
const idMD5Anim* MD5anim = NULL;
|
|
|
|
const idMD5Joint* MD5joint = NULL;
|
|
|
|
const idMD5Joint* MD5joints = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
int numMD5joints;
|
2012-11-28 15:47:07 +00:00
|
|
|
idJointMat* originalJoints = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
int parentNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
poseIsSet = false;
|
|
|
|
meshOrigin.Zero();
|
|
|
|
meshAxis.Identity();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
classname = args.GetString( "classname" );
|
|
|
|
defArgs = gameLocal.FindEntityDefDict( classname );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// get the articulated figure
|
|
|
|
afName = GetArgString( args, defArgs, "articulatedFigure" );
|
2012-11-28 15:47:07 +00:00
|
|
|
af = static_cast<const idDeclAF*>( declManager->FindType( DECL_AF, afName ) );
|
|
|
|
if( !af )
|
|
|
|
{
|
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
|
|
|
// get the md5 model
|
|
|
|
modelName = GetArgString( args, defArgs, "model" );
|
2012-11-28 15:47:07 +00:00
|
|
|
modelDef = static_cast< const idDeclModelDef*>( declManager->FindType( DECL_MODELDEF, modelName, false ) );
|
|
|
|
if( !modelDef )
|
|
|
|
{
|
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
|
|
|
// make sure model hasn't been purged
|
2012-11-28 15:47:07 +00:00
|
|
|
if( modelDef->ModelHandle() && !modelDef->ModelHandle()->IsLoaded() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
modelDef->ModelHandle()->LoadModel();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// get the md5
|
|
|
|
md5 = modelDef->ModelHandle();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !md5 || md5->IsDefaultModel() )
|
|
|
|
{
|
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
|
|
|
// get the articulated figure pose anim
|
|
|
|
int animNum = modelDef->GetAnim( "af_pose" );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !animNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
const idAnim* anim = modelDef->GetAnim( animNum );
|
|
|
|
if( !anim )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
MD5anim = anim->MD5Anim( 0 );
|
|
|
|
MD5joints = md5->GetJoints();
|
|
|
|
numMD5joints = md5->NumJoints();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// setup a render entity
|
|
|
|
memset( &ent, 0, sizeof( ent ) );
|
|
|
|
ent.customSkin = modelDef->GetSkin();
|
|
|
|
ent.bounds.Clear();
|
|
|
|
ent.numJoints = numMD5joints;
|
2012-11-28 15:47:07 +00:00
|
|
|
ent.joints = ( idJointMat* )_alloca16( ent.numJoints * sizeof( *ent.joints ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// create animation from of the af_pose
|
|
|
|
ANIM_CreateAnimFrame( md5, MD5anim, ent.numJoints, ent.joints, 1, modelDef->GetVisualOffset(), false );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// buffers to store the initial origin and axis for each body
|
2012-11-28 15:47:07 +00:00
|
|
|
bodyOrigin = ( idVec3* ) _alloca16( af->bodies.Num() * sizeof( idVec3 ) );
|
|
|
|
bodyAxis = ( idMat3* ) _alloca16( af->bodies.Num() * sizeof( idMat3 ) );
|
|
|
|
newBodyOrigin = ( idVec3* ) _alloca16( af->bodies.Num() * sizeof( idVec3 ) );
|
|
|
|
newBodyAxis = ( idMat3* ) _alloca16( af->bodies.Num() * sizeof( idMat3 ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// finish the AF positions
|
|
|
|
data.ent = &ent;
|
|
|
|
data.joints = MD5joints;
|
|
|
|
af->Finish( GetJointTransform, ent.joints, &data );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// get the initial origin and axis for each AF body
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < af->bodies.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fb = af->bodies[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fb->modelType == TRM_BONE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// axis of bone trace model
|
|
|
|
axis[2] = fb->v2.ToVec3() - fb->v1.ToVec3();
|
|
|
|
axis[2].Normalize();
|
|
|
|
axis[2].NormalVectors( axis[0], axis[1] );
|
|
|
|
axis[1] = -axis[1];
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
axis = fb->angles.ToMat3();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
newBodyOrigin[i] = bodyOrigin[i] = fb->origin.ToVec3();
|
|
|
|
newBodyAxis[i] = bodyAxis[i] = axis;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// get any new body transforms stored in the key/value pairs
|
2012-11-28 15:47:07 +00:00
|
|
|
for( arg = args.MatchPrefix( "body ", NULL ); arg; arg = args.MatchPrefix( "body ", arg ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
name = arg->GetKey();
|
|
|
|
name.Strip( "body " );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < af->bodies.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fb = af->bodies[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( fb->name.Icmp( name ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( i >= af->bodies.Num() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sscanf( arg->GetValue(), "%f %f %f %f %f %f", &origin.x, &origin.y, &origin.z, &angles.pitch, &angles.yaw, &angles.roll );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fb != NULL && fb->jointName.Icmp( "origin" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
meshAxis = bodyAxis[i].Transpose() * angles.ToMat3();
|
|
|
|
meshOrigin = origin - bodyOrigin[i] * meshAxis;
|
|
|
|
poseIsSet = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
newBodyOrigin[i] = origin;
|
|
|
|
newBodyAxis[i] = angles.ToMat3();
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// save the original joints
|
2012-11-28 15:47:07 +00:00
|
|
|
originalJoints = ( idJointMat* )_alloca16( numMD5joints * sizeof( originalJoints[0] ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
memcpy( originalJoints, ent.joints, numMD5joints * sizeof( originalJoints[0] ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// buffer to store the joint mods
|
2012-11-28 15:47:07 +00:00
|
|
|
jointMod = ( declAFJointMod_t* ) _alloca16( numMD5joints * sizeof( declAFJointMod_t ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( jointMod, -1, numMD5joints * sizeof( declAFJointMod_t ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
modifiedOrigin = ( idVec3* ) _alloca16( numMD5joints * sizeof( idVec3 ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( modifiedOrigin, 0, numMD5joints * sizeof( idVec3 ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
modifiedAxis = ( idMat3* ) _alloca16( numMD5joints * sizeof( idMat3 ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( modifiedAxis, 0, numMD5joints * sizeof( idMat3 ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// get all the joint modifications
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < af->bodies.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fb = af->bodies[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fb->jointName.Icmp( "origin" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( jointNum = 0; jointNum < numMD5joints; jointNum++ )
|
|
|
|
{
|
|
|
|
if( MD5joints[jointNum].name.Icmp( fb->jointName ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( jointNum >= 0 && jointNum < ent.numJoints )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
jointMod[ jointNum ] = fb->jointMod;
|
|
|
|
modifiedAxis[ jointNum ] = ( bodyAxis[i] * originalJoints[jointNum].ToMat3().Transpose() ).Transpose() * ( newBodyAxis[i] * meshAxis.Transpose() );
|
|
|
|
// FIXME: calculate correct modifiedOrigin
|
|
|
|
modifiedOrigin[ jointNum ] = originalJoints[ jointNum ].ToVec3();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// apply joint modifications to the skeleton
|
|
|
|
MD5joint = MD5joints + 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 1; i < numMD5joints; i++, MD5joint++ )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
parentNum = MD5joint->parent - MD5joints;
|
|
|
|
idMat3 parentAxis = originalJoints[ parentNum ].ToMat3();
|
|
|
|
idMat3 localm = originalJoints[i].ToMat3() * parentAxis.Transpose();
|
|
|
|
idVec3 localt = ( originalJoints[i].ToVec3() - originalJoints[ parentNum ].ToVec3() ) * parentAxis.Transpose();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
switch( jointMod[i] )
|
|
|
|
{
|
|
|
|
case DECLAF_JOINTMOD_ORIGIN:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent.joints[ i ].SetRotation( localm * ent.joints[ parentNum ].ToMat3() );
|
|
|
|
ent.joints[ i ].SetTranslation( modifiedOrigin[ i ] );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case DECLAF_JOINTMOD_AXIS:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent.joints[ i ].SetRotation( modifiedAxis[ i ] );
|
|
|
|
ent.joints[ i ].SetTranslation( ent.joints[ parentNum ].ToVec3() + localt * ent.joints[ parentNum ].ToMat3() );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
case DECLAF_JOINTMOD_BOTH:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent.joints[ i ].SetRotation( modifiedAxis[ i ] );
|
|
|
|
ent.joints[ i ].SetTranslation( modifiedOrigin[ i ] );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
default:
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ent.joints[ i ].SetRotation( localm * ent.joints[ parentNum ].ToMat3() );
|
|
|
|
ent.joints[ i ].SetTranslation( ent.joints[ parentNum ].ToVec3() + localt * ent.joints[ parentNum ].ToMat3() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// instantiate a mesh using the joint information from the render entity
|
|
|
|
return md5->InstantiateDynamicModel( &ent, NULL, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
idHarvestable
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
const idEventDef EV_Harvest_SpawnHarvestTrigger( "<spawnHarvestTrigger>", NULL );
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idEntity, idHarvestable )
|
|
|
|
EVENT( EV_Harvest_SpawnHarvestTrigger, idHarvestable::Event_SpawnHarvestTrigger )
|
|
|
|
EVENT( EV_Touch, idHarvestable::Event_Touch )
|
|
|
|
END_CLASS
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idHarvestable::idHarvestable()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
trigger = NULL;
|
|
|
|
parentEnt = NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idHarvestable::~idHarvestable()
|
|
|
|
{
|
|
|
|
if( trigger )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
delete trigger;
|
|
|
|
trigger = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
startTime = 0;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
spawnArgs.GetFloat( "triggersize", "120", triggersize );
|
2012-11-28 15:47:07 +00:00
|
|
|
spawnArgs.GetFloat( "give_delay", "3", giveDelay );
|
2012-11-26 18:58:24 +00:00
|
|
|
giveDelay *= 1000;
|
|
|
|
given = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
removeDelay = spawnArgs.GetFloat( "remove_delay" ) * 1000.0f;
|
|
|
|
|
|
|
|
fxFollowPlayer = spawnArgs.GetBool( "fx_follow_player", "1" );
|
|
|
|
fxOrient = spawnArgs.GetString( "fx_orient" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Init( idEntity* parent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
assert( parent );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
parentEnt = parent;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
GetPhysics()->SetOrigin( parent->GetPhysics()->GetOrigin() );
|
2012-11-28 15:47:07 +00:00
|
|
|
this->Bind( parent, true );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Set the skin of the entity to the harvest skin
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr skin = parent->spawnArgs.GetString( "skin_harvest", "" );
|
|
|
|
if( skin.Length() )
|
|
|
|
{
|
|
|
|
parent->SetSkin( declManager->FindSkin( skin.c_str() ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
idEntity* head = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( parent->IsType( idActor::Type ) )
|
|
|
|
{
|
|
|
|
idActor* withHead = ( idActor* )parent;
|
2012-11-26 18:58:24 +00:00
|
|
|
head = withHead->GetHeadEntity();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( parent->IsType( idAFEntity_WithAttachedHead::Type ) )
|
|
|
|
{
|
|
|
|
idAFEntity_WithAttachedHead* withHead = ( idAFEntity_WithAttachedHead* )parent;
|
2012-11-26 18:58:24 +00:00
|
|
|
head = withHead->head.GetEntity();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( head )
|
|
|
|
{
|
|
|
|
idStr headskin = parent->spawnArgs.GetString( "skin_harvest_head", "" );
|
|
|
|
if( headskin.Length() )
|
|
|
|
{
|
|
|
|
head->SetSkin( declManager->FindSkin( headskin.c_str() ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idStr sound = parent->spawnArgs.GetString( "harvest_sound" );
|
|
|
|
if( sound.Length() > 0 )
|
|
|
|
{
|
|
|
|
parent->StartSound( sound.c_str(), SND_CHANNEL_ANY, 0, false, NULL );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
PostEventMS( &EV_Harvest_SpawnHarvestTrigger, 0 );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteFloat( triggersize );
|
|
|
|
savefile->WriteClipModel( trigger );
|
|
|
|
savefile->WriteFloat( giveDelay );
|
|
|
|
savefile->WriteFloat( removeDelay );
|
|
|
|
savefile->WriteBool( given );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player.Save( savefile );
|
|
|
|
savefile->WriteInt( startTime );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->WriteBool( fxFollowPlayer );
|
|
|
|
fx.Save( savefile );
|
|
|
|
savefile->WriteString( fxOrient );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
parentEnt.Save( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadFloat( triggersize );
|
|
|
|
savefile->ReadClipModel( trigger );
|
|
|
|
savefile->ReadFloat( giveDelay );
|
|
|
|
savefile->ReadFloat( removeDelay );
|
|
|
|
savefile->ReadBool( given );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player.Restore( savefile );
|
|
|
|
savefile->ReadInt( startTime );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
savefile->ReadBool( fxFollowPlayer );
|
|
|
|
fx.Restore( savefile );
|
|
|
|
savefile->ReadString( fxOrient );
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
parentEnt.Restore( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::SetParent( idEntity* parent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
parentEnt = parent;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !parent )
|
|
|
|
{
|
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
|
|
|
//Update the orientation of the box
|
2012-11-28 15:47:07 +00:00
|
|
|
if( trigger && parent && !parent->GetPhysics()->IsAtRest() )
|
|
|
|
{
|
|
|
|
trigger->Link( gameLocal.clip, this, 0, parent->GetPhysics()->GetOrigin(), parent->GetPhysics()->GetAxis() );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( startTime && gameLocal.slow.time - startTime > giveDelay && ! given )
|
|
|
|
{
|
|
|
|
idPlayer* thePlayer = player.GetEntity();
|
|
|
|
|
|
|
|
thePlayer->Give( spawnArgs.GetString( "give_item" ), spawnArgs.GetString( "give_value" ), ITEM_GIVE_FEEDBACK | ITEM_GIVE_UPDATE_STATE );
|
2012-11-26 18:58:24 +00:00
|
|
|
thePlayer->harvest_lock = false;
|
|
|
|
given = true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( startTime && gameLocal.slow.time - startTime > removeDelay )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
parent->PostEventMS( &EV_Remove, 0 );
|
|
|
|
PostEventMS( &EV_Remove, 0 );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( fxFollowPlayer )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntityFx* fxEnt = fx.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( fxEnt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idMat3 orientAxisLocal;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( GetFxOrientationAxis( orientAxisLocal ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//gameRenderWorld->DebugAxis(fxEnt->GetPhysics()->GetOrigin(), orientAxisLocal);
|
2012-11-28 15:47:07 +00:00
|
|
|
fxEnt->GetPhysics()->SetAxis( orientAxisLocal );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Gib
|
|
|
|
Called when the parent object has been gibbed.
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Gib()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Stop any looping sound that was playing
|
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( parent )
|
|
|
|
{
|
|
|
|
idStr sound = parent->spawnArgs.GetString( "harvest_sound" );
|
|
|
|
if( sound.Length() > 0 )
|
|
|
|
{
|
|
|
|
parent->StopSound( SND_CHANNEL_ANY, false );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::BeginBurn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::BeginBurn()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !parent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !spawnArgs.GetBool( "burn" ) )
|
|
|
|
{
|
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
|
|
|
//Switch Skins if the parent would like us to.
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr skin = parent->spawnArgs.GetString( "skin_harvest_burn", "" );
|
|
|
|
if( skin.Length() )
|
|
|
|
{
|
|
|
|
parent->SetSkin( declManager->FindSkin( skin.c_str() ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
parent->GetRenderEntity()->noShadow = true;
|
|
|
|
parent->SetShaderParm( SHADERPARM_TIME_OF_DEATH, gameLocal.slow.time * 0.001f );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity* head = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( parent->IsType( idActor::Type ) )
|
|
|
|
{
|
|
|
|
idActor* withHead = ( idActor* )parent;
|
2012-11-26 18:58:24 +00:00
|
|
|
head = withHead->GetHeadEntity();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( parent->IsType( idAFEntity_WithAttachedHead::Type ) )
|
|
|
|
{
|
|
|
|
idAFEntity_WithAttachedHead* withHead = ( idAFEntity_WithAttachedHead* )parent;
|
2012-11-26 18:58:24 +00:00
|
|
|
head = withHead->head.GetEntity();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( head )
|
|
|
|
{
|
|
|
|
idStr headskin = parent->spawnArgs.GetString( "skin_harvest_burn_head", "" );
|
|
|
|
if( headskin.Length() )
|
|
|
|
{
|
|
|
|
head->SetSkin( declManager->FindSkin( headskin.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
|
|
|
head->GetRenderEntity()->noShadow = true;
|
|
|
|
head->SetShaderParm( SHADERPARM_TIME_OF_DEATH, gameLocal.slow.time * 0.001f );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::BeginFX
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::BeginFX()
|
|
|
|
{
|
|
|
|
if( strlen( spawnArgs.GetString( "fx" ) ) <= 0 )
|
|
|
|
{
|
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
|
|
|
idMat3* orientAxis = NULL;
|
|
|
|
idMat3 orientAxisLocal;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( GetFxOrientationAxis( orientAxisLocal ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
orientAxis = &orientAxisLocal;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
fx = idEntityFx::StartFx( spawnArgs.GetString( "fx" ), NULL, orientAxis, this, spawnArgs.GetBool( "fx_bind" ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::CalcTriggerBounds
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::CalcTriggerBounds( float size, idBounds& bounds )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !parent )
|
|
|
|
{
|
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
|
|
|
//Simple trigger bounds is the absolute bounds of the AF plus a defined size
|
|
|
|
bounds = parent->GetPhysics()->GetAbsBounds();
|
2012-11-28 15:47:07 +00:00
|
|
|
bounds.ExpandSelf( size );
|
2012-11-26 18:58:24 +00:00
|
|
|
bounds[0] -= parent->GetPhysics()->GetOrigin();
|
|
|
|
bounds[1] -= parent->GetPhysics()->GetOrigin();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idHarvestable::GetFxOrientationAxis( idMat3& mat )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !parent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idPlayer* thePlayer = player.GetEntity();
|
|
|
|
|
|
|
|
if( !fxOrient.Icmp( "up" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Orient up
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 grav = parent->GetPhysics()->GetGravityNormal() * -1;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 left, up;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
grav.OrthogonalBasis( left, up );
|
|
|
|
idMat3 temp( left.x, left.y, left.z, up.x, up.y, up.z, grav.x, grav.y, grav.z );
|
2012-11-26 18:58:24 +00:00
|
|
|
mat = temp;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( !fxOrient.Icmp( "weapon" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Orient the fx towards the muzzle of the weapon
|
|
|
|
jointHandle_t joint;
|
|
|
|
idVec3 joint_origin;
|
|
|
|
idMat3 joint_axis;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
joint = thePlayer->weapon.GetEntity()->GetAnimator()->GetJointHandle( spawnArgs.GetString( "fx_weapon_joint" ) );
|
|
|
|
if( joint != INVALID_JOINT )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
thePlayer->weapon.GetEntity()->GetJointWorldTransform( joint, gameLocal.slow.time, joint_origin, joint_axis );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
joint_origin = thePlayer->GetPhysics()->GetOrigin();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idVec3 toPlayer = joint_origin - parent->GetPhysics()->GetOrigin();
|
2012-11-26 18:58:24 +00:00
|
|
|
toPlayer.NormalizeFast();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 left, up;
|
2012-11-28 15:47:07 +00:00
|
|
|
toPlayer.OrthogonalBasis( left, up );
|
|
|
|
idMat3 temp( left.x, left.y, left.z, up.x, up.y, up.z, toPlayer.x, toPlayer.y, toPlayer.z );
|
2012-11-26 18:58:24 +00:00
|
|
|
mat = temp;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if( !fxOrient.Icmp( "player" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Orient the fx towards the eye of the player
|
|
|
|
idVec3 eye = thePlayer->GetEyePosition();
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 toPlayer = eye - parent->GetPhysics()->GetOrigin();
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
toPlayer.Normalize();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 left, up;
|
2012-11-28 15:47:07 +00:00
|
|
|
up.Set( 0, 1, 0 );
|
|
|
|
left = toPlayer.Cross( up );
|
|
|
|
up = left.Cross( toPlayer );
|
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//common->Printf("%.2f %.2f %.2f - %.2f %.2f %.2f - %.2f %.2f %.2f\n", toPlayer.x, toPlayer.y, toPlayer.z, left.x, left.y, left.z, up.x, up.y, up.z );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idMat3 temp( left.x, left.y, left.z, up.x, up.y, up.z, toPlayer.x, toPlayer.y, toPlayer.z );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
mat = temp;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
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
|
|
|
//Returning false indicates that the orientation is not used;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Event_SpawnHarvestTrigger
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Event_SpawnHarvestTrigger()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds bounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !parent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
CalcTriggerBounds( triggersize, bounds );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// create a trigger clip model
|
2012-11-28 15:47:07 +00:00
|
|
|
trigger = new( TAG_PHYSICS_CLIP_AF ) idClipModel( idTraceModel( bounds ) );
|
|
|
|
trigger->Link( gameLocal.clip, this, 255, parent->GetPhysics()->GetOrigin(), mat3_identity );
|
2012-11-26 18:58:24 +00:00
|
|
|
trigger->SetContents( CONTENTS_TRIGGER );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
startTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Event_Touch
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idHarvestable::Event_Touch( idEntity* other, trace_t* trace )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idEntity* parent = parentEnt.GetEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !parent )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( parent->IsType( idAFEntity_Gibbable::Type ) )
|
|
|
|
{
|
|
|
|
idAFEntity_Gibbable* gibParent = ( idAFEntity_Gibbable* )parent;
|
|
|
|
if( gibParent->IsGibbed() )
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
if( !startTime && other && other->IsType( idPlayer::Type ) )
|
|
|
|
{
|
|
|
|
idPlayer* thePlayer = static_cast<idPlayer*>( other );
|
|
|
|
|
|
|
|
if( thePlayer->harvest_lock )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Don't harvest if the player is in mid harvest
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
player = thePlayer;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
bool okToGive = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr requiredWeapons = spawnArgs.GetString( "required_weapons" );
|
|
|
|
|
|
|
|
if( requiredWeapons.Length() > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr playerWeap = thePlayer->GetCurrentWeapon();
|
2012-11-28 15:47:07 +00:00
|
|
|
if( playerWeap.Length() == 0 || requiredWeapons.Find( playerWeap, false ) == -1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
okToGive = false;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( okToGive )
|
|
|
|
{
|
|
|
|
if( thePlayer->CanGive( spawnArgs.GetString( "give_item" ), spawnArgs.GetString( "give_value" ) ) )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
startTime = gameLocal.slow.time;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Lock the player from harvesting to prevent multiple harvests when only one is needed
|
|
|
|
thePlayer->harvest_lock = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idWeapon* weap = ( idWeapon* )thePlayer->weapon.GetEntity();
|
|
|
|
if( weap )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//weap->PostEventMS(&EV_Weapon_State, 0, "Charge", 8);
|
2012-11-28 15:47:07 +00:00
|
|
|
weap->ProcessEvent( &EV_Weapon_State, "Charge", 8 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
BeginBurn();
|
|
|
|
BeginFX();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Stop any looping sound that was playing
|
2012-11-28 15:47:07 +00:00
|
|
|
idStr sound = parent->spawnArgs.GetString( "harvest_sound" );
|
|
|
|
if( sound.Length() > 0 )
|
|
|
|
{
|
|
|
|
parent->StopSound( SND_CHANNEL_ANY, false );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Make the parent object non-solid
|
|
|
|
parent->GetPhysics()->SetContents( 0 );
|
|
|
|
parent->GetPhysics()->GetClipModel()->Unlink();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Turn of the trigger so it doesn't process twice
|
|
|
|
trigger->SetContents( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
idAFEntity_Harvest
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
const idEventDef EV_Harvest_SpawnHarvestEntity( "<spawnHarvestEntity>", NULL );
|
|
|
|
|
|
|
|
CLASS_DECLARATION( idAFEntity_WithAttachedHead, idAFEntity_Harvest )
|
|
|
|
EVENT( EV_Harvest_SpawnHarvestEntity, idAFEntity_Harvest::Event_SpawnHarvestEntity )
|
|
|
|
END_CLASS
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::idAFEntity_Harvest
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Harvest::idAFEntity_Harvest()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
harvestEnt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::~idAFEntity_Harvest
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_Harvest::~idAFEntity_Harvest()
|
|
|
|
{
|
|
|
|
|
|
|
|
if( harvestEnt.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
harvestEnt.GetEntity()->PostEventMS( &EV_Remove, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Save
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Harvest::Save( idSaveGame* savefile ) const
|
|
|
|
{
|
|
|
|
harvestEnt.Save( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Restore
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Harvest::Restore( idRestoreGame* savefile )
|
|
|
|
{
|
|
|
|
harvestEnt.Restore( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
//if(harvestEnt.GetEntity()) {
|
|
|
|
// harvestEnt.GetEntity()->SetParent(this);
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Spawn
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Harvest::Spawn()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
PostEventMS( &EV_Harvest_SpawnHarvestEntity, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
idAFEntity_Harvest::Think
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Harvest::Think()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idAFEntity_WithAttachedHead::Think();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Harvest::Event_SpawnHarvestEntity()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const idDict* harvestDef = gameLocal.FindEntityDefDict( spawnArgs.GetString( "def_harvest_type" ), false );
|
|
|
|
if( harvestDef )
|
|
|
|
{
|
|
|
|
idEntity* temp;
|
2012-11-26 18:58:24 +00:00
|
|
|
gameLocal.SpawnEntityDef( *harvestDef, &temp, false );
|
2012-11-28 15:47:07 +00:00
|
|
|
harvestEnt = static_cast<idHarvestable*>( temp );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( harvestEnt.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Let the harvest entity set itself up
|
2012-11-28 15:47:07 +00:00
|
|
|
harvestEnt.GetEntity()->Init( this );
|
2012-11-26 18:58:24 +00:00
|
|
|
harvestEnt.GetEntity()->BecomeActive( TH_THINK );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAFEntity_Harvest::Gib( const idVec3& dir, const char* damageDefName )
|
|
|
|
{
|
|
|
|
if( harvestEnt.GetEntity() )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Let the harvest ent know that we gibbed
|
|
|
|
harvestEnt.GetEntity()->Gib();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idAFEntity_WithAttachedHead::Gib( dir, damageDefName );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|