Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc @ 9241

Last change on this file since 9241 was 8855, checked in by dafrick, 13 years ago

Cleaning up game immersion. Roughly documenting weapons module.

  • Property svn:eol-style set to native
File size: 6.3 KB
RevLine 
[8492]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
[8855]29/**
30    @file BasicProjectile.h
31    @brief Implementation of the BasicProjectile class.
32*/
33
[8492]34#include "BasicProjectile.h"
35
36#include "core/CoreIncludes.h"
37#include "core/GameMode.h"
38#include "core/command/Executor.h"
[8855]39
[8492]40#include "graphics/ParticleSpawner.h"
41
42namespace orxonox
43{
44    /**
45    @brief
46        Constructor. Registers the object and initializes some default values.
47    */
48    BasicProjectile::BasicProjectile() : OrxonoxClass()
49    {
[8855]50        RegisterRootObject(BasicProjectile);// Register the BasicProjectile class to the core
[8492]51
52        this->bDestroy_ = false;
53
[8550]54        // Default damage must be zero, otherwise it would be above zero if no settings are made in the weaponsettings xml file.
55        // same thing for all weaponmodes files
[8767]56        this->damage_ = 0.0f;
57        this->healthdamage_ = 0.0f;
58        this->shielddamage_ = 0.0f;
[8492]59    }
60
61    BasicProjectile::~BasicProjectile()
62    {
63    }
64
[8855]65    /**
66    @brief
67        The function called when a projectile hits another thing.
68        Calls the hit-function, starts the reload countdown, displays visual hit effects defined in Pawn.
69        Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile.
70    @param otherObject
71        A pointer to the object the Projectile has collided against.
72    @param contactPoint
73        A btManifoldPoint indicating the point of contact/impact.
74    @return
75        Returns true if the collision resulted in a successful hit.
76    @see Pawn.h
77    */
78    bool BasicProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint)
[8492]79    {
[8855]80        if (!this->bDestroy_ && GameMode::isMaster())
[8492]81        {
[8855]82            if (otherObject == this->getShooter()) // Prevents you from shooting yourself
[8492]83                return false;
84
[8855]85            this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
86                                    // The projectile is destroyed by its tick()-function (in the following tick).
[8492]87
[8855]88            Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL
[8492]89
[8855]90            WorldEntity* entity = orxonox_cast<WorldEntity*>(this);
91            assert(entity); // The projectile must not be a WorldEntity.
[8492]92
[8855]93            // If visual effects after destruction cause problems, put this block below the effects code block
[8492]94            if (victim)
95            {
[8855]96                victim->hit(this->getShooter(), contactPoint, this->getDamage(), this->getHealthDamage(), this->getShieldDamage());
[8492]97                victim->startReloadCountdown();
98            }
99
[8855]100            // Visual effects for being hit, depending on whether the shield is hit or not
101            if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed.
[8492]102            {
[8855]103                // Damping and explosion effect is only played if the victim is no Pawn (see cast above)
104                // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health
105                if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f)))
[8492]106                {
107                    {
[8855]108                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator());
[8492]109                        effect->setPosition(entity->getPosition());
110                        effect->setOrientation(entity->getOrientation());
111                        effect->setDestroyAfterLife(true);
112                        effect->setSource("Orxonox/explosion3");
113                        effect->setLifetime(2.0f);
114                    }
[8855]115                    // Second effect with same condition
[8492]116                    {
[8855]117                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator());
[8492]118                        effect->setPosition(entity->getPosition());
119                        effect->setOrientation(entity->getOrientation());
120                        effect->setDestroyAfterLife(true);
121                        effect->setSource("Orxonox/smoke4");
122                        effect->setLifetime(3.0f);
123                    }
124                }
[8542]125
126                // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead
[8855]127                if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f)
[8492]128                {
[8855]129                    ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator());
[8492]130                    effect->setDestroyAfterLife(true);
131                    effect->setSource("Orxonox/Shield");
[8645]132                    effect->setLifetime(0.5f);
[8635]133                    victim->attach(effect);
[8492]134                }
135            }
[8855]136            return true;
[8492]137        }
138        return false;
139    }
[8855]140
141    /**
142    @brief
143        Check whether the projectile needs to be destroyed and destroys it if so.
144        Needs to be called in the tick() by every Class directly inheriting from BasicProjectile, to make sure the projectile is destroyed after it has hit something.
145    */
146    void BasicProjectile::destroyCheck(void)
147    {
148        if(GameMode::isMaster() && this->bDestroy_)
149            this->destroy();
150    }
151
152    /**
153    @brief
154        Destroys the object.
155    */
156    void BasicProjectile::destroyObject(void)
157    {
158        if(GameMode::isMaster())
159            this->destroy();
160    }
[8492]161}
Note: See TracBrowser for help on using the repository browser.