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

  1. #include "RocketlauncherShot.h"
  2.  
  3. #include "Game.h"
  4. #include "Network.h"
  5. #include "WeaponEffectsParticleClusters.h"
  6. #include "intersection.h"
  7.  
  8. RocketlauncherShot::RocketlauncherShot(int clientId, int weaponId): Shot(clientId, weaponId, 10000){
  9.     this->type = GAME_WEAPON_ROCKETLAUNCHER;
  10.     this->moveSpeed = 25.0f;
  11.     this->inflictedDamage = 45;
  12.  
  13.     this->model = Game::preloadedGameMedia.rocketlauncherShotModel;
  14.  
  15.     this->nextSmokePuffMillis = 0;
  16. }
  17.  
  18. RocketlauncherShot::~RocketlauncherShot(){
  19. }
  20.  
  21. void RocketlauncherShot::leaveMuzzle(){
  22.     if( Renderer::info.var.useDynamicLighting ){
  23.         vec3_t col;
  24.         vectorInit3d(0.7f, 0.4f, 0.2f, col);
  25.         Renderer::particleSystem.linkParticleCluster( new DynamicLightParticleCluster(this, col, 5.0f, 10000) );
  26.     }
  27.  
  28.     if( Sound::info.var.enabled && Sound::info.var.playSamples ){
  29.         Sound::playEffect(pos, Game::preloadedGameMedia.rocketlauncherFireSound, 0);
  30.     }
  31.  
  32.     // push
  33.     if( Network::server->clients[clientId] != NULL && Network::server->clients[clientId]->vehicle != NULL ){
  34.         vec3_t pushForce;
  35.         vectorScale3d(-1000.0f , this->dir, pushForce);
  36.         Network::server->clients[clientId]->vehicle->physicsInfo.addPushForce(pushForce, 100);
  37.     }
  38.  
  39.     Shot::leaveMuzzle(); // animation and some other stuff
  40. }
  41.  
  42. void RocketlauncherShot::move(float deltaT){
  43.     vec3_t newPos;
  44.     vectorMA3d(pos, deltaT*moveSpeed, dir, newPos);
  45.  
  46.     unsigned int i;
  47.     trace_t trace;
  48.     trace.ignoreFlags = 0 | COLLISION_FLAG_BACKFACES | COLLISION_FLAG_SHOOT_THROUGH;
  49.  
  50.     traceLinesegment(pos, newPos, &trace);
  51.  
  52.     for(i=0;i<trace.hits.size();i++){
  53.         if( trace.hits[i].face != NULL ){    // hit a face of the arena
  54.             hitFace( trace.hits[i].face, trace.hits[i].pos );
  55.             break;
  56.         }
  57.         if( trace.hits[i].vehicle != NULL ){    // hit a vehicle
  58.             if( trace.hits[i].vehicle == Network::server->clients[clientId]->vehicle )
  59.                 continue;
  60.             
  61.             hitVehicle( trace.hits[i].vehicle, trace.hits[i].pos );
  62.             break;
  63.         }
  64.     }
  65.  
  66.     if( Renderer::info.var.renderParticleEffects >= 2 && SDL_GetTicks() > nextSmokePuffMillis ){
  67.         Renderer::particleSystem.linkParticleCluster( new SmallSmokePuffParticleCluster(pos) );
  68.         nextSmokePuffMillis = SDL_GetTicks() + 30;
  69.     }
  70.  
  71.  
  72.     vectorCopy3d(newPos, pos);
  73.  
  74.     vectorRotateAroundNormal3d(up, dir, deltaT*10.0f, up);
  75.     vectorRotateAroundNormal3d(left, dir, deltaT*10.0f, left);
  76.  
  77. }
  78.  
  79. void RocketlauncherShot::hitFace(Face* face, vec3_t hp){
  80.     vec3_t p;
  81.     vectorMA3d(hp, 0.5f, face->normal, p);
  82.     Renderer::particleSystem.linkParticleCluster( new MediumExplosionParticleCluster(p) );
  83.  
  84.     doSplashDamage(hp);
  85.  
  86.     Shot::hitFace(face, hp);
  87. }
  88.  
  89. void RocketlauncherShot::hitVehicle(Vehicle* vehicle, vec3_t hp){
  90.  
  91.     Renderer::particleSystem.linkParticleCluster( new MediumExplosionParticleCluster(hp) );
  92.  
  93.     if( Sound::info.var.enabled && Sound::info.var.playSamples ){
  94.         Sound::playEffect(hp, Game::preloadedGameMedia.rocketlauncherImpactSound, 0);
  95.     }
  96.  
  97.     doSplashDamage(hp);
  98.  
  99.     //Shot::hitVehicle(vehicle, hp);
  100.     this->lifetimeMillis = 0;
  101. }
  102.  
  103. void RocketlauncherShot::doSplashDamage(vec3_t hp){
  104.     float r = 3.0f;
  105.     vec3_t min, max;
  106.     vectorInit3d(hp[0]-r, hp[1]-r, hp[2]-r, min);
  107.     vectorInit3d(hp[0]+r, hp[1]+r, hp[2]+r, max);
  108.  
  109.     for(int i=0;i<GAME_MAX_VEHICLES;i++){
  110.         if( Game::vehicles[i] == NULL )
  111.             continue;
  112.  
  113.         Vehicle* v = Game::vehicles[i];
  114.  
  115.         vec3_t absMin, absMax;
  116.         vectorAdd3d(v->pos, v->hitAABB.min, absMin);
  117.         vectorAdd3d(v->pos, v->hitAABB.max, absMax);
  118.  
  119.         if( AABBIntersectsAABB(min, max, absMin, absMax ) ){
  120.             vec3_t tmp;
  121.             vectorSub3d(v->pos, hp, tmp);
  122.             float dist = vectorLength3d(tmp);
  123.  
  124.             if( dist < r ){
  125.                 // push
  126.                 vec3_t pushForce;
  127.                 vectorScale3d(3000.0f * (1.0f/dist - 1.0f/r), tmp, pushForce);
  128.                 v->physicsInfo.addPushForce(pushForce, 100);
  129.  
  130.                 // damage
  131.                 if( !Game::info.var.clientGame ){    // we are the server -> send client Hurt
  132.                     unsigned char damage = (unsigned char)( this->inflictedDamage * (1.0f - dist/r) );
  133.                     v->takeDamage(damage);
  134.                     if( v->armor > 0 ){
  135.                         Network::server->sendClientHurt(v->client->clientId, this->clientId, damage);
  136.                     }else{
  137.                         Network::server->sendClientKill(v->client->clientId, this->clientId, this->type);
  138.                         Game::killClient(v->client, Network::server->clients[this->clientId], this->type);
  139.                     }
  140.                 }
  141.             }
  142.  
  143.         }
  144.     }
  145. }
  146.  
  147.  
  148. void RocketlauncherShot::render(){
  149.     glPushMatrix();
  150.     float m[] = {    left[0], left[1], left[2], 0.0f,
  151.                     up[0], up[1], up[2], 0.0f,
  152.                     dir[0], dir[1], dir[2], 0.0f,
  153.                     pos[0], pos[1], pos[2], 1.0f
  154.                 };
  155.     glMultMatrixf(m);
  156.  
  157.     Renderer::renderModel(model);
  158.  
  159.     glPopMatrix();
  160. }
  161.