Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/Projectile.cc @ 2051

Last change on this file since 2051 was 1907, checked in by scheusso, 16 years ago

merged network branch back to trunk

  • Property svn:eol-style set to native
File size: 4.1 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Projectile.h"
31
32#include <OgreBillboard.h>
33
34#include "core/CoreIncludes.h"
35#include "core/Executor.h"
36#include "core/ConfigValueIncludes.h"
[1747]37#include "core/Iterator.h"
[1553]38#include "tools/ParticleInterface.h"
[1505]39
[1552]40#include "SpaceShipAI.h"
41#include "ParticleSpawner.h"
[1505]42#include "Model.h"
[1907]43#include "Settings.h"
[1505]44
45namespace orxonox
46{
[1747]47    float Projectile::speed_s = 5000;
[1505]48
[1552]49    Projectile::Projectile(SpaceShip* owner) : owner_(owner)
[1505]50    {
51        RegisterObject(Projectile);
52
53        this->setConfigValues();
[1602]54        this->explosionTemplateName_ = "Orxonox/explosion3";
55        this->smokeTemplateName_ = "Orxonox/smoke4";
[1505]56
[1824]57        this->setStatic(false);
58        this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
[1907]59       
[1505]60        if (this->owner_)
61        {
[1907]62            this->setOrientation(this->owner_->getOrientation());
[1822]63            this->setPosition(this->owner_->getPosition());
[1552]64            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
[1505]65        }
66
[1907]67        if(!orxonox::Settings::isClient()) //only if not on client
68          this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
[1505]69    }
70
71    Projectile::~Projectile()
72    {
73    }
74
75    void Projectile::setConfigValues()
76    {
[1552]77        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
[1554]78        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
[1747]79        SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);
80    }
[1505]81
[1747]82    void Projectile::speedChanged()
83    {
84        Projectile::speed_s = this->speed_;
85        if (this->owner_)
86            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
[1505]87    }
88
89    void Projectile::tick(float dt)
90    {
[1747]91        SUPER(Projectile, tick, dt);
[1505]92
[1558]93        if (!this->isActive())
94            return;
95
[1505]96        float radius;
[1747]97        for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it)
[1505]98        {
99            if ((*it) != this->owner_)
100            {
[1747]101                radius = it->getScale3D().x * 3.0;
[1505]102
103                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
104                {
[1552]105                    // hit
[1789]106                    if (it->isA(Class(SpaceShipAI)))
[1552]107                        ((SpaceShipAI*)(*it))->damage(this->damage_);
[1563]108                    ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0);
[1552]109                    explosion->setPosition(this->getPosition());
110                    explosion->create();
[1602]111                    ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0);
[1552]112                    smoke->setPosition(this->getPosition());
[1602]113//                    smoke->getParticleInterface()->setSpeedFactor(3.0);
[1552]114                    smoke->create();
[1505]115                    delete this;
116                    return;
117                }
118            }
119        }
120    }
121
122    void Projectile::destroyObject()
123    {
124        delete this;
125    }
[1907]126   
127    bool Projectile::create(){
128      return WorldEntity::create();
129    }
[1505]130}
Note: See TracBrowser for help on using the repository browser.