Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/projectile.cc @ 10569

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

merged the branche playability into the trunk

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