Index: /orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc
===================================================================
--- /orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc	(revision 4879)
+++ /orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc	(revision 4880)
@@ -120,5 +120,4 @@
   alDeleteSources(1, &this->sourceID);
 }
-
 
 /**
Index: /orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc
===================================================================
--- /orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc	(revision 4879)
+++ /orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc	(revision 4880)
@@ -91,8 +91,8 @@
       this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
     }
-
+/*
   this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
   this->weaponSource = new SoundSource(this->fireSound, this);
-  this->weaponSource->setRolloffFactor(.1);
+  this->weaponSource->setRolloffFactor(.1);*/
   Projectile* p = new TestBullet(this);
 //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
@@ -182,13 +182,4 @@
 void TestGun::destroy ()
 {}
-
-
-/**
- *  tick signal for time dependent/driven stuff
-*/
-void TestGun::tick (float time)
-{
-  this->stateTime += time;
-}
 
 
Index: /orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h
===================================================================
--- /orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h	(revision 4879)
+++ /orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h	(revision 4880)
@@ -47,5 +47,4 @@
     virtual void destroy();
 
-    virtual void tick(float time);
     virtual void weaponIdle();
     virtual void draw();
Index: /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc
===================================================================
--- /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc	(revision 4879)
+++ /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc	(revision 4880)
@@ -13,4 +13,6 @@
    main-programmer: Patrick Boenzli
    co-programmer: Benjamin Grauer
+
+   2005-07-15: Benjamin Grauer: restructurating the entire Class
 */
 
@@ -23,4 +25,6 @@
 #include "list.h"
 #include "state.h"
+#include "animation3d.h"
+#include "sound_engine.h"
 
 /**
@@ -42,27 +46,31 @@
 Weapon::~Weapon ()
 {
-  // model will be deleted from WorldEntity-destructor
-  //this->worldEntities = NULL;
-
-  /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */
-
-  /* all animations are deleted via the animation player*/
-}
-
+  for (int i = 0; i < WS_STATE_COUNT; i++)
+    if (this->animation[i])
+      delete this->animation[i];
+  for (int i = 0; i < WA_ACTION_COUNT; i++)
+    if (this->soundBuffers[i])
+      delete this->soundBuffers[i];
+}
+
+/**
+ * initializes the Weapon with ALL default values
+ */
 void Weapon::init()
 {
   this->currentState     = WS_INACTIVE;
-  this->stateTime        = 0.0;
+  this->stateDuration    = 0.0;
   for (int i = 0; i < WS_STATE_COUNT; i++)
-  {
-    this->times[i] = 0.0;
-    this->animation[i] = NULL;
-  }
+    {
+      this->times[i] = 0.0;
+      this->animation[i] = NULL;
+    }
   for (int i = 0; i < WA_ACTION_COUNT; i++)
     this->soundBuffers[i] = NULL;
 
+  this->requestedAction = WA_NONE;
   this->weaponSource = NULL;
-  this->minCharge;
-  this->maxCharge;
+  this->minCharge = 0.0;
+  this->maxCharge = 0.0;
 
   this->active = false;
@@ -94,10 +102,35 @@
 
 
+void Weapon::requestAction(WeaponAction action)
+{
+  this->requestedAction = action;
+}
+
+bool Weapon::execute(WeaponAction action)
+{
+  this->stateDuration = this->times[action] + this->stateDuration;
+
+  switch (action)
+  {
+    case WA_SHOOT:
+      this->fire();
+      break;
+    case WA_CHARGE:
+      this->charge();
+      break;
+    case WA_RELOAD:
+      this->reload();
+      break;
+    case WA_DEACTIVATE:
+      this->deactivate();
+      break;
+    case WA_ACTIVATE:
+      this->activate();
+      break;
+  }
+}
+
 /**
  * this activates the weapon
- *
- * This is needed, since there can be more than one weapon on a ship. the
- * activation can be connected with an animation. for example the weapon is
- * been armed out.
 */
 void Weapon::activate()
@@ -107,22 +140,21 @@
 /**
  * this deactivates the weapon
- *
- * This is needed, since there can be more than one weapon on a ship. the
- * activation can be connected with an animation. for example the weapon is
- * been armed out.
 */
 void Weapon::deactivate()
 {}
 
-/**
- * is called, when the weapon gets hit (=collide with something)
- * @param from which entity it is been hit
- * @param where it is been hit
- *
- * this may not be used, since it would make the game relay complicated when one
- * can destroy the weapons of enemies or vice versa.
-*/
-void Weapon::hit (WorldEntity* entity, const Vector& position)
-{}
+void Weapon::fire()
+{
+
+}
+
+void Weapon::reload()
+{
+
+}
+
+void Weapon::charge()
+{
+}
 
 
@@ -138,8 +170,20 @@
 
 /**
- *  tick signal for time dependent/driven stuff
-*/
-void Weapon::tick (float time)
-{}
+ * tick signal for time dependent/driven stuff
+*/
+void Weapon::tick(float dt)
+{
+  if (this->isActive())
+  {
+    this->stateDuration -= dt;
+
+    if (this->stateDuration < 0.0)
+      this->execute(this->requestedAction);
+  }
+  else
+    if (this->requestedAction == WA_ACTIVATE)
+      this->activate();
+
+}
 
 /**
@@ -153,4 +197,27 @@
 
 
+//////////////////////
+// HELPER FUNCTIONS //
+//////////////////////
+// inclass
+/**
+ * checks if the next Action given is valid
+ * @returns if the Action that comes next is valid
+ * @todo more checks
+ */
+bool Weapon::nextActionValid() const
+{
+  if (this->currentState == WS_INACTIVE)
+  {
+    return (this->requestedAction == WA_ACTIVATE || this->requestedAction == WA_NONE);
+  }
+  else
+    return true;
+
+}
+
+
+
+// static
 /**
  * Converts a String into an Action.
@@ -175,8 +242,8 @@
     return WA_SPECIAL1;
   else
-  {
-    PRINTF(2)("action %s could not be identified.\n", action);
-    return WA_NONE;
-  }
+    {
+      PRINTF(2)("action %s could not be identified.\n", action);
+      return WA_NONE;
+    }
 }
 
@@ -192,4 +259,6 @@
   else if (!strcmp(state, "shooting"))
     return WS_SHOOTING;
+  else if (!strcmp(state, "charging"))
+    return WS_CHARGING;
   else if (!strcmp(state, "reloading"))
     return WS_RELOADING;
@@ -203,8 +272,7 @@
     return WS_IDLE;
   else
-  {
-    PRINTF(2)("state %s could not be identified.\n", state);
-    return WS_NONE;
-  }
-}
-
+    {
+      PRINTF(2)("state %s could not be identified.\n", state);
+      return WS_NONE;
+    }
+}
Index: /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h
===================================================================
--- /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h	(revision 4879)
+++ /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h	(revision 4880)
@@ -12,5 +12,5 @@
     weapon in this world:
      o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
-     o shooting animation
+     o animations
 */
 
@@ -45,4 +45,5 @@
   WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
   WS_SHOOTING      =    1,    //!< The State of the Shooting
+  WS_CHARGING      =    2,    //!< The state of charging th weapon
   WS_RELOADING     =    3,    //!< The State of the Reloading
   WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
@@ -68,64 +69,82 @@
 class Weapon : public WorldEntity
 {
-  friend class World;
+  public:
+    // INITIALISATION //
+    Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
+    Weapon(const TiXmlElement* root);
+    virtual ~Weapon ();
 
- public:
-  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
-  Weapon(const TiXmlElement* root);
-  virtual ~Weapon ();
+    void init();
+    void loadParams(const TiXmlElement* root);
+    ////////////////////
 
-  void init();
-  void loadParams(const TiXmlElement* root);
+    void requestAction(WeaponAction action);
 
-  void setProjectile(Projectile* projectile);
-  Projectile* getProjectile();
+    /** @returns true if the Weapon is Active */
+    inline bool isActive() const { return this->active; };
 
-  virtual void activate();
-  virtual void deactivate();
-  virtual void fire() = 0;
-  //virtual void reload();
-  //virtual void charge();
-  bool isActive() const { return this->active; };
+    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
+    void setProjectile(Projectile* projectile);
+    Projectile* getProjectile();
 
-  // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
-  void setStateDuration(const char* state, float duration);
-  void setStateDuration(WeaponState state, float duration);
-  float getStateDuration(WeaponState state) { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
-  /** @return true if idletime is elapsed, false otherwise */
-  inline bool stateTimeElapsed() const { return (this->stateTime > this->times[currentState])?true:false; };
+    /** @param state the State to time @param duration the duration of the State */
+    inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); };
+    /** @param state the State to time @param duration the duration of the State */
+    inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; };
+    /** @param state The state to query @returns the Time the queried State takes to complete */
+    inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
+    /** @returns true if the time of the currentState is elapsed, false otherwise */
+    inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])?true:false; };
+    /** @returns the current State of the Weapon */
+    inline WeaponState getCurrentState() const { return this->currentState; };
 
-  /**  fires the weapon */
-  virtual void hit (WorldEntity* weapon, const Vector& loc);
-  virtual void destroy();
 
-  virtual void tick(float time);
-  virtual void draw();
 
-  private:
+    virtual void destroy();
+
+
+
+    virtual void tick(float dt);
+    virtual void draw();
+
+  protected:
     static WeaponAction  charToAction(const char* action);
     static WeaponState   charToState(const char* state);
 
 
- protected:
-  ////////////
-  // PHASES //
-  ////////////
-  WeaponState          currentState;                     //!< The State the weapon is in.
-  WeaponAction         requestAction;                    //!< An action to try to Engage after the currentState ends.
-  float                stateTime;                        //!< how long the state has taken until now.
-  float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
-  SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
-  Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
+    bool execute(WeaponAction action);
+    virtual void activate();
+    virtual void deactivate();
+    virtual void fire();
+    virtual void reload();
+    virtual void charge();
 
-  SoundBuffer*         fireSound;
-  SoundSource*         weaponSource;
+  private:
+    bool nextActionValid() const;
 
-  float                minCharge;
-  float                maxCharge;
+  protected:
+    SoundSource*         weaponSource;
+    float                energy;
+    int                  energyI;
 
- private:
-   bool                 active;                          //!< states wheter the weapon is enabled or not
-   Projectile*          projectile;                      //!< the projectile used for this weapon
-};
+    ////////////
+    // PHASES //
+    ////////////
+    WeaponState          currentState;                     //!< The State the weapon is in.
+    WeaponAction         requestedAction;                  //!< An action to try to Engage after the currentState ends.
+    float                stateDuration;                    //!< how long the state has taken until now.
+    float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
+    SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
+    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
+
+  private:
+    bool                 active;                          //!< states wheter the weapon is enabled or not
+    Projectile*          projectile;                      //!< the projectile used for this weapon
+  };
 
 #endif /* _WEAPON_H */
Index: /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon_manager.cc
===================================================================
--- /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon_manager.cc	(revision 4879)
+++ /orxonox/branches/weaponSystem/src/world_entities/weapons/weapon_manager.cc	(revision 4880)
@@ -201,10 +201,10 @@
       if( w1 != NULL )
       {
-        w1->deactivate();
+        w1->requestAction(WA_DEACTIVATE);
         printf("deactivating %i,%i\n", j,lastConfID);
       }
       if( w2 != NULL)
       {
-        w2->activate();
+        w2->requestAction(WA_ACTIVATE);
         printf("activating %i,%i\n", j, this->currConfID);
       }
@@ -223,5 +223,5 @@
   {
     firingWeapon = this->configs[this->currConfID].slots[i];
-    if( firingWeapon != NULL) firingWeapon->fire();
+    if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
   }
   this->crosshair->setRotationSpeed(500);
