Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2331 was 2331, checked in by polakma, 16 years ago

fixed attaching

  • Property svn:eol-style set to native
File size: 4.1 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        XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
57    }
58
59    void Weapon::fire()
60    {
61
62    }
63
64
65    void Weapon::bulletTimer()
66    {
67        this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
68    }
69    void Weapon::magazineTimer()
70    {
71        this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
72    }
73
74    void Weapon::bulletReloaded()
75    { this->bulletReadyToShoot_ = true; }
76
77    void Weapon::magazineReloaded()
78    { this->magazineReadyToShoot_ = true; }
79
80
81    void Weapon::attachNeededMunition(std::string munitionName)
82    {
83        //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
84        if (this->parentWeaponSystem_)
85        {
86            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
87            if ( munition )
88                this->munition_ = munition;
89            else
90            {
91                //create new munition with identifier
92                this->munitionIdentifier_ = ClassByString(munitionName);
93                this->munition_ = this->munitionIdentifier_.fabricate(this);
94                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
95            }
96        }
97    }
98
99
100    /*get and set functions
101     *
102     */
103
104    void Weapon::setMunitionType(std::string munitionType)
105    {   this->munitionType_ = munitionType; }
106
107    std::string Weapon::getMunitionType()
108    {   return this->munitionType_;  }
109
110    Munition * Weapon::getAttachedMunition()
111    {   return this->munition_; }
112
113    void Weapon::setBulletLoadingTime(float loadingTime)
114    {   this->bulletLoadingTime_ = loadingTime;   }
115
116    float Weapon::getBulletLoadingTime()
117    {   return this->bulletLoadingTime_;  }
118
119    void Weapon::setMagazineLoadingTime(float loadingTime)
120    {   this->magazineLoadingTime_ = loadingTime;   }
121
122    float Weapon::getMagazineLoadingTime()
123    {   return this->magazineLoadingTime_;  }
124
125    void Weapon::setBulletReadyToShoot(bool b)
126    {   this->bulletReadyToShoot_ = b;   }
127
128    bool Weapon::getBulletReadyToShoot()
129    {   return this->bulletReadyToShoot_;    }
130
131    void Weapon::setMagazineReadyToShoot(bool b)
132    {   this->magazineReadyToShoot_ = b;   }
133
134    bool Weapon::getMagazineReadyToShoot()
135    {   return this->magazineReadyToShoot_;    }
136
137    Timer<Weapon> * Weapon::getBulletTimer()
138    {   return &this->bulletReloadTimer_;   }
139
140    Timer<Weapon> * Weapon::getMagazineTimer()
141    {   return &this->magazineReloadTimer_;   }
142}
Note: See TracBrowser for help on using the repository browser.