Index: orxonox/branches/physics/src/world_entities/weapon.cc
===================================================================
--- orxonox/branches/physics/src/world_entities/weapon.cc	(revision 3866)
+++ orxonox/branches/physics/src/world_entities/weapon.cc	(revision 3953)
@@ -16,4 +16,5 @@
 */
 
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
 
 #include "weapon.h"
@@ -30,44 +31,165 @@
 
 
+/**
+   \brief this initializes the weaponManager for a given nnumber of weapon slots
+   \param number of weapon slots of the model/ship <= 8 (limitied)
+*/
 WeaponManager::WeaponManager(int nrOfSlots) 
 {
+  for(int i = 0; i < W_MAX_CONFIGS; ++i)
+    {
+      this->configs[i].bUsed = false;
+      for(int j = 0; j < W_MAX_SLOTS; ++j)
+	this->configs[i].slots[j] = NULL;
+    }
   this->nrOfSlots = nrOfSlots;
-  this->nrOfConfigs = 1;
-
-  for(int i = 0; i < W_MAX_CONFS; ++i)
-    this->configs[i] = NULL;
-  this->currentConfig = new weaponConfig;
-  this->configs[0] = this->currentConfig;
-}
+  this->currConfID = W_CONFIG0;
+}
+
 
 WeaponManager::~WeaponManager() 
 {
-
-}
-
-void WeaponManager::addWeapon(Weapon* weapon, slotID slot, configID config) 
-{
-  if(this->configs[config] == NULL)
-    PRINTF(0)("");
-  //  this->configs[(int)config]->
-}
-
-void WeaponManager::addWeaponConfig(weaponConfig* config) 
-{}
-
+  /* 
+     i dont have to delete the weapons itself, because they are 
+     worldentities and therefore in the entities list of the world.
+     world will clean them up for me
+  */
+  for(int i = 0; i < W_MAX_CONFIGS; ++i)
+    {
+      this->configs[i].bUsed = false;
+      for(int j = 0; j < W_MAX_SLOTS; ++j)
+	this->configs[i].slots[j] = NULL;
+    }
+}
+
+
+/**
+   \brief adds a weapon to the selected weaponconfiguration into the selected slot
+   \param the weapon to add
+   \param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot
+   \param an identifier for the weapon configuration, number between 0..3
+
+   if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be
+   replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free
+   slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be 
+   a error message.
+*/
+void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 
+{
+  if( slotID == W_FREE_SLOT)
+    {
+      int freeSlot = this->getNextFreeSlot( configID);
+      if( freeSlot < 0 || freeSlot >= this->nrOfSlots)
+	{
+	  PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");
+	  return;
+	}
+      PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot);
+      this->configs[configID].bUsed = true;
+      this->configs[configID].slots[freeSlot] = weapon;
+      return;
+    }
+  this->configs[configID].bUsed = true;
+  this->configs[configID].slots[slotID] = weapon;
+  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
+}
+
+
+void WeaponManager::removeWeapon(Weapon* weapon, int configID)
+{
+  /* empty */
+}
+
+
+/**
+   \brief changes to the next weapon configuration
+
+   if there are multiple weapon configurations defined by the manager, use this to switch between them
+   this function will deactivate the weapons first, change the config and reactivate them later
+*/
 void WeaponManager::nextWeaponConf() 
-{}
-
-void WeaponManager::prevWeaponConf() 
-{}
-
-
-void WeaponManager::selectConfig(configID config) 
-{
-  if( this->configs[(int)config] != NULL)
-    this->currentConfig = this->configs[(int)config];
-  else
-    PRINTF(0)("There is no weapon config defined with the number W_CONF%i", (int)config);
-}
+{
+  PRINTF(4)("Changing weapon configuration: from %i\n", this->currConfID);
+
+  Weapon* w;
+  for(int i = 0; i < W_MAX_SLOTS; ++i)
+    {
+      w = this->configs[this->currConfID].slots[i];
+      if( w != NULL) w->deactivate();
+    }
+  int i;
+  for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
+  if( i == W_MAX_CONFIGS) this->currConfID = W_CONFIG0;
+  else this->currConfID = i;  
+  PRINTF(4)("\tto %i\n", this->currConfID);
+
+  for(int i = 0; i < W_MAX_SLOTS; ++i)
+    {
+      w = this->configs[this->currConfID].slots[i];
+      if( w != NULL) w->activate();
+    }
+}
+
+
+
+/**
+   \brief triggers fire of all weapons in the current weaponconfig
+*/
+void WeaponManager::fire()
+{
+  Weapon* firingWeapon;
+  for(int i = 0; i < W_MAX_SLOTS; ++i)
+    {
+      firingWeapon = this->configs[this->currConfID].slots[i];
+      if( firingWeapon != NULL) firingWeapon->fire();
+    }
+}
+
+
+/**
+   \brief triggers tick of all weapons in the current weaponconfig
+   \param second passed since last tick
+*/
+void WeaponManager::tick(float sec)
+{
+  Weapon* w;
+  for(int i = 0; i < W_MAX_SLOTS; ++i)
+    {
+      w = this->configs[this->currConfID].slots[i];
+      if( w != NULL) w->tick(sec);
+    }
+}
+
+
+/**
+   \brief triggers draw of all weapons in the current weaponconfig
+*/
+void WeaponManager::draw()
+{
+  Weapon* w;
+  for(int i = 0; i < W_MAX_SLOTS; ++i)
+    {
+      w = this->configs[this->currConfID].slots[i];
+      if( w != NULL) w->draw();
+    }
+}
+
+
+/**
+   \brief private gets the next free slot in a certain weaponconfig
+   \param the selected weaponconfig
+*/
+int WeaponManager::getNextFreeSlot(int configID)
+{
+  for( int i = 0; i < W_MAX_SLOTS; ++i)
+    {
+      if( this->configs[configID].slots[i] == NULL)
+	return i;
+    }
+  return -1;
+}
+
+
+
 
 
@@ -78,12 +200,20 @@
    creates a new weapon
 */
-Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction) 
+Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction) 
   : WorldEntity()
 {
   parent->addChild(this, PNODE_ALL);
-  this->setRelCoor(*coordinate);
-  this->setRelDir(*direction);
+  this->setRelCoor(coordinate);
+  this->setRelDir(direction);
   WorldInterface* wi = WorldInterface::getInstance();
   this->worldEntities = wi->getEntityList();
+
+  this->objectComponent1 = NULL;
+  this->objectComponent2 = NULL;
+  this->objectComponent3 = NULL;
+
+  this->animation1 = NULL;
+  this->animation2 = NULL;
+  this->animation3 = NULL;
 }
 
@@ -95,4 +225,9 @@
 {
   // 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*/
 }
 
@@ -190,48 +325,7 @@
 {}
 
-/**
-   \brief sets a weapon idle time
-   \param idle time in ms
-
-   a weapon idle time is the time spend after a shoot until the weapon can
-   shoot again
-*/
-void Weapon::setWeaponIdleTime(float time)
-{
-  this->idleTime = time;
-}
-
-/**
-   \brief gets the weapon idle time
-   \returns idle time in ms
-
-   a weapon idle time is the time spend after a shoot until the weapon can
-   shoot again
-*/
-float Weapon::getWeaponIdleTime(void)
-{
-  return this->idleTime;
-}
-
-/**
-   \brief checks if the idle time is elapsed
-   \return true if time is elapsed
-
-   a weapon idle time is the time spend after a shoot until the weapon can
-   shoot again
-*/
-bool Weapon::hasWeaponIdleTimeElapsed(void)
-{
-  return (this->localTime>this->idleTime)?true:false;
-}
-
-
-/**
-   \brief fires the weapon
-   
-   this is called from the player.cc, when fire-button is been pushed
-*/
-void Weapon::fire()
-{}
+
+
+
 
 
