Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon/src/orxonox/objects/Projectile.cc @ 2138

Last change on this file since 2138 was 2060, checked in by polakma, 16 years ago

WeaponSystem, Projectile (kompiliert nicht)

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
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"
37#include "core/Iterator.h"
38#include "tools/ParticleInterface.h"
39
40#include "SpaceShipAI.h"
41#include "ParticleSpawner.h"
42#include "Model.h"
43#include "Settings.h"
44
45namespace orxonox
46{
47    float Projectile::speed_s = 5000;
48
49    Projectile::Projectile(Weapon* owner) : owner_(owner)
50    {
51        RegisterObject(Projectile);
52
53        this->setConfigValues();
54        this->explosionTemplateName_ = "Orxonox/explosion3";
55        this->smokeTemplateName_ = "Orxonox/smoke4";
56
57        this->setStatic(false);
58        this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
59
60        if (this->owner_)
61        {
62            this->setOrientation(this->owner_->getOrientation());
63            this->setPosition(this->owner_->getPosition());
64            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
65        }
66
67        if(!orxonox::Settings::isClient()) //only if not on client
68          this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
69    }
70
71    Projectile::~Projectile()
72    {
73    }
74
75    void Projectile::setConfigValues()
76    {
77        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
78        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
79        SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);
80    }
81
82    void Projectile::speedChanged()
83    {
84        Projectile::speed_s = this->speed_;
85        if (this->owner_)
86            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
87    }
88
89    void Projectile::tick(float dt)
90    {
91        SUPER(Projectile, tick, dt);
92
93        if (!this->isActive())
94            return;
95
96        float radius;
97        for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it)
98        {
99            if ((*it) != this->owner_)
100            {
101                radius = it->getScale3D().x * 3.0;
102
103                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
104                {
105                    // hit
106                    if (it->isA(Class(SpaceShipAI)))
107                        ((SpaceShipAI*)(*it))->damage(this->damage_);
108                    ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0);
109                    explosion->setPosition(this->getPosition());
110                    explosion->create();
111                    ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0);
112                    smoke->setPosition(this->getPosition());
113//                    smoke->getParticleInterface()->setSpeedFactor(3.0);
114                    smoke->create();
115                    delete this;
116                    return;
117                }
118            }
119        }
120    }
121
122    void Projectile::destroyObject()
123    {
124        delete this;
125    }
126
127    bool Projectile::create(){
128      return WorldEntity::create();
129    }
130}
Note: See TracBrowser for help on using the repository browser.