Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/weaponsystem/projectiles/Projectile.cc @ 3088

Last change on this file since 3088 was 3088, checked in by scheusso, 15 years ago

fix in Projectile (there was no createFactory) and some additional debugging
and in hubtimer (only on server now)
and in lightninggun (material is synchronised)

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[2099]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
[2100]40#include "objects/worldentities/Model.h"
41#include "objects/worldentities/ParticleSpawner.h"
[2662]42#include "objects/collisionshapes/SphereCollisionShape.h"
[2896]43#include "core/GameMode.h"
[2099]44
45namespace orxonox
46{
[3088]47    CreateFactory(Projectile);
48 
[2662]49    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator)
[2099]50    {
51        RegisterObject(Projectile);
52
53        this->setConfigValues();
[2662]54        this->bDestroy_ = false;
55        this->owner_ = 0;
[2099]56
[2662]57        // Get notification about collisions
[2099]58
[2896]59        if (GameMode::isMaster())
[2099]60        {
[2662]61            this->enableCollisionCallback();
62
63            this->setCollisionType(Kinematic);
64
65            SphereCollisionShape* shape = new SphereCollisionShape(this);
66            shape->setRadius(10);
67            this->attachCollisionShape(shape);
68
69            this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
[2099]70        }
71    }
72
73    Projectile::~Projectile()
74    {
75    }
76
77    void Projectile::setConfigValues()
78    {
79        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
80        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
81    }
82
83
84    void Projectile::tick(float dt)
85    {
[2809]86        SUPER(Projectile, tick, dt);
[2099]87
88        if (!this->isActive())
89            return;
90
[2662]91        if (this->bDestroy_)
92            delete this;
93    }
94
95    void Projectile::destroyObject()
96    {
[2896]97        if (GameMode::isMaster())
[2662]98            delete this;
99    }
100
101    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
102    {
[2896]103        if (!this->bDestroy_ && GameMode::isMaster())
[2099]104        {
[2918]105            if (otherObject == this->owner_)
106                return true;
107
[2662]108            this->bDestroy_ = true;
109
110            if (this->owner_)
[2099]111            {
112                {
[2662]113                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
114                    effect->setPosition(this->getPosition());
115                    effect->setOrientation(this->getOrientation());
116                    effect->setDestroyAfterLife(true);
117                    effect->setSource("Orxonox/explosion3");
118                    effect->setLifetime(2.0f);
[2099]119                }
[2662]120                {
121                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
122                    effect->setPosition(this->getPosition());
123                    effect->setOrientation(this->getOrientation());
124                    effect->setDestroyAfterLife(true);
125                    effect->setSource("Orxonox/smoke4");
126                    effect->setLifetime(3.0f);
127                }
[2099]128            }
[2662]129
[3073]130            float dmg = this->damage_;
131            if (this->owner_)
132                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
133
[2662]134            Pawn* victim = dynamic_cast<Pawn*>(otherObject);
135            if (victim)
[3073]136                victim->damage(dmg, this->owner_);
[2099]137        }
[2662]138        return false;
[2099]139    }
140
[2662]141    void Projectile::destroyedPawn(Pawn* pawn)
[2099]142    {
[2662]143        if (this->owner_ == pawn)
144            this->owner_ = 0;
[2099]145    }
146}
Note: See TracBrowser for help on using the repository browser.