Changeset 10694 in orxonox.OLD for branches/adm/src/world_entities
- Timestamp:
- Jun 14, 2007, 3:50:14 PM (18 years ago)
- Location:
- branches/adm/src/world_entities
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/adm/src/world_entities/effects/explosion.h
r9869 r10694 27 27 virtual void tick (float time); 28 28 29 private: 29 void setLifeTime( float lifeTime ){ this->lifeTime = lifeTime; } 30 31 protected: 30 32 static FastFactory* fastFactory; 31 33 -
branches/adm/src/world_entities/npcs/adm_turret.cc
r10690 r10694 76 76 LoadParamXML(root, "Sensor", this, AdmTurret, addSensor) 77 77 .describe("add sensor to ADM"); 78 LoadParamXML(root, "Weapon", this, AdmTurret, addWeapon) 79 .describe("add weapon to ADM"); 78 80 79 81 } … … 137 139 this->range = 400; 138 140 this->isCeil = false; 139 this->bFire = false;140 141 this->playerVisible = false; 141 142 … … 146 147 { 147 148 WorldEntity::tick(dt); 148 149 this->weapon->fire(false); 149 150 this->updatePlayerVisible(); 150 151 … … 158 159 { 159 160 this->moveTowards( ds, dt); 160 161 //if target within +/- 2.5 degrees of aim -> fire162 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 } 171 172 } 172 173 else … … 178 179 WorldEntity::draw(); 179 180 180 181 #if 0 181 182 glMatrixMode(GL_MODELVIEW); 182 183 glPushMatrix(); … … 212 213 glPopAttrib(); 213 214 glPopMatrix(); 214 215 #endif 215 216 } 216 217 … … 227 228 } 228 229 229 void AdmTurret::fire()230 {231 }232 233 230 void AdmTurret::addCannons( const TiXmlElement * root ) 234 231 { 235 232 this->cannons = new WorldEntity(); 236 233 this->cannons->setParent(this); 237 234 this->cannons->loadParams( root ); … … 242 239 this->cannons->toList( getOMListNumber() ); 243 240 241 242 } 243 244 void AdmTurret::addWeapon( const TiXmlElement * root ) 245 { 244 246 this->weapon = new BspWeapon(); 247 this->weapon->setParent( this->cannons ); 245 248 this->weapon->loadParams(root); 246 this->weapon->setParent( this->cannons );247 249 this->weapon->toList( getOMListNumber() ); 248 this->weapon->setAbsCoor( this->cannons->getAbsCoor() );250 //this->weapon->setAbsCoor( this->cannons->getAbsCoor() ); 249 251 this->weapon->setAbsDir( this->weapon->getAbsDir() * Quaternion( PI, Vector(0, 1, 0) ) ); 250 252 } … … 252 254 void AdmTurret::addSensor( const TiXmlElement * root ) 253 255 { 254 256 this->sensor = new WorldEntity(); 255 257 this->sensor->setParent(this); 256 258 this->sensor->loadParams( root ); … … 285 287 if ( isCeil ) 286 288 { 287 printf( "ceil\n" );288 289 baseRot = Quaternion( PI, Vector( 1, 0, 0 ) ); 289 290 } -
branches/adm/src/world_entities/npcs/adm_turret.h
r10689 r10694 37 37 WorldEntity* sensor; 38 38 WorldEntity* myTarget; 39 void fire();40 39 41 40 void addCannons(const TiXmlElement* root); 42 41 void addSensor(const TiXmlElement* root); 42 void addWeapon(const TiXmlElement* root); 43 43 44 44 void moveTowards( Vector targetDir, float dt ); … … 53 53 void setType( const std::string& type ); 54 54 55 bool bFire;56 55 bool playerVisible; 57 56 void updatePlayerVisible(); … … 61 60 62 61 #endif 62 -
branches/adm/src/world_entities/weapons/bsp_weapon.cc
r10690 r10694 21 21 22 22 #include "environments/bsp_entity.h" 23 #include "loading/fast_factory.h" 23 24 24 25 ObjectListDefinition(BspWeapon); 25 26 CREATE_FACTORY(BspWeapon); 27 28 ObjectListDefinition(MuzzleFlash); 26 29 27 30 /** … … 73 76 LOAD_PARAM_START_CYCLE(root, element); 74 77 { 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 } 77 82 } 78 83 LOAD_PARAM_END_CYCLE(element); … … 82 87 void BspWeapon::addPoint(float x, float y, float z) 83 88 { 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); 91 92 } 92 93 … … 107 108 bRate = 0; 108 109 } 110 109 111 } 110 112 … … 112 114 { 113 115 bRate = 0; 114 bFire = true;116 bFire = false; 115 117 range = 1000; 116 118 damage = 10; 117 119 fireRate = 0.5; 118 120 alwaysHits = true; 119 element=1;120 121 121 122 this->registerObject(this, BspWeapon::_objectList); … … 123 124 this->aimingSystem->setParent( this ); 124 125 this->aimingSystem->toList(OM_GROUP_00); 126 125 127 } 126 128 127 129 void BspWeapon::shoot() 128 130 { 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 131 139 std::list<WorldEntity*>::iterator entityIterator; 132 140 // for all bsp managers check all entities … … 151 159 152 160 if ( target == NULL ) 153 printf("NO TING HIT\n");161 printf("NO TARGET\n"); 154 162 else 155 163 { 156 printf( "HIT %s\n", target->getClassName().c_str() );157 158 164 if (!alwaysHits){ 159 165 float r = rand(); … … 161 167 float res = (target->getAbsCoor() - this->getAbsCoor()).len(); 162 168 float p = 1 - res*res/range/range; 163 if (r < p ) 169 if (r < p ){ 164 170 hit = true; 171 printf( "HIT %s\n", target->getClassName().c_str() ); 172 } 173 else 174 printf( "MISHIT %s\n", target->getClassName().c_str() ); 175 165 176 } 166 177 else hit = true; … … 169 180 if ( !hit ) 170 181 { 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; 172 183 173 184 //TODO create explosion at explosionPos 174 185 } 175 186 176 187 177 188 } … … 181 192 WorldEntity::draw(); 182 193 183 194 for ( std::list<MuzzleFlash*>::const_iterator it = gunFire.begin(); it!=gunFire.end(); it++) 195 { 196 (*it)->draw(); 197 } 198 #if 0 184 199 glMatrixMode(GL_MODELVIEW); 185 200 glPushMatrix(); … … 207 222 glPopAttrib(); 208 223 glPopMatrix(); 209 210 } 224 #endif 225 } 226 227 void MuzzleFlash::draw( ) const 228 { 229 if (explosionParticles) explosionParticles->draw(); 230 } 231 232 void 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 257 void 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 266 MuzzleFlash::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 */ 286 MuzzleFlash::~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 298 void 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 */ 309 void 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 10 10 #include "aiming_system.h" 11 11 #include "effects/explosion.h" 12 13 #include <list> 14 15 #include "particles/box_emitter.h" 16 #include "particles/sprite_particles.h" 17 18 class 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 12 48 13 49 class BspWeapon : public WorldEntity … … 38 74 void setAlwaysHits( bool r ){ this->alwaysHits = r; } 39 75 void addPoint(float x, float y, float z); 40 PNode* gunFire1;41 PNode* gunFire2;76 77 std::list<MuzzleFlash*> gunFire; 42 78 43 79 float bRate; 44 80 bool bFire; 45 int element;46 47 Explosion gunFire;48 81 49 82 AimingSystem* aimingSystem;
Note: See TracChangeset
for help on using the changeset viewer.