doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AI_Vagary.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
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.
13 
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.
18 
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/>.
21 
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.
23 
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.
25 
26 ===========================================================================
27 */
28 /***********************************************************************
29 
30 game/ai/AI_Vagary.cpp
31 
32 Vagary specific AI code
33 
34 ***********************************************************************/
35 
36 #include "../../idlib/precompiled.h"
37 #pragma hdrstop
38 
39 #include "../Game_local.h"
40 
41 class idAI_Vagary : public idAI {
42 public:
44 
45 private:
46  void Event_ChooseObjectToThrow( const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset );
47  void Event_ThrowObjectAtEnemy( idEntity *ent, float speed );
48 };
49 
50 const idEventDef AI_Vagary_ChooseObjectToThrow( "vagary_ChooseObjectToThrow", "vvfff", 'e' );
51 const idEventDef AI_Vagary_ThrowObjectAtEnemy( "vagary_ThrowObjectAtEnemy", "ef" );
52 
54  EVENT( AI_Vagary_ChooseObjectToThrow, idAI_Vagary::Event_ChooseObjectToThrow )
55  EVENT( AI_Vagary_ThrowObjectAtEnemy, idAI_Vagary::Event_ThrowObjectAtEnemy )
57 
58 /*
59 ================
60 idAI_Vagary::Event_ChooseObjectToThrow
61 ================
62 */
63 void idAI_Vagary::Event_ChooseObjectToThrow( const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset ) {
64  idEntity * ent;
65  idEntity * entityList[ MAX_GENTITIES ];
66  int numListedEntities;
67  int i, index;
68  float dist;
69  idVec3 vel;
70  idVec3 offsetVec( 0, 0, offset );
71  idEntity *enemyEnt = enemy.GetEntity();
72 
73  if ( !enemyEnt ) {
75  }
76 
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 );
82 
83  index = gameLocal.random.RandomInt( numListedEntities );
84  for ( i = 0; i < numListedEntities; i++, index++ ) {
85  if ( index >= numListedEntities ) {
86  index = 0;
87  }
88  ent = entityList[ index ];
89  if ( !ent->IsType( idMoveable::Type ) ) {
90  continue;
91  }
92 
93  if ( ent->fl.hidden ) {
94  // don't throw hidden objects
95  continue;
96  }
97 
98  idPhysics *entPhys = ent->GetPhysics();
99  const idVec3 &entOrg = entPhys->GetOrigin();
100  dist = ( entOrg - enemyEyePos ).LengthFast();
101  if ( dist < minDist ) {
102  continue;
103  }
104 
105  idBounds expandedBounds = myBounds.Expand( entPhys->GetBounds().GetRadius() );
106  if ( expandedBounds.LineIntersection( entOrg, enemyEyePos ) ) {
107  // ignore objects that are behind us
108  continue;
109  }
110 
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 );
114  return;
115  }
116  }
117 
119 }
120 
121 /*
122 ================
123 idAI_Vagary::Event_ThrowObjectAtEnemy
124 ================
125 */
127  idVec3 vel;
128  idEntity *enemyEnt;
129  idPhysics *entPhys;
130 
131  entPhys = ent->GetPhysics();
132  enemyEnt = enemy.GetEntity();
133  if ( !enemyEnt ) {
134  vel = ( viewAxis[ 0 ] * physicsObj.GetGravityAxis() ) * speed;
135  } else {
137  entPhys->GetClipModel(), entPhys->GetClipMask(), MAX_WORLD_SIZE, NULL, enemyEnt, ai_debugTrajectory.GetBool() ? 4000 : 0, vel );
138  vel *= speed;
139  }
140 
141  entPhys->SetLinearVelocity( vel );
142 
143  if ( ent->IsType( idMoveable::Type ) ) {
144  idMoveable *ment = static_cast<idMoveable*>( ent );
145  ment->EnableDamage( true, 2.5f );
146  }
147 }
virtual const idVec3 & GetOrigin(int id=0) const =0
idBounds & TranslateSelf(const idVec3 &translation)
Definition: Bounds.h:336
virtual int GetClipMask(int id=-1) const =0
idClip clip
Definition: Game_local.h:296
struct idEntity::entityFlags_s fl
#define MAX_GENTITIES
Definition: Game_local.h:83
type * GetEntity(void) const
Definition: Game_local.h:695
#define MAX_WORLD_SIZE
Definition: Lib.h:100
#define const
Definition: getdate.c:251
idRandom random
Definition: Game_local.h:291
bool IsType(const idTypeInfo &c) const
Definition: Class.h:337
idEntityPtr< idActor > enemy
Definition: AI.h:406
Definition: Vector.h:316
virtual void SetLinearVelocity(const idVec3 &newLinearVelocity, int id=0)=0
idVec3 lastVisibleEnemyPos
Definition: AI.h:407
idCVar ai_debugTrajectory("ai_debugTrajectory","0", CVAR_GAME|CVAR_BOOL,"draws trajectory tests for monsters")
float GetRadius(void) const
Definition: Bounds.cpp:39
int i
Definition: process.py:33
GLintptr offset
Definition: glext.h:3113
#define EVENT(event, function)
Definition: Class.h:53
idMat3 viewAxis
Definition: Actor.h:117
int EntitiesTouchingBounds(const idBounds &bounds, int contentMask, idEntity **entityList, int maxCount) const
Definition: Clip.cpp:833
virtual const idBounds & GetBounds(int id=-1) const =0
int RandomInt(void)
Definition: Random.h:70
idPhysics * GetPhysics(void) const
Definition: Entity.cpp:2607
GLuint index
Definition: glext.h:3476
#define NULL
Definition: Lib.h:88
idGameLocal gameLocal
Definition: Game_local.cpp:64
#define END_CLASS
Definition: Class.h:54
idBounds Expand(const float d) const
Definition: Bounds.h:317
virtual idClipModel * GetClipModel(int id=0) const =0
bool LineIntersection(const idVec3 &start, const idVec3 &end) const
Definition: Bounds.cpp:135
idVec3 lastVisibleEnemyEyeOffset
Definition: AI.h:408
static bool PredictTrajectory(const idVec3 &firePos, const idVec3 &target, float projectileSpeed, const idVec3 &projGravity, const idClipModel *clip, int clipmask, float max_height, const idEntity *ignore, const idEntity *targetEntity, int drawtime, idVec3 &aimDir)
idPhysics_Monster physicsObj
Definition: AI.h:315
bool GetBool(void) const
Definition: CVarSystem.h:142
tuple f
Definition: idal.py:89
#define CLASS_DECLARATION(nameofsuperclass, nameofclass)
Definition: Class.h:110
static void ReturnEntity(idEntity *ent)
CLASS_PROTOTYPE(idAI_Vagary)
const idMat3 & GetGravityAxis(void) const
void Event_ThrowObjectAtEnemy(idEntity *ent, float speed)
Definition: AI_Vagary.cpp:126
const idEventDef AI_Vagary_ChooseObjectToThrow("vagary_ChooseObjectToThrow","vvfff", 'e')
void EnableDamage(bool enable, float duration)
Definition: Moveable.cpp:416
const idEventDef AI_Vagary_ThrowObjectAtEnemy("vagary_ThrowObjectAtEnemy","ef")
virtual const idVec3 & GetGravity(void) const =0
Definition: AI.h:253
void Event_ChooseObjectToThrow(const idVec3 &mins, const idVec3 &maxs, float speed, float minDist, float offset)
Definition: AI_Vagary.cpp:63