Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/WagnisProjectile.cc @ 12343

Last change on this file since 12343 was 12191, checked in by merholzl, 6 years ago

merged Wagnis

File size: 2.8 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
23#include "WagnisProjectile.h"
24
25#include "core/config/ConfigValueIncludes.h"
26#include "core/CoreIncludes.h"
27#include "core/GameMode.h"
28#include "core/command/Executor.h"
29
30#include "worldentities/pawns/Pawn.h"
31
32namespace orxonox
33{
34    RegisterClass(WagnisProjectile);
35
36    WagnisProjectile::WagnisProjectile(Context* context) : MovableEntity(context), BasicProjectile()
37    {
38        RegisterObject(WagnisProjectile);
39
40        this->setConfigValues();
41
42        // Get notification about collisions
43        if (GameMode::isMaster())
44        {
45            this->setMass(0.1f);
46            this->enableCollisionCallback();
47            this->setCollisionResponse(false);
48            this->setCollisionType(CollisionType::Dynamic);
49
50            // Create a sphere collision shape and attach it to the projectile.
51            collisionShape_ = new SphereCollisionShape(this->getContext());
52            setCollisionShapeRadius(3.0f);
53            this->attachCollisionShape(collisionShape_);
54
55            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
56        }
57    }
58
59    WagnisProjectile::~WagnisProjectile()
60    {
61    }
62
63    void WagnisProjectile::setConfigValues()
64    {
65        SetConfigValue(lifetime_, 4.0f).description("The time in seconds a projectile stays alive");
66    }
67
68    void WagnisProjectile::tick(float dt)
69    {
70        SUPER(WagnisProjectile, tick, dt);
71
72        if (!this->isActive())
73            return;
74
75        this->destroyCheck();
76    }
77
78    bool WagnisProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
79    {
80        return this->processCollision(otherObject, contactPoint, cs);
81    }
82
83    void WagnisProjectile::setCollisionShapeRadius(float radius)
84    {
85        if (collisionShape_ != nullptr && radius > 0)
86        {
87            collisionShape_->setRadius(radius);
88        }       
89    }
90}
Note: See TracBrowser for help on using the repository browser.