Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/projectile.cc @ 9960

Last change on this file since 9960 was 9960, checked in by nicolasc, 17 years ago

fixed get*Damage() return values

File size: 4.0 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
18
19#include "projectile.h"
20
21#include "world_entity.h"
22#include "world_entities/weapons/weapon.h"
23#include "model.h"
24#include "sound/resource_sound_buffer.h"
25
26#include "debug.h"
27
28ObjectListDefinition(Projectile);
29
30/**
31 *  standard constructor
32*/
33Projectile::Projectile () : WorldEntity()
34{
35  this->registerObject(this, Projectile::_objectList);
36
37  this->lifeCycle = 0.0;
38  this->lifeSpan = 1.0f; /* sec */
39  this->target = NULL;
40  this->removeNode();
41
42  /* character attributes */
43  this->setHealth(1.0f);
44  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
45
46  this->physDamage = 0.0f;
47  this->elecDamage = 0.0f;
48  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
49}
50
51
52/**
53 *  standard deconstructor
54*/
55Projectile::~Projectile ()
56{
57  /*
58     do not delete the test projectModel, since it is pnode
59     and will be cleaned out by world
60  */
61  //delete this->projectileModel;
62}
63
64Projectile::Projectile (float pDamage, float eDamage, PNode* target) : WorldEntity()
65{
66  this->registerObject(this, Projectile::_objectList);
67
68  this->lifeCycle = 0.0;
69  this->lifeSpan = 1.0f; /* sec */
70  this->removeNode();
71
72  /* character attributes */
73  this->setHealth(1.0f);
74  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
75
76  this->physDamage = pDamage;
77  this->elecDamage = eDamage;
78  this->target = target;
79
80  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
81}
82
83void Projectile::initialize(float pDamage, float eDamage, PNode* target)
84{
85  /* character attributes*/
86  this->physDamage = pDamage;
87  this->elecDamage = eDamage;
88  this->target = target;
89}
90
91
92void Projectile::loadExplosionSound(const std::string& explosionSound)
93{
94  if (!explosionSound.empty())
95    this->explosionBuffer = OrxSound::ResourceSoundBuffer(explosionSound);
96  else
97    this->explosionBuffer = OrxSound::SoundBuffer();
98}
99
100
101void Projectile::loadEngineSound(const std::string& engineSound)
102{
103  if (!engineSound.empty())
104    this->engineBuffer = OrxSound::ResourceSoundBuffer(engineSound);
105  else
106    this->engineBuffer = OrxSound::SoundBuffer();
107}
108
109
110void Projectile::setMinEnergy(float energyMin)
111{
112  this->energyMin = energyMin;
113}
114
115
116/**
117 *  this sets the flight direction of the projectile
118 * @param directin in which to flight
119
120   this function will calculate a vector out of this to be used in the
121   tick function
122*/
123void Projectile::setFlightDirection(const Quaternion& flightDirection)
124{
125  Vector v(1, 0, 0);
126  this->flightDirection = flightDirection.apply(v);
127  this->flightDirection.normalize();
128}
129
130/**
131 *  sets the velocity vector to a spec speed
132 * @param velocity: vector of the velocity
133*/
134void Projectile::setVelocity(const Vector &velocity)
135{
136  //Vector offsetVel =
137  this->velocity = velocity;
138  // offsetVel.normalize();
139  //this->velocity += (offsetVel * 50.0);
140}
141
142
143
144void Projectile::setTarget(PNode* target)
145{
146  if (this->target == NULL)
147    this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT);
148  else
149    this->target->setParent(target);
150}
151
152
153void Projectile::collidesWith (SpaceShip* target, const Vector& location)
154{
155  target->damage(this->physDamage, this->elecDamage);
156  this->destroy(target);
157}
158
159/**
160 * signal tick, time dependent things will be handled here
161 * @param dt since last tick
162*/
163void Projectile::tick (float dt)
164{
165  Vector v = this->velocity * (dt);
166  this->shiftCoor(v);
167
168  if (this->tickLifeCycle(dt))
169    this->destroy( NULL );
170}
171
172
173/**
174 *  the function gets called, when the projectile is destroyed
175*/
176void Projectile::destroy (WorldEntity* killer)
177{
178  if (this->explosionBuffer.loaded())
179    this->soundSource.play(this->explosionBuffer);
180}
Note: See TracBrowser for help on using the repository browser.