Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/projectile_weapon.cc @ 10742

Last change on this file since 10742 was 10368, checked in by patrick, 18 years ago

merged the branche playability into the trunk

File size: 4.1 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: Nicolas Schlumberger
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
18
19#include "projectile_weapon.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 <cmath>
27
28#include "debug.h"
29
30ObjectListDefinition(ProjectileWeapon);
31
32/**
33 *  standard constructor
34*/
35ProjectileWeapon::ProjectileWeapon () : Projectile()
36{
37  this->registerObject(this, ProjectileWeapon::_objectList);
38
39  this->lifeCycle = 0.0;
40  this->lifeSpan = 1.0f; /* sec */
41  this->target = NULL;
42  this->removeNode();
43
44  /* character attributes */
45  this->setHealth(1.0f);
46  this->setDamage(1.0f); // default damage of a projectile_weapon set to 100.0 damage points
47
48  this->physDamage = 0.0f;
49  this->elecDamage = 0.0f;
50  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
51}
52
53
54/**
55 *  standard deconstructor
56*/
57ProjectileWeapon::~ProjectileWeapon ()
58{
59}
60
61ProjectileWeapon::ProjectileWeapon (float pDamage, float eDamage, PNode* target) : Projectile()
62{
63  this->registerObject(this, ProjectileWeapon::_objectList);
64
65  this->lifeCycle = 0.0;
66  this->lifeSpan = 1.0f; /* sec */
67  this->removeNode();
68
69  /* character attributes */
70  this->setHealth(1.0f);
71  this->setDamage(1.0f); // default damage of a projectile_weapon set to 100.0 damage points
72
73  this->physDamage = pDamage;
74  this->elecDamage = eDamage;
75  this->target = target;
76
77  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
78}
79
80void ProjectileWeapon::initialize(float pDamage, float eDamage, PNode* target)
81{
82  /* character attributes*/
83  this->physDamage = pDamage;
84  this->elecDamage = eDamage;
85  this->target = target;
86}
87
88
89void ProjectileWeapon::loadExplosionSound(const std::string& explosionSound)
90{
91  if (!explosionSound.empty())
92    this->explosionBuffer = OrxSound::ResourceSoundBuffer(explosionSound);
93  else
94    this->explosionBuffer = OrxSound::SoundBuffer();
95}
96
97
98void ProjectileWeapon::loadEngineSound(const std::string& engineSound)
99{
100  if (!engineSound.empty())
101    this->engineBuffer = OrxSound::ResourceSoundBuffer(engineSound);
102  else
103    this->engineBuffer = OrxSound::SoundBuffer();
104}
105
106
107void ProjectileWeapon::setMinEnergy(float energyMin)
108{
109  this->energyMin = energyMin;
110}
111
112
113/**
114 *  this sets the flight direction of the projectile_weapon
115 * @param directin in which to flight
116
117   this function will calculate a vector out of this to be used in the
118   tick function
119*/
120void ProjectileWeapon::setFlightDirection(const Quaternion& flightDirection)
121{
122  Vector v(1, 0, 0);
123  this->flightDirection = flightDirection.apply(v);
124  this->flightDirection.normalize();
125}
126
127/**
128 *  sets the velocity vector to a spec speed
129 * @param velocity: vector of the velocity
130*/
131void ProjectileWeapon::setVelocity(const Vector &velocity)
132{
133  //Vector offsetVel =
134  this->velocity = velocity;
135  // offsetVel.normalize();
136  //this->velocity += (offsetVel * 50.0);
137}
138
139
140
141void ProjectileWeapon::setTarget(PNode* target)
142{
143  if (this->target == NULL)
144    this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT);
145  else
146    this->target->setParent(target);
147}
148
149
150void ProjectileWeapon::collidesWith (WorldEntity* target, const Vector& location)
151{
152  dynamic_cast<SpaceShip*>(target)->damage(this->getPhysDamage(),this->getElecDamage());
153//   this->destroy(NULL);
154  this->destroy(target);
155}
156
157
158
159/**
160 * signal tick, time dependent things will be handled here
161 * @param dt since last tick
162*/
163void ProjectileWeapon::tick (float dt)
164{
165  if (this->tickLifeCycle(dt))
166    this->destroy( NULL );
167}
168
169
170/**
171 *  the function gets called, when the projectile_weapon is destroyed
172*/
173void ProjectileWeapon::destroy (WorldEntity* killer)
174{
175  if (this->explosionBuffer.loaded())
176    this->soundSource.play(this->explosionBuffer);
177}
178
179void ProjectileWeapon::blow()
180{
181}
182
Note: See TracBrowser for help on using the repository browser.