Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menue/src/modules/weapons/weaponmodes/HsW01.cc @ 9215

Last change on this file since 9215 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: 4.2 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 HsW01.h
31    @brief Implementation of the HsW01 class.
32*/
33
34#include "HsW01.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/WorldEntity.h"
45#include "worldentities/pawns/Pawn.h"
46
47#include "weapons/projectiles/Projectile.h"
48#include "weapons/MuzzleFlash.h"
49
50namespace orxonox
51{
52    CreateFactory(HsW01);
53
54    HsW01::HsW01(BaseObject* creator) : WeaponMode(creator)
55    {
56        RegisterObject(HsW01);
57
58        this->reloadTime_ = 0.25f;
59        this->damage_ = 0.0f; //default 15
60        this->speed_ = 2500.0f;
61        this->delay_ = 0.0f;
62        this->setMunitionName("LaserMunition");
63
64        this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&HsW01::shot, this)));
65        this->delayTimer_.stopTimer();
66
67        this->setDefaultSound("sounds/Weapon_HsW01.ogg");
68    }
69
70    HsW01::~HsW01()
71    {
72    }
73
74    void HsW01::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        SUPER(HsW01, XMLPort, xmlelement, mode);
77
78        XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode);
79        XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode);
80    }
81
82    /**
83    @brief
84        Set the firing delay.
85    @param delay
86        The firing delay in seconds.
87    */
88    void HsW01::setDelay(float delay)
89    {
90        this->delay_ = delay;
91        this->delayTimer_.setInterval(this->delay_);
92    }
93
94    void HsW01::fire()
95    {
96        this->delayTimer_.startTimer();
97    }
98
99    /**
100    @brief
101        Fires the weapon. Creates a projectile and fires it.
102    */
103    void HsW01::shot()
104    {
105        assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() );
106
107        // Create the projectile.
108        Projectile* projectile = new Projectile(this);
109        Model* model = new Model(projectile);
110        model->setMeshSource("laserbeam.mesh");
111        model->setCastShadows(false);
112        projectile->attach(model);
113        model->setScale(5);
114
115        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
116        projectile->setOrientation(this->getMuzzleOrientation());
117        projectile->setPosition(this->getMuzzlePosition());
118        projectile->setVelocity(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getVelocity() + this->getMuzzleDirection() * this->speed_);
119
120        projectile->setShooter(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
121        projectile->setDamage(this->getDamage());
122        projectile->setShieldDamage(this->getShieldDamage());
123        projectile->setHealthDamage(this->getHealthDamage());
124
125        // Display the muzzle flash.
126        this->HsW01::muzzleflash();
127    }
128
129    /**
130    @brief
131        Displays the muzzle flash.
132    */
133    void HsW01::muzzleflash()
134    {
135        MuzzleFlash *muzzleFlash = new MuzzleFlash(this);
136        this->getWeapon()->attach(muzzleFlash);
137        muzzleFlash->setPosition(this->getMuzzleOffset());
138        muzzleFlash->setMaterial(this->material_);
139    }
140}
Note: See TracBrowser for help on using the repository browser.