[5590] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Stefan Lienhard |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "bomb.h" |
---|
[5603] | 17 | #include "glincl.h" |
---|
[5744] | 18 | #include "state.h" |
---|
[5603] | 19 | #include "model.h" |
---|
[5828] | 20 | #include "primitive_model.h" |
---|
| 21 | |
---|
[5603] | 22 | #include "fast_factory.h" |
---|
[5590] | 23 | |
---|
[6222] | 24 | |
---|
[5826] | 25 | #include "object_manager.h" |
---|
[5744] | 26 | |
---|
[6822] | 27 | #include "dot_emitter.h" |
---|
[5744] | 28 | #include "particle_system.h" |
---|
| 29 | |
---|
[5590] | 30 | using namespace std; |
---|
| 31 | |
---|
[5603] | 32 | CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB); |
---|
[5590] | 33 | |
---|
| 34 | /** |
---|
| 35 | * constructs and loads a Bomb from a XML-element |
---|
| 36 | * @param root the XML-element to load from |
---|
| 37 | */ |
---|
| 38 | Bomb::Bomb(const TiXmlElement* root) |
---|
| 39 | { |
---|
| 40 | this->init(); |
---|
| 41 | if (root != NULL) |
---|
| 42 | this->loadParams(root); |
---|
[5744] | 43 | |
---|
| 44 | float modelSize = 1.0; |
---|
| 45 | this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0); |
---|
| 46 | |
---|
[6431] | 47 | this->setMinEnergy(1); |
---|
[6700] | 48 | this->setHealthMax(10); |
---|
[6431] | 49 | |
---|
[5744] | 50 | this->lifeSpan = 15; |
---|
| 51 | |
---|
[6825] | 52 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
[5744] | 53 | this->emitter->setParent(this); |
---|
| 54 | this->emitter->setSpread(M_PI, M_PI); |
---|
[5590] | 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * standard deconstructor |
---|
| 60 | */ |
---|
| 61 | Bomb::~Bomb () |
---|
| 62 | { |
---|
[5828] | 63 | delete this->detonationSphere; |
---|
| 64 | delete this->detonationMaterial; |
---|
[5590] | 65 | |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * initializes the Bomb |
---|
| 71 | * @todo change this to what you wish |
---|
| 72 | */ |
---|
| 73 | void Bomb::init() |
---|
| 74 | { |
---|
[5603] | 75 | this->setClassID(CL_BOMB, "Bomb"); |
---|
[5590] | 76 | |
---|
[5828] | 77 | |
---|
| 78 | this->detonationSphere = new PrimitiveModel(PRIM_SPHERE); |
---|
| 79 | this->detonationMaterial = new Material(); |
---|
| 80 | this->detonationMaterial->setDiffuse(1, 0, 0); |
---|
[7084] | 81 | |
---|
| 82 | this->loadExplosionSound("sound/explosions/explosion_7_far.wav"); |
---|
[5828] | 83 | // this->detonationMaterial->setTransparency(.1); |
---|
[5590] | 84 | /** |
---|
| 85 | * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition) |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | * loads a Bomb from a XML-element |
---|
| 93 | * @param root the XML-element to load from |
---|
| 94 | * @todo make the class Loadable |
---|
| 95 | */ |
---|
| 96 | void Bomb::loadParams(const TiXmlElement* root) |
---|
| 97 | { |
---|
| 98 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
[6512] | 99 | Projectile::loadParams(root); |
---|
[5590] | 100 | |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * @todo: make the class Loadable |
---|
| 104 | */ |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | /** |
---|
| 109 | * advances the Bomb about time seconds |
---|
| 110 | * @param time the Time to step |
---|
| 111 | */ |
---|
[5603] | 112 | void Bomb::tick(float time) |
---|
[5590] | 113 | { |
---|
[5744] | 114 | this->lifeCycle += time/this->lifeSpan; |
---|
| 115 | if( this->lifeCycle >= 1.0) |
---|
| 116 | { |
---|
| 117 | PRINTF(5)("FINALIZE==========================\n"); |
---|
| 118 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
| 119 | PRINTF(5)("FINALIZE===========================\n"); |
---|
| 120 | |
---|
| 121 | this->deactivate(); |
---|
| 122 | } |
---|
[5828] | 123 | else if (this->lifeCycle > 0.9f) |
---|
| 124 | this->detonate ((this->lifeCycle-.89) *1000.0); |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | Vector v = this->velocity * (time); |
---|
| 128 | this->shiftCoor(v); |
---|
| 129 | } |
---|
[5590] | 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * draws this worldEntity |
---|
| 134 | */ |
---|
| 135 | void Bomb::draw () const |
---|
| 136 | { |
---|
| 137 | glMatrixMode(GL_MODELVIEW); |
---|
| 138 | glPushMatrix(); |
---|
| 139 | float matrix[4][4]; |
---|
| 140 | |
---|
| 141 | /* translate */ |
---|
| 142 | glTranslatef (this->getAbsCoor ().x, |
---|
| 143 | this->getAbsCoor ().y, |
---|
| 144 | this->getAbsCoor ().z); |
---|
| 145 | /* rotate */ |
---|
| 146 | this->getAbsDir().matrix(matrix); |
---|
| 147 | glMultMatrixf((float*)matrix); |
---|
| 148 | |
---|
[5828] | 149 | if (this->lifeCycle < .9) |
---|
| 150 | { |
---|
[5994] | 151 | if (this->getModel() != NULL) |
---|
| 152 | this->getModel()->draw(); |
---|
[5828] | 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | glScalef((this->lifeCycle-.89) *1000.0, |
---|
| 157 | (this->lifeCycle-.89) *1000.0, |
---|
| 158 | (this->lifeCycle-.89) *1000.0); |
---|
| 159 | this->detonationMaterial->select(); |
---|
| 160 | this->detonationSphere->draw(); |
---|
| 161 | } |
---|
[5590] | 162 | glPopMatrix(); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | * |
---|
| 168 | * |
---|
| 169 | */ |
---|
| 170 | void Bomb::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 171 | { |
---|
[5828] | 172 | if (this->lifeCycle < .9f && entity->isA(CL_NPC)) |
---|
| 173 | this->lifeCycle = 0.9f; |
---|
[5590] | 174 | } |
---|
[5603] | 175 | |
---|
| 176 | void Bomb::activate() |
---|
| 177 | { |
---|
| 178 | |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | void Bomb::deactivate() |
---|
| 182 | { |
---|
[6142] | 183 | this->toList(OM_DEAD); |
---|
[5828] | 184 | this->lifeCycle = 0.0f; |
---|
[5744] | 185 | Bomb::fastFactory->kill(this); |
---|
| 186 | } |
---|
[5603] | 187 | |
---|
[5826] | 188 | void Bomb::detonate(float size) |
---|
[5744] | 189 | { |
---|
[5826] | 190 | std::list<WorldEntity*>* detonationList = ObjectManager::distanceFromObject(*this, size, CL_NPC); |
---|
| 191 | if (detonationList != NULL) |
---|
[5744] | 192 | { |
---|
[5826] | 193 | while( !detonationList->empty() ) |
---|
| 194 | { |
---|
[5828] | 195 | detonationList->front()->collidesWith(this, Vector(0,0,0)); |
---|
[5826] | 196 | detonationList->pop_front(); |
---|
| 197 | } |
---|
| 198 | delete detonationList; |
---|
[5744] | 199 | } |
---|
[5603] | 200 | } |
---|