Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed some pointer bugs

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