Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

adm working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.