Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9717 was 9656, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy bache back with no conflicts

File size: 4.1 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"
[7193]24#include "util/loading/resource_manager.h"
[3573]25
[8362]26#include "debug.h"
[3573]27
28
[3578]29/**
[4836]30 *  standard constructor
[3578]31*/
[4932]32Projectile::Projectile () : WorldEntity()
[3573]33{
[4322]34  this->setClassID(CL_PROJECTILE, "Projectile");
[4597]35
[4890]36  this->lifeCycle = 0.0;
[5063]37  this->lifeSpan = 1.0f; /* sec */
[6078]38  this->target = NULL;
[5769]39  this->removeNode();
[7084]40
[8190]41  /* character attributes */
42  this->setHealth(1.0f);
[9235]43  this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points
[8190]44
[7084]45  this->explosionBuffer = NULL;
46  this->engineBuffer = NULL;
[9656]47
48  //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[3573]49}
50
51
[3578]52/**
[4836]53 *  standard deconstructor
[3578]54*/
[4597]55Projectile::~Projectile ()
[3573]56{
[7084]57  if (this->explosionBuffer != NULL)
58    ResourceManager::getInstance()->unload(this->explosionBuffer);
59  if (this->engineBuffer != NULL)
60    ResourceManager::getInstance()->unload(this->engineBuffer);
[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
[3578]68
[7221]69void Projectile::loadExplosionSound(const std::string& explosionSound)
[7084]70{
71  if (this->explosionBuffer != NULL)
72    ResourceManager::getInstance()->unload(this->explosionBuffer);
73
[7221]74  else if (!explosionSound.empty())
[7084]75  {
[7460]76    this->explosionBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV);
[7084]77    if (this->explosionBuffer != NULL)
78    {
[9406]79      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getCName());
[7084]80    }
81    else
82    {
[9406]83      PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getCName());
[7084]84    }
85  }
86  else
87    this->explosionBuffer = NULL;
88}
89
90
[7221]91void Projectile::loadEngineSound(const std::string& engineSound)
[7084]92{
93  if (this->engineBuffer != NULL)
94    ResourceManager::getInstance()->unload(this->engineBuffer);
95
[7221]96  else if (!engineSound.empty())
[7084]97  {
[7460]98    this->engineBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV);
[7084]99    if (this->engineBuffer != NULL)
100    {
[9406]101      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getCName());
[7084]102    }
103    else
104    {
[9406]105      PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getCName());
[7084]106    }
107  }
108  else
109    this->engineBuffer = NULL;
110}
111
112
[6431]113void Projectile::setMinEnergy(float energyMin)
[4948]114{
115  this->energyMin = energyMin;
116}
117
118
[3578]119/**
[4836]120 *  this sets the flight direction of the projectile
121 * @param directin in which to flight
[3632]122
123   this function will calculate a vector out of this to be used in the
124   tick function
125*/
[4927]126void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]127{
128  Vector v(1, 0, 0);
[4890]129  this->flightDirection = flightDirection.apply(v);
130  this->flightDirection.normalize();
[3632]131}
132
133/**
[4836]134 *  sets the velocity vector to a spec speed
135 * @param velocity: vector of the velocity
[4464]136*/
137void Projectile::setVelocity(const Vector &velocity)
138{
[4955]139  //Vector offsetVel =
140  this->velocity = velocity;
141 // offsetVel.normalize();
142  //this->velocity += (offsetVel * 50.0);
[4464]143}
144
[5766]145
146
147void Projectile::setTarget(PNode* target)
148{
[6078]149  if (this->target == NULL)
150    this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE);
151  else
152    this->target->setParent(target);
[5766]153}
154
155
[4464]156/**
[4927]157 * signal tick, time dependent things will be handled here
[6056]158 * @param dt since last tick
[3578]159*/
[6056]160void Projectile::tick (float dt)
[3632]161{
[6056]162  Vector v = this->velocity * (dt);
[3686]163  this->shiftCoor(v);
[3683]164
[6056]165  if (this->tickLifeCycle(dt))
[9235]166    this->destroy( NULL );
[3632]167}
[3573]168
169
[3578]170/**
[4836]171 *  the function gets called, when the projectile is destroyed
[3578]172*/
[9235]173void Projectile::destroy (WorldEntity* killer)
[7084]174{
175  if (this->explosionBuffer != NULL)
176    this->soundSource.play(this->explosionBuffer);
177}
[3573]178
Note: See TracBrowser for help on using the repository browser.