home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / ChaingunShot.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-17  |  3.4 KB  |  122 lines

  1. #include "ChaingunShot.h"
  2.  
  3. #include "Game.h"
  4. #include "Network.h"
  5. #include "WeaponEffectsParticleClusters.h"
  6. #include "random.h"
  7.  
  8. ChaingunShot::ChaingunShot(int clientId, int weaponId): Shot(clientId, weaponId, 10000){
  9.     this->type = GAME_WEAPON_CHAINGUN;
  10.     this->moveSpeed = 5.0f;
  11.     this->inflictedDamage = 2;
  12. }
  13.  
  14. ChaingunShot::~ChaingunShot(){
  15. }
  16.  
  17. void ChaingunShot::leaveMuzzle(){
  18.     if( Renderer::info.var.useDynamicLighting ){
  19.         vec3_t col;
  20.         vectorInit3d(0.6f, 0.5f, 0.1f, col);
  21.         Renderer::particleSystem.linkParticleCluster( new DynamicLightParticleCluster(pos, col, 1.0f, 20) );
  22.     }
  23.  
  24.     Renderer::particleSystem.linkParticleCluster( new ChaingunMuzzleFlashParticleCluster(this) );
  25.  
  26.  
  27.     if( Sound::info.var.enabled && Sound::info.var.playSamples ){
  28.         Sound::playEffect(pos, Game::preloadedGameMedia.chaingunFireSound, 0);
  29.     }
  30.  
  31.  
  32.     // push
  33.     if( Network::server->clients[clientId] != NULL && Network::server->clients[clientId]->vehicle != NULL ){
  34.         vec3_t pushForce;
  35.         vectorScale3d(-100.0f , this->dir, pushForce);
  36.         Network::server->clients[clientId]->vehicle->physicsInfo.addPushForce(pushForce, 40);
  37.     }
  38.  
  39.     Shot::leaveMuzzle(); // animation and some other stuff
  40. }
  41.  
  42. void ChaingunShot::move(float deltaT){
  43.     unsigned int i;
  44.     trace_t trace;
  45.     trace.ignoreFlags = 0 | COLLISION_FLAG_BACKFACES | COLLISION_FLAG_SHOOT_THROUGH;
  46.  
  47.     traceRay(pos, dir, &trace);
  48.  
  49.     for(i=0;i<trace.hits.size();i++){
  50.         if( trace.hits[i].face != NULL ){    // hit a face of the arena
  51.             hitFace( trace.hits[i].face, trace.hits[i].pos );
  52.             break;
  53.         }
  54.         if( trace.hits[i].vehicle != NULL ){    // hit a vehicle
  55.             if( trace.hits[i].vehicle == Network::server->clients[clientId]->vehicle )
  56.                 continue;
  57.             
  58.             hitVehicle( trace.hits[i].vehicle, trace.hits[i].pos);
  59.             break;
  60.         }
  61.     }
  62.  
  63.  
  64.     lifetimeMillis = 0;
  65. }
  66.  
  67. void ChaingunShot::hitFace(Face* face, vec3_t hp){
  68.     vec3_t p;
  69.     vectorMA3d(hp, 0.05f, face->normal, p);
  70.     Renderer::particleSystem.linkParticleCluster( new ChaingunImpactParticleCluster(this, p) );
  71.  
  72.     if( Renderer::info.var.renderParticleEffects >= 2 && frand() < 0.2f && vectorPointDistance3d(hp, pos) > 2.0f ){
  73.         vec3_t sp;
  74.         vectorMA3d(pos, 0.5f, dir, sp);
  75.         Renderer::particleSystem.linkParticleCluster( new ChaingunRicochetParticleCluster(sp, p) );
  76.     }
  77.  
  78.     if( Sound::info.var.enabled && Sound::info.var.playSamples ){
  79.         int r = (int)(frand()*6);
  80.         if( r < 3 ){
  81.             Mix_Chunk* sound = Game::preloadedGameMedia.chaingunImpactSounds[face->material->surfaceType][r];
  82.             if (sound != NULL ){
  83.                 Sound::playEffect(hp, sound, 0);
  84.             }
  85.         }
  86.     }
  87.  
  88.  
  89.     if( Renderer::info.var.renderParticleEffects >= 3 ){
  90.         Renderer::particleSystem.linkParticleCluster( new ChaingunMarkParticleCluster(hp, face) );
  91.     }
  92.  
  93.     Shot::hitFace(face, hp);
  94. }
  95.  
  96. void ChaingunShot::hitVehicle(Vehicle* vehicle, vec3_t hp){
  97.     Renderer::particleSystem.linkParticleCluster( new ChaingunImpactParticleCluster(this, hp) );
  98.  
  99.     if( frand() < 0.2f ){
  100.         Renderer::particleSystem.linkParticleCluster( new ChaingunRicochetParticleCluster(pos, hp) );
  101.     }
  102.  
  103.     if( Sound::info.var.enabled && Sound::info.var.playSamples ){
  104.         Mix_Chunk* sound = Game::preloadedGameMedia.chaingunImpactSounds[MATERIAL_SURFACE_TYPE_METAL][0];
  105.         if (sound != NULL ){
  106.             Sound::playEffect(hp, sound, 0);
  107.         }
  108.     }
  109.  
  110.     // push
  111.     vec3_t pushForce;
  112.     vectorScale3d(100.0f , this->dir, pushForce);
  113.     vehicle->physicsInfo.addPushForce(pushForce, 40);
  114.  
  115.     Shot::hitVehicle(vehicle, hp);
  116. }
  117.  
  118. void ChaingunShot::render(){
  119. }
  120.  
  121.  
  122.