Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/clangenb/src/modules/weapons/weaponmodes/EnergyDrink.cc @ 10494

Last change on this file since 10494 was 10494, checked in by clangenb, 9 years ago

branch added

  • Property svn:eol-style set to native
File size: 4.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 *      Hagen Seifert
24 *   Co-authors:
25 *      simonmie
26 *
27 */
28
29/**
30    @file EnergyDrink.h
31    @brief Implementation of the EnergyDrink class.
32*/
33
34#include "EnergyDrink.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "core/command/Executor.h"
39
40#include "graphics/Model.h"
41#include "weaponsystem/Weapon.h"
42#include "weaponsystem/WeaponPack.h"
43#include "weaponsystem/WeaponSystem.h"
44#include "worldentities/pawns/Pawn.h"
45
46#include "weapons/projectiles/Projectile.h"
47#include "weapons/MuzzleFlash.h"
48
49namespace orxonox
50{
51    RegisterClass(EnergyDrink);
52
53    EnergyDrink::EnergyDrink(Context* context) : WeaponMode(context)
54    {
55        RegisterObject(EnergyDrink);
56
57        this->reloadTime_ = 0.25f;
58        this->damage_ = 0.0f;
59        this->speed_ = 750.0f;
60        this->delay_ = 0.0f;
61        this->setMunitionName("FusionMunition");
62
63        this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&EnergyDrink::shot, this)));
64        this->delayTimer_.stopTimer();
65    }
66
67    void EnergyDrink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
68    {
69        SUPER(EnergyDrink, XMLPort, xmlelement, mode);
70
71        XMLPortParam(EnergyDrink, "delay", setDelay, getDelay, xmlelement, mode);
72        XMLPortParam(EnergyDrink, "material", setMaterial, getMaterial, xmlelement, mode);
73    }
74
75    /**
76    @brief
77        Sets the delay with which is fired.
78    @param delay
79        The delay in seconds.
80    */
81    void EnergyDrink::setDelay(float delay)
82    {
83        this->delay_ = delay;
84        this->delayTimer_.setInterval(this->delay_);
85    }
86
87    /**
88    @brief
89        Fires the weapon.
90    */
91    void EnergyDrink::fire()
92    {
93        this->delayTimer_.startTimer();
94    }
95
96    /**
97    @brief
98        Executes the shot, be creating the projectile and sending it on its way.
99    */
100    void EnergyDrink::shot()
101    {
102        // Create the projectile
103        Projectile* projectile = new Projectile(this->getContext());
104        Model* model = new Model(projectile->getContext());
105        model->setMeshSource("can.mesh");
106        model->setCastShadows(false);
107        projectile->attach(model);
108        model->setScale(5);
109
110        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
111        projectile->setOrientation(this->getMuzzleOrientation());
112        projectile->setPosition(this->getMuzzlePosition());
113        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
114
115        projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
116        projectile->setDamage(this->getDamage());
117        projectile->setShieldDamage(this->getShieldDamage());
118        projectile->setHealthDamage(this->getHealthDamage());
119
120        // Display a muzzle flash.
121        this->muzzleflash();
122    }
123
124    /**
125    @brief
126        Displays a muzzle flash.
127    */
128    void EnergyDrink::muzzleflash()
129    {
130        MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext());
131        this->getWeapon()->attach(muzzleFlash);
132        muzzleFlash->setPosition(this->getMuzzleOffset());
133        muzzleFlash->setMaterial(this->material_);
134    }
135}
Note: See TracBrowser for help on using the repository browser.