Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

changed Weapon::fire and munition reloading

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