Index: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10871)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10872)
@@ -35,5 +35,5 @@
     
 <!-- HERE STARTS DEMO FOR THE "WAYPOINTS" -->
-      <!-- 
+     <!--  
     <Model mesh="cube.mesh" scale=8 position="  0,2000,-600" />
     <Model mesh="cube.mesh" scale=8 position="  0,2000,-800" />
@@ -62,5 +62,5 @@
 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 
 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
-       
+       <!-- 
     <Model mesh="cube.mesh" scale=8 position="0,0,0" />
 
@@ -124,5 +124,5 @@
     </SpaceShip> 
  
-   
+    -->
 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
 <!-- HERE STARTS DEMO FOR FIGHTING -->
@@ -210,5 +210,5 @@
 <!-- HERE ENDS DEMO FOR FIGHTING -->
 <!-- HERE STARTS DEMO FOR FORMATIONS -->
-    <!-- 
+    
     <Model mesh="cube.mesh" scale=8 position="   0,2000,    0" />
     <Model mesh="cube.mesh" scale=8 position="   0,2000,-2000" />
@@ -259,5 +259,5 @@
       </controller>
     </SpaceShip> 
-    -->
+   
 <!-- HERE ENDS DEMO FOR FORMATIONS -->
     
Index: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	(revision 10871)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	(revision 10872)
@@ -229,216 +229,124 @@
     void ActionpointController::executeActionpoint()
     {
-        if (this->bLoop_)
-        {
-            if (!this->loopActionpoints_.empty())
-            {
-                this->action_ = this->loopActionpoints_.back().action;
-                switch ( this->action_ )
-                {
-                    case Action::FIGHT:
+        Point p;
+        if (this->bLoop_ && !loopActionpoints_.empty())
+        {
+            p = loopActionpoints_.back();
+        }
+        else if (this->bLoop_)
+        {
+            this->bLoop_ = false;
+            return;
+        }
+        else if (!this->bLoop_ && !parsedActionpoints_.empty())
+        {
+            p = parsedActionpoints_.back();
+        }
+        else
+        {
+            this->setTarget(0);
+            this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
+            this->action_ = Action::NONE;
+            return;
+        }
+        if (!this->bLoop_ && this->parsedActionpoints_.back().inLoop)
+        {
+            //MOVES all points that are in loop to a loop vector
+            this->fillLoop();
+            this->bLoop_ = true;
+            executeActionpoint();
+            return;
+        }
+        this->action_ = p.action;
+        switch ( this->action_ )
+        {
+            case Action::FIGHT:
+            {
+                std::string targetName = p.name;
+                if (targetName == "")
+                {
+                    break;
+                }
+                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                {
+                    if (CommonController::getName(*itP) == targetName)
                     {
-                        std::string targetName = this->loopActionpoints_.back().name;
-                        if (targetName == "")
+                        this->setTarget (static_cast<ControllableEntity*>(*itP));
+                    }
+                }          
+                break;
+            }
+            case Action::FLY:
+            {
+                this->setTargetPosition( p.position );
+                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                {
+                    this->nextActionpoint();
+                    this->executeActionpoint();
+                }
+                break;
+            }
+            case Action::PROTECT:
+            {
+                
+                std::string protectName = p.name;
+                if (protectName == "reservedKeyword:human")
+                {
+                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    {
+                        if (orxonox_cast<ControllableEntity*>(*itP) && ((*itP)->getController()) && orxonox_cast <NewHumanController*> ((*itP)->getController()))
                         {
-                            break;
+                            this->setProtect (static_cast<ControllableEntity*>(*itP));
                         }
-                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    }
+                }
+                else
+                {
+                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    {
+                        if (CommonController::getName(*itP) == protectName)
                         {
-                            if (CommonController::getName(*itP) == targetName)
-                            {
-                                this->setTarget (static_cast<ControllableEntity*>(*itP));
-                            }
-                        }          
-                        break;
+                            this->setProtect (static_cast<ControllableEntity*>(*itP));
+                        }
+                    }                            
+                }
+                if (!this->getProtect())
+                {
+                    this->nextActionpoint();
+                    this->executeActionpoint();
+                }
+                break;
+            }
+            case Action::NONE:
+            {
+                break;
+            }
+            case Action::FIGHTALL:
+            {
+                break;
+            }
+            case Action::ATTACK:
+            {
+                std::string targetName = p.name;
+
+                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                {
+                    if (CommonController::getName(*itP) == targetName)
+                    {
+                        this->setTarget (static_cast<ControllableEntity*>(*itP));
                     }
-                    case Action::FLY:
-                    {
-                        this->setTargetPosition( this->loopActionpoints_.back().position );
-                        if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
-                        {
-                            this->nextActionpoint();
-                            this->executeActionpoint();
-                        }
-                        break;
-                    }
-                    case Action::PROTECT:
-                    {
-                        std::string protectName = this->loopActionpoints_.back().name;
-                        if (protectName == "reservedKeyword:human")
-                        {
-                            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                            {
-                                if (orxonox_cast<ControllableEntity*>(*itP) && ((*itP)->getController()) && orxonox_cast <NewHumanController*> ((*itP)->getController()))
-                                {
-                                    this->setProtect (static_cast<ControllableEntity*>(*itP));
-                                }
-                            }
-                        }
-                        else
-                        {
-                            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                            {
-                                if (CommonController::getName(*itP) == protectName)
-                                {
-                                    this->setProtect (static_cast<ControllableEntity*>(*itP));
-                                }
-                            }                            
-                        }
-                        if (!this->getProtect())
-                        {
-                            this->nextActionpoint();
-                            this->executeActionpoint();
-                        }
-                        break;
-                    }
-                    case Action::NONE:
-                    {
-                        break;
-                    }
-                    case Action::FIGHTALL:
-                    {
-                        break;
-                    }
-                    case Action::ATTACK:
-                    {
-                        std::string targetName = this->loopActionpoints_.back().name;
-
-                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                        {
-                            if (CommonController::getName(*itP) == targetName)
-                            {
-                                this->setTarget (static_cast<ControllableEntity*>(*itP));
-                            }
-                        }
-                        if (!this->hasTarget())
-                        {
-                            this->nextActionpoint();
-                            this->executeActionpoint();
-                        }
-                        break;
-                    }
-                    default:
-                    {
-                        break;
-                    }
-                      
-                }
-            }
-            else
-            {
-                this->bLoop_ = false;
-            }
-        }
-        else
-        {
-            if (!this->parsedActionpoints_.empty())
-            {
-                if (this->parsedActionpoints_.back().inLoop)
-                {
-                    //MOVES all points that are in loop to a loop vector
-                    this->fillLoop();
-                    this->bLoop_ = true;
-                    executeActionpoint();
-                    return;
-                }
-                this->action_ = this->parsedActionpoints_.back().action;
-                switch ( this->action_ )
-                {
-                    case Action::FIGHT:
-                    {
-                        std::string targetName = this->parsedActionpoints_.back().name;
-                        if (targetName == "")
-                        {
-                            break;
-                        }
-                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                        {
-                            if (CommonController::getName(*itP) == targetName)
-                            {
-                                this->setTarget (static_cast<ControllableEntity*>(*itP));
-                            }
-                        }          
-                        break;
-                    }
-                    case Action::FLY:
-                    {
-                        this->setTargetPosition( this->parsedActionpoints_.back().position );
-                        if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
-                        {
-                            this->nextActionpoint();
-                            this->executeActionpoint();
-                        }
-                        break;
-                    }
-                    case Action::PROTECT:
-                    {
-                        
-                        std::string protectName = this->parsedActionpoints_.back().name;
-                        if (protectName == "reservedKeyword:human")
-                        {
-                            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                            {
-                                if (orxonox_cast<ControllableEntity*>(*itP) && ((*itP)->getController()) && orxonox_cast <NewHumanController*> ((*itP)->getController()))
-                                {
-                                    this->setProtect (static_cast<ControllableEntity*>(*itP));
-                                }
-                            }
-                        }
-                        else
-                        {
-                            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                            {
-                                if (CommonController::getName(*itP) == protectName)
-                                {
-                                    this->setProtect (static_cast<ControllableEntity*>(*itP));
-                                }
-                            }                            
-                        }
-                        if (!this->getProtect())
-                        {
-                            this->nextActionpoint();
-                            this->executeActionpoint();
-                        }
-                        break;
-                    }
-                    case Action::NONE:
-                    {
-                        break;
-                    }
-                    case Action::FIGHTALL:
-                    {
-                        break;
-                    }
-                    case Action::ATTACK:
-                    {
-                        std::string targetName = this->parsedActionpoints_.back().name;
-
-                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                        {
-                            if (CommonController::getName(*itP) == targetName)
-                            {
-                                this->setTarget (static_cast<ControllableEntity*>(*itP));
-                            }
-                        }
-                        if (!this->hasTarget())
-                        {
-                            this->nextActionpoint();
-                            this->executeActionpoint();
-                        }
-                        break;
-                    }
-                    default:
-                        break;
-                }
-            }
-
-            else
-            {
-                this->setTarget(0);
-                this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
-                this->action_ = Action::NONE;
-            }
-        }
-      }
+                }
+                if (!this->hasTarget())
+                {
+                    this->nextActionpoint();
+                    this->executeActionpoint();
+                }
+                break;
+            }
+            default:
+                break;
+        }
+        
+    }
 
     
@@ -613,5 +521,5 @@
       this->parsedActionpoints_ = vector;
       this->loopActionpoints_ = loop;
-      this->bLoop_ = this->bLoop_;
+      this->bLoop_ = b;
       this->bTakenOver_ = true;
       // orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl;
