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, 14 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
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"
33#include "core/GameMode.h"
[7284]34#include "core/command/Executor.h"
[3196]35#include "objects/collisionshapes/SphereCollisionShape.h"
[5735]36#include "worldentities/pawns/Pawn.h"
[5737]37#include "graphics/ParticleSpawner.h"
[8492]38#include "BasicProjectile.h"
[2099]39
40namespace orxonox
41{
[3088]42    CreateFactory(Projectile);
[3105]43
[8492]44    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator), BasicProjectile()
[2099]45    {
46        RegisterObject(Projectile);
47
48        this->setConfigValues();
[8492]49//        this->bDestroy_ = false;
[2662]50        this->owner_ = 0;
[8492]51//        this->damage_ = 115;
[8386]52///////////////////me
[8492]53//        this->healthdamage_ = 0;
54//        this->shielddamage_ = 0;
[8386]55///////////////////end me
[2099]56
[2662]57        // Get notification about collisions
[2099]58
[2896]59        if (GameMode::isMaster())
[2099]60        {
[6417]61            this->setMass(1.0);
[2662]62            this->enableCollisionCallback();
[3105]63            this->setCollisionResponse(false);
[2662]64            this->setCollisionType(Kinematic);
65
66            SphereCollisionShape* shape = new SphereCollisionShape(this);
[3105]67            shape->setRadius(20);
[2662]68            this->attachCollisionShape(shape);
69
[5929]70            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Projectile::destroyObject, this)));
[2099]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    {
[2809]86        SUPER(Projectile, tick, dt);
[2099]87
88        if (!this->isActive())
89            return;
90
[8492]91        if (this->getBDestroy())
[5929]92            this->destroy(); // TODO: use a scheduler instead of deleting the object right here in tick()
[2662]93    }
94
95    void Projectile::destroyObject()
96    {
[2896]97        if (GameMode::isMaster())
[5929]98            this->destroy();
[2662]99    }
100
101    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
102    {
[8492]103        return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->owner_,this);
104    }
105
106//////////////////////////me edit
107/*    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
108    {
[2896]109        if (!this->bDestroy_ && GameMode::isMaster())
[2099]110        {
[2918]111            if (otherObject == this->owner_)
[3105]112                return false;
[2918]113
[2662]114            this->bDestroy_ = true;
115
[8183]116            Pawn* victim = orxonox_cast<Pawn*>(otherObject); //if otherObject isn't a Pawn, then victim is NULL
[8152]117
[2662]118            if (this->owner_)
[2099]119            {
[8183]120                if (!victim || (victim && !victim->hasShield())) //same like below
[2099]121                {
[2662]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);
[2099]128                }
[8183]129                if (!victim || (victim && !victim->hasShield())) //same like above
[2662]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                }
[8152]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                }
[2099]147            }
[2662]148
149            if (victim)
[8183]150            {
[8386]151                victim->hit(this->owner_, contactPoint, this->damage_, this->healthdamage_, this->shielddamage_);
[8183]152                victim->startReloadCountdown();
153            }
[2099]154        }
[2662]155        return false;
[2099]156    }
[8183]157//////////////////////////////////////////////////////////////////////end edit
[8492]158*/
[5929]159    void Projectile::setOwner(Pawn* owner)
[2099]160    {
[5929]161        this->owner_ = owner;
[2099]162    }
[8492]163
[2099]164}
Note: See TracBrowser for help on using the repository browser.