Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8898 was 8362, checked in by bensch, 18 years ago

orxonox/trunk: removed stupid included in base_object.h
this should lead to faster compile-times

File size: 4.0 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);
43  this->setDamage(100.0f); // default damage of a projectile set to 100.0 damage points
44
[7084]45  this->explosionBuffer = NULL;
46  this->engineBuffer = NULL;
[3573]47}
48
49
[3578]50/**
[4836]51 *  standard deconstructor
[3578]52*/
[4597]53Projectile::~Projectile ()
[3573]54{
[7084]55  if (this->explosionBuffer != NULL)
56    ResourceManager::getInstance()->unload(this->explosionBuffer);
57  if (this->engineBuffer != NULL)
58    ResourceManager::getInstance()->unload(this->engineBuffer);
[4597]59  /*
60     do not delete the test projectModel, since it is pnode
61     and will be cleaned out by world
[3629]62  */
63  //delete this->projectileModel;
[3573]64}
65
[3578]66
[7221]67void Projectile::loadExplosionSound(const std::string& explosionSound)
[7084]68{
69  if (this->explosionBuffer != NULL)
70    ResourceManager::getInstance()->unload(this->explosionBuffer);
71
[7221]72  else if (!explosionSound.empty())
[7084]73  {
[7460]74    this->explosionBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV);
[7084]75    if (this->explosionBuffer != NULL)
76    {
[7221]77      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getName());
[7084]78    }
79    else
80    {
[7221]81      PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getName());
[7084]82    }
83  }
84  else
85    this->explosionBuffer = NULL;
86}
87
88
[7221]89void Projectile::loadEngineSound(const std::string& engineSound)
[7084]90{
91  if (this->engineBuffer != NULL)
92    ResourceManager::getInstance()->unload(this->engineBuffer);
93
[7221]94  else if (!engineSound.empty())
[7084]95  {
[7460]96    this->engineBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV);
[7084]97    if (this->engineBuffer != NULL)
98    {
[7221]99      PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getName());
[7084]100    }
101    else
102    {
[7221]103      PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getName());
[7084]104    }
105  }
106  else
107    this->engineBuffer = NULL;
108}
109
110
[6431]111void Projectile::setMinEnergy(float energyMin)
[4948]112{
113  this->energyMin = energyMin;
114}
115
116
[3578]117/**
[4836]118 *  this sets the flight direction of the projectile
119 * @param directin in which to flight
[3632]120
121   this function will calculate a vector out of this to be used in the
122   tick function
123*/
[4927]124void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]125{
126  Vector v(1, 0, 0);
[4890]127  this->flightDirection = flightDirection.apply(v);
128  this->flightDirection.normalize();
[3632]129}
130
131/**
[4836]132 *  sets the velocity vector to a spec speed
133 * @param velocity: vector of the velocity
[4464]134*/
135void Projectile::setVelocity(const Vector &velocity)
136{
[4955]137  //Vector offsetVel =
138  this->velocity = velocity;
139 // offsetVel.normalize();
140  //this->velocity += (offsetVel * 50.0);
[4464]141}
142
[5766]143
144
145void Projectile::setTarget(PNode* target)
146{
[6078]147  if (this->target == NULL)
148    this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE);
149  else
150    this->target->setParent(target);
[5766]151}
152
153
[4464]154/**
[4927]155 * signal tick, time dependent things will be handled here
[6056]156 * @param dt since last tick
[3578]157*/
[6056]158void Projectile::tick (float dt)
[3632]159{
[6056]160  Vector v = this->velocity * (dt);
[3686]161  this->shiftCoor(v);
[3683]162
[6056]163  if (this->tickLifeCycle(dt))
164    this->destroy();
[3632]165}
[3573]166
167
[3578]168/**
[4836]169 *  the function gets called, when the projectile is destroyed
[3578]170*/
[4597]171void Projectile::destroy ()
[7084]172{
173  if (this->explosionBuffer != NULL)
174    this->soundSource.play(this->explosionBuffer);
175}
[3573]176
Note: See TracBrowser for help on using the repository browser.