Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapons/src/orxonox/objects/weaponsystem/projectiles/Projectile.cc @ 2969

Last change on this file since 2969 was 2918, checked in by landauf, 16 years ago

Added many new features in the Munition class:

  • there are now 3 modes: a) every weapon has it's own magazine b) all weapons use the same magazin c) no magazines, just a big munition pool
  • the Munition class handles the reloading of the magazine

Split the Weapon class into Weapon and WeaponMode. WeaponMode creates the fire of the Weapon. A weapon can own several WeaponModes (for example primary and secondary fire). But it's also possible to have a weapon with several muzzles which all fire at the same time (there's a WeaponMode for each muzzle).

Renamed LaserGun to LaserFire and Fusion to FusionFire. They inherit now from WeaponMode.

Changed the code in the Weapon class to use the new Munition functionality.

Added ReplenishingMunition, a subclass of Munition that replenishes itself (used for LaserGunMunition).

Added a reload command to reload magazines.

  • Property svn:eol-style set to native
File size: 4.1 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Projectile.h"
31
32#include <OgreBillboard.h>
33
34#include "core/CoreIncludes.h"
35#include "core/Executor.h"
36#include "core/ConfigValueIncludes.h"
37#include "core/Iterator.h"
38#include "tools/ParticleInterface.h"
39
40#include "objects/worldentities/Model.h"
41#include "objects/worldentities/ParticleSpawner.h"
42#include "objects/collisionshapes/SphereCollisionShape.h"
43#include "core/GameMode.h"
44
45namespace orxonox
46{
47    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator)
48    {
49        RegisterObject(Projectile);
50
51        this->setConfigValues();
52        this->bDestroy_ = false;
53        this->owner_ = 0;
54
55        // Get notification about collisions
56
57        if (GameMode::isMaster())
58        {
59            this->enableCollisionCallback();
60
61            this->setCollisionType(Kinematic);
62
63            SphereCollisionShape* shape = new SphereCollisionShape(this);
64            shape->setRadius(10);
65            this->attachCollisionShape(shape);
66
67            this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
68        }
69    }
70
71    Projectile::~Projectile()
72    {
73    }
74
75    void Projectile::setConfigValues()
76    {
77        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
78        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
79    }
80
81
82    void Projectile::tick(float dt)
83    {
84        SUPER(Projectile, tick, dt);
85
86        if (!this->isActive())
87            return;
88
89        if (this->bDestroy_)
90            delete this;
91    }
92
93    void Projectile::destroyObject()
94    {
95        if (GameMode::isMaster())
96            delete this;
97    }
98
99    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
100    {
101        if (!this->bDestroy_ && GameMode::isMaster())
102        {
103            if (otherObject == this->owner_)
104                return true;
105
106            this->bDestroy_ = true;
107
108            if (this->owner_)
109            {
110                {
111                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
112                    effect->setPosition(this->getPosition());
113                    effect->setOrientation(this->getOrientation());
114                    effect->setDestroyAfterLife(true);
115                    effect->setSource("Orxonox/explosion3");
116                    effect->setLifetime(2.0f);
117                }
118                {
119                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
120                    effect->setPosition(this->getPosition());
121                    effect->setOrientation(this->getOrientation());
122                    effect->setDestroyAfterLife(true);
123                    effect->setSource("Orxonox/smoke4");
124                    effect->setLifetime(3.0f);
125                }
126            }
127
128            Pawn* victim = dynamic_cast<Pawn*>(otherObject);
129            if (victim)
130                victim->damage(this->damage_, this->owner_);
131        }
132        return false;
133    }
134
135    void Projectile::destroyedPawn(Pawn* pawn)
136    {
137        if (this->owner_ == pawn)
138            this->owner_ = 0;
139    }
140}
Note: See TracBrowser for help on using the repository browser.