Index: code/branches/main_reto_vs05/src/weapon_manager.cc
===================================================================
--- code/branches/main_reto_vs05/src/weapon_manager.cc	(revision 169)
+++ code/branches/main_reto_vs05/src/weapon_manager.cc	(revision 177)
@@ -27,7 +27,15 @@
 
 #include "OgreSceneManager.h"
+#include "OgreEntity.h"
+#include "OgreSceneNode.h"
+#include "OgreVector3.h"
+#include "OgreStringConverter.h"
 
 #include "weapon.h"
+#include "bullet.h"
+#include "bullet_manager.h"
 #include "weapon_manager.h"
+
+#define ACTION_LIST_SIZE 4
 
 
@@ -38,8 +46,15 @@
 
   WeaponManager::WeaponManager(SceneManager *sceneMgr, SceneNode *node,
-        int slotSize)
-        : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0)
+        BulletManager *bulletManager, int slotSize)
+        : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0),
+        bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE),
+        secondaryFireRequest_(false), selectedWeapon_(0),
+        bulletManager_(bulletManager),
+        actionListReadIndex_(0), actionListWriteIndex_(0)
   {
   	slots_ = new Weapon*[slotSize];
+    actionList_ = new Action[ACTION_LIST_SIZE];
+    for (int i = 0; i < ACTION_LIST_SIZE; i++)
+      actionList_[i] = NOTHING;
   }
 
@@ -49,4 +64,6 @@
     if (slots_)
       delete slots_;
+    if (actionList_)
+      delete actionList_;
   }
 
@@ -54,7 +71,11 @@
   bool WeaponManager::addWeapon(const Ogre::String &name)
   {
+    if (!weaponList_s)
+      return false;
+
     if (name == weaponList_s[0]->name_)
     {
       // this is ugly, but for the time being, it has to fit.
+      selectedWeapon_ = slotIndex_;
       slots_[slotIndex_++] = weaponList_s[0];
       return true;
@@ -65,8 +86,117 @@
 
 
+  bool WeaponManager::addAction(const Action act)
+  {
+    if (actionList_[actionListWriteIndex_] == NOTHING)
+    {
+      actionList_[actionListWriteIndex_] = act;
+      actionListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE;
+      return true;
+    }
+    else
+      return false;
+  }
+
+
+  void WeaponManager::primaryFireRequest()
+  {
+    primaryFireRequest_ = true;
+  }
+
+
+  void WeaponManager::primaryFire()
+  {
+    currentState_ = PRIMARY_FIRE;
+
+    // TODO: add the name of the weapon manager. but for that,
+    // the factory is required.
+    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
+          "BulletNode" + StringConverter::toString(bulletCounter_),
+          node_->getWorldPosition(), node_->getWorldOrientation());
+	  temp->setScale(Vector3(1, 1, 1) * 10);
+	  temp->yaw(Degree(-90));
+    Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
+          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
+    Vector3 speed = (node_->getOrientation() * Vector3(0, 0, -1))
+          .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_;
+	  bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
+  
+    currentState_ = IDLE;
+  }
+
+
+  void WeaponManager::secondaryFireRequest()
+  {
+    secondaryFireRequest_ = true;
+  }
+
+  void WeaponManager::secondaryFire()
+  {
+  }
+
+
+  bool WeaponManager::tick(unsigned long time, Real deltaTime)
+  {
+    // return if no weapon has been added
+    if (!slots_[slotIndex_])
+      return true;
+
+    switch (currentState_)
+    {
+    case IDLE:
+      // first, process actions
+      if (actionList_[actionListReadIndex_] != NOTHING)
+      {
+        actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE;
+        break;
+      }
+
+      switch (actionList_[actionListReadIndex_])
+      {
+      case RELOAD:
+        break;
+
+      case ZOOM_IN:
+        break;
+
+      case ZOOM_OUT:
+        break;
+
+      default:
+        break;
+      }
+
+      // secondly, execute firing
+      if (primaryFireRequest_)
+        primaryFire();
+      else if (secondaryFireRequest_)
+        secondaryFire();
+
+      break;
+
+    case PRIMARY_FIRE:
+      break;
+
+    case SECONDARY_FIRE:
+      break;
+
+    case RELOADING:
+      break;
+    }
+
+    primaryFireRequest_ = false;
+    secondaryFireRequest_ = false;
+
+    return true;
+  }
+
+
   // static
   bool WeaponManager::loadWeapons()
   {
-    weaponList_s[0] = new Weapon("Barrel Gun", 10, 2);
+    weaponList_s = new Weapon*[5];
+    for (int i = 0; i < 5; i++)
+      weaponList_s[i] = NULL;
+    weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500);
     return true;
   }
@@ -76,5 +206,11 @@
   void WeaponManager::destroyWeapons()
   {
-    delete weaponList_s[0];
+    if (weaponList_s)
+    {
+      for (int i = 0; i < 5; i++)
+        if (weaponList_s[i])
+          delete weaponList_s[i];
+      delete weaponList_s;
+    }
   }
 
