Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10703 in orxonox.OLD


Ignore:
Timestamp:
Jun 15, 2007, 10:18:36 AM (17 years ago)
Author:
retolu
Message:

explosion, when deleted

Location:
branches/presentation/src/world_entities/npcs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/presentation/src/world_entities/npcs/adm_turret.cc

    r10698 r10703  
    2525
    2626#include "environments/bsp_entity.h"
     27#include "effects/explosion.h"
    2728
    2829ObjectListDefinition(AdmTurret);
     
    6869                        .describe("The filename of the World Entity, that is to be shot at")
    6970                        .defaultValues("");
    70                
    71                 LoadParam(root, "type", this, AdmTurret, setType)
    72                         .describe("floor|ceil");
    73 
     71    LoadParam(root, "type", this, AdmTurret, setType)
     72      .describe("floor|ceil");
    7473                LoadParamXML(root, "Cannons", this, AdmTurret, addCannons)
    7574                        .describe("add cannons to ADM");
     
    7877                LoadParamXML(root, "Weapon", this, AdmTurret, addWeapon)
    7978                        .describe("add weapon to ADM");
    80 
    8179        }
    8280//         this->removeNodeFlags( PNODE_ALL );
     
    134132{
    135133        this->registerObject(this, AdmTurret::_objectList);
    136        
     134        this->setHealthMax(100);
     135        this->setHealth(100);
    137136        this->bodyAngle = this->cannonAngle = 0.0f;
    138137        this->isActive = true;
     
    149148  WorldEntity::tick(dt);
    150149  if (this->weapon) this->weapon->fire(false);
    151   this->updatePlayerVisible();
    152 
    153   //rotate sensor 2PI/sec
    154   this->sensor->setAbsDir( this->sensor->getAbsDir() * Quaternion( PI*2*dt, Vector( 0, -1, 0 ) ) );
    155 
    156 
    157   Vector playerPos = this->myTarget->getAbsCoor() + Vector(0, 12, 0);
    158   Vector ds = playerPos - ( this->cannons->getAbsCoor() );
    159   if ( isActive && ds.len() <= range && playerVisible )
    160   {
    161     this->moveTowards( ds,  dt);
     150  if ( this->getHealth() <= 0 )
     151  {
     152    this->moveTowards( Vector(0, -1, 0), dt*2 );
     153  }
     154  else
     155  {
     156 
    162157   
    163     //if target within +/- 2.5 degrees of aim -> fire
    164     Vector dv1 = ds;
    165     dv1.normalize();
    166     Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0));
    167     dv2.normalize();
    168     float angle = dv1.dot(dv2);
    169     if (angle > 0.999)
     158    this->updatePlayerVisible();
     159 
     160    //rotate sensor 2PI/sec
     161    this->sensor->setAbsDir( this->sensor->getAbsDir() * Quaternion( PI*2*dt, Vector( 0, -1, 0 ) ) );
     162 
     163 
     164    Vector playerPos = this->myTarget->getAbsCoor() + Vector(0, 12, 0);
     165    Vector ds = playerPos - ( this->cannons->getAbsCoor() );
     166    if ( isActive && ds.len() <= range && playerVisible )
    170167    {
    171         if (this->weapon) this->weapon->fire(true);
     168      this->moveTowards( ds,  dt);
     169     
     170      //if target within +/- 2.5 degrees of aim -> fire
     171      Vector dv1 = ds;
     172      dv1.normalize();
     173      Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0));
     174      dv2.normalize();
     175      float angle = dv1.dot(dv2);
     176      if (angle > 0.999)
     177      {
     178        if (this->weapon) this->weapon->fire(true);
     179      }
    172180    }
    173   }
    174   else
    175     this->moveTowards( Vector(0, -1, 0), dt );
     181    else
     182    {
     183      if ( !( isActive && ds.len() <= range ) )
     184        this->moveTowards( Vector(0, -1, 0), dt );
     185    }
     186  }
    176187}
    177188
     
    237248        //this->cannons->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    238249        //this->cannons->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
    239        
     250
    240251        this->cannons->toList( getOMListNumber() );
    241 
    242 
    243252}
    244253
     
    270279    this->cannons->setParent( NullParent::getNullParent() );
    271280    this->cannons->shiftCoor( this->getAbsCoor() );
    272    
     281
    273282    this->sensor->setParent( NullParent::getNullParent() );
    274283    this->sensor->shiftCoor( this->getAbsCoor() );
    275284  }
    276  
     285
    277286  targetDir.normalize();
    278  
     287
    279288  float dAngle = dt;
    280  
     289
    281290  float bestResult = -1.0f;
    282291  Quaternion bestBodyRot;
     
    284293  float bestBodyAngle = 0.0f;
    285294  float bestCannonAngle = 0.0f;
    286  
     295
    287296   Quaternion baseRot(0, Vector(1, 0, 0));
    288297   if ( isCeil )
     
    290299     baseRot = Quaternion( PI, Vector( 1, 0, 0 ) );
    291300   }
    292  
     301
    293302  for ( int dBodyAngle = -1; dBodyAngle<2; dBodyAngle++ )
    294303  {
     
    297306      float bodyAngle = this->bodyAngle + dBodyAngle*dAngle;
    298307      float cannonAngle = this->cannonAngle + dCannonAngle*dAngle;
    299      
     308
    300309      while ( bodyAngle > 2*PI )
    301310        bodyAngle -= 2*PI;
     
    306315      while ( cannonAngle < 0 )
    307316        cannonAngle += 2*PI;
    308      
     317
    309318      Quaternion bodyRot( bodyAngle, Vector( 0, 1, 0 ) );
    310319      Quaternion cannonRot( cannonAngle, Vector( 0, 0, 1) );
    311      
     320
    312321       bodyRot = baseRot * bodyRot;
    313322       cannonRot = baseRot * cannonRot;
    314      
     323
    315324      float result = (bodyRot * cannonRot).apply( Vector( -1, 0, 0 ) ).dot( targetDir );
    316      
     325
    317326      if ( result > bestResult )
    318327      {
     
    325334    }
    326335  }
    327  
     336
    328337  this->bodyAngle = bestBodyAngle;
    329338  this->cannonAngle = bestCannonAngle;
    330  
     339
    331340  this->setAbsDir( bestBodyRot );
    332341  this->cannons->setAbsDir( bestBodyRot * bestCannonRot );
     
    338347  // for all bsp managers check all entities
    339348  Vector pos = this->cannons->getAbsCoor();
    340   Vector dir = this->myTarget->getAbsCoor() - pos;
    341 
     349  Vector dir = this->myTarget->getAbsCoor() - pos  + Vector(0, 12, 0);
    342350
    343351  this->playerVisible = true;
     
    346354       bspIterator++) {
    347355      float res = (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollisionRay( pos, dir, dir.len() + 1 );
    348      
    349       if ( res < dir.len() )
    350         this->playerVisible = false;
    351   }
    352 }
     356
     357      if ( res < dir.len() ) this->playerVisible = false;
     358  }
     359}
     360
     361void AdmTurret::destroy( WorldEntity * killer )
     362{
     363  Explosion().explode(this->cannons,Vector(1,1,1));
     364}
  • branches/presentation/src/world_entities/npcs/adm_turret.h

    r10698 r10703  
    1212#include "world_entity.h"
    1313#include "weapons/bsp_weapon.h"
     14
    1415
    1516class AdmTurret : public WorldEntity
     
    3233                   
    3334                   virtual void setTarget(const std::string& target);
     35                   
     36                   virtual void destroy(WorldEntity* killer);
    3437                   
    3538      private:
Note: See TracChangeset for help on using the changeset viewer.