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

  1. #include "ArenaEffectsParticleClusters.h"
  2.  
  3. #include "Renderer.h"
  4. #include "Network.h"
  5. #include "Vehicle.h"
  6. #include "intersection.h"
  7. #include "Game.h"
  8.  
  9. //Model* SupplyPadEffectParticleCluster::model = NULL;
  10.  
  11.  
  12. SupplyPadEffectParticleCluster::SupplyPadEffectParticleCluster(vec3_t pos):ParticleCluster(86400000) {    // 1 day lifetime
  13.     importance = 1;
  14.     vectorCopy3d(pos, this->pos);
  15.     lastImpulseMillis = 0;
  16.     model = Game::preloadedGameMedia.supplyPadCylindersModel;
  17.     activeSound = Game::preloadedGameMedia.supplyPadActiveSound;
  18.     impulseSound = Game::preloadedGameMedia.supplyPadImpulseSound;
  19.  
  20.     boundingSphereRadius = 5.0f;
  21. }
  22.  
  23. SupplyPadEffectParticleCluster::~SupplyPadEffectParticleCluster(){
  24. //    printf("dest\n");
  25. }
  26.  
  27. void SupplyPadEffectParticleCluster::move(){
  28.     unsigned long currentMillis = SDL_GetTicks();
  29.     bool dlpcAdded = false;
  30.  
  31.     if( lastImpulseMillis + 500 < currentMillis ){
  32.         for(int i=0;i<GAME_MAX_VEHICLES;i++){
  33.             if( Game::vehicles[i] == NULL )
  34.                 continue;
  35.  
  36.             vec3_t relPos;
  37.             vectorSub3d(Game::vehicles[i]->pos, pos, relPos);
  38.             relPos[1] -= 1.3f;
  39.             if( pointIntersectsAABB(relPos, Game::vehicles[i]->moveAABB.min, Game::vehicles[i]->moveAABB.max) ){
  40.                 Vehicle* v = Game::vehicles[i];
  41.                 // add energy & armor
  42.                 v->energy += 10;
  43.                 v->armor += 10;
  44.                 if( v->energy > v->maxEnergy )
  45.                     v->energy = v->maxEnergy;
  46.                 if( v->armor > v->maxArmor )
  47.                     v->armor = v->maxArmor;
  48.  
  49.                 for(int k=0;k<4;k++){
  50.                     if( v->weapons[k] == NULL )
  51.                         continue;
  52.  
  53.                     if( v->weapons[k]->maxEnergy > 0 ){
  54.                         v->weapons[k]->energy += 10.0f;
  55.                         if( v->weapons[k]->energy > v->weapons[k]->maxEnergy ){
  56.                             v->weapons[k]->energy = v->weapons[k]->maxEnergy;
  57.                         }
  58.                     }
  59.                     if( v->weapons[k]->maxAmmo > 0 ){
  60.                         v->weapons[k]->ammo += (int)( 0.1f * v->weapons[k]->maxAmmo );
  61.                         if( v->weapons[k]->ammo > v->weapons[k]->maxAmmo ){
  62.                             v->weapons[k]->ammo = v->weapons[k]->maxAmmo;
  63.                         }
  64.                     }
  65.                 }
  66.  
  67.                 // play sound
  68.                 if( Sound::info.var.enabled && Sound::info.var.playSamples ){
  69.                     Sound::playEffect(pos, impulseSound);
  70.                 }
  71.  
  72.                 // add light impulse if it's not there already 
  73.                 if( !dlpcAdded && Renderer::info.var.useDynamicLighting ){
  74.                     vec3_t col, lightPos;
  75.                     vectorInit3d(0.3f, 0.5f, 0.8f, col);
  76.                     vectorInit3d(pos[0], pos[1]+1.0f, pos[2], lightPos);
  77.                     Renderer::particleSystem.linkParticleCluster(new DynamicLightParticleCluster(lightPos, col, 4.0f, 100));
  78.  
  79.                     dlpcAdded = true;
  80.                 }
  81.             }
  82.  
  83.         }
  84.  
  85.         lastImpulseMillis = currentMillis;
  86.     }
  87.  
  88.     lifetimeMillis = currentMillis + 60000;    // for one more hour!
  89. //    printf("move\n");
  90. }
  91.  
  92. void SupplyPadEffectParticleCluster::render(){
  93.     for(int i=0;i<GAME_MAX_VEHICLES;i++){
  94.         if( Game::vehicles[i] == NULL )
  95.             continue;
  96.  
  97.         vec3_t relPos;
  98.         vectorSub3d(Game::vehicles[i]->pos, pos, relPos);
  99.         relPos[1] -= 1.3f;
  100.         if( pointIntersectsAABB(relPos, Game::vehicles[i]->moveAABB.min, Game::vehicles[i]->moveAABB.max) ){
  101.             glPushMatrix();
  102.             glTranslatef(pos[0], pos[1], pos[2]);
  103.             Renderer::renderModel(model);
  104.             glPopMatrix();
  105.  
  106.             break;    // only one effect, no matter how many are standing on pad
  107.         }
  108.  
  109.  
  110.     }
  111. //    printf("render\n");
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.