Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gameimmersion/src/modules/weapons/projectiles/BasicProjectile.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

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 *      simonmie
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "BasicProjectile.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 "core/OrxonoxClass.h"
39
40namespace orxonox
41{
42    /**
43    @brief
44        Constructor. Registers the object and initializes some default values.
45    */
46    BasicProjectile::BasicProjectile() : OrxonoxClass()
47    {
48        RegisterRootObject(BasicProjectile);// - register the BasicProjectile class to the core
49
50        this->bDestroy_ = false;
51//        this->owner_ = 0;
52
53        this->damage_ = 0;
54        this->healthdamage_ = 0;
55        this->shielddamage_ = 0;
56    }
57
58    BasicProjectile::~BasicProjectile()
59    {
60    }
61
62    bool BasicProjectile::basicCollidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint, Pawn* owner, BasicProjectile* this_)
63    {
64        if (!this_->getBDestroy() && GameMode::isMaster())
65        {
66            if (otherObject == /*this->*/owner/*_*/) //prevents you from shooting yourself
67                return false;
68
69            this_->setBDestroy(true); //if something is hit, the object is destroyed and can't hit something else
70// instead of returning false, bDestroy is returned
71
72            Pawn* victim = orxonox_cast<Pawn*>(otherObject); //if otherObject isn't a Pawn, then victim is NULL
73
74            WorldEntity* entity = orxonox_cast<WorldEntity*>(this_);
75            assert(entity); //entity must not be null
76
77
78            // if visual effects after destruction cause problems, put this block below the effects code block
79            if (victim)
80            {
81                victim->hit(/*this->*/owner/*_*/, contactPoint, this_->getDamage(), this_->getHealthDamage(), this_->getShieldDamage());
82                victim->startReloadCountdown();
83            }
84
85            // visual effects for being hit, depending on whether the shield is hit or not
86            if (/*this->*/owner/*_*/) //if the owner does not exist (anymore??), no effects are displayed.
87            {
88                if (!victim || (victim && !victim->hasShield())) //same like below
89                {
90                    {
91                        ParticleSpawner* effect = new ParticleSpawner(/*this->*/owner/*_*/->getCreator());
92                        effect->setPosition(entity->getPosition());
93                        effect->setOrientation(entity->getOrientation());
94                        effect->setDestroyAfterLife(true);
95                        effect->setSource("Orxonox/explosion3");
96                        effect->setLifetime(2.0f);
97                    }
98                        // second effect with same condition
99                    {
100                        ParticleSpawner* effect = new ParticleSpawner(/*this->*/owner/*_*/->getCreator());
101                        effect->setPosition(entity->getPosition());
102                        effect->setOrientation(entity->getOrientation());
103                        effect->setDestroyAfterLife(true);
104                        effect->setSource("Orxonox/smoke4");
105                        effect->setLifetime(3.0f);
106                    }
107                }
108                        // victim->isAlive() is not false until the next tick, so getHealth() is used instead
109                if (victim && victim->hasShield() && (this_->getDamage() > 0 || this_->getShieldDamage() > 0) && victim->getHealth() > 0)
110                {
111                    ParticleSpawner* effect = new ParticleSpawner(/*this->*/owner/*_*/->getCreator());
112                    effect->setPosition(entity->getPosition());
113                    effect->setOrientation(entity->getOrientation());
114                    effect->setDestroyAfterLife(true);
115                    effect->setSource("Orxonox/Shield");
116                    effect->setLifetime(0.5f);
117                }
118            }
119
120//            if (victim)
121//            {
122//                victim->hit(/*this->*/owner/*_*/, contactPoint, this_->getDamage(), this_->getHealthDamage(), this_->getShieldDamage());
123//                victim->startReloadCountdown();
124//            }
125        }
126        return false;
127    }
128
129/*    void BasicProjectile::setOwner(Pawn* owner)
130    {
131        this->owner_ = owner;
132    }
133
134    void BasicProjectile::destroyObject()
135    {
136        if (GameMode::isMaster())
137            this->destroy();
138    }
139*/
140}
Note: See TracBrowser for help on using the repository browser.