Index: code/branches/formation/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/AIController.cc	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/AIController.cc	(revision 8990)
@@ -65,6 +65,6 @@
                 if (this->freedomCount_ == 1)
                 {
-                this->state_ = SLAVE;
-                this->freedomCount_ = 0;
+                    this->state_ = SLAVE;
+                    this->freedomCount_ = 0;
                 }
 
@@ -74,13 +74,14 @@
             }
 
+            this->defaultBehaviour(maxrand);
+
+        }
+
+        if (this->state_ == SLAVE && this->mode_ == ATTACK) //TODO: add botlevel parameter
+        {
             // search enemy
             random = rnd(maxrand);
-            if (random < 15 && (!this->target_))
+            if (random < 75 && (!this->target_))
                 this->searchNewTarget();
-
-            // forget enemy
-            random = rnd(maxrand);
-            if (random < 5 && (this->target_))
-                this->forgetTarget();
 
             // next enemy
@@ -89,19 +90,4 @@
                 this->searchNewTarget();
 
-            // fly somewhere
-            random = rnd(maxrand);
-            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
-                this->searchRandomTargetPosition();
-
-            // stop flying
-            random = rnd(maxrand);
-            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
-                this->bHasTargetPosition_ = false;
-
-            // fly somewhere else
-            random = rnd(maxrand);
-            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
-                this->searchRandomTargetPosition();
-
             // shoot
             random = rnd(maxrand);
@@ -116,32 +102,6 @@
         }
 
-        if (this->state_ == SLAVE && this->mode_==ATTACK)
-        {
-            // search enemy
-            random = rnd(maxrand);
-            if (random < 75 && (!this->target_))
-                this->searchNewTarget();
-
-            // next enemy
-            random = rnd(maxrand);
-            if (random < 10 && (this->target_))
-                this->searchNewTarget();
-
-            // shoot
-            random = rnd(maxrand);
-            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
-                this->bShooting_ = true;
-
-            // stop shooting
-            random = rnd(maxrand);
-            if (random < 25 && (this->bShooting_))
-                this->bShooting_ = false;
-
-        }
-
         if (this->state_ == MASTER)
         {
-
-
             this->commandSlaves();
 
@@ -176,42 +136,5 @@
                     this->searchNewMaster();
 
-                // search enemy
-                random = rnd(maxrand);
-                if (random < 15 && (!this->target_))
-                    this->searchNewTarget();
-
-                // forget enemy
-                random = rnd(maxrand);
-                if (random < 5 && (this->target_))
-                    this->forgetTarget();
-
-                // next enemy
-                random = rnd(maxrand);
-                if (random < 10 && (this->target_))
-                    this->searchNewTarget();
-
-                // fly somewhere
-                random = rnd(maxrand);
-                if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
-                    this->searchRandomTargetPosition();
-
-
-                // fly somewhere else
-                random = rnd(maxrand);
-                if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
-                    this->searchRandomTargetPosition();
-
-                // shoot
-                random = rnd(maxrand);
-                if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
-                {
-                this->bShooting_ = true;
-                this->forceFreeSlaves();
-                }
-
-                // stop shooting
-                random = rnd(maxrand);
-                if (random < 25 && (this->bShooting_))
-                    this->bShooting_ = false;
+                this->defaultBehaviour(maxrand);
 
             }
@@ -225,7 +148,70 @@
             return;
 
-        if (this->state_ == MASTER)
-        {
-            if (this->specificMasterAction_ ==  NONE)
+        float random;
+        float maxrand = 100.0f / ACTION_INTERVAL;
+        ControllableEntity* controllable = this->getControllableEntity();
+
+        if (controllable && this->mode_ == NORMAL)// bot is ready to move to a target // mode was DEFAULT in original implementation!
+        {
+            if (this->waypoints_.size() > 0 ) //Waypoint functionality.
+            {
+                WorldEntity* wPoint = this->waypoints_[this->waypoints_.size()-1];
+                if(wPoint)
+                {
+                    this->moveToPosition(wPoint->getWorldPosition()); //BUG ?? sometime wPoint->getWorldPosition() causes crash
+                    if (wPoint->getWorldPosition().squaredDistance(controllable->getPosition()) <= this->squaredaccuracy_)
+                        this->waypoints_.pop_back(); // if goal is reached, remove it from the list
+                }
+                else
+                    this->waypoints_.pop_back(); // remove invalid waypoints
+
+            }
+            else if(this->defaultWaypoint_ && ((this->defaultWaypoint_->getPosition()-controllable->getPosition()).length()  > 200.0f))
+            {
+                this->moveToPosition(this->defaultWaypoint_->getPosition()); // stay within a certain range of the defaultWaypoint_
+                random = rnd(maxrand);
+            }
+        }
+
+        if (this->mode_ != ROCKET)
+        {
+            if (this->state_ == MASTER)
+            {
+                if (this->specificMasterAction_ ==  NONE)
+                {
+                    if (this->target_)
+                    {
+                        if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
+                            this->forgetTarget();
+                        else
+                        {
+                            this->aimAtTarget();
+                            random = rnd(maxrand);
+                            if(this->botlevel_*70 > random && !this->isCloseAtTarget(100))
+                                this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
+                        }
+                    }
+
+                    if (this->bHasTargetPosition_)
+                        this->moveToTargetPosition();
+                    this->doFire();
+                }
+
+                if (this->specificMasterAction_  == TURN180)
+                    this->turn180();
+
+                if (this->specificMasterAction_ == SPIN)
+                    this->spin();
+                if (this->specificMasterAction_ == FOLLOW)
+                    this->follow();
+            }
+
+            if (this->state_ == SLAVE && this->mode_!=ATTACK)
+            {
+                if (this->bHasTargetPosition_)
+                    this->moveToTargetPosition();
+            }
+
+            if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
             {
                 if (this->target_)
@@ -239,43 +225,99 @@
                     this->moveToTargetPosition();
 
-                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
-                    this->getControllableEntity()->fire(0);
-            }
-
-            if (this->specificMasterAction_  == TURN180)
-                    this->turn180();
-
-            if (this->specificMasterAction_ == SPIN)
-                    this->spin();
-            if (this->specificMasterAction_ == FOLLOW)
+                    this->doFire();
+            }
+        }
+        else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
+        {   //Vector-implementation: mode_.back() == ROCKET;
+            if(controllable)
+            {//Check wether the bot is controlling the rocket and if the timeout is over.
+                if(controllable->getIdentifier() == ClassByString("Rocket"))
+
+                {
                     this->follow();
-        }
-
-        if (this->state_ == SLAVE && this->mode_!=ATTACK)
-        {
-
-            if (this->bHasTargetPosition_)
-                this->moveToTargetPosition();
-
-        }
-
-         if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
-        {
-            if (this->target_)
-            {
-                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
-                    this->forgetTarget();
-                else this->aimAtTarget();
-            }
-
-            if (this->bHasTargetPosition_)
-                this->moveToTargetPosition();
-
-            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
-                this->getControllableEntity()->fire(0);
-        }
+                    this->timeout_ -= dt;
+                    if((timeout_< 0)||(!target_))//Check if the timeout is over or target died.
+                    {
+                       controllable->fire(0);//kill the rocket
+                       this->setPreviousMode();//get out of rocket mode
+                    }
+                }
+                else
+                    this->setPreviousMode();//no rocket entity -> get out of rocket mode
+            }
+            else
+                this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
+        }//END_OF ROCKET MODE
 
         SUPER(AIController, tick, dt);
     }
+//**********************************************NEW
+    void AIController::defaultBehaviour(float maxrand)
+    {       float random;
+            // search enemy
+            random = rnd(maxrand);
+            if (random < (botlevel_* 100) && (!this->target_))
+                this->searchNewTarget();
+
+            // forget enemy
+            random = rnd(maxrand);
+            if (random < ((1-botlevel_)*20) && (this->target_))
+                this->forgetTarget();
+
+            // next enemy
+            random = rnd(maxrand);
+            if (random < (botlevel_*30) && (this->target_))
+                this->searchNewTarget();
+
+            // fly somewhere
+            random = rnd(maxrand);
+            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+            // stop flying
+            random = rnd(maxrand);
+            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
+                this->bHasTargetPosition_ = false;
+
+            // fly somewhere else
+            random = rnd(maxrand);
+            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
+                this->searchRandomTargetPosition();
+
+            if (this->state_ == MASTER) // master: shoot
+            {
+                random = rnd(maxrand);
+                if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_))
+                {
+                    this->bShooting_ = true;
+                    this->forceFreeSlaves();
+                }
+            }
+            else
+            {
+                // shoot
+                random = rnd(maxrand);
+                if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
+                    this->bShooting_ = true;
+            }
+
+            // stop shooting
+            random = rnd(maxrand);
+            if (random < ((1 - botlevel_)*50) && (this->bShooting_))
+                this->bShooting_ = false;
+
+            // boost
+            random = rnd(maxrand);
+            if (random < botlevel_*50 )
+                this->boostControl();
+
+            // update Checkpoints
+            /*random = rnd(maxrand);
+            if (this->defaultWaypoint_ && random > (maxrand-10))
+                this->manageWaypoints();
+            else //if(random > maxrand-10) //CHECK USABILITY!!*/
+            if (this->waypoints_.size() == 0 )
+                this->manageWaypoints();
+    }
 
 }
Index: code/branches/formation/src/orxonox/controllers/AIController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/AIController.h	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/AIController.h	(revision 8990)
@@ -44,13 +44,14 @@
             virtual ~AIController();
 
-            virtual void tick(float dt);
+            virtual void tick(float dt); //<! Carrying out the targets set in action().
 
         protected:
-            virtual void action();
+            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
+            void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
 
         private:
             static const float ACTION_INTERVAL;
 
-            Timer actionTimer_;
+            Timer actionTimer_; //<! Regularly calls action().
     };
 }
Index: code/branches/formation/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/ArtificialController.cc	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/ArtificialController.cc	(revision 8990)
@@ -30,4 +30,11 @@
 #include "core/CoreIncludes.h"
 #include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/SpaceShip.h"
+
+#include "weaponsystem/WeaponMode.h"
+#include "weaponsystem/WeaponPack.h"
+#include "weaponsystem/Weapon.h"
+#include "weaponsystem/WeaponSlot.h"
+#include "weaponsystem/WeaponSlot.h"
 
 
@@ -37,10 +44,19 @@
     ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator)
     {
-          
+        this->bSetupWorked = false;
+        this->botlevel_ = 0.5f;
+        this->timeout_ = 0;
+        this->currentWaypoint_ = 0;
+        this->setAccuracy(5);
+        this->defaultWaypoint_ = NULL;
     }
 
     ArtificialController::~ArtificialController()
     {
-        
+        if (this->isInitialized())
+        {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
+            this->waypoints_.clear();
+            this->weaponModes_.clear();
+        }
     }
 
@@ -181,5 +197,5 @@
     void ArtificialController::setPreviousMode()
     {
-        this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();
+        this->mode_ = NORMAL; //Vector-implementation: mode_.pop_back();
     }
 
@@ -249,5 +265,5 @@
 
     /**
-        @brief Adds point of interest depending on context. Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
+        @brief Adds point of interest depending on context.  TODO: Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
     */
     void ArtificialController::manageWaypoints()
Index: code/branches/formation/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/FormationController.cc	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/FormationController.cc	(revision 8990)
@@ -40,4 +40,5 @@
 #include "gametypes/TeamDeathmatch.h"
 #include "gametypes/Dynamicmatch.h"
+//#include "gametypes/Mission.h" TODO: include mission after merging
 #include "gametypes/Gametype.h"
 #include "controllers/WaypointPatrolController.h"
@@ -961,5 +962,5 @@
         }
 
-        Mission* miss = orxonox_cast<Mission*>(gametype); //NEW
+        /*Mission* miss = orxonox_cast<Mission*>(gametype); //NEW
         if (miss)
         {
@@ -969,5 +970,5 @@
             if (entity2->getPlayer())
                 team2 = miss->getTeam(entity2->getPlayer());
-        }
+        }*/
 
         TeamBaseMatchBase* base = 0;
Index: code/branches/formation/src/orxonox/controllers/FormationController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/FormationController.h	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/FormationController.h	(revision 8990)
@@ -88,5 +88,5 @@
                Attack-leave formation, attack every target
       */ 
-      enum Mode {NORMAL,DEFEND,ATTACK};
+      enum Mode {NORMAL,DEFEND,ATTACK,ROCKET};
       
       /**
Index: code/branches/formation/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/HumanController.cc	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/HumanController.cc	(revision 8990)
@@ -318,16 +318,18 @@
         {
             switch (HumanController::localController_s->getMode()) {
-              case NORMAL:
-                HumanController::localController_s->setMode(DEFEND);
-                orxout(message) <<"Mode: DEFEND "<< endl;
-                break;
-              case DEFEND:
-                HumanController::localController_s->setMode(ATTACK);
-                orxout(message) <<"Mode: ATTACK "<< endl;
-                break;
-              case ATTACK:
-                HumanController::localController_s->setMode(NORMAL);
-                orxout(message) <<"Mode: NORMAL "<< endl;
-                break;
+                case NORMAL:
+                    HumanController::localController_s->setMode(DEFEND);
+                    orxout(message) <<"Mode: DEFEND "<< endl;
+                    break;
+                case DEFEND:
+                    HumanController::localController_s->setMode(ATTACK);
+                    orxout(message) <<"Mode: ATTACK "<< endl;
+                    break;
+                case ATTACK:
+                    HumanController::localController_s->setMode(NORMAL);
+                    orxout(message) <<"Mode: NORMAL "<< endl;
+                    break;
+                default: //catch all non-formation related states
+                    break;
             }
         }
Index: code/branches/formation/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/NewHumanController.cc	(revision 8989)
+++ code/branches/formation/src/orxonox/controllers/NewHumanController.cc	(revision 8990)
@@ -277,5 +277,5 @@
     }
 
-    void NewHumanController::doFire(unsigned int firemode)
+    void NewHumanController::doFire(unsigned int firemode)//TODO??
     {
         if (!this->controllableEntity_)
