Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

made some changes to munition attaching

  • Property svn:eol-style set to native
File size: 4.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        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    {
86        //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
87        if (this->parentWeaponSystem_)
88        {
89            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
90            if ( munition )
91                this->munition_ = munition;
92            else
93            {
94                //create new munition with identifier
95COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
96                this->munitionIdentifier_ = ClassByString(munitionName);
97                this->munition_ = this->munitionIdentifier_.fabricate(this);
98                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
99            }
100        }
101    }
102
103
104    /*get and set functions
105     *
106     */
107
108    void Weapon::setMunitionType(std::string munitionType)
109    {   
110COUT(0) << "Weapon::setMunitionType (XMLPort) "<< munitionType << std::endl;
111this->munitionType_ = munitionType; }
112
113    const std::string Weapon::getMunitionType()
114    {   return this->munitionType_;  }
115
116    Munition * Weapon::getAttachedMunition(std::string munitionType)
117    {   
118COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
119        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
120COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
121return this->munition_; }
122
123    void Weapon::setBulletLoadingTime(float loadingTime)
124    {   this->bulletLoadingTime_ = loadingTime;   }
125
126    float Weapon::getBulletLoadingTime()
127    {   return this->bulletLoadingTime_;  }
128
129    void Weapon::setMagazineLoadingTime(float loadingTime)
130    {   this->magazineLoadingTime_ = loadingTime;   }
131
132    float Weapon::getMagazineLoadingTime()
133    {   return this->magazineLoadingTime_;  }
134
135    void Weapon::setBulletReadyToShoot(bool b)
136    {   this->bulletReadyToShoot_ = b;   }
137
138    bool Weapon::getBulletReadyToShoot()
139    {   return this->bulletReadyToShoot_;    }
140
141    void Weapon::setMagazineReadyToShoot(bool b)
142    {   this->magazineReadyToShoot_ = b;   }
143
144    bool Weapon::getMagazineReadyToShoot()
145    {   return this->magazineReadyToShoot_;    }
146
147    Timer<Weapon> * Weapon::getBulletTimer()
148    {   return &this->bulletReloadTimer_;   }
149
150    Timer<Weapon> * Weapon::getMagazineTimer()
151    {   return &this->magazineReloadTimer_;   }
152}
Note: See TracBrowser for help on using the repository browser.