Index: orxonox/branches/weaponSystem/orxonox.kdevelop
===================================================================
--- orxonox/branches/weaponSystem/orxonox.kdevelop	(revision 4881)
+++ orxonox/branches/weaponSystem/orxonox.kdevelop	(revision 4882)
@@ -1,24 +1,24 @@
-<?xml version="1.0"?>
+<?xml version = '1.0'?>
 <kdevelop>
- <general>
-  <author>orxonox-crew:</author>
-  <email>orxonox-dev@mail.datacore.ch</email>
-  <version>$VERSION$</version>
-  <projectmanagement>KDevCustomProject</projectmanagement>
-  <primarylanguage>C++</primarylanguage>
-  <ignoreparts>
-  </ignoreparts>
- </general>
- <kdevcustomproject>
-  <run>
-   <mainprogram>orxonox</mainprogram>
-  </run>
- </kdevcustomproject>
- <kdevdebugger>
   <general>
-   <dbgshell></dbgshell>
+    <author>orxonox-crew:</author>
+    <email>orxonox-dev@mail.datacore.ch</email>
+    <version>$VERSION$</version>
+    <projectmanagement>KDevCustomProject</projectmanagement>
+    <primarylanguage>C++</primarylanguage>
+    <ignoreparts/>
   </general>
- </kdevdebugger>
- <kdevdoctreeview>
+  <kdevcustomproject>
+    <run>
+      <mainprogram>orxonox</mainprogram>
+      <directoryradio>executable</directoryradio>
+    </run>
+  </kdevcustomproject>
+  <kdevdebugger>
+    <general>
+      <dbgshell/>
+    </general>
+  </kdevdebugger>
+  <kdevdoctreeview>
     <ignoretocs>
       <toc>ada</toc>
@@ -65,5 +65,5 @@
       <toc>KDE Libraries (Doxygen)</toc>
     </ignoredoxygen>
- </kdevdoctreeview>
+  </kdevdoctreeview>
   <kdevfilecreate>
     <filetypes/>
@@ -74,3 +74,28 @@
     </useglobaltypes>
   </kdevfilecreate>
+  <kdevcppsupport>
+    <references/>
+    <codecompletion>
+      <includeGlobalFunctions>true</includeGlobalFunctions>
+      <includeTypes>true</includeTypes>
+      <includeEnums>true</includeEnums>
+      <includeTypedefs>false</includeTypedefs>
+      <automaticCodeCompletion>true</automaticCodeCompletion>
+      <automaticArgumentsHint>true</automaticArgumentsHint>
+      <automaticHeaderCompletion>true</automaticHeaderCompletion>
+      <codeCompletionDelay>250</codeCompletionDelay>
+      <argumentsHintDelay>400</argumentsHintDelay>
+      <headerCompletionDelay>250</headerCompletionDelay>
+    </codecompletion>
+  </kdevcppsupport>
+  <kdevfileview>
+    <groups>
+      <hidenonprojectfiles>false</hidenonprojectfiles>
+      <hidenonlocation>false</hidenonlocation>
+    </groups>
+    <tree>
+      <hidepatterns>*.o,*.lo,*~,*in</hidepatterns>
+      <hidenonprojectfiles>false</hidenonprojectfiles>
+    </tree>
+  </kdevfileview>
 </kdevelop>
Index: orxonox/branches/weaponSystem/src/orxonox.cc
===================================================================
--- orxonox/branches/weaponSystem/src/orxonox.cc	(revision 4881)
+++ orxonox/branches/weaponSystem/src/orxonox.cc	(revision 4882)
@@ -51,5 +51,5 @@
 #include <string.h>
 
-int verbose = 3;
+int verbose = 4;
 
 using namespace std;
Index: orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc
===================================================================
--- orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc	(revision 4881)
+++ orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc	(revision 4882)
@@ -100,4 +100,7 @@
 
   this->setStateDuration(WS_SHOOTING, 2);
+
+  this->energy = 100;
+  this->minCharge = 2;
 }
 
@@ -146,4 +149,6 @@
 void TestGun::fire()
 {
+  this->energyLoaded -= this->minCharge;
+
   Projectile* pj =  new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));
 //  weaponSource->play();
Index: orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h
===================================================================
--- orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h	(revision 4881)
+++ orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h	(revision 4882)
@@ -34,6 +34,4 @@
 class TestGun : public Weapon
 {
-  friend class World;
-
   public:
     TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
Index: orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc
===================================================================
--- orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc	(revision 4881)
+++ orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc	(revision 4882)
@@ -62,4 +62,5 @@
 {
   this->currentState     = WS_INACTIVE;
+  this->requestedAction  = WA_NONE;
   this->stateDuration    = 0.0;
   for (int i = 0; i < WS_STATE_COUNT; i++)
@@ -73,9 +74,14 @@
   this->requestedAction = WA_NONE;
   this->weaponSource = NULL;
-  this->minCharge = 0.0;
-  this->maxCharge = 0.0;
 
   this->active = true;
   this->projectile = NULL;
+
+  this->minCharge = 1.0;
+  this->maxCharge = 1.0;
+  this->energyLoaded = .0;
+  this->energyLoadedMax = 10.0;
+  this->energy = .0;
+  this->energyMax = 100.0;
 }
 
@@ -106,6 +112,11 @@
 void Weapon::requestAction(WeaponAction action)
 {
-  printf("next action will be %d\n", action);
-  this->requestedAction = action;
+  if (this->requestedAction != WA_NONE)
+    return;
+  else
+  {
+    printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration);
+    this->requestedAction = action;
+  }
 }
 
@@ -114,25 +125,58 @@
   this->stateDuration = this->times[this->requestedAction] + this->stateDuration;
 
-  PRINT(3)("executing action %d\n", this->requestedAction);
+  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
+  this->debug();
 
   switch (this->requestedAction)
   {
     case WA_SHOOT:
-      this->fire();
+      //if (likely(this->currentState != WS_INACTIVE))
+      {
+        if (this->minCharge < this->energyLoaded)
+        {
+          this->fire();
+          this->requestedAction = WA_NONE;
+        }
+        else  // reload if we still have the charge
+        {
+          this->requestedAction = WA_NONE;
+          this->requestAction(WA_RELOAD);
+        }
+      }
       break;
     case WA_CHARGE:
-      this->charge();
+      if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
+      {
+        this->charge();
+        this->requestedAction = WA_NONE;
+      }
+      else // deactivate the Weapon if we do not have enough energy
+      {
+        this->requestedAction = WA_NONE;
+        this->requestAction(WA_RELOAD);
+      }
       break;
     case WA_RELOAD:
-      this->reload();
+      //if (this->currentState != WS_INACTIVE && this->energy + this->energyLoaded >= this->minCharge)
+      {
+        this->reload();
+        this->requestedAction = WA_NONE;
+      }
       break;
     case WA_DEACTIVATE:
-      this->deactivate();
+      if (this->currentState != WS_INACTIVE)
+      {
+        this->deactivate();
+        this->requestedAction = WA_NONE;
+      }
       break;
     case WA_ACTIVATE:
-      this->activate();
-      break;
-  }
-  this->requestedAction = WA_NONE;
+      if (this->currentState == WS_INACTIVE)
+      {
+        this->activate();
+        this->requestedAction = WA_NONE;
+      }
+      break;
+  }
 }
 
@@ -141,5 +185,7 @@
 */
 void Weapon::activate()
-{}
+{
+  PRINTF(4)("Activating the Weapon %s\n", this->getName());
+}
 
 
@@ -148,13 +194,36 @@
 */
 void Weapon::deactivate()
-{}
+{
+  PRINTF(4)("Deactivating the Weapon %s\n", this->getName());
+}
 
 void Weapon::fire()
 {
+  this->energyLoaded -= this->minCharge;
 }
 
 void Weapon::reload()
 {
-
+  PRINTF(4)("Reloading Weapon %s\n", this->getName());
+  if (this->energy + this->energyLoaded < this->minCharge)
+  {
+    this->requestAction(WA_DEACTIVATE);
+    return;
+  }
+
+  float chargeSize = this->energyLoadedMax - this->energyLoaded;       //!< The energy to be charged
+
+  if (chargeSize > this->energy)
+  {
+    this->energyLoaded += this->energy;
+    this->energy = 0.0;
+    PRINT(3)("Energy empty");
+  }
+  else
+  {
+    PRINTF(3)("Loaded %f energy into the Guns Buffer\n", chargeSize);
+    this->energyLoaded += chargeSize;
+    this->energy -= chargeSize;
+  }
 }
 
@@ -185,5 +254,8 @@
   {
     if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE)
+    {
+      this->stateDuration = -dt;
       this->execute();
+    }
   }
   else
@@ -223,4 +295,14 @@
 }
 
+
+/**
+ * some nice debugging information about this Weapon
+ */
+void Weapon::debug() const
+{
+  PRINT(3)("Weapon-Debug %s, state: %s, nexAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), Weapon::actionToChar(requestedAction));
+  PRINT(3)("Energy: max: %f; current: %f;  loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n",
+            this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
+}
 
 
@@ -252,4 +334,37 @@
       return WA_NONE;
     }
+}
+
+/**
+ * converts an action into a String
+ * @param action the action to convert
+ * @return a String matching the name of the action
+ */
+const char* Weapon::actionToChar(WeaponAction action)
+{
+  switch (action)
+  {
+    case WA_SHOOT:
+      return "shoot";
+      break;
+    case WA_CHARGE:
+      return "charge";
+      break;
+    case WA_RELOAD:
+      return "reload";
+      break;
+    case WA_ACTIVATE:
+      return "activate";
+      break;
+    case WA_DEACTIVATE:
+      return "deactivate";
+      break;
+    case WA_SPECIAL1:
+      return "special1";
+      break;
+    default:
+      return "none";
+      break;
+  }
 }
 
@@ -283,2 +398,35 @@
     }
 }
+
+/**
+ * converts a State into a String
+ * @param state the state to convert
+ * @return a String matching the name of the state
+ */
+const char* Weapon::stateToChar(WeaponState state)
+{
+  switch (state)
+  {
+    case WS_SHOOTING:
+      return "shooting";
+      break;
+    case WS_CHARGING:
+      return "charging";
+      break;
+    case WS_RELOADING:
+      return "reloading";
+      break;
+    case WS_ACTIVATING:
+      return "activating";
+      break;
+    case WS_DEACTIVATING:
+      return "deactivating";
+      break;
+    case WS_IDLE:
+      return "idle";
+      break;
+    default:
+      return "none";
+      break;
+  }
+}
Index: orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h
===================================================================
--- orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h	(revision 4881)
+++ orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h	(revision 4882)
@@ -99,18 +99,23 @@
     inline WeaponState getCurrentState() const { return this->currentState; };
 
-
+    inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
 
     virtual void destroy();
 
 
-
+    // FLOW
     virtual void tick(float dt);
     virtual void draw();
 
+    void debug() const;
+
   protected:
+    // utility:
     static WeaponAction  charToAction(const char* action);
+    static const char*   actionToChar(WeaponAction action);
     static WeaponState   charToState(const char* state);
+    static const char*   stateToChar(WeaponState state);
 
-
+    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
     bool execute();
     virtual void activate();
@@ -125,6 +130,11 @@
   protected:
     SoundSource*         weaponSource;
+    // it is all about energy
     float                energy;
-    int                  energyI;
+    float                energyLoaded;
+    float                energyMax;
+    float                energyLoadedMax;
+    float                minCharge;
+    float                maxCharge;
 
     ////////////
@@ -138,6 +148,4 @@
     Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
 
-    float                minCharge;
-    float                maxCharge;
 
     bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
