Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2008, 2:10:11 AM (16 years ago)
Author:
landauf
Message:

merged weapon2 branch to presentation

Location:
code/branches/presentation
Files:
23 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/weaponSystem/CMakeLists.txt

    r2131 r2493  
    22  Munition.cc
    33  Weapon.cc
     4  WeaponPack.cc
    45  WeaponSet.cc
    56  WeaponSlot.cc
     
    78)
    89
    9 #ADD_SOURCE_DIRECTORY(SRC_FILES munitions)
    10 #ADD_SOURCE_DIRECTORY(SRC_FILES projectiles)
    11 #ADD_SOURCE_DIRECTORY(SRC_FILES weapons)
     10ADD_SOURCE_DIRECTORY(SRC_FILES munitions)
     11ADD_SOURCE_DIRECTORY(SRC_FILES projectiles)
     12ADD_SOURCE_DIRECTORY(SRC_FILES weapons)
    1213
    1314ADD_SOURCE_FILES(SRC_FILES)
  • code/branches/presentation/src/orxonox/objects/weaponSystem/Munition.cc

    r2097 r2493  
    3737namespace orxonox
    3838{
     39    CreateFactory(Munition);
     40
    3941    Munition::Munition(BaseObject* creator) : BaseObject(creator)
    4042    {
     
    4648    }
    4749
     50    unsigned int Munition::bullets()
     51    {
     52        if (this->bullets_ > 0)
     53            return bullets_;
     54        else
     55            return 0;
     56    }
     57
     58    unsigned int Munition::magazines()
     59    {
     60        if (this->magazines_ > 0)
     61            return magazines_;
     62        else
     63            return 0;
     64    }
     65
     66    void Munition::setMaxBullets(unsigned int amount)
     67    { this->maxBullets_ = amount; }
     68
     69    void Munition::setMaxMagazines(unsigned int amount)
     70    { this->maxMagazines_ = amount; }
     71
     72    void Munition::removeBullets(unsigned int amount)
     73    {
     74        if ( this->bullets_ != 0 )
     75            this->bullets_ = this->bullets_ - amount;
     76    }
     77
     78    void Munition::removeMagazines(unsigned int amount)
     79    {
     80        if ( this->magazines_ != 0 )
     81            this->magazines_ = this->magazines_ - amount;
     82    }
     83
     84    void Munition::addBullets(unsigned int amount)
     85    {
     86        if ( this->bullets_ == this->maxBullets_ )
     87        {
     88            //cannot add bullets to actual magazine
     89        }
     90        else
     91            this->bullets_ = this->bullets_ + amount;
     92    }
     93
     94    void Munition::addMagazines(unsigned int amount)
     95    {
     96        if ( this->magazines_ == this->maxMagazines_ )
     97        {
     98            //no more capacity for another magazine
     99        }
     100        else
     101            this->magazines_ = this->magazines_ + amount;
     102    }
     103
     104
     105    void Munition::fillBullets()
     106    {
     107//COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl;
     108        this->bullets_ = this->maxBullets_;
     109    }
     110
     111    void Munition::fillMagazines()
     112    {
     113        this->magazines_ = this->maxMagazines_;
     114    }
     115
    48116    void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    49117    {
    50 
     118        SUPER(Munition, XMLPort, xmlelement, mode);
    51119    }
    52120
  • code/branches/presentation/src/orxonox/objects/weaponSystem/Munition.h

    r2106 r2493  
    3434#include "core/BaseObject.h"
    3535
     36#include "Weapon.h"
     37
    3638
    3739namespace orxonox
     
    4547            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4648
     49            void setMaxBullets(unsigned int amount);
     50            void setMaxMagazines(unsigned int amount);
     51
     52            void fillBullets();
     53            void fillMagazines();
     54
     55            unsigned int bullets();
     56            unsigned int magazines();
     57
     58            void removeBullets(unsigned int k);
     59            void removeMagazines(unsigned int k);
     60            void addBullets(unsigned int k);
     61            void addMagazines(unsigned int k);
    4762
    4863        private:
    4964
    50 
     65        protected:
     66            unsigned int bullets_;
     67            unsigned int magazines_;
     68            unsigned int maxBullets_;
     69            unsigned int maxMagazines_;
    5170    };
    5271}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/Weapon.cc

    r2098 r2493  
    3737namespace orxonox
    3838{
    39     Weapon::Weapon(BaseObject* creator) : BaseObject(creator)
     39    CreateFactory(Weapon);
     40
     41    Weapon::Weapon(BaseObject* creator) : StaticEntity(creator)
    4042    {
    4143        RegisterObject(Weapon);
    42 
    43         this->loadingTime_ = 0;
     44        this->bulletReadyToShoot_ = true;
     45        this->magazineReadyToShoot_ = true;
     46        this->parentWeaponSystem_ = 0;
     47        this->attachedToWeaponSlot_ = 0;
    4448        this->munition_ = 0;
    45 
     49        this->bulletLoadingTime_ = 0;
     50        this->magazineLoadingTime_ = 0;
     51        this->bReloading_ = false;
    4652    }
    4753
     
    5056    }
    5157
    52     void Weapon::addMunition()
     58
     59    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5360    {
     61        SUPER(Weapon, XMLPort, xmlelement, mode);
     62        XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
     63        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
     64        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
     65    }
     66
     67    void Weapon::setWeapon()
     68    {
     69        this->munition_->fillBullets();
     70        this->munition_->fillMagazines();
     71    }
     72
     73
     74    void Weapon::fire()
     75    {
     76//COUT(0) << "LaserGun::fire, this=" << this << std::endl;
     77        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
     78        {
     79//COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
     80//COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
     81            this->bulletReadyToShoot_ = false;
     82            if ( this->munition_->bullets() > 0)
     83            {
     84                //shoot
     85                this->takeBullets();
     86                this->createProjectile();
     87            }
     88            //if there are no bullets, but magazines
     89            else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
     90            {
     91//COUT(0) << "LaserGun::fire - no bullets" << std::endl;
     92                this->takeMagazines();
     93            }
     94            else
     95            {
     96//COUT(0) << "LaserGun::fire - no magazines" << std::endl;
     97                //actions
     98            }
     99        }
     100        else
     101        {
     102//COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
     103            //actions
     104        }
    54105
    55106    }
    56107
    57     void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     108
     109    void Weapon::bulletTimer(float bulletLoadingTime)
    58110    {
    59 
     111//COUT(0) << "Weapon::bulletTimer started" << std::endl;
     112        this->bReloading_ = true;
     113        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
     114    }
     115    void Weapon::magazineTimer(float magazineLoadingTime)
     116    {
     117//COUT(0) << "Weapon::magazineTimer started" << std::endl;
     118        this->bReloading_ = true;
     119        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
    60120    }
    61121
    62     void Weapon::fire()
     122    void Weapon::bulletReloaded()
    63123    {
     124        this->bReloading_ = false;
     125        this->bulletReadyToShoot_ = true;
     126    }
    64127
     128    void Weapon::magazineReloaded()
     129    {
     130        this->bReloading_ = false;
     131        this->munition_->fillBullets();
     132        this->magazineReadyToShoot_ = true;
     133        this->bulletReadyToShoot_ = true;
    65134    }
     135
     136
     137    void Weapon::attachNeededMunition(std::string munitionName)
     138    {
     139//COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
     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
     141        if (this->parentWeaponSystem_)
     142        {
     143//COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
     144            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
     145            if ( munition )
     146                this->munition_ = munition;
     147            else
     148            {
     149                //create new munition with identifier
     150//COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
     151                this->munitionIdentifier_ = ClassByString(munitionName);
     152                this->munition_ = this->munitionIdentifier_.fabricate(this);
     153                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
     154            }
     155        }
     156    }
     157
     158
     159     /*get and set functions
     160     *
     161     */
     162
     163    void Weapon::setMunitionType(std::string munitionType)
     164    {   this->munitionType_ = munitionType; }
     165
     166    const std::string Weapon::getMunitionType()
     167    {   return this->munitionType_;  }
     168
     169    void Weapon::setBulletLoadingTime(float loadingTime)
     170    {   this->bulletLoadingTime_ = loadingTime; }
     171
     172    const float Weapon::getBulletLoadingTime()
     173    {   return this->bulletLoadingTime_;  }
     174
     175    void Weapon::setMagazineLoadingTime(float loadingTime)
     176    {   this->magazineLoadingTime_ = loadingTime; }
     177
     178    const float Weapon::getMagazineLoadingTime()
     179    {   return this->magazineLoadingTime_;  }
     180
     181
     182    Munition * Weapon::getAttachedMunition(std::string munitionType)
     183    {
     184//COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
     185        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
     186//COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
     187        return this->munition_;
     188    }
     189
     190    void Weapon::takeBullets() { };
     191    void Weapon::createProjectile() { };
     192    void Weapon::takeMagazines() { };
     193
    66194}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/Weapon.h

    r2106 r2493  
    3333
    3434#include "core/BaseObject.h"
     35#include "tools/BillboardSet.h"
     36#include "tools/Timer.h"
     37#include "core/Identifier.h"
    3538
     39#include "WeaponSystem.h"
     40#include "Munition.h"
     41
     42#include "objects/worldentities/StaticEntity.h"
    3643
    3744namespace orxonox
    3845{
    39     class _OrxonoxExport Weapon : public BaseObject
     46    class _OrxonoxExport Weapon : public StaticEntity
    4047    {
    4148        public:
     
    4552            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4653
    47             void addMunition();
    4854            virtual void fire();
     55            void attachNeededMunition(std::string munitionType);
     56            Munition * getAttachedMunition(std::string munitiontype);
     57
     58            //reloading
     59            void bulletTimer(float bulletLoadingTime);
     60            void magazineTimer(float magazineLoadingTime);
     61            void bulletReloaded();
     62            void magazineReloaded();
     63
     64            virtual void setMunitionType(std::string munitionType);
     65            virtual const std::string getMunitionType();
     66            virtual void setBulletLoadingTime(float loadingTime);
     67            virtual const float getBulletLoadingTime();
     68            virtual void setMagazineLoadingTime(float loadingTime);
     69            virtual const float getMagazineLoadingTime();
     70
     71            virtual void takeBullets();
     72            virtual void takeMagazines();
     73            virtual void createProjectile();
     74
     75            inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
     76                { this->parentWeaponSystem_=parentWeaponSystem; };
     77            inline WeaponSystem * getParentWeaponSystem()
     78                { return this->parentWeaponSystem_; };
     79
     80            inline void setAttachedToWeaponSlot(WeaponSlot * wSlot)
     81                { this->attachedToWeaponSlot_ = wSlot; }
     82            inline WeaponSlot * getAttachedToWeaponSlot()
     83                { return this->attachedToWeaponSlot_; }
     84
     85            virtual void setWeapon();
    4986
    5087        private:
    51             int loadingTime_;
    52             Munition *munition_;
    5388
     89        protected:
     90            bool bReloading_;
     91            bool bulletReadyToShoot_;
     92            bool magazineReadyToShoot_;
     93            float bulletLoadingTime_;
     94            float magazineLoadingTime_;
     95            std::string munitionType_;
    5496
     97            WeaponSlot * attachedToWeaponSlot_;
     98            Munition * munition_;
     99            WeaponSystem * parentWeaponSystem_;
    55100
     101            SubclassIdentifier<Munition> munitionIdentifier_;
     102
     103            Timer<Weapon> bulletReloadTimer_;
     104            Timer<Weapon> magazineReloadTimer_;
    56105    };
    57106}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2489 r2493  
    6363        for (int i=0; i < (int) this->weapons_.size(); i++)
    6464        {
    65 COUT(0) << "WeaponPack::fire (attached from WeaponSet)  from Weapon: "<< i << std::endl;
     65//COUT(0) << "WeaponPack::fire (attached from WeaponSet)  from Weapon: "<< i << std::endl;
    6666            this->weapons_[i]->getAttachedToWeaponSlot()->fire();
    6767        }
     
    8383    void WeaponPack::setFireMode(unsigned int firemode)
    8484    {
    85 COUT(0) << "WeaponPack::setFireMode " << std::endl;
     85//COUT(0) << "WeaponPack::setFireMode " << std::endl;
    8686        this->firemode_ = firemode;
    8787    }
     
    9494    void WeaponPack::addWeapon(Weapon * weapon)
    9595    {
    96 COUT(0) << "WeaponPack::addWeapon:" << weapon << "   munition " << weapon->getMunitionType() << std::endl;
     96//COUT(0) << "WeaponPack::addWeapon:" << weapon << "   munition " << weapon->getMunitionType() << std::endl;
    9797        this->weapons_.push_back(weapon);
    9898    }
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2098 r2493  
    3333#include "core/XMLPort.h"
    3434#include "util/Debug.h"
     35#include "objects/worldentities/pawns/Pawn.h"
    3536
    3637#include "WeaponSet.h"
     38#include "WeaponPack.h"
    3739
    3840namespace orxonox
    3941{
     42    CreateFactory(WeaponSet);
     43
    4044    WeaponSet::WeaponSet(BaseObject* creator, int k) : BaseObject(creator)
    4145    {
     
    4347
    4448        this->parentWeaponSystem_ = 0;
    45 
    46         for (int i=0;i<k;i++)
    47         {
    48             attachWeaponSlot(new WeaponSlot(this));
    49         }
     49        this->attachedWeaponPack_ = 0;
    5050    }
    5151
     
    5454    }
    5555
    56     //Vorwärtsdeklaration
    57     WeaponSystem * parentWeaponSystem_;
     56    void WeaponSet::attachWeaponPack(WeaponPack *wPack)
     57    {
     58//COUT(0) << "WeaponSet::attachWeaponPack" << std::endl;
     59//COUT(0) << "........ parentWeaponSystem_=" << this->parentWeaponSystem_ << std::endl;
     60//COUT(0) << "........ this->parentWeaponSystem_->getWeaponSlotSize()" << this->parentWeaponSystem_->getWeaponSlotSize() << std::endl;
     61//COUT(0) << "........ wPack->getSize()" << wPack->getSize() << std::endl;
     62        if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) )
     63        {
     64//COUT(0) << "WeaponSet::attachWeaponPack after if" << std::endl;
     65            this->attachedWeaponPack_ = wPack;
     66            int wPackWeapon = 0;    //WeaponCounter for Attaching
     67            //should be possible to choose which slot to use
     68            for (  int i=0; i < wPack->getSize() ; i++  )
     69            {
     70                //at the moment this function only works for one weaponPack in the entire WeaponSystem...
     71                if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full
     72                {
     73//COUT(0) << "WeaponSet::attachWeaponPack attaching Weapon" << std::endl;
     74                    this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) );
     75                    this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
     76                    this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );
     77                    wPackWeapon++;
     78                }
     79                else
     80                {
     81                    for (int k=0; k < this->parentWeaponSystem_->getWeaponSlotSize(); k++)
     82                    {
     83                        if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 )
     84                        {
     85//COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl;
     86                            this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) );
     87                            this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
     88                            this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );
     89                            wPackWeapon++;
     90                        }
     91                    }
     92                }
     93            }
     94        }
     95    }
    5896
    59     void WeaponSet::attachWeaponSlot(WeaponSlot *wSlot)
    60     {
    61         this->weaponSlots_.push_back(wSlot);
    62     }
    6397
    6498    void WeaponSet::fire()
    6599    {
    66         for (int i=0; i < (int) this->weaponSlots_.size(); i++)
    67         {
    68             this->weaponSlots_[i]->fire();
    69         }
     100        //fires all WeaponSlots available for this weaponSet attached from the WeaponPack
     101//COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl;
     102        if (this->attachedWeaponPack_)
     103            this->attachedWeaponPack_->fire();
    70104    }
    71105
    72     WeaponSlot * WeaponSet::getWeaponSlotPointer(unsigned int n)
    73     {
    74         if (n < this->weaponSlots_.size())
    75             return this->weaponSlots_[n];
    76         else
    77             return 0;
    78     }
     106    void WeaponSet::setFireMode(const unsigned int firemode)
     107    {   this->firemode_ = firemode; }
    79108
     109    const unsigned int WeaponSet::getFireMode() const
     110    {   return this->firemode_; }
    80111
    81112    void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    82113    {
    83 
     114        SUPER(WeaponSet, XMLPort, xmlelement, mode);
     115        XMLPortParam(WeaponSet, "firemode", setFireMode, getFireMode, xmlelement, mode);
    84116    }
    85117
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSet.h

    r2106 r2493  
    4848            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4949
    50             void attachWeaponSlot(WeaponSlot *wSlot);
     50            void attachWeaponPack(WeaponPack *wPack);
    5151            void fire();
    52             WeaponSlot * getWeaponSlotPointer(unsigned int n);
     52
     53            void setFireMode(const unsigned int firemode);
     54            const unsigned int getFireMode() const;
    5355
    5456            inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
     
    5860
    5961        private:
    60             std::vector<WeaponSlot *> weaponSlots_;
    6162            WeaponSystem *parentWeaponSystem_;
     63            std::vector<WeaponSlot *> setWeaponSlots_;
     64            unsigned int firemode_;
     65            WeaponPack * attachedWeaponPack_;
    6266    };
    6367}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2098 r2493  
    3636
    3737
    38 
    3938namespace orxonox
    4039{
    41     WeaponSlot::WeaponSlot(BaseObject* creator) : BaseObject(creator)
     40    CreateFactory(WeaponSlot);
     41
     42    WeaponSlot::WeaponSlot(BaseObject* creator) : StaticEntity(creator)
    4243    {
    4344        RegisterObject(WeaponSlot);
    4445
    4546        this->unlimitedAmmo_ = false;
    46 
    4747        this->attachedWeapon_ = 0;
    48         this->parentWeaponSet_ = 0;
     48        this->setObjectMode(0x0);
    4949    }
    5050
     
    5353    }
    5454
    55     void WeaponSlot::attachWeapon(Weapon *weaponName)
    56     {
    57 
    58     }
    5955
    6056    /*sets the munition type
     
    6763    }
    6864
     65
    6966    void WeaponSlot::fire()
    7067    {
     68        if ( this->attachedWeapon_ )
     69//COUT(0) << "WeaponSlot::fire" << std::endl;
     70        this->attachedWeapon_->fire();
     71    }
    7172
    72     }
    7373
    7474    void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7575    {
     76        SUPER(WeaponSlot, XMLPort, xmlelement, mode);
     77    }
    7678
     79    void WeaponSlot::attachWeapon(Weapon *weapon)
     80    {
     81        this->attachedWeapon_ = weapon;
     82        weapon->setAttachedToWeaponSlot(this);
     83//COUT(0) << "WeaponSlot::attachWeapon position=" << this->getWorldPosition() << std::endl;
     84        weapon->setPosition(this->getPosition());
     85    }
     86
     87    Weapon * WeaponSlot::getAttachedWeapon() const
     88    {
     89        return this->attachedWeapon_;
    7790    }
    7891}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSlot.h

    r2106 r2493  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "core/BaseObject.h"
    35 
    36 
    3734#include "Weapon.h"
    38 
     35#include "objects/worldentities/StaticEntity.h"
    3936
    4037namespace orxonox
    4138{
    42     class _OrxonoxExport WeaponSlot : public BaseObject
     39    class _OrxonoxExport WeaponSlot : public StaticEntity
    4340    {
    4441        public:
     
    4845            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4946
    50             void attachWeapon(Weapon *weaponName);
     47            void attachWeapon(Weapon *weapon);
     48            Weapon * getAttachedWeapon() const;
    5149            void setAmmoType(bool isUnlimited);
    5250            void fire();
    5351
    54             inline void setParentWeaponSet(WeaponSet *parentWeaponSet)
    55                 { parentWeaponSet_=parentWeaponSet; }
    56             inline WeaponSet * getParentWeaponSet()
    57                 { return parentWeaponSet_; }
    58 
     52            inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
     53                { parentWeaponSystem_=parentWeaponSystem; }
     54            inline WeaponSystem * getParentWeaponSystem()
     55                { return parentWeaponSystem_; }
    5956
    6057
     
    6360            bool unlimitedAmmo_;
    6461
    65             WeaponSet *parentWeaponSet_;
     62            WeaponSystem *parentWeaponSystem_;
    6663    };
    6764}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2492 r2493  
    3737#include "WeaponSystem.h"
    3838
     39
    3940/* WEAPONSYSTEM
    4041 * creates the WeaponSystem and the ability to use weapons and munition
     
    4546namespace orxonox
    4647{
     48    CreateFactory(WeaponSystem);
     49
    4750    WeaponSystem::WeaponSystem(BaseObject* creator) : BaseObject(creator)
    4851    {
     
    5053
    5154        this->activeWeaponSet_ = 0;
    52         this->parentSpaceShip_ = 0;
     55        this->parentPawn_ = 0;
    5356    }
    5457
     
    5760    }
    5861
    59     //creates empty weaponSet
     62    void WeaponSystem::attachWeaponPack(WeaponPack *wPack, unsigned int firemode)
     63    {
     64        if (firemode < this->weaponSets_.size())
     65            this->weaponSets_[firemode]->attachWeaponPack(wPack);
     66        this->weaponPacks_.push_back(wPack);
     67    }
     68
     69    void WeaponSystem::attachWeaponSlot(WeaponSlot *wSlot)
     70    {
     71        wSlot->setParentWeaponSystem(this);
     72        this->weaponSlots_.push_back(wSlot);
     73    }
     74
    6075    void WeaponSystem::attachWeaponSet(WeaponSet *wSet)
    6176    {
     77        wSet->setParentWeaponSystem(this);
    6278        this->weaponSets_.push_back(wSet);
    63         wSet->setParentWeaponSystem(this);
    6479    }
    6580
     81    void WeaponSystem::setNewMunition(std::string munitionType, Munition * munitionToAdd)
     82    {
     83        this->munitionSet_[munitionType] = munitionToAdd;
     84    }
     85
     86    //returns the Pointer to the munitionType
     87    Munition * WeaponSystem::getMunitionType(std::string munitionType)
     88    {
     89//COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl;
     90        std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
     91        if (it != this->munitionSet_.end())
     92            return it->second;
     93        else
     94            return 0;
     95    }
     96
     97
     98/*
    6699    //the first weaponSet is at n=0
    67100    void WeaponSystem::setActiveWeaponSet(unsigned int n)
     
    69102        if (n < this->weaponSets_.size())
    70103            this->activeWeaponSet_ = this->weaponSets_[n];
     104        else
     105            this->activeWeaponSet_ = this->weaponSets_[0];
     106    }
     107*/
     108
     109
     110    //n is the n'th weaponSet, starting with zero
     111    //SpaceShip.cc only needs to have the keybinding to a specific Set-number n
     112    void WeaponSystem::fire(WeaponMode::Enum n)
     113    {
     114        int set = 0;
     115        switch (n)
     116        {
     117            case WeaponMode::fire:
     118                set = 0;
     119                break;
     120            case WeaponMode::altFire:
     121                set = 1;
     122                break;
     123            case WeaponMode::altFire2:
     124                set = 2;
     125                break;
     126        }
     127//COUT(0) << "WeaponSystem::fire" << std::endl;
     128        if (set < (int)this->weaponSets_.size())
     129//COUT(0) << "WeaponSystem::fire - after if" << std::endl;
     130            this->weaponSets_[set]->fire();
    71131    }
    72132
    73     //n is the n'th weaponSet, starting with zero
    74     //Spaceship.cc only needs to have the keybinding to a specific Set-number n
    75     void WeaponSystem::fire(unsigned int n)
    76     {
    77         if (n < this->weaponSets_.size())
    78             this->weaponSets_[n]->fire();
    79     }
    80 
    81     void WeaponSystem::fire()
    82     {
    83         if (this->activeWeaponSet_)
    84             this->activeWeaponSet_->fire();
    85     }
    86133
    87134    WeaponSet * WeaponSystem::getWeaponSetPointer(unsigned int n)
     
    93140    }
    94141
     142    WeaponSlot * WeaponSystem::getWeaponSlotPointer(unsigned int n)
     143    {
     144        if (n < this->weaponSlots_.size())
     145            return this->weaponSlots_[n];
     146        else
     147            return 0;
     148    }
     149
     150    WeaponPack * WeaponSystem::getWeaponPackPointer(unsigned int n)
     151    {
     152        if (n < this->weaponPacks_.size())
     153            return this->weaponPacks_[n];
     154        else
     155            return 0;
     156    }
     157
    95158    void WeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    96159    {
    97 
     160        SUPER(WeaponSystem, XMLPort, xmlelement, mode);
    98161    }
    99162
  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2492 r2493  
    3636
    3737#include "WeaponSet.h"
     38#include "WeaponPack.h"
    3839
    3940namespace orxonox
    4041{
     42
    4143    class _OrxonoxExport WeaponSystem : public BaseObject
    4244    {
     
    4749            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4850
     51            void attachWeaponSlot(WeaponSlot *wSlot);
    4952            void attachWeaponSet(WeaponSet *wSet);
    50             void fire();
    51             void fire(unsigned int n);
    52             void setActiveWeaponSet(unsigned int n);
     53            //void fire();
     54            void fire(WeaponMode::Enum fireMode);
     55            //void setActiveWeaponSet(unsigned int n);
     56            void attachWeaponPack(WeaponPack * wPack, unsigned int firemode);
    5357            WeaponSet * getWeaponSetPointer(unsigned int n);
     58            WeaponSlot * getWeaponSlotPointer(unsigned int n);
     59            WeaponPack * getWeaponPackPointer(unsigned int n);
     60            void setNewMunition(std::string munitionType, Munition * munitionToAdd);
     61            Munition * getMunitionType(std::string munitionType);
    5462
    55             inline void setParentSpaceShip(SpaceShip *parentSpaceShip)
    56                 { parentSpaceShip_=parentSpaceShip; }
    57             inline SpaceShip * getParentSpaceShip()
    58                 { return parentSpaceShip_; }
     63            inline void setParentPawn(Pawn *parentPawn)
     64                { parentPawn_=parentPawn; }
     65            inline Pawn * getParentPawn()
     66                { return parentPawn_; }
    5967
     68            inline int getWeaponSlotSize()
     69                { return this->weaponSlots_.size(); }
    6070
    6171        private:
    6272            std::vector<WeaponSet *> weaponSets_;
     73            std::vector<WeaponSlot *> weaponSlots_;
     74            std::vector<WeaponPack *> weaponPacks_;
     75            std::map<std::string, Munition *> munitionSet_;
    6376            WeaponSet *activeWeaponSet_;
    64 
    65             SpaceShip *parentSpaceShip_;
     77            Pawn *parentPawn_;
    6678    };
    6779}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc

    r2097 r2493  
    3737namespace orxonox
    3838{
    39     LaserGunMunition::LaserGunMunition(BaseObject* creator) : BaseObject(creator)
     39    CreateFactory(LaserGunMunition);
     40
     41    LaserGunMunition::LaserGunMunition(BaseObject* creator) : Munition(creator)
    4042    {
    4143        RegisterObject(LaserGunMunition);
     44
     45        this->maxBullets_ = 40;
     46        this->maxMagazines_ = 100;
    4247    }
    4348
  • code/branches/presentation/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h

    r2106 r2493  
    3333
    3434#include "core/BaseObject.h"
    35 
     35#include "../Munition.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport LaserGunMunition : public BaseObject
     39    class _OrxonoxExport LaserGunMunition : public Munition
    4040    {
    4141        public:
     
    4747
    4848        private:
    49             int bullets_;
    50             int magazines_;
    51             int maxBullets_;
    52             int maxMagazines_;
    5349
    5450
  • code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc

    r2099 r2493  
    3030#include "BillboardProjectile.h"
    3131
    32 #include <OgreBillboard.h>
     32#include <OgreBillboardSet.h>
    3333
    3434#include "core/CoreIncludes.h"
     35#include "objects/Scene.h"
    3536
    3637namespace orxonox
     
    3839    CreateFactory(BillboardProjectile);
    3940
    40     BillboardProjectile::BillboardProjectile(BaseObject* creator, Weapon* owner) : Projectile(creator, owner)
     41    BillboardProjectile::BillboardProjectile(BaseObject* creator) : Projectile(creator)
    4142    {
    4243        RegisterObject(BillboardProjectile);
    4344
    44         this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
    45         this->attachObject(this->billboard_.getBillboardSet());
    46         this->scale(0.5);
     45        assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity
     46
     47        this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5, 0.5, 0.7, 0.8), 1);
     48        this->attachOgreObject(this->billboard_.getBillboardSet());
     49        this->scale(0.2);
    4750    }
    4851
    4952    BillboardProjectile::~BillboardProjectile()
    5053    {
    51         if (this->isInitialized() && this->owner_)
    52             this->detachObject(this->billboard_.getBillboardSet());
     54        //if (this->isInitialized() && this->owner_)
     55            //this->detachObject(this->billboard_.getBillboardSet());
    5356    }
    5457
    5558    void BillboardProjectile::setColour(const ColourValue& colour)
    5659    {
    57         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
     60        this->billboard_.setColour(colour);
    5861    }
    5962
  • code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h

    r2099 r2493  
    4141    {
    4242        public:
    43             BillboardProjectile(BaseObject* creator, Weapon* owner = 0);
     43            BillboardProjectile(BaseObject* creator);
    4444            virtual ~BillboardProjectile();
    4545
  • code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc

    r2099 r2493  
    3030#include "ParticleProjectile.h"
    3131
    32 #include "SpaceShip.h"
     32#include <OgreParticleSystem.h>
     33#include <OgreParticleEmitter.h>
     34
     35#include "../../worldentities/pawns/SpaceShip.h"
    3336#include "core/CoreIncludes.h"
    3437#include "core/ConfigValueIncludes.h"
     38#include "objects/Scene.h"
    3539
    3640namespace orxonox
     
    3842    CreateFactory(ParticleProjectile);
    3943
    40     ParticleProjectile::ParticleProjectile(BaseObject* creator, Weapon* owner) : BillboardProjectile(creator, owner)
     44    ParticleProjectile::ParticleProjectile(BaseObject* creator) : BillboardProjectile(creator)
    4145    {
    4246        RegisterObject(ParticleProjectile);
    4347
    44         this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal);
    45         this->particles_->addToSceneNode(this->getNode());
    46         this->particles_->setKeepParticlesInLocalSpace(true);
     48        this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::normal);
     49        this->attachOgreObject(this->particles_->getParticleSystem());
     50        this->particles_->setKeepParticlesInLocalSpace(0);
     51
     52        this->particles_->getAllEmitters()->setDirection(-WorldEntity::FRONT);
     53        /*
    4754        if (this->owner_)
    4855        {
     
    5259//            this->particles_ = 0;
    5360//        }
     61        */
    5462
    5563        this->setConfigValues();
     
    5967    {
    6068        if (this->isInitialized() && this->particles_)
     69        {
     70            this->detachOgreObject(this->particles_->getParticleSystem());
    6171            delete this->particles_;
     72        }
    6273    }
    6374
    6475    void ParticleProjectile::setConfigValues()
    6576    {
    66         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback((Projectile*)this, &ParticleProjectile::speedChanged);
     77        //SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback((Projectile*)this, &ParticleProjectile::speedChanged);
    6778    }
    6879
     
    7283        this->particles_->setEnabled(this->isVisible());
    7384    }
    74 
    75     bool ParticleProjectile::create(){
    76       if(!Projectile::create())
    77         return false;
    78       this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0));
    79       return true;
    80     }
    8185}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h

    r2099 r2493  
    4141    {
    4242        public:
    43             ParticleProjectile(BaseObject* creator, Weapon* owner = 0);
     43            ParticleProjectile(BaseObject* creator);
    4444            virtual ~ParticleProjectile();
    4545            virtual void changedVisibility();
    4646            void setConfigValues();
    47 
    48             virtual bool create();
    4947
    5048        private:
  • code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2466 r2493  
    4040#include "objects/worldentities/Model.h"
    4141#include "objects/worldentities/ParticleSpawner.h"
    42 #include "Settings.h"
     42#include "core/Core.h"
    4343
    4444namespace orxonox
    4545{
    46     float Projectile::speed_s = 5000;
    47 
    48     Projectile::Projectile(BaseObject* creator, Weapon* owner) : MovableEntity(creator), owner_(owner)
     46    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator)
    4947    {
    5048        RegisterObject(Projectile);
     
    5452        this->smokeTemplateName_ = "Orxonox/smoke4";
    5553
    56         this->setStatic(false);
    57         this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
     54        //this->setStatic(false);
     55//        this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
    5856
    5957        // Get notification about collisions
    6058        this->enableCollisionCallback();
    6159
     60        /*
    6261        if (this->owner_)
    6362        {
     
    6665            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    6766        }
     67        */
    6868
    69         if(!orxonox::Settings::isClient()) //only if not on client
     69        if(!Core::isClient()) //only if not on client
    7070          this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    7171    }
     
    7979        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
    8080        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
    81         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);
    8281    }
    8382
    84     void Projectile::speedChanged()
    85     {
    86         Projectile::speed_s = this->speed_;
    87         if (this->owner_)
    88             this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    89     }
    9083
    9184    void Projectile::tick(float dt)
     
    9588        if (!this->isActive())
    9689            return;
    97 
     90/*
    9891        float radius;
    9992        for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it)
     
    10699                {
    107100                    // hit
    108                     ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0);
     101                    ParticleSpawner* explosion = new ParticleSpawner(this);
     102                    explosion->setSource(this->explosionTemplateName_);
     103                    explosion->setLOD(LODParticle::low);
     104                    explosion->configure(2.0);
    109105                    explosion->setPosition(this->getPosition());
    110106                    explosion->create();
    111                     ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0);
     107                    ParticleSpawner* smoke = new ParticleSpawner(this);
     108                    smoke->setSource(this->smokeTemplateName_);
     109                    smoke->setLOD(LODParticle::normal);
     110                    smoke->configure(2.0, 0.0);
    112111                    smoke->setPosition(this->getPosition());
    113112//                    smoke->getParticleInterface()->setSpeedFactor(3.0);
     
    118117            }
    119118        }
     119*/
    120120    }
    121121
     
    124124        delete this;
    125125    }
    126 
    127     bool Projectile::create(){
    128       return WorldEntity::create();
    129     }
    130126}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/projectiles/Projectile.h

    r2099 r2493  
    4242            virtual ~Projectile();
    4343            void setConfigValues();
    44             void speedChanged();
    4544            void destroyObject();
    4645            virtual void tick(float dt);
    4746
    48             virtual bool create();
    49 
    50             static float getSpeed()
    51                 { return Projectile::speed_s; }
    52 
    5347        protected:
    54             Projectile(BaseObject* creator, Weapon* owner = 0);
    55             SpaceShip* owner_;
     48            Projectile(BaseObject* creator);
    5649
    5750        private:
     
    5952            std::string smokeTemplateName_;
    6053        protected:
    61             static float speed_s;
    6254            float speed_;
    6355        private:
  • code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt

    r2131 r2493  
    11SET( SRC_FILES
     2  Fusion.cc
    23  LaserGun.cc
    3   Missile.cc
     4#  Missile.cc
    45)
    56
  • code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/Fusion.cc

    r2489 r2493  
    4444    {
    4545        RegisterObject(Fusion);
    46        
     46
    4747        this->speed_ = 1250;
    4848
     
    5555    void Fusion::takeBullets()
    5656    {
    57 COUT(0) << "Fusion::takeBullets" << std::endl;
     57//COUT(0) << "Fusion::takeBullets" << std::endl;
    5858        this->munition_->removeBullets(1);
    5959        this->bulletTimer(this->bulletLoadingTime_);
     
    6868    void Fusion::createProjectile()
    6969    {
    70 COUT(0) << "Fusion::createProjectile" << std::endl;
     70//COUT(0) << "Fusion::createProjectile" << std::endl;
    7171        BillboardProjectile* projectile = new ParticleProjectile(this);
    7272        projectile->setOrientation(this->getWorldOrientation());
    7373        projectile->setPosition(this->getWorldPosition());
    74         projectile->setVelocity(WorldEntity::FRONT * this->speed_);
     74        projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_);
    7575    }
    7676}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2097 r2493  
    3434#include "util/Debug.h"
    3535
     36#include "LaserGun.h"
     37
    3638
    3739namespace orxonox
    3840{
     41    CreateFactory(LaserGun);
     42
    3943    LaserGun::LaserGun(BaseObject* creator) : Weapon(creator)
    4044    {
    4145        RegisterObject(LaserGun);
    4246
    43         projectileColor_ = ColourValue(1.0, 1.0, 0.5)
     47        this->speed_ = 1250;
     48
    4449    }
    4550
     
    4853    }
    4954
    50     LaserGun::fire()
     55    void LaserGun::takeBullets()
    5156    {
    52             BillboardProjectile* projectile = new ParticleProjectile(this);
    53             projectile->setColour(this->projectileColor_);
    54             projectile->create();
    55             if (projectile->getClassID() == 0)
    56             {
    57               COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
    58             }
    59 
    60             projectile->setObjectMode(0x3);
     57//COUT(0) << "LaserGun::takeBullets" << std::endl;
     58        this->munition_->removeBullets(1);
     59        this->bulletTimer(this->bulletLoadingTime_);
    6160    }
    6261
    63     LaserGun::addMunition()
     62    void LaserGun::takeMagazines()
    6463    {
    65         //this->munition_ = ;
     64        this->munition_->removeMagazines(1);
     65        this->magazineTimer(this->magazineLoadingTime_);
    6666    }
    6767
    68     void LaserGun::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     68    void LaserGun::createProjectile()
    6969    {
    70 
    71     }
    72 
    73     ColorValue LaserGun::getProjectileColor()
    74     {
    75         return projectileColor_;
     70//COUT(0) << "LaserGun::createProjectile" << std::endl;
     71        BillboardProjectile* projectile = new ParticleProjectile(this);
     72        projectile->setOrientation(this->getWorldOrientation());
     73        projectile->setPosition(this->getWorldPosition());
     74        projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_);
    7675    }
    7776}
  • code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2106 r2493  
    3434#include "core/BaseObject.h"
    3535
    36 #include "LaserGunMunition.h"
    37 #include "tools/BillboardSet.h"
     36#include "../munitions/LaserGunMunition.h"
    3837#include "util/Math.h"
     38#include "../Weapon.h"
     39#include "../projectiles/BillboardProjectile.h"
     40#include "../projectiles/ParticleProjectile.h"
    3941
    4042namespace orxonox
     
    4648            virtual ~LaserGun();
    4749
    48             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    49 
    50             ColourValue LaserGun::getProjectileColour();
     50            virtual void takeBullets();
     51            virtual void takeMagazines();
     52            virtual void createProjectile();
    5153
    5254        private:
    53             ColorValue projectileColor_;
    54 
    55 
     55            float speed_;
    5656
    5757    };
Note: See TracChangeset for help on using the changeset viewer.