Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2009, 12:05:01 AM (16 years ago)
Author:
landauf
Message:

More changes in the WeaponSystem:

  • WeaponSets can now contain several WeaponPacks
  • WeaponPacks can now belong to several WeaponSets

(until now this seemingly was a 1:1 relationship… now it's n:m)

  • Started support for multiple weaponmodes
  • Added some code to the destructor of some classes… according to some legends, this helps destroying objects. (WeaponSets and WeaponPacks weren't deleted before…)

Not yet finished, but I have to synchronize desktop computer and notebook.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2912 r2914  
    3434
    3535#include "Weapon.h"
     36#include "WeaponSystem.h"
    3637
    3738namespace orxonox
     
    4344        RegisterObject(WeaponSlot);
    4445
    45         this->unlimitedAmmo_ = false;
    46         this->attachedWeapon_ = 0;
     46        this->weaponSystem_ = 0;
     47        this->weapon_ = 0;
     48
    4749        this->setObjectMode(0x0);
    4850
     
    5355    {
    5456COUT(0) << "~WeaponSlot" << std::endl;
     57
     58        if (this->isInitialized() && this->weaponSystem_)
     59            this->weaponSystem_->removeWeaponSlot(this);
    5560    }
    5661
     
    5863    {
    5964        SUPER(WeaponSlot, XMLPort, xmlelement, mode);
    60     }
    6165
    62     /*sets the munition type
    63      *unlimited: true
    64      *limited:   false  (in this case there will be munition)
    65      */
    66     void WeaponSlot::setAmmoType(bool isUnlimited)
    67     {
    68         unlimitedAmmo_ = isUnlimited;
    69     }
    70 
    71 
    72     void WeaponSlot::fire()
    73     {
    74         if ( this->attachedWeapon_ )
    75 //COUT(0) << "WeaponSlot::fire" << std::endl;
    76         this->attachedWeapon_->fire();
     66        // ...
    7767    }
    7868
    7969    void WeaponSlot::attachWeapon(Weapon *weapon)
    8070    {
    81         this->attachedWeapon_ = weapon;
    82         weapon->setAttachedToWeaponSlot(this);
    83 //COUT(0) << "WeaponSlot::attachWeapon position=" << this->getWorldPosition() << std::endl;
    84         weapon->setPosition(this->getPosition());
     71        if (this->weapon_)
     72            this->removeWeapon();
     73
     74        this->weapon_ = weapon;
     75
     76        if (this->weapon_)
     77        {
     78            this->weapon_->setWeaponSlot(this);
     79            this->weapon_->setPosition(this->getPosition());
     80        }
    8581    }
    8682
    87     Weapon * WeaponSlot::getAttachedWeapon() const
     83    void WeaponSlot::removeWeapon()
    8884    {
    89         return this->attachedWeapon_;
     85        if (this->weapon_)
     86        {
     87            this->weapon_->setWeaponSlot(0);
     88            this->weapon_ = 0;
     89        }
    9090    }
    9191}
Note: See TracChangeset for help on using the changeset viewer.