Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/bomb.cc @ 10009

Last change on this file since 10009 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 4.0 KB
RevLine 
[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
[9869]22#include "particles/dot_emitter.h"
23#include "particles/particle_system.h"
[5744]24
[8362]25#include "debug.h"
[5590]26
[9869]27#include "class_id_DEPRECATED.h"
28ObjectListDefinitionID(Bomb, CL_BOMB);
29CREATE_FAST_FACTORY_STATIC(Bomb);
[5590]30
31/**
32 * constructs and loads a Bomb from a XML-element
33 * @param root the XML-element to load from
34 */
35Bomb::Bomb(const TiXmlElement* root)
36{
37  this->init();
38  if (root != NULL)
39    this->loadParams(root);
[5744]40
41  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
42
[6431]43  this->setMinEnergy(1);
[6700]44  this->setHealthMax(10);
[6431]45
[5744]46  this->lifeSpan = 15;
47
[6825]48  this->emitter = new DotEmitter(100, 5, M_2_PI);
[5744]49  this->emitter->setParent(this);
50  this->emitter->setSpread(M_PI, M_PI);
[5590]51}
52
53
54/**
55 * standard deconstructor
56 */
57Bomb::~Bomb ()
58{
[5828]59  delete this->detonationSphere;
60  delete this->detonationMaterial;
[5590]61
62}
63
64
65/**
66 * initializes the Bomb
67 * @todo change this to what you wish
68 */
69void Bomb::init()
70{
[9869]71  this->registerObject(this, Bomb::_objectList);
[5590]72
[5828]73
74  this->detonationSphere = new PrimitiveModel(PRIM_SPHERE);
75  this->detonationMaterial = new Material();
76  this->detonationMaterial->setDiffuse(1, 0, 0);
[7084]77
78  this->loadExplosionSound("sound/explosions/explosion_7_far.wav");
[5828]79  //   this->detonationMaterial->setTransparency(.1);
[5590]80  /**
81   * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition)
82   */
83
84}
85
86
87/**
88 * loads a Bomb from a XML-element
89 * @param root the XML-element to load from
90 * @todo make the class Loadable
91 */
92void Bomb::loadParams(const TiXmlElement* root)
93{
94  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
[6512]95  Projectile::loadParams(root);
[5590]96
97
98  /**
99   * @todo: make the class Loadable
100   */
101}
102
103
104/**
105 * advances the Bomb about time seconds
106 * @param time the Time to step
107 */
[5603]108void Bomb::tick(float time)
[5590]109{
[5744]110  this->lifeCycle += time/this->lifeSpan;
111  if( this->lifeCycle >= 1.0)
112    {
113      PRINTF(5)("FINALIZE==========================\n");
114      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
115      PRINTF(5)("FINALIZE===========================\n");
116
117      this->deactivate();
118    }
[5828]119  else if (this->lifeCycle > 0.9f)
120    this->detonate ((this->lifeCycle-.89) *1000.0);
121  else
122  {
123    Vector v = this->velocity * (time);
124    this->shiftCoor(v);
125  }
[5590]126}
127
128/**
129 * draws this worldEntity
130 */
131void Bomb::draw () const
132{
133  glMatrixMode(GL_MODELVIEW);
134  glPushMatrix();
135  float matrix[4][4];
136
137  /* translate */
138  glTranslatef (this->getAbsCoor ().x,
139                this->getAbsCoor ().y,
140                this->getAbsCoor ().z);
141  /* rotate */
142  this->getAbsDir().matrix(matrix);
143  glMultMatrixf((float*)matrix);
144
[5828]145  if (this->lifeCycle < .9)
146  {
[5994]147    if (this->getModel() != NULL)
148      this->getModel()->draw();
[5828]149  }
150  else
151  {
152    glScalef((this->lifeCycle-.89) *1000.0,
153              (this->lifeCycle-.89) *1000.0,
154              (this->lifeCycle-.89) *1000.0);
155    this->detonationMaterial->select();
156    this->detonationSphere->draw();
157  }
[5590]158  glPopMatrix();
159}
160
161
162/**
163 *
164 *
165 */
166void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
167{
[5828]168  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
169    this->lifeCycle = 0.9f;
[5590]170}
[5603]171
172void Bomb::activate()
173{
174
175}
176
[9869]177
[5603]178void Bomb::deactivate()
179{
[6142]180  this->toList(OM_DEAD);
[5828]181  this->lifeCycle = 0.0f;
[5744]182  Bomb::fastFactory->kill(this);
183}
[5603]184
[5826]185void Bomb::detonate(float size)
[5744]186{
[9869]187  /// FIXME
188/*  ObjectManager::EntityList detonationList;
189  ObjectManager::distanceFromObject(detonationList, *this, size, NPC::objectList());
[7368]190    while( !detonationList.empty() )
[5826]191    {
[7368]192      detonationList.front()->collidesWith(this, Vector(0,0,0));
193      detonationList.pop_front();
[9869]194    }*/
[5603]195}
Note: See TracBrowser for help on using the repository browser.