[Orxonox-commit 1358] r6076 - in code/branches/particles2: data/levels/includes src/orxonox/weaponsystem

scheusso at orxonox.net scheusso at orxonox.net
Mon Nov 16 17:58:34 CET 2009


Author: scheusso
Date: 2009-11-16 17:58:34 +0100 (Mon, 16 Nov 2009)
New Revision: 6076

Modified:
   code/branches/particles2/data/levels/includes/weaponsettings3.oxi
   code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.cc
   code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.h
   code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.cc
   code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.h
Log:
some fixes in the weaponsystem and weaponsettings3.oxi


Modified: code/branches/particles2/data/levels/includes/weaponsettings3.oxi
===================================================================
--- code/branches/particles2/data/levels/includes/weaponsettings3.oxi	2009-11-16 10:29:59 UTC (rev 6075)
+++ code/branches/particles2/data/levels/includes/weaponsettings3.oxi	2009-11-16 16:58:34 UTC (rev 6076)
@@ -45,8 +45,8 @@
         <links>
           <DefaultWeaponmodeLink firemode=1 weaponmode=0 />
         </links>
-        <Weapon>
-          <!-- EnergyDrink mode=0 munitionpershot=0 delay=0  material="Flares/point_lensflare"muzzleoffset="2,-0.2,-1" / -->
-        </Weapon>
+        <!--Weapon>
+          <EnergyDrink mode=0 munitionpershot=0 delay=0  material="Flares/point_lensflare"muzzleoffset="2,-0.2,-1" />
+        </Weapon-->
       </WeaponPack>
     </weapons>

Modified: code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.cc
===================================================================
--- code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.cc	2009-11-16 10:29:59 UTC (rev 6075)
+++ code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.cc	2009-11-16 16:58:34 UTC (rev 6076)
@@ -48,9 +48,10 @@
 
     WeaponPack::~WeaponPack()
     {
-        if (this->isInitialized() && this->weaponSystem_)
+        if (this->isInitialized())
         {
-            this->weaponSystem_->removeWeaponPack(this);
+            if( this->weaponSystem_ )
+                this->weaponSystem_->removeWeaponPack(this);
 
             while (!this->weapons_.empty())
                 (*this->weapons_.begin())->destroy();
@@ -70,13 +71,13 @@
 
     void WeaponPack::fire(unsigned int weaponmode)
     {
-        for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
+        for (std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
             (*it)->fire(weaponmode);
     }
 
     void WeaponPack::reload()
     {
-        for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
+        for (std::vector<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
             (*it)->reload();
     }
 
@@ -85,7 +86,7 @@
         if (!weapon)
             return;
 
-        this->weapons_.insert(weapon);
+        this->weapons_.push_back(weapon);
         weapon->setWeaponPack(this);
     }
 
@@ -94,7 +95,8 @@
         if (!weapon)
             return;
 
-        this->weapons_.erase(weapon);
+        assert( std::find(this->weapons_.begin(), this->weapons_.end(), weapon)!=this->weapons_.end() );
+        this->weapons_.erase( std::find(this->weapons_.begin(), this->weapons_.end(), weapon) );
         weapon->setWeaponPack(0);
     }
 
@@ -102,7 +104,7 @@
     {
         unsigned int i = 0;
 
-        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
+        for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
         {
             if (i == index)
                 return (*it);
@@ -141,7 +143,7 @@
 
     void WeaponPack::notifyWeapons()
     {
-        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
+        for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
             (*it)->setWeaponPack(this);
     }
 }

Modified: code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.h
===================================================================
--- code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.h	2009-11-16 10:29:59 UTC (rev 6075)
+++ code/branches/particles2/src/orxonox/weaponsystem/WeaponPack.h	2009-11-16 16:58:34 UTC (rev 6076)
@@ -68,7 +68,7 @@
         private:
             void notifyWeapons();
 
-            std::set<Weapon *> weapons_;
+            std::vector<Weapon *> weapons_;
             std::set<DefaultWeaponmodeLink *> links_;
             WeaponSystem * weaponSystem_;
     };

Modified: code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.cc
===================================================================
--- code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.cc	2009-11-16 10:29:59 UTC (rev 6075)
+++ code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.cc	2009-11-16 16:58:34 UTC (rev 6076)
@@ -201,7 +201,7 @@
                 it->second->setWeaponmodeLink(wPack, weaponmode);
         }
 
-        this->weaponPacks_.insert(wPack);
+        this->weaponPacks_.push_back(wPack);
         wPack->setWeaponSystem(this);
 
         return true;
@@ -220,13 +220,14 @@
             it->second->removeWeaponmodeLink(wPack);
 
         // Remove the WeaponPack from the WeaponSystem
-        this->weaponPacks_.erase(wPack);
+        assert( std::find(this->weaponPacks_.begin(),this->weaponPacks_.end(),wPack)!=this->weaponPacks_.end() );
+        this->weaponPacks_.erase( std::find(this->weaponPacks_.begin(),this->weaponPacks_.end(),wPack) );
     }
 
     WeaponPack * WeaponSystem::getWeaponPack(unsigned int index) const
     {
         unsigned int i = 0;
-        for (std::set<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
+        for (std::vector<WeaponPack*>::const_iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it)
         {
             ++i;
             if (i > index)
@@ -257,7 +258,7 @@
             return;
 
         // Check if the WeaponPack belongs to this WeaponSystem
-        std::set<WeaponPack *>::iterator it1 = this->weaponPacks_.find(wPack);
+        std::vector<WeaponPack *>::iterator it1 = std::find( this->weaponPacks_.begin(), this->weaponPacks_.end(), wPack );
         if (it1 == this->weaponPacks_.end())
             return;
 

Modified: code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.h
===================================================================
--- code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.h	2009-11-16 10:29:59 UTC (rev 6075)
+++ code/branches/particles2/src/orxonox/weaponsystem/WeaponSystem.h	2009-11-16 16:58:34 UTC (rev 6076)
@@ -91,7 +91,7 @@
         private:
             std::map<unsigned int, WeaponSet *> weaponSets_;
             std::vector<WeaponSlot *> weaponSlots_;
-            std::set<WeaponPack *> weaponPacks_;
+            std::vector<WeaponPack *> weaponPacks_;
             std::map<Identifier *, Munition *> munitions_;
             Pawn * pawn_;
     };




More information about the Orxonox-commit mailing list