Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai2/src/modules/weapons/weaponmodes/HsW01.cc @ 8757

Last change on this file since 8757 was 8757, checked in by jo, 13 years ago

ai && weapons. Trying to identify each weapon installed on a spaceship.

  • 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#include "HsW01.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33#include "core/command/Executor.h"
34#include "graphics/Model.h"
35
36#include "weapons/projectiles/Projectile.h"
37#include "weapons/MuzzleFlash.h"
38#include "weaponsystem/Weapon.h"
39#include "weaponsystem/WeaponPack.h"
40#include "weaponsystem/WeaponSystem.h"
41#include "worldentities/WorldEntity.h"
42#include "worldentities/pawns/Pawn.h"
43
44namespace orxonox
45{
46    CreateFactory(HsW01);
47
48    HsW01::HsW01(BaseObject* creator) : WeaponMode(creator)
49    {
50        RegisterObject(HsW01);
51
52        this->reloadTime_ = 0.25;
53        this->damage_ = 0; //default 15
54        this->speed_ = 2500;
55        this->delay_ = 0;
56        this->setMunitionName("LaserMunition");
57
58        this->delayTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&HsW01::shot, this)));
59        this->delayTimer_.stopTimer();
60
61        this->setDefaultSound("sounds/Weapon_HsW01.ogg");
62        this->setName("HSW01");
63    }
64
65    HsW01::~HsW01()
66    {
67    }
68
69    void HsW01::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
71        SUPER(HsW01, XMLPort, xmlelement, mode);
72
73        XMLPortParam(HsW01, "delay", setDelay, getDelay, xmlelement, mode);
74        XMLPortParam(HsW01, "material", setMaterial, getMaterial, xmlelement, mode);
75
76    }
77
78    void HsW01::setMaterial(const std::string& material)
79    {
80        this->material_ = material;
81    }
82
83    std::string& HsW01::getMaterial()
84    {
85        return this->material_;
86    }
87
88    void HsW01::setDelay(float d)
89    {
90        this->delay_ = d;
91        this->delayTimer_.setInterval(this->delay_);
92    }
93
94    float HsW01::getDelay() const
95    {
96        return this->delay_;
97    }
98
99    void HsW01::fire()
100    {
101        this->delayTimer_.startTimer();
102    }
103
104    void HsW01::muendungsfeuer()
105    {
106        MuzzleFlash *muzzleFlash = new MuzzleFlash(this);
107        this->getWeapon()->attach(muzzleFlash);
108        muzzleFlash->setPosition(this->getMuzzleOffset());
109        muzzleFlash->setMaterial(this->material_);
110    }
111
112    /* Creates the projectile object, sets its properties to the HsW01 properties, calls muendungsfeuer()
113     */
114    void HsW01::shot()
115    {
116        assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() );
117        Projectile* projectile = new Projectile(this);
118        Model* model = new Model(projectile);
119        model->setMeshSource("laserbeam.mesh");
120        model->setCastShadows(false);
121        projectile->attach(model);
122        model->setScale(5);
123
124        this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition());
125        projectile->setOrientation(this->getMuzzleOrientation());
126        projectile->setPosition(this->getMuzzlePosition());
127        projectile->setVelocity(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getVelocity() + this->getMuzzleDirection() * this->speed_);
128
129        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
130        projectile->setDamage(this->getDamage());
131        projectile->setShieldDamage(this->getShieldDamage());
132        projectile->setHealthDamage(this->getHealthDamage());
133
134        HsW01::muendungsfeuer();
135    }
136}
Note: See TracBrowser for help on using the repository browser.