home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / vehicle / VehicleMonster.cpp < prev    next >
C/C++ Source or Header  |  2005-11-14  |  4KB  |  189 lines

  1. //----------------------------------------------------------------
  2. // Vehicle.cpp
  3. //
  4. // Copyright 2002-2004 Raven Software
  5. //----------------------------------------------------------------
  6.  
  7. #include "../../idlib/precompiled.h"
  8. #pragma hdrstop
  9.  
  10. #include "../Game_local.h"
  11. #include "VehicleMonster.h"
  12. #include "../ai/VehicleAI.h"
  13.  
  14. CLASS_DECLARATION( rvVehicle, rvVehicleMonster )
  15. END_CLASS
  16.  
  17. rvVehicleMonster::rvVehicleMonster ( void ) {
  18. }
  19.  
  20. rvVehicleMonster::~rvVehicleMonster ( void ) {
  21. }
  22.  
  23. /*
  24. ================
  25. rvVehicleMonster::Spawn
  26. ================
  27. */
  28. void rvVehicleMonster::Spawn( void ) {
  29.     idDict dict;
  30.     int count = 0;
  31.     const idKeyValue * val = NULL;
  32.  
  33.     for (;;) {
  34.         val = spawnArgs.MatchPrefix( "target", val );
  35.  
  36.         if ( !val )
  37.             break;
  38.  
  39.         dict.Set( "target" + (( count ) ? idStr( count ) : idStr( "" ) ), val->GetValue() );
  40.         count++;
  41.     }
  42.  
  43.     dict.Set( "bind", name );
  44.     dict.SetBool( "hide", true );
  45.  
  46.     driver = static_cast<rvVehicleAI *>( gameLocal.SpawnEntityDef( "ai_vehicle_driver", &dict ) );
  47.  
  48.     if ( driver ) {
  49.         driver->SetVehicle( this );
  50.         driver->GetPhysics()->SetOrigin( vec3_zero );
  51.     } else {
  52.         gameLocal.Warning( "Unable to find \"entityDef ai_vehicle_driver\"." );
  53.     }
  54. }
  55.  
  56. /*
  57. ================
  58. rvVehicleMonster::SetClipModel
  59. ================
  60. */
  61. void rvVehicleMonster::SetClipModel ( idPhysics & physicsObj ) {    
  62.     idStr            clipModelName;
  63.     idTraceModel    trm;
  64.     float            mass;
  65.  
  66.     // rebuild clipmodel
  67.     spawnArgs.GetString( "clipmodel", "", clipModelName );
  68.  
  69.     // load the trace model
  70.     if ( clipModelName.Length() ) {
  71.         if ( !collisionModelManager->TrmFromModel( gameLocal.GetMapName(), clipModelName, trm ) ) {
  72.             gameLocal.Error( "rvVehicleMonster '%s': cannot load collision model %s", name.c_str(), clipModelName.c_str() );
  73.             return;
  74.         }
  75.  
  76.         physicsObj.SetClipModel( new idClipModel( trm ), spawnArgs.GetFloat ( "density", "1" ) );
  77.     } else {
  78.         physicsObj.SetClipModel( new idClipModel( GetPhysics()->GetClipModel() ), spawnArgs.GetFloat ( "density", "1" ) );
  79.     }
  80.  
  81.     if ( spawnArgs.GetFloat ( "mass", "0", mass ) && mass > 0 )    {
  82.         physicsObj.SetMass ( mass );
  83.     }
  84. }
  85.  
  86. /*
  87. ================
  88. rvVehicleMonster::Save
  89. ================
  90. */
  91. void rvVehicleMonster::Save ( idSaveGame *savefile ) const {
  92.     driver.Save ( savefile );
  93. }
  94.  
  95. /*
  96. ================
  97. rvVehicleMonster::Restore
  98. ================
  99. */
  100. void rvVehicleMonster::Restore ( idRestoreGame *savefile ) {
  101.     driver.Restore ( savefile );
  102. }
  103.  
  104. /*
  105. ================
  106. rvVehicleMonster::Think
  107. ================
  108. */
  109. void rvVehicleMonster::Think ( void ) {
  110.     if ( !driver ) {
  111.         PostEventMS( &EV_Remove, 0 );
  112.         return;
  113.     }
  114.  
  115.     stateThread.Execute();
  116.     rvVehicle::Think();
  117. }
  118.  
  119. /*
  120. ================
  121. rvVehicleMonster::GetTargetOrigin
  122. ================
  123. */
  124. const idVec3 & rvVehicleMonster::GetTargetOrigin ( void ) {
  125.     if ( driver && driver->driver && driver->driver->pathTargetInfo.node ) {
  126.         return driver->driver->pathTargetInfo.node->GetPhysics()->GetOrigin();
  127.     }
  128.     return vec3_origin;
  129. }
  130.  
  131. /*
  132. ================
  133. rvVehicleMonster::GetVectorToTarget
  134. ================
  135. */
  136. idVec3 rvVehicleMonster::GetVectorToTarget ( void ) {
  137.     if ( driver && driver->driver && driver->driver->pathTargetInfo.node ) {
  138.         return driver->driver->pathTargetInfo.node->GetPhysics()->GetOrigin() - GetOrigin();
  139.     }
  140.     return vec3_origin;
  141. }
  142.  
  143. /*
  144. ================
  145. rvVehicleMonster::GetEnemyOrigin
  146. ================
  147. */
  148. const idVec3 & rvVehicleMonster::GetEnemyOrigin ( void ) {
  149.     if ( driver && driver->enemy.ent ) {
  150.         return driver->enemy.ent->GetPhysics()->GetOrigin();
  151.     }
  152.     return vec3_origin;
  153. }
  154.  
  155. /*
  156. ================
  157. rvVehicleMonster::GetVectorToEnemy
  158. ================
  159. */
  160. idVec3 rvVehicleMonster::GetVectorToEnemy ( void ) {
  161.     if ( driver && driver->enemy.ent ) {
  162.         //HACK: this is hideous, I'm ashamed.
  163.         return ( driver->enemy.ent->GetPhysics()->GetOrigin() + idVec3( 0, 0, 36 ) )- GetOrigin();
  164.     }
  165.     return vec3_origin;
  166. }
  167.  
  168. /*
  169. ================
  170. rvVehicleMonster::LookAtEntity
  171. ================
  172. */
  173. void rvVehicleMonster::LookAtEntity    ( idEntity *ent, float duration ) {
  174.     const idVec3 entOrigin    = ent->GetPhysics()->GetOrigin();
  175.     const idVec3 origin        = GetOrigin();
  176.     idVec3 toEnt            = entOrigin - origin;
  177.     toEnt.Normalize();
  178.     GetPhysics()->SetAxis( toEnt.ToMat3() );
  179. }
  180.  
  181. /*
  182. ================
  183. rvVehicleMonster::SkipImpulse
  184. ================
  185. */
  186. bool rvVehicleMonster::SkipImpulse( idEntity* ent, int id ) {
  187.     return false;
  188. }
  189.