/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Stefan Lienhard co-programmer: ... */ #include "bomb.h" #include "glincl.h" #include "state.h" #include "model.h" #include "primitive_model.h" #include "particles/dot_emitter.h" #include "particles/particle_system.h" #include "debug.h" #include "class_id_DEPRECATED.h" ObjectListDefinitionID(Bomb, CL_BOMB); CREATE_FAST_FACTORY_STATIC(Bomb); /** * constructs and loads a Bomb from a XML-element * @param root the XML-element to load from */ Bomb::Bomb(const TiXmlElement* root) { this->init(); if (root != NULL) this->loadParams(root); this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0); this->setMinEnergy(1); this->setHealthMax(10); this->lifeSpan = 15; this->emitter = new DotEmitter(100, 5, M_2_PI); this->emitter->setParent(this); this->emitter->setSpread(M_PI, M_PI); } /** * standard deconstructor */ Bomb::~Bomb () { delete this->detonationSphere; delete this->detonationMaterial; } /** * initializes the Bomb * @todo change this to what you wish */ void Bomb::init() { this->registerObject(this, Bomb::_objectList); this->detonationSphere = new PrimitiveModel(PRIM_SPHERE); this->detonationMaterial = new Material(); this->detonationMaterial->setDiffuse(1, 0, 0); this->loadExplosionSound("sound/explosions/explosion_7_far.wav"); // this->detonationMaterial->setTransparency(.1); /** * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition) */ } /** * loads a Bomb from a XML-element * @param root the XML-element to load from * @todo make the class Loadable */ void Bomb::loadParams(const TiXmlElement* root) { // all the clases this Entity is directly derived from must be called in this way, to load all settings. Projectile::loadParams(root); /** * @todo: make the class Loadable */ } /** * advances the Bomb about time seconds * @param time the Time to step */ void Bomb::tick(float time) { this->lifeCycle += time/this->lifeSpan; if( this->lifeCycle >= 1.0) { PRINTF(5)("FINALIZE==========================\n"); PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); PRINTF(5)("FINALIZE===========================\n"); this->deactivate(); } else if (this->lifeCycle > 0.9f) this->detonate ((this->lifeCycle-.89) *1000.0); else { Vector v = this->velocity * (time); this->shiftCoor(v); } } /** * draws this worldEntity */ void Bomb::draw () const { glMatrixMode(GL_MODELVIEW); glPushMatrix(); float matrix[4][4]; /* translate */ glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); /* rotate */ this->getAbsDir().matrix(matrix); glMultMatrixf((float*)matrix); if (this->lifeCycle < .9) { if (this->getModel() != NULL) this->getModel()->draw(); } else { glScalef((this->lifeCycle-.89) *1000.0, (this->lifeCycle-.89) *1000.0, (this->lifeCycle-.89) *1000.0); this->detonationMaterial->select(); this->detonationSphere->draw(); } glPopMatrix(); } /** * * */ void Bomb::collidesWith (WorldEntity* entity, const Vector& location) { if (this->lifeCycle < .9f && entity->isA(CL_NPC)) this->lifeCycle = 0.9f; } void Bomb::activate() { } void Bomb::deactivate() { this->toList(OM_DEAD); this->lifeCycle = 0.0f; Bomb::fastFactory->kill(this); } void Bomb::detonate(float size) { /// FIXME /* ObjectManager::EntityList detonationList; ObjectManager::distanceFromObject(detonationList, *this, size, NPC::objectList()); while( !detonationList.empty() ) { detonationList.front()->collidesWith(this, Vector(0,0,0)); detonationList.pop_front(); }*/ }