Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2319


Ignore:
Timestamp:
Dec 3, 2008, 3:11:48 PM (16 years ago)
Author:
polakma
Message:

fixed WeaponPack attaching

Location:
code/branches/weapon2/src/orxonox/objects
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2288 r2319  
    3535
    3636#include "WeaponPack.h"
     37#include "objects/worldentities/pawns/Pawn.h"
    3738
    3839namespace orxonox
     
    4344
    4445        this->parentWeaponSystem_ = 0;
     46        this->firemode_ = 1;
    4547
    4648    }
     
    7678    void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7779    {
    78 
     80        XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
     81        XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);
    7982    }
    8083
     84    void WeaponPack::setFireMode(unsigned int firemode)
     85    {
     86        this->firemode_ = firemode;
     87    }
     88
     89    unsigned int WeaponPack::getFireMode()
     90    {
     91        return this->firemode_;
     92    }
     93
     94    void WeaponPack::addWeapon(Weapon * weapon)
     95    {
     96        this->weapons_.push_back(weapon);
     97    }
     98   
     99    Weapon * WeaponPack::getWeapon(unsigned int index)
     100    {
     101        return weapons_[index];
     102    }
    81103}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponPack.h

    r2288 r2319  
    5454            void attachWeapon(Weapon *weapon);
    5555
     56            void setFireMode(unsigned int firemode);
     57            unsigned int getFireMode();
     58
     59            void addWeapon(Weapon * weapon);
     60            Weapon * getWeapon(unsigned int index);
     61
    5662            inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
    5763                { parentWeaponSystem_=parentWeaponSystem; }
     
    6268            std::vector<Weapon *> weapons_;
    6369            WeaponSystem *parentWeaponSystem_;
     70            unsigned int firemode_;
    6471    };
    6572}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2308 r2319  
    5353    void WeaponSet::attachWeaponPack(WeaponPack *wPack)
    5454    {
    55         if (this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) )
     55        if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) )
    5656        {
    5757            this->attachedWeaponPack_ = wPack;
     58            int wPackWeapon = 0;    //WeaponCounter for Attaching
    5859            //should be possible to choose which slot to use
    5960            for (  int i=0; i < wPack->getSize() ; i++  )
    6061            {
    6162                //at the moment this function only works for one weaponPack in the entire WeaponSystem...
    62                 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) );
    63                 this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(i) );
     63                if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() != 0 ) //if slot not full
     64                {
     65                    this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) );
     66                    this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
     67                    wPackWeapon++;
     68                }
    6469            }
    6570        }
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2308 r2319  
    6969
    7070
    71     //XMLPort functions
    7271    void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7372    {
     
    7877    {   this->attachedWeapon_ = weaponPointer;   }
    7978
    80     Weapon * WeaponSlot::getAttachedWeapon(unsigned int index) const
     79    Weapon * WeaponSlot::getAttachedWeapon() const
    8180    {   return this->attachedWeapon_;   }
    8281
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.h

    r2288 r2319  
    4646
    4747            void attachWeapon(Weapon *weaponPointer);
    48             Weapon * getAttachedWeapon(unsigned int index) const;
     48            Weapon * getAttachedWeapon() const;
    4949            void setAmmoType(bool isUnlimited);
    5050            void fire();
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2308 r2319  
    3636
    3737#include "WeaponSystem.h"
    38 #include "WeaponPack.h"
     38
    3939
    4040/* WEAPONSYSTEM
     
    5252
    5353        this->activeWeaponSet_ = 0;
    54         this->parentSpaceShip_ = 0;
     54        this->parentPawn_ = 0;
    5555    }
    5656
     
    5959    }
    6060
    61     void WeaponSystem::attachWeaponPack(WeaponPack *wPack, int setNumber)
     61    void WeaponSystem::attachWeaponPack(WeaponPack *wPack, unsigned int firemode)
    6262    {
    63         this->weaponSets_[setNumber]->attachWeaponPack(wPack);
     63        this->weaponSets_[firemode]->attachWeaponPack(wPack);
     64        this->weaponPacks_[firemode] = wPack;
     65        wPack->setParentWeaponSystem(this);
    6466    }
    6567
     
    125127    }
    126128
     129    WeaponPack * WeaponSystem::getWeaponPackPointer(unsigned int n)
     130    {
     131        if (n < this->weaponPacks_.size())
     132            return this->weaponPacks_[n];
     133        else
     134            return 0;
     135    }
     136
    127137    void WeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    128138    {
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2288 r2319  
    3636
    3737#include "WeaponSet.h"
     38#include "WeaponPack.h"
    3839
    3940namespace orxonox
     
    5354            void fire(WeaponMode::Enum fireMode);
    5455            //void setActiveWeaponSet(unsigned int n);
    55             void attachWeaponPack(WeaponPack * wPack, int setNumber);
     56            void attachWeaponPack(WeaponPack * wPack, unsigned int firemode);
    5657            WeaponSet * getWeaponSetPointer(unsigned int n);
    5758            WeaponSlot * getWeaponSlotPointer(unsigned int n);
    58 
     59            WeaponPack * getWeaponPackPointer(unsigned int n);
    5960            void setNewMunition(std::string munitionType, Munition * munitionToAdd);
    6061            Munition * getMunitionType(std::string munitionType);
    6162
    62             inline void setParentSpaceShip(SpaceShip *parentSpaceShip)
    63                 { parentSpaceShip_=parentSpaceShip; }
    64             inline SpaceShip * getParentSpaceShip()
    65                 { return parentSpaceShip_; }
     63            inline void setParentPawn(Pawn *parentPawn)
     64                { parentPawn_=parentPawn; }
     65            inline Pawn * getParentPawn()
     66                { return parentPawn_; }
    6667
    6768            inline int getWeaponSlotSize()
     
    7172            std::vector<WeaponSet *> weaponSets_;
    7273            std::vector<WeaponSlot *> weaponSlots_;
     74            std::vector<WeaponPack *> weaponPacks_;
    7375            std::map<std::string, Munition *> munitionSet_;
    7476            WeaponSet *activeWeaponSet_;
    75             SpaceShip *parentSpaceShip_;
     77            Pawn *parentPawn_;
    7678    };
    7779}
  • code/branches/weapon2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2308 r2319  
    7878        XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode);
    7979        XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode);
    80         //XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode);
     80        XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode);
    8181
    8282        }
     
    155155
    156156
     157
    157158    void Pawn::setWeaponSlot(WeaponSlot * wSlot)
    158159    {   this->weaponSystem_->attachWeaponSlot(wSlot);   }
    159160    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
    160161    {   return this->weaponSystem_->getWeaponSlotPointer(index);    }
    161 
    162     /*
     162   
    163163    void Pawn::setWeaponPack(WeaponPack * wPack)
    164     {   this->weaponSystem_->attachWeaponPack(wPack);   }
    165     WeaponPack * Pawn::getWeaponPack(unsigned int index) const
    166     {   return this->weaponSystem_->getWeaponPackPointer(index);
    167     */
    168 
     164    {   this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() );   }
     165    WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const
     166    {   return this->weaponSystem_->getWeaponPackPointer(firemode);    }
     167   
    169168    void Pawn::setWeaponSet(WeaponSet * wSet)
    170169    {   this->weaponSystem_->attachWeaponSet(wSet);   }
  • code/branches/weapon2/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2308 r2319  
    8181            void setWeaponSlot(WeaponSlot * wSlot);
    8282            WeaponSlot * getWeaponSlot(unsigned int index) const;
    83          //   void setWeaponPack(WeaponPack * wPack);
    84          //   WeaponPack * getWeaponPack(unsigned int index) const;
     83            void setWeaponPack(WeaponPack * wPack);
     84            WeaponPack * getWeaponPack(unsigned int firemode) const;
    8585            void setWeaponSet(WeaponSet * wSet);
    8686            WeaponSet * getWeaponSet(unsigned int index) const;
Note: See TracChangeset for help on using the changeset viewer.