2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 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 Source Code. If not, please request a copy in writing from id Software at the address below.
24 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.
26 ===========================================================================
28 /***********************************************************************
32 Vagary specific AI code
34 ***********************************************************************/
36 #include "../../idlib/precompiled.h"
39 #include "../Game_local.h"
41 class idAI_Vagary : public idAI {
43 CLASS_PROTOTYPE( idAI_Vagary );
46 void Event_ChooseObjectToThrow( const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset );
47 void Event_ThrowObjectAtEnemy( idEntity *ent, float speed );
50 const idEventDef AI_Vagary_ChooseObjectToThrow( "vagary_ChooseObjectToThrow", "vvfff", 'e' );
51 const idEventDef AI_Vagary_ThrowObjectAtEnemy( "vagary_ThrowObjectAtEnemy", "ef" );
53 CLASS_DECLARATION( idAI, idAI_Vagary )
54 EVENT( AI_Vagary_ChooseObjectToThrow, idAI_Vagary::Event_ChooseObjectToThrow )
55 EVENT( AI_Vagary_ThrowObjectAtEnemy, idAI_Vagary::Event_ThrowObjectAtEnemy )
60 idAI_Vagary::Event_ChooseObjectToThrow
63 void idAI_Vagary::Event_ChooseObjectToThrow( const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset ) {
65 idEntity * entityList[ MAX_GENTITIES ];
66 int numListedEntities;
70 idVec3 offsetVec( 0, 0, offset );
71 idEntity *enemyEnt = enemy.GetEntity();
74 idThread::ReturnEntity( NULL );
77 idVec3 enemyEyePos = lastVisibleEnemyPos + lastVisibleEnemyEyeOffset;
78 const idBounds &myBounds = physicsObj.GetAbsBounds();
79 idBounds checkBounds( mins, maxs );
80 checkBounds.TranslateSelf( physicsObj.GetOrigin() );
81 numListedEntities = gameLocal.clip.EntitiesTouchingBounds( checkBounds, -1, entityList, MAX_GENTITIES );
83 index = gameLocal.random.RandomInt( numListedEntities );
84 for ( i = 0; i < numListedEntities; i++, index++ ) {
85 if ( index >= numListedEntities ) {
88 ent = entityList[ index ];
89 if ( !ent->IsType( idMoveable::Type ) ) {
93 if ( ent->fl.hidden ) {
94 // don't throw hidden objects
98 idPhysics *entPhys = ent->GetPhysics();
99 const idVec3 &entOrg = entPhys->GetOrigin();
100 dist = ( entOrg - enemyEyePos ).LengthFast();
101 if ( dist < minDist ) {
105 idBounds expandedBounds = myBounds.Expand( entPhys->GetBounds().GetRadius() );
106 if ( expandedBounds.LineIntersection( entOrg, enemyEyePos ) ) {
107 // ignore objects that are behind us
111 if ( PredictTrajectory( entPhys->GetOrigin() + offsetVec, enemyEyePos, speed, entPhys->GetGravity(),
112 entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel ) ) {
113 idThread::ReturnEntity( ent );
118 idThread::ReturnEntity( NULL );
123 idAI_Vagary::Event_ThrowObjectAtEnemy
126 void idAI_Vagary::Event_ThrowObjectAtEnemy( idEntity *ent, float speed ) {
131 entPhys = ent->GetPhysics();
132 enemyEnt = enemy.GetEntity();
134 vel = ( viewAxis[ 0 ] * physicsObj.GetGravityAxis() ) * speed;
136 PredictTrajectory( entPhys->GetOrigin(), lastVisibleEnemyPos + lastVisibleEnemyEyeOffset, speed, entPhys->GetGravity(),
137 entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel );
141 entPhys->SetLinearVelocity( vel );
143 if ( ent->IsType( idMoveable::Type ) ) {
144 idMoveable *ment = static_cast<idMoveable*>( ent );
145 ment->EnableDamage( true, 2.5f );