Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3110 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

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