Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gameimmersion/src/modules/weapons/projectiles/Projectile.cc @ 8492

Last change on this file since 8492 was 8492, checked in by simonmie, 13 years ago

New Shield effect added (from tibork), first working BasicProjectile class, changes in weapon classes to fit new BasicProjectile system, some spam messages in Pawn.cc removed

  • Property svn:eol-style set to native
File size: 5.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 "core/CoreIncludes.h"
32#include "core/ConfigValueIncludes.h"
33#include "core/GameMode.h"
34#include "core/command/Executor.h"
35#include "objects/collisionshapes/SphereCollisionShape.h"
36#include "worldentities/pawns/Pawn.h"
37#include "graphics/ParticleSpawner.h"
38#include "BasicProjectile.h"
39
40namespace orxonox
41{
42    CreateFactory(Projectile);
43
44    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator), BasicProjectile()
45    {
46        RegisterObject(Projectile);
47
48        this->setConfigValues();
49//        this->bDestroy_ = false;
50        this->owner_ = 0;
51//        this->damage_ = 115;
52///////////////////me
53//        this->healthdamage_ = 0;
54//        this->shielddamage_ = 0;
55///////////////////end me
56
57        // Get notification about collisions
58
59        if (GameMode::isMaster())
60        {
61            this->setMass(1.0);
62            this->enableCollisionCallback();
63            this->setCollisionResponse(false);
64            this->setCollisionType(Kinematic);
65
66            SphereCollisionShape* shape = new SphereCollisionShape(this);
67            shape->setRadius(20);
68            this->attachCollisionShape(shape);
69
70            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Projectile::destroyObject, this)));
71        }
72    }
73
74    Projectile::~Projectile()
75    {
76    }
77
78    void Projectile::setConfigValues()
79    {
80        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
81    }
82
83
84    void Projectile::tick(float dt)
85    {
86        SUPER(Projectile, tick, dt);
87
88        if (!this->isActive())
89            return;
90
91        if (this->getBDestroy())
92            this->destroy(); // TODO: use a scheduler instead of deleting the object right here in tick()
93    }
94
95    void Projectile::destroyObject()
96    {
97        if (GameMode::isMaster())
98            this->destroy();
99    }
100
101    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
102    {
103        return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->owner_,this);
104    }
105
106//////////////////////////me edit
107/*    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
108    {
109        if (!this->bDestroy_ && GameMode::isMaster())
110        {
111            if (otherObject == this->owner_)
112                return false;
113
114            this->bDestroy_ = true;
115
116            Pawn* victim = orxonox_cast<Pawn*>(otherObject); //if otherObject isn't a Pawn, then victim is NULL
117
118            if (this->owner_)
119            {
120                if (!victim || (victim && !victim->hasShield())) //same like below
121                {
122                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
123                    effect->setPosition(this->getPosition());
124                    effect->setOrientation(this->getOrientation());
125                    effect->setDestroyAfterLife(true);
126                    effect->setSource("Orxonox/explosion3");
127                    effect->setLifetime(2.0f);
128                }
129                if (!victim || (victim && !victim->hasShield())) //same like above
130                {
131                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
132                    effect->setPosition(this->getPosition());
133                    effect->setOrientation(this->getOrientation());
134                    effect->setDestroyAfterLife(true);
135                    effect->setSource("Orxonox/smoke4");
136                    effect->setLifetime(3.0f);
137                }
138                if (victim && victim->hasShield())
139                {
140                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
141                    effect->setPosition(this->getPosition());
142                    effect->setOrientation(this->getOrientation());
143                    effect->setDestroyAfterLife(true);
144                    effect->setSource("Orxonox/engineglow");
145                    effect->setLifetime(0.5f);
146                }
147            }
148
149            if (victim)
150            {
151                victim->hit(this->owner_, contactPoint, this->damage_, this->healthdamage_, this->shielddamage_);
152                victim->startReloadCountdown();
153            }
154        }
155        return false;
156    }
157//////////////////////////////////////////////////////////////////////end edit
158*/
159    void Projectile::setOwner(Pawn* owner)
160    {
161        this->owner_ = owner;
162    }
163
164}
Note: See TracBrowser for help on using the repository browser.