Index: orxonox/trunk/src/world_entities/weapons/weapon.cc
===================================================================
--- orxonox/trunk/src/world_entities/weapons/weapon.cc	(revision 4910)
+++ orxonox/trunk/src/world_entities/weapons/weapon.cc	(revision 4926)
@@ -77,5 +77,4 @@
     this->soundBuffers[i] = NULL;
 
-  this->requestedAction = WA_NONE;
   this->soundSource = new SoundSource(this);
   this->emissionPoint.setParent(this);
@@ -183,8 +182,7 @@
   {
     this->currentState = WS_ACTIVATING;
-    this->requestAction(WA_ACTIVATE);
-  }
-}
-
+    this->requestedAction = WA_ACTIVATE;
+  }
+}
 
 /**
@@ -227,5 +225,8 @@
 #endif
 
-  switch (this->requestedAction)
+  WeaponAction action = this->requestedAction;
+  this->requestedAction = WA_NONE;
+
+  switch (action)
   {
     case WA_SHOOT:
@@ -254,19 +255,15 @@
 bool Weapon::activateW()
 {
-  if (this->currentState == WS_INACTIVE)
+//  if (this->currentState == WS_INACTIVE)
   {
         // play Sound
     if (likely(this->soundBuffers[WA_ACTIVATE] != NULL))
       this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
-    if (likely(this->animation[WS_ACTIVATING] != NULL))
-      this->animation[WS_ACTIVATING]->replay();
         // activate
     PRINTF(4)("Activating the Weapon %s\n", this->getName());
     this->activate();
     // setting up for next action
-    this->currentState = WS_ACTIVATING;
-    this->stateDuration = this->times[WS_ACTIVATING] + this->stateDuration;
-  }
-  this->requestedAction = WA_NONE;
+    this->enterState(WS_ACTIVATING);
+  }
 }
 
@@ -284,13 +281,8 @@
     if (this->soundBuffers[WA_DEACTIVATE] != NULL)
       this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
-    if (likely(this->animation[WS_DEACTIVATING] != NULL))
-      this->animation[WS_DEACTIVATING]->replay();
-        // deactivate
+    // deactivate
     this->deactivate();
-        // setting up for next action
-    this->currentState = WS_DEACTIVATING;
-    this->stateDuration = this->times[WS_DEACTIVATING] + this->stateDuration;
-  }
-  this->requestedAction = WA_NONE;
+    this->enterState(WS_DEACTIVATING);
+  }
 }
 
@@ -306,17 +298,12 @@
     if (this->soundBuffers[WA_CHARGE] != NULL)
       this->soundSource->play(this->soundBuffers[WA_CHARGE]);
-    if (likely(this->animation[WS_CHARGING] != NULL))
-      this->animation[WS_CHARGING]->replay();
 
         // charge
     this->charge();
         // setting up for the next state
-    this->requestedAction = WA_NONE;
-    this->currentState = WS_CHARGING;
-    this->stateDuration = this->times[WS_CHARGING] + this->stateDuration;
+    this->enterState(WS_CHARGING);
   }
   else // deactivate the Weapon if we do not have enough energy
   {
-    this->requestedAction = WA_NONE;
     this->requestAction(WA_RELOAD);
   }
@@ -336,17 +323,12 @@
     if (this->soundBuffers[WA_SHOOT] != NULL)
       this->soundSource->play(this->soundBuffers[WA_SHOOT]);
-    if (likely(this->animation[WS_SHOOTING] != NULL))
-      this->animation[WS_SHOOTING]->replay();
           // fire
     this->fire();
     this->energyLoaded -= this->minCharge;
           // setting up for the next state
-    this->stateDuration = this->times[WS_SHOOTING] + this->stateDuration;
-    this->currentState = WS_SHOOTING;
-    this->requestedAction = WA_NONE;
+    this->enterState(WS_SHOOTING);
   }
   else  // reload if we still have the charge
   {
-    this->requestedAction = WA_NONE;
     this->requestAction(WA_RELOAD);
   }
@@ -371,6 +353,4 @@
   if (this->soundBuffers[WA_RELOAD] != NULL)
     this->soundSource->play(this->soundBuffers[WA_RELOAD]);
-  if (likely(this->animation[WS_RELOADING] != NULL))
-    this->animation[WS_RELOADING]->replay();
 
   if (chargeSize > this->energy)
@@ -387,9 +367,20 @@
   }
   this->reload();
-
-  this->requestedAction = WA_NONE;
-  this->currentState = WS_RELOADING;
-  this->stateDuration = this->times[WS_RELOADING] + this->stateDuration;
-
+  this->enterState(WS_RELOADING);
+}
+
+
+/**
+ * enters the requested State, plays back animations updates the timing.
+ * @param state the state to enter.
+ */
+inline void Weapon::enterState(WeaponState state)
+{
+  // playing animation if availiable
+  if (likely(this->animation[state] != NULL))
+    this->animation[state]->replay();
+
+  this->stateDuration = this->times[state] + this->stateDuration;
+  this->currentState = state;
 }
 
