Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc @ 2327

Last change on this file since 2327 was 2327, checked in by polakma, 15 years ago

fixed parentWeaponSystem-Pointer bugs

  • Property svn:eol-style set to native
File size: 3.7 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 *      Martin Polak
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33#include "util/Debug.h"
34
35#include "Weapon.h"
36
37namespace orxonox
38{
39    CreateFactory(Weapon);
40
41    Weapon::Weapon(BaseObject* creator) : BaseObject(creator)
42    {
43        RegisterObject(Weapon);
44        this->bulletReadyToShoot_ = true;
45        this->magazineReadyToShoot_ = true;
46    }
47
48    Weapon::~Weapon()
49    {
50    }
51
52
53    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
54    {
55        SUPER(Weapon, XMLPort, xmlelement, mode);
56    }
57
58    void Weapon::fire()
59    {
60
61    }
62
63
64    void Weapon::bulletTimer()
65    {
66        this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
67    }
68    void Weapon::magazineTimer()
69    {
70        this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
71    }
72
73    void Weapon::bulletReloaded()
74    { this->bulletReadyToShoot_ = true; }
75
76    void Weapon::magazineReloaded()
77    { this->magazineReadyToShoot_ = true; }
78
79
80    void Weapon::attachNeededMunition(std::string munitionName)
81    {
82        //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem
83        if ( this->parentWeaponSystem_->getMunitionType(munitionName) )
84            this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionName);
85        else
86        {
87            //create new munition with identifier
88            this->munitionIdentifier_ = ClassByString(munitionName);
89            this->munition_ = this->munitionIdentifier_.fabricate(this);
90            this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
91        }
92    }
93
94
95    /*get and set functions
96     *
97     */
98    Munition * Weapon::getAttachedMunition()
99    {   return this->munition_; }
100
101    void Weapon::setBulletLoadingTime(float loadingTime)
102    {   this->bulletLoadingTime_ = loadingTime;   }
103
104    float Weapon::getBulletLoadingTime()
105    {   return this->bulletLoadingTime_;  }
106
107    void Weapon::setMagazineLoadingTime(float loadingTime)
108    {   this->magazineLoadingTime_ = loadingTime;   }
109
110    float Weapon::getMagazineLoadingTime()
111    {   return this->magazineLoadingTime_;  }
112
113    void Weapon::setBulletReadyToShoot(bool b)
114    {   this->bulletReadyToShoot_ = b;   }
115
116    bool Weapon::getBulletReadyToShoot()
117    {   return this->bulletReadyToShoot_;    }
118
119    void Weapon::setMagazineReadyToShoot(bool b)
120    {   this->magazineReadyToShoot_ = b;   }
121
122    bool Weapon::getMagazineReadyToShoot()
123    {   return this->magazineReadyToShoot_;    }
124
125    Timer<Weapon> * Weapon::getBulletTimer()
126    {   return &this->bulletReloadTimer_;   }
127
128    Timer<Weapon> * Weapon::getMagazineTimer()
129    {   return &this->magazineReloadTimer_;   }
130}
Note: See TracBrowser for help on using the repository browser.