Index: code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc
===================================================================
--- code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc	(revision 2098)
+++ code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc	(revision 2662)
@@ -37,11 +37,19 @@
 namespace orxonox
 {
-    Weapon::Weapon(BaseObject* creator) : BaseObject(creator)
+    CreateFactory(Weapon);
+
+    Weapon::Weapon(BaseObject* creator) : StaticEntity(creator)
     {
         RegisterObject(Weapon);
+        this->bulletReadyToShoot_ = true;
+        this->magazineReadyToShoot_ = true;
+        this->parentWeaponSystem_ = 0;
+        this->attachedToWeaponSlot_ = 0;
+        this->munition_ = 0;
+        this->bulletLoadingTime_ = 0;
+        this->magazineLoadingTime_ = 0;
+        this->bReloading_ = false;
 
-        this->loadingTime_ = 0;
-        this->munition_ = 0;
-
+        this->setObjectMode(0x0);
     }
 
@@ -50,17 +58,139 @@
     }
 
-    void Weapon::addMunition()
+
+    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
+        SUPER(Weapon, XMLPort, xmlelement, mode);
+        XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
+        XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
+        XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
+    }
+
+    void Weapon::setWeapon()
+    {
+        this->munition_->fillBullets();
+        this->munition_->fillMagazines();
+    }
+
+
+    void Weapon::fire()
+    {
+//COUT(0) << "LaserGun::fire, this=" << this << std::endl;
+        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
+        {
+//COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
+//COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
+            this->bulletReadyToShoot_ = false;
+            if ( this->munition_->bullets() > 0)
+            {
+                //shoot
+                this->takeBullets();
+                this->createProjectile();
+            }
+            //if there are no bullets, but magazines
+            else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
+            {
+//COUT(0) << "LaserGun::fire - no bullets" << std::endl;
+                this->takeMagazines();
+            }
+            else
+            {
+//COUT(0) << "LaserGun::fire - no magazines" << std::endl;
+                //actions
+            }
+        }
+        else
+        {
+//COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
+            //actions
+        }
 
     }
 
-    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+
+    void Weapon::bulletTimer(float bulletLoadingTime)
     {
-
+//COUT(0) << "Weapon::bulletTimer started" << std::endl;
+        this->bReloading_ = true;
+        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
+    }
+    void Weapon::magazineTimer(float magazineLoadingTime)
+    {
+//COUT(0) << "Weapon::magazineTimer started" << std::endl;
+        this->bReloading_ = true;
+        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
     }
 
-    void Weapon::fire()
+    void Weapon::bulletReloaded()
     {
+        this->bReloading_ = false;
+        this->bulletReadyToShoot_ = true;
+    }
 
+    void Weapon::magazineReloaded()
+    {
+        this->bReloading_ = false;
+        this->munition_->fillBullets();
+        this->magazineReadyToShoot_ = true;
+        this->bulletReadyToShoot_ = true;
     }
+
+
+    void Weapon::attachNeededMunition(std::string munitionName)
+    {
+//COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
+        //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
+        if (this->parentWeaponSystem_)
+        {
+//COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
+            Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
+            if ( munition )
+                this->munition_ = munition;
+            else
+            {
+                //create new munition with identifier
+//COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
+                this->munitionIdentifier_ = ClassByString(munitionName);
+                this->munition_ = this->munitionIdentifier_.fabricate(this);
+                this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
+            }
+        }
+    }
+
+
+     /*get and set functions
+     *
+     */
+
+    void Weapon::setMunitionType(std::string munitionType)
+    {   this->munitionType_ = munitionType; }
+
+    const std::string Weapon::getMunitionType()
+    {   return this->munitionType_;  }
+
+    void Weapon::setBulletLoadingTime(float loadingTime)
+    {   this->bulletLoadingTime_ = loadingTime; }
+
+    const float Weapon::getBulletLoadingTime()
+    {   return this->bulletLoadingTime_;  }
+
+    void Weapon::setMagazineLoadingTime(float loadingTime)
+    {   this->magazineLoadingTime_ = loadingTime; }
+
+    const float Weapon::getMagazineLoadingTime()
+    {   return this->magazineLoadingTime_;  }
+
+
+    Munition * Weapon::getAttachedMunition(std::string munitionType)
+    {
+//COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
+        this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
+//COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
+        return this->munition_;
+    }
+
+    void Weapon::takeBullets() { };
+    void Weapon::createProjectile() { };
+    void Weapon::takeMagazines() { };
+
 }
