Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gameimmersion/src/modules/weapons/projectiles/BasicProjectile.cc @ 8542

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

comments added, unused parts removed, some spam messages removed

File size: 5.0 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
52        this->damage_ = 0;
53        this->healthdamage_ = 0;
54        this->shielddamage_ = 0;
55    }
56
57    BasicProjectile::~BasicProjectile()
58    {
59    }
60
61    /* The function called when a projectile hits another thing.
62     * calls the hit-function, starts the reload countdown, displays visual effects
63     * hit is defined in src/orxonox/worldentities/pawns/pawn.cc
64     */
65    bool BasicProjectile::basicCollidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint, Pawn* owner, BasicProjectile* this_)
66    {
67        if (!this_->getBDestroy() && GameMode::isMaster())
68        {
69            if (otherObject == owner) //prevents you from shooting yourself
70                return false;
71
72            this_->setBDestroy(true); // If something is hit, the object is destroyed and can't hit something else.
73                                      // The projectile is destroyed by its tick()-function (in the following tick).
74
75            Pawn* victim = orxonox_cast<Pawn*>(otherObject); //if otherObject isn't a Pawn, then victim is NULL
76
77            WorldEntity* entity = orxonox_cast<WorldEntity*>(this_);
78            assert(entity); //entity must not be null
79
80
81            // if visual effects after destruction cause problems, put this block below the effects code block
82            if (victim)
83            {
84                victim->hit(owner, contactPoint, this_->getDamage(), this_->getHealthDamage(), this_->getShieldDamage());
85                victim->startReloadCountdown();
86            }
87
88            // visual effects for being hit, depending on whether the shield is hit or not
89            if (owner) //if the owner does not exist (anymore?), no effects are displayed.
90            {
91                if (!victim || (victim && !victim->hasShield()))
92                {
93                    {
94                        ParticleSpawner* effect = new ParticleSpawner(owner->getCreator());
95                        effect->setPosition(entity->getPosition());
96                        effect->setOrientation(entity->getOrientation());
97                        effect->setDestroyAfterLife(true);
98                        effect->setSource("Orxonox/explosion3");
99                        effect->setLifetime(2.0f);
100                    }
101                        // second effect with same condition
102                    {
103                        ParticleSpawner* effect = new ParticleSpawner(owner->getCreator());
104                        effect->setPosition(entity->getPosition());
105                        effect->setOrientation(entity->getOrientation());
106                        effect->setDestroyAfterLife(true);
107                        effect->setSource("Orxonox/smoke4");
108                        effect->setLifetime(3.0f);
109                    }
110                }
111
112                // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead
113                if (victim && victim->hasShield() && (this_->getDamage() > 0 || this_->getShieldDamage() > 0) && victim->getHealth() > 0)
114                {
115                    ParticleSpawner* effect = new ParticleSpawner(owner->getCreator());
116                    effect->setPosition(entity->getPosition());
117                    effect->setOrientation(entity->getOrientation());
118                    effect->setDestroyAfterLife(true);
119                    effect->setSource("Orxonox/Shield");
120                    effect->setLifetime(0.5f);
121                }
122            }
123
124        }
125        return false;
126    }
127}
Note: See TracBrowser for help on using the repository browser.