Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/Projectile.cc @ 6126

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

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

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