Index: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	(revision 10910)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	(revision 10912)
@@ -32,4 +32,5 @@
 #include <algorithm>
 #include "worldentities/Actionpoint.h"
+
 namespace orxonox
 {
@@ -55,4 +56,7 @@
         this->bStartedDodging_ = false;
         this->timeDodged_ = 0;
+        this->bDefaultPatrol_ = true;
+        this->bDefaultFightAll_ = true;
+        this->stop_ = false;
         RegisterObject(ActionpointController);
 
@@ -61,6 +65,28 @@
     {
         SUPER( ActionpointController, XMLPort, xmlelement, mode );
+        // XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
+        // XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
+
         XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
-    }
+        XMLPortParam(ActionpointController, "defaultFightAll", setDefaultFightAll, getDefaultFightAll, xmlelement, mode).defaultValues(true);
+        XMLPortParam(ActionpointController, "defaultPatrol", setDefaultPatrol, getDefaultPatrol, xmlelement, mode).defaultValues(true);
+    }
+    // void ActionpointController::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+    // {
+    //     SUPER(ActionpointController, XMLEventPort, xmlelement, mode);
+    //     XMLPortEventSink(ActionpointController, BaseObject, "stop", stop, xmlelement, mode);
+    //     XMLPortEventSink(ActionpointController, BaseObject, "go", stop, xmlelement, mode);
+
+    // }
+    // bool ActionpointController::stop(bool bTriggered, BaseObject* trigger)
+    // {
+    //     this->stop_ = true;
+    //     return true;
+    // }
+    // bool ActionpointController::go(bool bTriggered, BaseObject* trigger)
+    // {
+    //     this->stop_ = false;
+    //     return true;
+    // }
     ActionpointController::~ActionpointController()
     {
@@ -74,5 +100,6 @@
     void ActionpointController::tick(float dt)
     {
-
+        if (stop_)
+            return;
         if (this->timeout_ > 0 && this->bFiredRocket_)
         {
@@ -143,225 +170,5 @@
         SUPER(ActionpointController, tick, dt);
     }
-    std::pair <ControllableEntity*, ControllableEntity*> ActionpointController::closestTargets()
-    {
-        WeakPtr<ControllableEntity> firstTarget, secondTarget, tempTarget;
-        float firstDistance = std::numeric_limits<float>::infinity(), secondDistance = std::numeric_limits<float>::infinity(), tempDistance = 0;
-        Gametype* gt = this->getGametype();
-        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-        {
-            tempTarget = static_cast<ControllableEntity*>(*itP);
-            if (CommonController::sameTeam (this->getControllableEntity(), tempTarget, gt))
-                continue;
-
-            tempDistance = CommonController::distance (*itP, this->getControllableEntity());
-            if (tempDistance < firstDistance)
-            {
-                secondDistance = firstDistance;
-                secondTarget = firstTarget;
-
-                firstDistance = tempDistance;
-                firstTarget = tempTarget;
-            }
-            else if (tempDistance < secondDistance)
-            {
-                secondDistance = tempDistance;
-                secondTarget = tempTarget;
-            }
-        }
-        return std::make_pair (firstTarget, secondTarget);  
-    }
-
-    //patrol can only be called by divisionController or others if they don't have a leader
-    //searches for closest enemy and sets target to it. If wasn't fighting, pushes Action::FIGHT on a stack.
-    //patrol gets called constantly either if this is fighting or if this->bDefaultPatrol_ is set to true via XML
-    bool ActionpointController::patrol()
-    {
-        std::pair <ControllableEntity*, ControllableEntity*> newTargets = this->closestTargets();
-        if (!newTargets.first)
-            return false;
-        ControllableEntity* newTarget = newTargets.first;
-
-        float distance = CommonController::distance (this->getControllableEntity(), newTarget);
-        if (distance < this->attackRange_ && distance < CommonController::distance(this->getControllableEntity(), this->target_))
-        {
-            this->setTarget (newTarget);
-
-            if (this->getIdentifier()->getName() == "DivisionController")
-            {
-                if (!newTargets.second)
-                {
-                    if (this->myFollower_)
-                        this->myFollower_->setTarget(newTargets.first);
-                }
-                else
-                {
-                    if (this->myFollower_ && CommonController::distance(this->getControllableEntity(), newTargets.second) < this->attackRange_ + 600.0f)
-                        this->myFollower_->setTarget(newTargets.second);
-                    else if (this->myFollower_)
-                        this->myFollower_->setTarget(newTargets.first);
-                }
-            }
-            if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
-            {
-                this->bPatrolling_ = true;
-                if (this->bLoop_)
-                {
-                    Point p = { Action::FIGHT, "", Vector3::ZERO, true };
-                    this->loopActionpoints_.push_back(p);
-                    this->executeActionpoint();
-                }
-                else
-                {
-                    Point p = { Action::FIGHT, "", Vector3::ZERO, false };
-                    this->parsedActionpoints_.push_back(p);
-                    this->executeActionpoint();   
-                }                    
-            }
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-    }
-    //checks if state is still to be executed and makes a transition otherwise.
-    //if this->bDefaultPatrol_ == true, patrols area for enemies and, if not fighting, pushes a state with action = FIGHT
-    void ActionpointController::stateMachine()
-    {
-        //Check if calculations needed
-        if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()) || !this->isActive())
-            return;
-
-        //state NONE means that either previous state finished executing and next state is to be fetched or no states are left to execute
-        //NONE is never on a stack -> it is only a transition state saved in a variable
-        if (this->action_ == Action::NONE || this->bTakenOver_)
-        {
-            //no actionpoints a.k.a. states left to execute
-            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
-            {
-                //default action is fighting
-                if (this->bDefaultFightAll_)
-                {
-                    //make state
-                    Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
-                    //push it on the stack
-                    this->parsedActionpoints_.push_back (p);
-                }
-                //default action is nothing
-                else
-                {
-                    this->bActive_ = false;
-                    return;
-                }     
-            }
-            //switch to the new state
-            this->executeActionpoint(); 
-            this->bTakenOver_ = false; 
-        }
-        if (this->action_ == Action::FIGHTALL)
-        {
-            if (!this->hasTarget())
-            {
-                ControllableEntity* newTarget = this->closestTarget();    
-                if (newTarget)
-                {
-                    this->setTarget (newTarget);
-                }
-                else
-                {
-                    this->nextActionpoint();
-                    this->executeActionpoint();
-                }
-            }
-            else
-            {
-                bool b = this->patrol();
-            }
-
-        }
-        if (this->action_ == Action::FIGHT)
-        {
-            if (!this->hasTarget() )
-            {
-                if (!this->patrol())
-                {
-                    if (this->bPatrolling_)
-                    {
-                        if (this->bLoop_)
-                        {
-                            if (!this->loopActionpoints_.empty())
-                            {
-                                this->loopActionpoints_.pop_back();
-                            }
-                        }
-                        else
-                        {
-                            if (!this->parsedActionpoints_.empty())
-                            {
-                                this->parsedActionpoints_.pop_back();
-                            }            
-                        }
-                        this->setAction(Action::NONE);
-                        this->bHasTargetPosition_ = false;
-                        this->bPatrolling_ = false;
-                    }
-                    else
-                    {
-                        this->nextActionpoint();
-                    }
-                    this->executeActionpoint();
-                }
-            }
-            else if (this->hasTarget())
-            {
-                if (CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_)
-                {
-                    this->setTarget(0);
-                    this->stateMachine();
-                }
-            }
-        }
-        if (this->action_ == Action::FLY)
-        {
-            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
-            {
-                this->nextActionpoint();   
-                this->executeActionpoint();
-            }
-            else if (this->bDefaultPatrol_)
-            {
-                bool b = this->patrol();
-            }
-        }
-        if (this->action_ == Action::PROTECT)
-        {
-            if (!this->getProtect())
-            {
-                this->nextActionpoint();
-                this->executeActionpoint(); 
-            }
-            else
-            {
-                this->stayNearProtect();
-            }
-            if (this->bDefaultPatrol_)
-            {
-                bool b = this->patrol();
-            }
-        }
-        if (this->action_ == Action::ATTACK)
-        {   
-            if (!this->hasTarget())
-            {
-                this->nextActionpoint();
-                this->executeActionpoint();
-            }
-            if (this->bDefaultPatrol_)
-            {
-                bool b = this->patrol();
-            }
-        }
-    }
-
+     
 
 
@@ -372,5 +179,8 @@
         if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity()))
             return;
-        this->startAttackingEnemiesThatAreClose();
+        if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
+        {
+            this->startAttackingEnemiesThatAreClose();
+        }
 
         this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
@@ -388,5 +198,5 @@
             // }
 
-            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())
+            if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
             {
                 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false };
@@ -395,5 +205,5 @@
             this->executeActionpoint();
             this->bTakenOver_ = false;
-            this->action();
+            // this->action();
         }
         //Action fightall -> fight till nobody alive
Index: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	(revision 10910)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	(revision 10912)
@@ -35,4 +35,6 @@
 #include "../modules/pickup/PickupSpawner.h"
 #include <map>
+
+
 
 namespace orxonox
@@ -159,5 +161,18 @@
             */
             void addActionpoint(WorldEntity* actionpoint); 
-            WorldEntity* getActionpoint(unsigned int index) const;           
+            WorldEntity* getActionpoint(unsigned int index) const;    
+            void setDefaultFightAll(bool value)
+                { this->bDefaultFightAll_ = value; }
+            bool getDefaultFightAll ()
+                { return this->bDefaultFightAll_; }
+            void setDefaultPatrol(bool value)
+                { this->bDefaultPatrol_ = value; }
+            bool getDefaultPatrol ()
+                { return this->bDefaultPatrol_; }
+                 // Trigger interface
+            // bool stop(bool bTriggered, BaseObject* trigger);
+            // bool go(bool bTriggered, BaseObject* trigger);
+            // virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+
             virtual void stayNearProtect();
             virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
@@ -180,7 +195,5 @@
             virtual bool hasFollower()
                 { return true; }
-            void stateMachine();
-            bool patrol();
-            std::pair <ControllableEntity*, ControllableEntity*> closestTargets();
+
 
         protected:
@@ -243,7 +256,9 @@
                 bool bManeuverCalled_;
                 bool bDefaultFightAll_;
+
                 bool bActive_;
                 bool bPatrolling_;
                 bool bDefaultPatrol_;
+                bool stop_;
 
         private:
Index: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10910)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10912)
@@ -60,5 +60,5 @@
     {
         SUPER(DivisionController, XMLPort, xmlelement, mode);
-
+        
         //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     }
Index: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10910)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10912)
@@ -125,4 +125,6 @@
             {
                 this->keepFormation();
+                //orxout (internal_error) << "Keeping formation" << endl;
+
             }
             else if (!this->myDivisionLeader_->bKeepFormation_)
@@ -130,5 +132,6 @@
                 if (!this->hasTarget())
                 {
-                    this->chooseTarget(); 
+                    //this->chooseTarget(); 
+                    //orxout (internal_error) << "Section ain't got no target" << endl;
                 }
                 if (this->hasTarget())
