doom3-bfg/neo/d3xp/ai/AI_Vagary.cpp

165 lines
5.1 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +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.
===========================================================================
*/
/***********************************************************************
game/ai/AI_Vagary.cpp
Vagary specific AI code
***********************************************************************/
#pragma hdrstop
#include "../../idlib/precompiled.h"
#include "../Game_local.h"
class idAI_Vagary : public idAI
{
2012-11-26 18:58:24 +00:00
public:
CLASS_PROTOTYPE( idAI_Vagary );
2012-11-26 18:58:24 +00:00
private:
void Event_ChooseObjectToThrow( const idVec3& mins, const idVec3& maxs, float speed, float minDist, float offset );
void Event_ThrowObjectAtEnemy( idEntity* ent, float speed );
2012-11-26 18:58:24 +00:00
};
const idEventDef AI_Vagary_ChooseObjectToThrow( "vagary_ChooseObjectToThrow", "vvfff", 'e' );
const idEventDef AI_Vagary_ThrowObjectAtEnemy( "vagary_ThrowObjectAtEnemy", "ef" );
CLASS_DECLARATION( idAI, idAI_Vagary )
EVENT( AI_Vagary_ChooseObjectToThrow, idAI_Vagary::Event_ChooseObjectToThrow )
EVENT( AI_Vagary_ThrowObjectAtEnemy, idAI_Vagary::Event_ThrowObjectAtEnemy )
2012-11-26 18:58:24 +00:00
END_CLASS
/*
================
idAI_Vagary::Event_ChooseObjectToThrow
================
*/
void idAI_Vagary::Event_ChooseObjectToThrow( const idVec3& mins, const idVec3& maxs, float speed, float minDist, float offset )
{
idEntity* ent;
idEntity* entityList[ MAX_GENTITIES ];
2012-11-26 18:58:24 +00:00
int numListedEntities;
int i, index;
float dist;
idVec3 vel;
idVec3 offsetVec( 0, 0, offset );
idEntity* enemyEnt = enemy.GetEntity();
if( !enemyEnt )
{
2012-11-26 18:58:24 +00:00
idThread::ReturnEntity( NULL );
return;
}
2012-11-26 18:58:24 +00:00
idVec3 enemyEyePos = lastVisibleEnemyPos + lastVisibleEnemyEyeOffset;
const idBounds& myBounds = physicsObj.GetAbsBounds();
2012-11-26 18:58:24 +00:00
idBounds checkBounds( mins, maxs );
checkBounds.TranslateSelf( physicsObj.GetOrigin() );
numListedEntities = gameLocal.clip.EntitiesTouchingBounds( checkBounds, -1, entityList, MAX_GENTITIES );
2012-11-26 18:58:24 +00:00
index = gameLocal.random.RandomInt( numListedEntities );
for( i = 0; i < numListedEntities; i++, index++ )
{
if( index >= numListedEntities )
{
2012-11-26 18:58:24 +00:00
index = 0;
}
ent = entityList[ index ];
if( !ent->IsType( idMoveable::Type ) )
{
2012-11-26 18:58:24 +00:00
continue;
}
if( ent->fl.hidden )
{
2012-11-26 18:58:24 +00:00
// don't throw hidden objects
continue;
}
idPhysics* entPhys = ent->GetPhysics();
const idVec3& entOrg = entPhys->GetOrigin();
2012-11-26 18:58:24 +00:00
dist = ( entOrg - enemyEyePos ).LengthFast();
if( dist < minDist )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
idBounds expandedBounds = myBounds.Expand( entPhys->GetBounds().GetRadius() );
if( expandedBounds.LineIntersection( entOrg, enemyEyePos ) )
{
2012-11-26 18:58:24 +00:00
// ignore objects that are behind us
continue;
}
if( PredictTrajectory( entPhys->GetOrigin() + offsetVec, enemyEyePos, speed, entPhys->GetGravity(),
entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel ) )
{
2012-11-26 18:58:24 +00:00
idThread::ReturnEntity( ent );
return;
2012-11-26 18:58:24 +00:00
}
}
2012-11-26 18:58:24 +00:00
idThread::ReturnEntity( NULL );
}
/*
================
idAI_Vagary::Event_ThrowObjectAtEnemy
================
*/
void idAI_Vagary::Event_ThrowObjectAtEnemy( idEntity* ent, float speed )
{
2012-11-26 18:58:24 +00:00
idVec3 vel;
idEntity* enemyEnt;
idPhysics* entPhys;
2012-11-26 18:58:24 +00:00
entPhys = ent->GetPhysics();
enemyEnt = enemy.GetEntity();
if( !enemyEnt )
{
2012-11-26 18:58:24 +00:00
vel = ( viewAxis[ 0 ] * physicsObj.GetGravityAxis() ) * speed;
}
else
{
PredictTrajectory( entPhys->GetOrigin(), lastVisibleEnemyPos + lastVisibleEnemyEyeOffset, speed, entPhys->GetGravity(),
entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel );
2012-11-26 18:58:24 +00:00
vel *= speed;
}
2012-11-26 18:58:24 +00:00
entPhys->SetLinearVelocity( vel );
if( ent->IsType( idMoveable::Type ) )
{
idMoveable* ment = static_cast<idMoveable*>( ent );
2012-11-26 18:58:24 +00:00
ment->EnableDamage( true, 2.5f );
}
}