Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (16 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
23 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/weaponSystem/CMakeLists.txt

    r2131 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/Munition.cc

    r2097 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/Munition.h

    r2106 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/Weapon.cc

    r2098 r2662  
    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);
     44        this->bulletReadyToShoot_ = true;
     45        this->magazineReadyToShoot_ = true;
     46        this->parentWeaponSystem_ = 0;
     47        this->attachedToWeaponSlot_ = 0;
     48        this->munition_ = 0;
     49        this->bulletLoadingTime_ = 0;
     50        this->magazineLoadingTime_ = 0;
     51        this->bReloading_ = false;
    4252
    43         this->loadingTime_ = 0;
    44         this->munition_ = 0;
    45 
     53        this->setObjectMode(0x0);
    4654    }
    4755
     
    5058    }
    5159
    52     void Weapon::addMunition()
     60
     61    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5362    {
     63        SUPER(Weapon, XMLPort, xmlelement, mode);
     64        XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
     65        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
     66        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
     67    }
     68
     69    void Weapon::setWeapon()
     70    {
     71        this->munition_->fillBullets();
     72        this->munition_->fillMagazines();
     73    }
     74
     75
     76    void Weapon::fire()
     77    {
     78//COUT(0) << "LaserGun::fire, this=" << this << std::endl;
     79        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
     80        {
     81//COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
     82//COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
     83            this->bulletReadyToShoot_ = false;
     84            if ( this->munition_->bullets() > 0)
     85            {
     86                //shoot
     87                this->takeBullets();
     88                this->createProjectile();
     89            }
     90            //if there are no bullets, but magazines
     91            else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
     92            {
     93//COUT(0) << "LaserGun::fire - no bullets" << std::endl;
     94                this->takeMagazines();
     95            }
     96            else
     97            {
     98//COUT(0) << "LaserGun::fire - no magazines" << std::endl;
     99                //actions
     100            }
     101        }
     102        else
     103        {
     104//COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
     105            //actions
     106        }
    54107
    55108    }
    56109
    57     void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     110
     111    void Weapon::bulletTimer(float bulletLoadingTime)
    58112    {
    59 
     113//COUT(0) << "Weapon::bulletTimer started" << std::endl;
     114        this->bReloading_ = true;
     115        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
     116    }
     117    void Weapon::magazineTimer(float magazineLoadingTime)
     118    {
     119//COUT(0) << "Weapon::magazineTimer started" << std::endl;
     120        this->bReloading_ = true;
     121        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
    60122    }
    61123
    62     void Weapon::fire()
     124    void Weapon::bulletReloaded()
    63125    {
     126        this->bReloading_ = false;
     127        this->bulletReadyToShoot_ = true;
     128    }
    64129
     130    void Weapon::magazineReloaded()
     131    {
     132        this->bReloading_ = false;
     133        this->munition_->fillBullets();
     134        this->magazineReadyToShoot_ = true;
     135        this->bulletReadyToShoot_ = true;
    65136    }
     137
     138
     139    void Weapon::attachNeededMunition(std::string munitionName)
     140    {
     141//COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
     142        //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
     143        if (this->parentWeaponSystem_)
     144        {
     145//COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
     146            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
     147            if ( munition )
     148                this->munition_ = munition;
     149            else
     150            {
     151                //create new munition with identifier
     152//COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
     153                this->munitionIdentifier_ = ClassByString(munitionName);
     154                this->munition_ = this->munitionIdentifier_.fabricate(this);
     155                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
     156            }
     157        }
     158    }
     159
     160
     161     /*get and set functions
     162     *
     163     */
     164
     165    void Weapon::setMunitionType(std::string munitionType)
     166    {   this->munitionType_ = munitionType; }
     167
     168    const std::string Weapon::getMunitionType()
     169    {   return this->munitionType_;  }
     170
     171    void Weapon::setBulletLoadingTime(float loadingTime)
     172    {   this->bulletLoadingTime_ = loadingTime; }
     173
     174    const float Weapon::getBulletLoadingTime()
     175    {   return this->bulletLoadingTime_;  }
     176
     177    void Weapon::setMagazineLoadingTime(float loadingTime)
     178    {   this->magazineLoadingTime_ = loadingTime; }
     179
     180    const float Weapon::getMagazineLoadingTime()
     181    {   return this->magazineLoadingTime_;  }
     182
     183
     184    Munition * Weapon::getAttachedMunition(std::string munitionType)
     185    {
     186//COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
     187        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
     188//COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
     189        return this->munition_;
     190    }
     191
     192    void Weapon::takeBullets() { };
     193    void Weapon::createProjectile() { };
     194    void Weapon::takeMagazines() { };
     195
    66196}
  • code/trunk/src/orxonox/objects/weaponSystem/Weapon.h

    r2106 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2098 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSet.h

    r2106 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2098 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSlot.h

    r2106 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2261 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2261 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc

    r2097 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h

    r2106 r2662  
    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/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc

    r2099 r2662  
    3030#include "BillboardProjectile.h"
    3131
    32 #include <OgreBillboard.h>
     32#include <OgreBillboardSet.h>
    3333
     34#include "core/Core.h"
    3435#include "core/CoreIncludes.h"
     36#include "objects/Scene.h"
    3537
    3638namespace orxonox
     
    3840    CreateFactory(BillboardProjectile);
    3941
    40     BillboardProjectile::BillboardProjectile(BaseObject* creator, Weapon* owner) : Projectile(creator, owner)
     42    BillboardProjectile::BillboardProjectile(BaseObject* creator) : Projectile(creator)
    4143    {
    4244        RegisterObject(BillboardProjectile);
    4345
    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);
     46        if (Core::showsGraphics())
     47        {
     48            assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity
     49            this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5, 0.5, 0.7, 0.8), 1);
     50            this->attachOgreObject(this->billboard_.getBillboardSet());
     51        }
     52
     53        this->setScale(0.2);
    4754    }
    4855
    4956    BillboardProjectile::~BillboardProjectile()
    5057    {
    51         if (this->isInitialized() && this->owner_)
    52             this->detachObject(this->billboard_.getBillboardSet());
     58        if (this->isInitialized() && Core::showsGraphics() && this->billboard_.getBillboardSet())
     59            this->detachOgreObject(this->billboard_.getBillboardSet());
    5360    }
    5461
    5562    void BillboardProjectile::setColour(const ColourValue& colour)
    5663    {
    57         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
     64        this->billboard_.setColour(colour);
    5865    }
    5966
     
    6168    {
    6269        SUPER(BillboardProjectile, changedVisibility);
     70
    6371        this->billboard_.setVisible(this->isVisible());
    6472    }
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h

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

    r2099 r2662  
    3030#include "ParticleProjectile.h"
    3131
    32 #include "SpaceShip.h"
     32#include <OgreParticleSystem.h>
     33#include <OgreParticleEmitter.h>
     34
     35#include "core/Core.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);
    47         if (this->owner_)
     48        if (Core::showsGraphics())
    4849        {
     50            this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::normal);
     51            this->attachOgreObject(this->particles_->getParticleSystem());
     52            this->particles_->setKeepParticlesInLocalSpace(0);
     53
     54            this->particles_->getAllEmitters()->setDirection(-WorldEntity::FRONT);
    4955        }
    50 //        else
    51 //        {
    52 //            this->particles_ = 0;
    53 //        }
    54 
    55         this->setConfigValues();
     56        else
     57            this->particles_ = 0;
    5658    }
    5759
     
    5961    {
    6062        if (this->isInitialized() && this->particles_)
     63        {
     64            this->detachOgreObject(this->particles_->getParticleSystem());
    6165            delete this->particles_;
    62     }
    63 
    64     void ParticleProjectile::setConfigValues()
    65     {
    66         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback((Projectile*)this, &ParticleProjectile::speedChanged);
     66        }
    6767    }
    6868
     
    7070    {
    7171        SUPER(ParticleProjectile, changedVisibility);
    72         this->particles_->setEnabled(this->isVisible());
    73     }
    7472
    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;
     73        if (this->particles_)
     74            this->particles_->setEnabled(this->isVisible());
    8075    }
    8176}
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h

    r2099 r2662  
    4141    {
    4242        public:
    43             ParticleProjectile(BaseObject* creator, Weapon* owner = 0);
     43            ParticleProjectile(BaseObject* creator);
    4444            virtual ~ParticleProjectile();
    4545            virtual void changedVisibility();
    46             void setConfigValues();
    47 
    48             virtual bool create();
    4946
    5047        private:
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2100 r2662  
    4040#include "objects/worldentities/Model.h"
    4141#include "objects/worldentities/ParticleSpawner.h"
    42 #include "Settings.h"
     42#include "objects/collisionshapes/SphereCollisionShape.h"
     43#include "core/Core.h"
    4344
    4445namespace orxonox
    4546{
    46     float Projectile::speed_s = 5000;
    47 
    48     Projectile::Projectile(BaseObject* creator, Weapon* owner) : MovableEntity(creator), owner_(owner)
     47    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator)
    4948    {
    5049        RegisterObject(Projectile);
    5150
    5251        this->setConfigValues();
    53         this->explosionTemplateName_ = "Orxonox/explosion3";
    54         this->smokeTemplateName_ = "Orxonox/smoke4";
     52        this->bDestroy_ = false;
     53        this->owner_ = 0;
    5554
    56         this->setStatic(false);
    57         this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
     55        // Get notification about collisions
    5856
    59         if (this->owner_)
     57        if (Core::isMaster())
    6058        {
    61             this->setOrientation(this->owner_->getOrientation());
    62             this->setPosition(this->owner_->getPosition());
    63             this->setVelocity(this->owner_->getInitialDir() * this->speed_);
     59            this->enableCollisionCallback();
     60
     61            this->setCollisionType(Kinematic);
     62
     63            SphereCollisionShape* shape = new SphereCollisionShape(this);
     64            shape->setRadius(10);
     65            this->attachCollisionShape(shape);
     66
     67            this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    6468        }
    65 
    66         if(!orxonox::Settings::isClient()) //only if not on client
    67           this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    6869    }
    6970
     
    7677        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
    7778        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
    78         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);
    7979    }
    8080
    81     void Projectile::speedChanged()
    82     {
    83         Projectile::speed_s = this->speed_;
    84         if (this->owner_)
    85             this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    86     }
    8781
    8882    void Projectile::tick(float dt)
     
    9387            return;
    9488
    95         float radius;
    96         for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it)
    97         {
    98 //            if ((*it) != this->owner_)
    99             {
    100                 radius = it->getScale3D().x * 3.0;
    101 
    102                 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    103                 {
    104                     // hit
    105                     ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0);
    106                     explosion->setPosition(this->getPosition());
    107                     explosion->create();
    108                     ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0);
    109                     smoke->setPosition(this->getPosition());
    110 //                    smoke->getParticleInterface()->setSpeedFactor(3.0);
    111                     smoke->create();
    112                     delete this;
    113                     return;
    114                 }
    115             }
    116         }
     89        if (this->bDestroy_)
     90            delete this;
    11791    }
    11892
    11993    void Projectile::destroyObject()
    12094    {
    121         delete this;
     95        if (Core::isMaster())
     96            delete this;
    12297    }
    12398
    124     bool Projectile::create(){
    125       return WorldEntity::create();
     99    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
     100    {
     101        if (!this->bDestroy_ && Core::isMaster())
     102        {
     103            this->bDestroy_ = true;
     104
     105            if (this->owner_)
     106            {
     107                {
     108                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
     109                    effect->setPosition(this->getPosition());
     110                    effect->setOrientation(this->getOrientation());
     111                    effect->setDestroyAfterLife(true);
     112                    effect->setSource("Orxonox/explosion3");
     113                    effect->setLifetime(2.0f);
     114                }
     115                {
     116                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
     117                    effect->setPosition(this->getPosition());
     118                    effect->setOrientation(this->getOrientation());
     119                    effect->setDestroyAfterLife(true);
     120                    effect->setSource("Orxonox/smoke4");
     121                    effect->setLifetime(3.0f);
     122                }
     123            }
     124
     125            Pawn* victim = dynamic_cast<Pawn*>(otherObject);
     126            if (victim)
     127                victim->damage(this->damage_, this->owner_);
     128        }
     129        return false;
     130    }
     131
     132    void Projectile::destroyedPawn(Pawn* pawn)
     133    {
     134        if (this->owner_ == pawn)
     135            this->owner_ = 0;
    126136    }
    127137}
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.h

    r2099 r2662  
    3333
    3434#include "objects/worldentities/MovableEntity.h"
     35#include "objects/worldentities/pawns/Pawn.h"
    3536#include "tools/Timer.h"
    3637
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport Projectile : public MovableEntity
     40    class _OrxonoxExport Projectile : public MovableEntity, public PawnListener
    4041    {
    4142        public:
     43            Projectile(BaseObject* creator);
    4244            virtual ~Projectile();
     45
    4346            void setConfigValues();
    44             void speedChanged();
    4547            void destroyObject();
     48
    4649            virtual void tick(float dt);
     50            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     51            virtual void destroyedPawn(Pawn* pawn);
    4752
    48             virtual bool create();
    49 
    50             static float getSpeed()
    51                 { return Projectile::speed_s; }
    52 
    53         protected:
    54             Projectile(BaseObject* creator, Weapon* owner = 0);
    55             SpaceShip* owner_;
     53            inline void setOwner(Pawn* owner)
     54                { this->owner_ = owner; }
     55            inline Pawn* getOwner() const
     56                { return this->owner_; }
    5657
    5758        private:
    58             std::string explosionTemplateName_;
    59             std::string smokeTemplateName_;
    60         protected:
    61             static float speed_s;
    62             float speed_;
    63         private:
     59            Pawn* owner_;
    6460            float lifetime_;
    6561            float damage_;
     62            bool bDestroy_;
    6663            Timer<Projectile> destroyTimer_;
    6764    };
  • code/trunk/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt

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

    r2097 r2662  
    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_);
     75        projectile->setOwner(this->getParentWeaponSystem()->getParentPawn());
    7676    }
    7777}
  • code/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2106 r2662  
    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.