Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10694 in orxonox.OLD


Ignore:
Timestamp:
Jun 14, 2007, 3:50:14 PM (17 years ago)
Author:
retolu
Message:

adm working

Location:
branches/adm/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/adm/src/story_entities/game_world.cc

    r10618 r10694  
    695695    AtmosphericEngine::getInstance()->draw();
    696696
     697    /* draw bounding boxes */
    697698    if( unlikely( this->showBV))
    698699    {
  • branches/adm/src/world_entities/effects/explosion.h

    r9869 r10694  
    2727    virtual void tick (float time);
    2828
    29   private:
     29    void setLifeTime( float lifeTime ){ this->lifeTime = lifeTime; }
     30
     31  protected:
    3032    static FastFactory*        fastFactory;
    3133
  • branches/adm/src/world_entities/npcs/adm_turret.cc

    r10690 r10694  
    7676                LoadParamXML(root, "Sensor", this, AdmTurret, addSensor)
    7777                        .describe("add sensor to ADM");
     78                LoadParamXML(root, "Weapon", this, AdmTurret, addWeapon)
     79                        .describe("add weapon to ADM");
    7880
    7981        }
     
    137139        this->range = 400;
    138140        this->isCeil = false;
    139         this->bFire = false;
    140141        this->playerVisible = false;
    141142
     
    146147{
    147148  WorldEntity::tick(dt);
    148  
     149  this->weapon->fire(false);
    149150  this->updatePlayerVisible();
    150151
     
    158159  {
    159160    this->moveTowards( ds,  dt);
    160 
    161   //if target within +/- 2.5 degrees of aim -> fire
    162   Vector dv1 = ds;
    163   dv1.normalize();
    164   Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0));
    165   dv2.normalize();
    166   float angle = dv1.dot(dv2);
    167   if (angle > 0.999)
    168         {
    169         this->fire();
    170         }
     161   
     162    //if target within +/- 2.5 degrees of aim -> fire
     163    Vector dv1 = ds;
     164    dv1.normalize();
     165    Vector dv2 = this->cannons->getAbsDir().apply( Vector(-1, 0, 0));
     166    dv2.normalize();
     167    float angle = dv1.dot(dv2);
     168    if (angle > 0.999)
     169          {
     170     this->weapon->fire(true);
     171          }
    171172  }
    172173  else
     
    178179  WorldEntity::draw();
    179180
    180 
     181#if 0
    181182  glMatrixMode(GL_MODELVIEW);
    182183  glPushMatrix();
     
    212213  glPopAttrib();
    213214  glPopMatrix();
    214  
     215#endif
    215216}
    216217
     
    227228}
    228229
    229 void AdmTurret::fire()
    230 {
    231 }
    232 
    233230void AdmTurret::addCannons( const TiXmlElement * root )
    234231{
    235         this->cannons = new WorldEntity();
     232  this->cannons = new WorldEntity();
    236233        this->cannons->setParent(this);
    237234        this->cannons->loadParams( root );
     
    242239        this->cannons->toList( getOMListNumber() );
    243240
     241
     242}
     243
     244void AdmTurret::addWeapon( const TiXmlElement * root )
     245{
    244246        this->weapon = new BspWeapon();
     247        this->weapon->setParent( this->cannons );
    245248        this->weapon->loadParams(root);
    246         this->weapon->setParent( this->cannons );
    247249        this->weapon->toList( getOMListNumber() );
    248         this->weapon->setAbsCoor( this->cannons->getAbsCoor() );
     250        //this->weapon->setAbsCoor( this->cannons->getAbsCoor() );
    249251        this->weapon->setAbsDir( this->weapon->getAbsDir() * Quaternion( PI, Vector(0, 1, 0) ) );
    250252}
     
    252254void AdmTurret::addSensor( const TiXmlElement * root )
    253255{
    254         this->sensor = new WorldEntity();
     256  this->sensor = new WorldEntity();
    255257        this->sensor->setParent(this);
    256258        this->sensor->loadParams( root );
     
    285287   if ( isCeil )
    286288   {
    287      printf( "ceil\n" );
    288289     baseRot = Quaternion( PI, Vector( 1, 0, 0 ) );
    289290   }
  • branches/adm/src/world_entities/npcs/adm_turret.h

    r10689 r10694  
    3737                   WorldEntity* sensor;
    3838                   WorldEntity* myTarget;
    39                    void fire();
    4039
    4140                   void addCannons(const TiXmlElement* root);
    4241                   void addSensor(const TiXmlElement* root);
     42                   void addWeapon(const TiXmlElement* root);
    4343
    4444                   void moveTowards( Vector targetDir, float dt );
     
    5353                   void setType( const std::string& type );
    5454                   
    55                    bool bFire;
    5655                   bool playerVisible;
    5756                   void updatePlayerVisible();
     
    6160
    6261#endif
     62
  • branches/adm/src/world_entities/weapons/bsp_weapon.cc

    r10690 r10694  
    2121
    2222#include "environments/bsp_entity.h"
     23#include "loading/fast_factory.h"
    2324
    2425ObjectListDefinition(BspWeapon);
    2526CREATE_FACTORY(BspWeapon);
     27
     28ObjectListDefinition(MuzzleFlash);
    2629
    2730/**
     
    7376                LOAD_PARAM_START_CYCLE(root, element);
    7477                {
    75                         LoadParam_CYCLE(element, "addPoint", this, BspWeapon, addPoint)
    76                         .describe("Adds a new Point for Gunfire");
     78                        if (root != 0){
     79                                LoadParam_CYCLE(element, "addPoint", this, BspWeapon, addPoint)
     80                                .describe("Adds a new Point for Gunfire");
     81                        }
    7782                }
    7883                LOAD_PARAM_END_CYCLE(element);
     
    8287void BspWeapon::addPoint(float x, float y, float z)
    8388{
    84         if (element == 1 ){
    85                 gunFire1->setRelCoor(Vector(x,y,z));
    86                 element++;
    87         }
    88         if (element == 2 ){
    89                 gunFire2->setRelCoor(Vector(x,y,z));
    90         }
     89  gunFire.push_back( new MuzzleFlash() );
     90        gunFire.back()->setParent( this->getParent() );
     91        gunFire.back()->setRelCoor(x, y, z);
    9192}
    9293
     
    107108                        bRate = 0;
    108109        }
     110
    109111}
    110112
     
    112114{
    113115        bRate = 0;
    114         bFire = true;
     116        bFire = false;
    115117        range = 1000;
    116118        damage = 10;
    117119        fireRate = 0.5;
    118120        alwaysHits = true;
    119         element=1;
    120121
    121122        this->registerObject(this, BspWeapon::_objectList);
     
    123124        this->aimingSystem->setParent( this );
    124125        this->aimingSystem->toList(OM_GROUP_00);
     126       
    125127}
    126128
    127129void BspWeapon::shoot()
    128130{
    129         gunFire.explode(gunFire1,Vector(2,2,2));
    130         gunFire.explode(gunFire2,Vector(2,2,2));
     131        //gunFirExpl.explode(gunFire1,Vector(2,2,2));
     132        //gunFirExpl.explode(gunFire2,Vector(2,2,2));
     133
     134  for ( std::list<MuzzleFlash*>::iterator it = gunFire.begin(); it!=gunFire.end(); it++)
     135        {
     136    (*it)->explode( 0.2 );
     137        }
     138
    131139        std::list<WorldEntity*>::iterator entityIterator;
    132140        // for all bsp managers check all entities
     
    151159
    152160        if ( target == NULL )
    153                 printf("NOTING HIT\n");
     161                printf("NO TARGET\n");
    154162        else
    155163        {
    156                 printf( "HIT %s\n", target->getClassName().c_str() );
    157 
    158164                if (!alwaysHits){
    159165                        float r = rand();
     
    161167                        float res = (target->getAbsCoor() - this->getAbsCoor()).len();
    162168                        float p = 1 - res*res/range/range;
    163                         if (r < p )
     169                        if (r < p ){
    164170                                hit = true;
     171                                printf( "HIT %s\n", target->getClassName().c_str() );
     172                        }
     173                        else
     174                                printf( "MISHIT %s\n", target->getClassName().c_str() );
     175                       
    165176                }
    166177                else hit = true;
     
    169180        if ( !hit )
    170181        {
    171                 Vector explosionPos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 1, 0, 0 ) )*shortestDist;
     182                //Vector explosionPos = this->getAbsCoor() + this->getAbsDir().apply( Vector( 1, 0, 0 ) )*shortestDist;
    172183
    173184                //TODO create explosion at explosionPos
    174185        }
    175 
     186       
    176187       
    177188}
     
    181192  WorldEntity::draw();
    182193
    183 
     194  for ( std::list<MuzzleFlash*>::const_iterator it = gunFire.begin(); it!=gunFire.end(); it++)
     195  {
     196    (*it)->draw();
     197  }
     198#if 0
    184199  glMatrixMode(GL_MODELVIEW);
    185200  glPushMatrix();
     
    207222  glPopAttrib();
    208223  glPopMatrix();
    209  
    210 }
     224#endif
     225}
     226
     227void MuzzleFlash::draw( ) const
     228{
     229  if (explosionParticles) explosionParticles->draw();
     230}
     231
     232void MuzzleFlash::activate()
     233{
     234        if (unlikely(explosionParticles == NULL))
     235        {
     236                explosionParticles = new SpriteParticles(5000);
     237                explosionParticles->setName("MuzzleFlashExplosionParticles");
     238                explosionParticles->setMaterialTexture("textures/radial-trans-noise.png");
     239                explosionParticles->setLifeSpan(0.1, 0);
     240                explosionParticles->setRadius(0.0, 8);
     241                explosionParticles->setRadius(.5, 6.0);
     242                explosionParticles->setRadius(1.0, 2.0);
     243                explosionParticles->setColor(0.0, 1,0.7,0,1);
     244                explosionParticles->setColor(0.4, 0.8,.5,0,1);
     245                explosionParticles->setColor(0.8, 0.5,0,0,.8);
     246                explosionParticles->setColor(1.0, 0,0,0,.6);
     247    explosionParticles->toList(OM_DEAD_TICK);
     248  }
     249                       
     250        this->emitter->setSystem(explosionParticles);
     251        this->emitter->updateNode(.01);
     252        this->emitter->updateNode(.01);
     253        this->toList(OM_DEAD_TICK);
     254        this->lifeCycle = 0.0;
     255}
     256
     257void MuzzleFlash::explode(float lifetime)
     258{
     259        MuzzleFlash* explosion = this;
     260        //explosion->setAbsCoor(this->getAbsCoor());
     261        explosion->emitter->setSize(1, 1, 1);
     262        explosion->activate();
     263        explosion->lifeTime = lifetime;
     264}
     265
     266MuzzleFlash::MuzzleFlash ()
     267{
     268  this->explosionParticles = NULL;
     269  this->registerObject(this, MuzzleFlash::_objectList);
     270  this->toList(OM_DEAD_TICK);
     271
     272  this->emitter = new BoxEmitter(Vector(10,10,10), 200, 45, M_2_PI);
     273  this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     274  this->emitter->setParent(this);
     275  this->emitter->setSpread(M_PI, M_PI);
     276
     277  this->lifeCycle = 0.0f;
     278  this->lifeTime = .5f;
     279
     280}
     281
     282
     283/**
     284 *  standard deconstructor
     285*/
     286MuzzleFlash::~MuzzleFlash ()
     287{
     288  delete this->emitter;
     289
     290  /* this is normaly done by World.cc by deleting the ParticleEngine */
     291  if (explosionParticles != NULL)
     292  {
     293    delete explosionParticles;
     294    MuzzleFlash::explosionParticles = NULL;
     295  }
     296}
     297
     298void MuzzleFlash::deactivate()
     299{
     300  this->emitter->setSystem(NULL);
     301  this->toList(OM_DEAD);
     302}
     303
     304
     305/**
     306 *  signal tick, time dependent things will be handled here
     307 * @param time since last tick
     308*/
     309void MuzzleFlash::tick (float dt)
     310{
     311  this->lifeCycle += dt;
     312  if(this->lifeTime < this->lifeCycle)
     313    this->deactivate();
     314}
     315
     316
     317
  • branches/adm/src/world_entities/weapons/bsp_weapon.h

    r10690 r10694  
    1010#include "aiming_system.h"
    1111#include "effects/explosion.h"
     12
     13#include <list>
     14
     15#include "particles/box_emitter.h"
     16#include "particles/sprite_particles.h"
     17
     18class MuzzleFlash : public WorldEntity
     19{
     20  ObjectListDeclaration(MuzzleFlash);
     21  public:
     22    void explode (float lifetime);
     23
     24    MuzzleFlash ();
     25    virtual ~MuzzleFlash ();
     26
     27    virtual void activate();
     28    virtual void deactivate();
     29
     30    virtual void tick (float time);
     31    virtual void draw() const;
     32
     33    void setLifeTime( float lifeTime ){ this->lifeTime = lifeTime; }
     34   
     35    void drawParticles(){ if (explosionParticles) explosionParticles->draw(); }
     36
     37  protected:
     38    //static FastFactory*        fastFactory;
     39
     40    float                      lifeTime;
     41    float                      lifeCycle;
     42
     43    SpriteParticles*    explosionParticles;
     44    BoxEmitter*                emitter;
     45
     46};
     47
    1248
    1349class BspWeapon : public WorldEntity
     
    3874                void setAlwaysHits( bool r ){ this->alwaysHits = r; }
    3975                void addPoint(float x, float y, float z);
    40                 PNode* gunFire1;
    41                 PNode* gunFire2;
     76               
     77    std::list<MuzzleFlash*> gunFire;
    4278
    4379                float bRate;
    4480                bool bFire;
    45                 int element;
    46 
    47                 Explosion gunFire;
    4881
    4982                AimingSystem* aimingSystem;
Note: See TracChangeset for help on using the changeset viewer.