Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/SplitGunProjectile.cc @ 11099

Last change on this file since 11099 was 11099, checked in by muemart, 8 years ago

Fix loads of doxygen warnings and other documentation issues

  • Property svn:eol-style set to native
File size: 5.4 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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file SplitGunProjectile.h
31    @brief Implementation of the SplitGunProjectile class.
32*/
33
34#include "SplitGunProjectile.h"
35
36#include "core/CoreIncludes.h"
37#include "core/command/Executor.h"
38#include "util/Convert.h"
39#include "util/Math.h"
40
41namespace orxonox
42{
43    RegisterClass(SplitGunProjectile);
44
45    SplitGunProjectile::SplitGunProjectile(Context* context) : BillboardProjectile(context)
46    {
47        RegisterObject(SplitGunProjectile);
48
49        this->numberOfSplits_ = 0;
50        this->numberOfChilds_ = 0;
51        this->splitTime_ = 1.0f;
52        this->spread_ = 0.2f;
53        this->damageReduction_ = 1.0f;
54    }
55
56    void SplitGunProjectile::setNumberOfSplits(int numberOfSplits)
57    {
58        if (numberOfSplits >= 0)
59        {
60            this->numberOfSplits_ = numberOfSplits;
61        }
62        else
63        {
64            this->numberOfSplits_ = 0;
65        }
66    }
67
68    void SplitGunProjectile::setNumberOfChilds(int numberOfChilds)
69    {
70        if (numberOfChilds >= 0)
71        {
72            this->numberOfChilds_ = numberOfChilds;
73        }
74        else
75        {
76            this->numberOfChilds_ = 0;
77        }
78    }
79
80    /**
81    @brief
82        This function starts a timer that will cause the projectile to split after a time defined by the argument @p splitTime.
83    @param splitTime The time
84    */
85    void SplitGunProjectile::setSplitTime(float splitTime)
86    {
87        if (splitTime >= 0)
88        {
89            this->splitTime_ = splitTime;
90            this->splitTimer_.setTimer(this->splitTime_, false, createExecutor(createFunctor(&SplitGunProjectile::split, this)));
91        }
92        else
93        {
94            this->splitTime_ = 0;
95        }
96    }
97
98    void SplitGunProjectile::setSpread(float spread)
99    {
100        this->spread_ = spread;
101    }
102
103    /**
104    @brief
105        This is the setter function for the damageReduction_ variable. The value of the variable is bounded between 0 and 1.
106    */
107    void SplitGunProjectile::setDamageReduction(float damageReduction)
108    {
109        this->damageReduction_ = (damageReduction >= 0.0f ? damageReduction : 1.0f);
110    }
111
112    /**
113    @brief
114        If this function is called the projectile splits up into many child projectiles. The original projectiles does not get destroyed but it will never split up again.
115    */
116    void SplitGunProjectile::split()
117    {
118        if (numberOfSplits_ > 0)
119        {
120            -- numberOfSplits_;
121
122            // Reduce damage of this projectile
123            this->setDamage(this->getDamage() * this->damageReduction_ / (this->numberOfChilds_+1));
124
125            // Calculate a normalized vector (velocityOffset) that is perpendicluar to the velocity of this projectile. Since there are infinitly many perpendicular vectors a random one is chosen.
126            Vector3 velocityInitial = this->getVelocity();
127            Vector3 velocityOffset = velocityInitial.perpendicular();
128            velocityOffset.normalise();
129            Degree angle = Degree(rnd(0,360));
130            velocityOffset = Quaternion(angle, velocityInitial.normalisedCopy()) * velocityOffset;
131            velocityOffset.normalise();
132
133            // Create as many childs as defined by numberOfChilds_
134            for (int i = 0; i < numberOfChilds_; ++i)
135            {
136                // Every child projectile should fly uniform in different directions -> Rotate the velocityOffset in every iteration
137                velocityOffset = Quaternion(Degree(360.0f/numberOfChilds_), velocityInitial.normalisedCopy()) * velocityOffset;
138                velocityOffset.normalise();
139
140                SplitGunProjectile* projectile = new SplitGunProjectile(this->getContext());               
141
142                projectile->setMaterial(this->getMaterial());
143                projectile->setOrientation(this->getOrientation());
144                projectile->setPosition(this->getPosition());
145                projectile->setVelocity(velocityInitial + spread_*velocityOffset*velocityInitial.length());
146
147                projectile->setNumberOfSplits(this->numberOfSplits_);
148                projectile->setNumberOfChilds(this->numberOfChilds_);
149                projectile->setSplitTime(this->splitTime_);
150                projectile->setSpread(this->spread_);
151                projectile->setDamageReduction(this->damageReduction_);
152
153                projectile->setShooter(this->getShooter());
154                projectile->setDamage(this->getDamage());
155                projectile->setShieldDamage(this->getShieldDamage());
156                projectile->setHealthDamage(this->getHealthDamage());
157            }
158
159            numberOfSplits_ = 0;
160        }
161    }
162}
Note: See TracBrowser for help on using the repository browser.