Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/animated_space_boundaries/src/modules/weapons/projectiles/BasicProjectile.cc @ 10181

Last change on this file since 10181 was 8645, checked in by landauf, 14 years ago

set svn:eol-style to native, removed svn:executable property. no code changes.

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