Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

altfire now available

  • Property svn:eol-style set to native
File size: 6.3 KB
RevLine 
[2049]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
[2096]35#include "Weapon.h"
36
[2049]37namespace orxonox
38{
[2327]39    CreateFactory(Weapon);
40
[2391]41    Weapon::Weapon(BaseObject* creator) : PositionableEntity(creator)
[2049]42    {
43        RegisterObject(Weapon);
[2232]44        this->bulletReadyToShoot_ = true;
45        this->magazineReadyToShoot_ = true;
[2337]46        this->parentWeaponSystem_ = 0;
[2398]47        this->attachedToWeaponSlot_ = 0;
[2337]48        this->munition_ = 0;
[2391]49        this->bulletLoadingTime_ = 0;
50        this->magazineLoadingTime_ = 0;
51        this->bReloading_ = false;
[2049]52    }
53
54    Weapon::~Weapon()
55    {
56    }
[2096]57
[2145]58
59    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[2096]60    {
[2232]61        SUPER(Weapon, XMLPort, xmlelement, mode);
[2331]62        XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
[2398]63        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
64        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
[2049]65    }
[2096]66
[2379]67    void Weapon::setWeapon()
68    {
69        this->munition_->fillBullets();
70        this->munition_->fillMagazines();
71    }
72
73
[2145]74    void Weapon::fire()
[2096]75    {
[2379]76COUT(0) << "LaserGun::fire, this=" << this << std::endl;
[2391]77        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
[2379]78        {
79COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
[2391]80COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
[2379]81            this->bulletReadyToShoot_ = false;
[2391]82            if ( this->munition_->bullets() > 0)
[2379]83            {
84                //shoot
85                this->takeBullets();
86                this->createProjectile();
87            }
88            //if there are no bullets, but magazines
[2391]89            else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
[2379]90            {
[2391]91COUT(0) << "LaserGun::fire - no bullets" << std::endl;
[2379]92                this->takeMagazines();
93            }
[2391]94            else
95            {
96COUT(0) << "LaserGun::fire - no magazines" << std::endl;
97                //actions
98            }
[2379]99        }
100        else
101        {
[2393]102COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
[2391]103            //actions
[2379]104        }
105
[2096]106    }
[2232]107
108
[2379]109    void Weapon::bulletTimer(float bulletLoadingTime)
[2203]110    {
[2379]111COUT(0) << "Weapon::bulletTimer started" << std::endl;
[2391]112        this->bReloading_ = true;
[2379]113        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
[2203]114    }
[2379]115    void Weapon::magazineTimer(float magazineLoadingTime)
[2097]116    {
[2379]117COUT(0) << "Weapon::magazineTimer started" << std::endl;
[2391]118        this->bReloading_ = true;
[2379]119        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
[2145]120    }
[2097]121
[2232]122    void Weapon::bulletReloaded()
[2391]123    {
124        this->bReloading_ = false;
125        this->bulletReadyToShoot_ = true;
126    }
[2232]127
128    void Weapon::magazineReloaded()
[2391]129    {
130        this->bReloading_ = false;
[2379]131        this->munition_->fillBullets();
132        this->magazineReadyToShoot_ = true;
[2393]133        this->bulletReadyToShoot_ = true;
[2379]134    }
[2232]135
136
[2203]137    void Weapon::attachNeededMunition(std::string munitionName)
[2145]138    {
[2366]139COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
[2232]140        //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
[2331]141        if (this->parentWeaponSystem_)
[2186]142        {
[2366]143COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
[2331]144            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
145            if ( munition )
146                this->munition_ = munition;
147            else
148            {
149                //create new munition with identifier
[2337]150COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
[2331]151                this->munitionIdentifier_ = ClassByString(munitionName);
152                this->munition_ = this->munitionIdentifier_.fabricate(this);
153                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
154            }
[2186]155        }
[2097]156    }
[2186]157
[2203]158
[2379]159     /*get and set functions
[2203]160     *
161     */
[2331]162
163    void Weapon::setMunitionType(std::string munitionType)
[2398]164    {   this->munitionType_ = munitionType; }
[2331]165
[2354]166    const std::string Weapon::getMunitionType()
[2331]167    {   return this->munitionType_;  }
168
[2232]169    void Weapon::setBulletLoadingTime(float loadingTime)
[2398]170    {   this->bulletLoadingTime_ = loadingTime; }
[2203]171
[2398]172    const float Weapon::getBulletLoadingTime()
[2232]173    {   return this->bulletLoadingTime_;  }
[2203]174
[2232]175    void Weapon::setMagazineLoadingTime(float loadingTime)
[2398]176    {   this->magazineLoadingTime_ = loadingTime; }
[2203]177
[2398]178    const float Weapon::getMagazineLoadingTime()
[2232]179    {   return this->magazineLoadingTime_;  }
180
181
[2398]182    Munition * Weapon::getAttachedMunition(std::string munitionType)
183    {   
184COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
185        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
186COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
187return this->munition_; }
[2232]188
[2379]189    void Weapon::takeBullets() { };
190    void Weapon::createProjectile() { };
191    void Weapon::takeMagazines() { };
192
[2096]193}
Note: See TracBrowser for help on using the repository browser.