Index: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10846)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	(revision 10847)
@@ -51,6 +51,7 @@
     <?lua end ?> -->
  
-    
-    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0" team=0>
+<!--                 <ActionPoint position="12,34,56" action="FIGHT" enemy="ss" />
+ -->
+    <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
       <templates>
         <Template link=spaceshipassff />
@@ -61,4 +62,18 @@
       </controller>
     </SpaceShip>
+    <SpaceShip position="0, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=12>
+          <actionpoints>
+            <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />
+            <Actionpoint position="12,34,56" action="FLY" />
+          </actionpoints>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+    
    <!--  <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
       <templates>
Index: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10846)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	(revision 10847)
@@ -60,5 +60,5 @@
         this->action_ = Action::FLY;
         this->stopLookingAtTarget();
-       
+        this->attackRange_ = 2500;
         RegisterObject( CommonController );
     }
@@ -69,12 +69,28 @@
         //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
     }
-   
+    void CommonController::backupAction()
+    {
+        this->actionpoints_.push_back (this->currentActionpoint_);
+    }
+    void CommonController::restoreAction()
+    {
+        this->currentActionpoint_ = this->actionpoints_.back();
+        this->actionpoints_.pop_back();
+    }
+    void CommonController::popAction()
+    {
+        this->currentActionpoint_ = actionpoints_.back();
+        actionpoints_.pop_back();
+    }
+
     void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
     {
         SUPER( CommonController, XMLPort, xmlelement, mode );
         XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
-        XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
-        XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
+        //XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
+        //XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
         //XMLPortParam ( CommonController, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
+        XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
+
     }
     void CommonController::setProtectXML( std::string val )
@@ -104,7 +120,19 @@
         if (!this->getProtect())
             return "noProtectWasSet";
-        return this->getProtect()->getName();
-    }
-
+        return CommonController::getName (this->getProtect());
+    }
+    std::string CommonController::getName(ControllableEntity* entity)
+    {
+        std::string name = entity->getName();
+        if (name == "")
+        {
+            const void * address = static_cast<const void*>(entity);
+            std::stringstream ss;
+            ss << address;  
+            name = ss.str();            
+        }
+        return name;
+
+    }
     void CommonController::setProtect (ControllableEntity* protect)
     {
@@ -126,4 +154,10 @@
         else if ( valUpper == "PROTECT" )
             value = Action::PROTECT;
+        else if ( valUpper == "NONE" )
+            value = Action::NONE;
+        else if ( valUpper == "FIGHTALL" )
+            value = Action::FIGHTALL;
+        else if ( valUpper == "ATTACK" )
+            value = Action::ATTACK;
         else
             ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
@@ -149,6 +183,21 @@
                 break;
             }
+            case Action::NONE:
+            {
+                return "NONE";
+                break;
+            }
+            case Action::FIGHTALL:
+            {
+                return "FIGHTALL";
+                break;
+            }
+            case Action::ATTACK:
+            {
+                return "ATTACK";
+                break;
+            }
             default:
-                return "FIGHT";
+                return "NONE";
                 break;
         }
@@ -237,8 +286,73 @@
        
     }
+    void CommonController::addActionpoint(WorldEntity* actionpoint)
+    {
+        std::string actionName;
+        Vector3 position;
+        std::string targetName;
+        this->actionpoints_.push_back(actionpoint);
+        if (static_cast<Actionpoint*> (actionpoint))
+        {
+            Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
+            actionName = ap->getActionXML();
+            targetName = ap->get
+            Action::Value value;
+            
+            if ( valUpper == "FIGHT" )
+            {
+                value = Action::FIGHT;
+
+            }
+            else if ( valUpper == "FLY" )
+            {
+                value = Action::FLY;
+
+            }
+            else if ( valUpper == "PROTECT" )
+            {
+                value = Action::PROTECT;
+
+            }
+            else if ( valUpper == "NONE" )
+            {
+                value = Action::NONE;
+
+            }
+            else if ( valUpper == "FIGHTALL" )
+            {
+                value = Action::FIGHTALL;
+
+            }
+            else if ( valUpper == "ATTACK" )
+            {
+                value = Action::ATTACK;
+
+            }
+            else
+                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
+            this->setAction( value );
+        }
+        else
+        {
+            actionName = "FLY";
+        }
+        
+    }
+
+    WorldEntity* CommonController::getActionpoint(unsigned int index) const
+    {
+        if (index < this->actionpoints_.size())
+            return this->actionpoints_[index];
+        else
+            return 0;
+    }
     void CommonController::setClosestTarget()
     {
+        this->setTarget (closestTarget()); 
+    }
+    ControllableEntity* CommonController::closestTarget()
+    {
         if (!this->getControllableEntity())
-            return;
+            return 0;
 
         Pawn* closestTarget = 0;
@@ -259,6 +373,7 @@
         if (closestTarget)
         {
-           (this)->setTarget(static_cast<ControllableEntity*>(closestTarget));
-        }   
+           return static_cast<ControllableEntity*>(closestTarget);
+        } 
+        return 0;  
     }
     void CommonController::maneuver() 
Index: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10846)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	(revision 10847)
@@ -39,5 +39,5 @@
 #include "tools/interfaces/Tickable.h"
 #include <limits>
-
+#include "worldentities/Actionpoint.h"
 
 namespace orxonox
@@ -63,5 +63,5 @@
         enum Value
         {
-            FLY, FIGHT, PROTECT
+            NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
         };
     }
@@ -111,4 +111,8 @@
                     ControllableEntity* getProtect ();
                 //----[/Protect data]----
+                //----[Actionpoint data]----
+                    void addActionpoint(WorldEntity* waypoint);
+                    WorldEntity* getActionpoint(unsigned int index) const;
+                //----[/Actionpoint data]----
             //----[/XML data]----
 
@@ -134,4 +138,5 @@
                 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
                 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
+                static std::string getName( ControllableEntity* entity ) ;
 
                 float squaredDistanceToTarget() const;
@@ -166,4 +171,5 @@
                 void doFire();
                 void setClosestTarget();
+                ControllableEntity* closestTarget();
 
                 bool bShooting_;
@@ -177,6 +183,5 @@
                 Quaternion targetOrientation_;
                 
-                Vector3 destination_;
-                bool bHasDestination;
+               
             //----[/where-to-fly information]----
             //----[protect information]----
@@ -185,6 +190,5 @@
             //----[who-to-kill information]----
                 WeakPtr<ControllableEntity> target_;
-                WeakPtr<ControllableEntity> enemy_;
-
+               
                 bool bHasPositionOfTarget_;
                 Vector3 positionOfTarget_;
@@ -193,4 +197,10 @@
             //----[/who-to-kill information]----
 
+            //----[Actionpoint information]----
+                std::vector<WeakPtr<WorldEntity> > actionpoints_;
+                float squaredaccuracy_;
+                <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_;
+                std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_;
+            //----[/Actionpoint information]----
             //----["Private" variables]----
                 FormationMode::Value formationMode_;
@@ -198,4 +208,6 @@
                 std::string protectName_;
                 Action::Value action_;
+                int attackRange_;
+                
             //----[/"Private" variables]----               
     };
Index: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10846)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	(revision 10847)
@@ -76,16 +76,73 @@
 
         
-        if (this->action_ == Action::FIGHT)
+  /*      if (this->target_)
+        {
+            if (CommonController::distance (this->getControllableEntity(), newTarget) < 
+                CommonController::distance (this->getControllableEntity(), target_))
+            {
+                Actionpoint* ap = new Actionpoint(this->getContext());
+                ap->setPosition (0, 0, 0);
+                ap->setActionXML ("FIGHT");
+                //ap->setEnemyXML(CommonController::getName(newTarget));
+                this->addActionpoint (ap);
+            }
+
+        }*/
+        //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them----
+        //analog to attack move
+        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
+        {
+            if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||
+             !this->target_)
+            {
+                ControllableEntity* newTarget = this->closestTarget();
+                if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                {
+                    this->backupAction();
+                    this->setAction (Action::FIGHT, newTarget);
+                }
+            }
+        }
+        //action is NONE whenever ships finishes current action, 
+        //if it was fighting before because enemies were close, resume what it was doing
+        //otherwise try to execute next action
+        if (this->action_ == Action::NONE)
+        {
+            if (this->bBackuped_)
+            {
+                this->restoreAction();
+            } else if (!this->actionpoints_.empty())
+            {
+                this->popAction();
+            }
+        }
+        if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
         {
             if (!this->hasTarget())
             {
                 //----find a target----
-                this->setClosestTarget(); 
-            }
-            else
+                if (this->action_ == Action::FIGHT)
+                {
+                    ControllableEntity* newTarget = this->closestTarget();
+                    if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                    {
+                        this->setAction (Action::FIGHT, newTarget);
+                    }
+                    else
+                    {
+                        this->setAction (Action::NONE);
+                    }
+                }
+                else if (this->action_ == Action::FIGHTALL)
+                {
+                    this->setClosestTarget();                     
+                }
+
+            }
+            else if (this->hasTarget())
             {
                 //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                if (diffVector.length() > 3000)
+                if (diffVector.length() > this->attackRange_)
                 {
                     this->setTargetPositionOfWingman();
@@ -131,4 +188,8 @@
                         this->setProtect (static_cast<ControllableEntity*>(*itP));
                     }
+                }
+                if (!this->getProtect())
+                {
+                    this->setAction (Action::NONE);
                 }
             }
Index: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc	(revision 10846)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc	(revision 10847)
@@ -27,5 +27,5 @@
  */
 
-#include "ActionPoint.h"
+#include "Actionpoint.h"
 
 #include "core/CoreIncludes.h"
@@ -34,18 +34,18 @@
 namespace orxonox
 {
-    RegisterClass(ActionPoint);
+    RegisterClass(Actionpoint);
 
-    ActionPoint::ActionPoint(Context* context) : StaticEntity(context)
+    Actionpoint::Actionpoint(Context* context) : StaticEntity(context)
     {
-        RegisterObject(ActionPoint);
+        RegisterObject(Actionpoint);
 
     }
     //usage:
     // <DivisionController team=12>
-    //     <actionpoints>
-    //          <ActionPoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant
-    //          <ActionPoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant
-    //          <ActionPoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of ActionPoint
-    //     </actionpoints>
+    //     <Actionpoints>
+    //          <Actionpoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant
+    //          <Actionpoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant
+    //          <Actionpoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of Actionpoint
+    //     </Actionpoints>
     // </DivisonController>
     //DivisionController will firstly fight enemy that it will find by name "enemyName", if finds nothing or when beats enemy,
@@ -56,55 +56,71 @@
     //another usage:
     // <DivisionController team=12>
-    //     <actionpoints>
-    //          <ActionPoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant
-    //          <ActionPoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant
-    //     </actionpoints>
+    //     <Actionpoints>
+    //          <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant
+    //          <Actionpoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant
+    //     </Actionpoints>
     // </DivisonController>
     //DivisionController will protect the first NewHumanController it finds, when it dies or if no controller found,
     //it will fight closest enemies one after another
-    void ActionPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    void Actionpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
-        SUPER(ActionPoint, XMLPort, xmlelement, mode);
+        SUPER(Actionpoint, XMLPort, xmlelement, mode);
         
-        XMLPortParam( ActionPoint, "action", setActionXML, getActionXML,  xmlelement, mode );
-        XMLPortParam( ActionPoint, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
-        XMLPortParam( ActionPoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
-        XMLPortParam( ActionPoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
-        XMLPortParam( ActionPoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
+        XMLPortParam( Actionpoint, "action", setActionXML, getActionXML,  xmlelement, mode );
+        XMLPortParam( Actionpoint, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
+        XMLPortParam( Actionpoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
+        XMLPortParam( Actionpoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
+        XMLPortParam( Actionpoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
 
     }
-    void ActionPoint::setActionXML( std::string val)
+    void Actionpoint::setActionXML( std::string val)
     {
         this->actionName_ = getUppercase( val );
+        orxout(internal_error) << "action = " << this->actionName_ << endl;
     }
 
-    std::string ActionPoint::getActionXML()
+    std::string Actionpoint::getActionXML()
     {
         return this->actionName_;
     }
-    void ActionPoint::setProtectXML( std::string val)
+    void Actionpoint::setProtectXML( std::string val)
     {
         this->protectName_ = getUppercase( val );
     }
 
-    std::string ActionPoint::getProtectXML()
+    std::string Actionpoint::getProtectXML()
     {
         return this->protectName_;
     }
-    void ActionPoint::setEnemyXML( std::string val)
+    void Actionpoint::setEnemyXML( std::string val)
     {
         this->enemyName_ = getUppercase( val );
     }
 
-    std::string ActionPoint::getEnemyXML()
+    std::string Actionpoint::getEnemyXML()
     {
         return this->enemyName_;
     }
-
-    void ActionPoint::setTargetPosition(const Vector3& target)
+    void Actionpoint::setProtect( ControllableEntity* protect)
+    {
+        this->protect_ = protect;
+    }
+    ControllableEntity* Actionpoint::getProtect()
+    {
+        return this->protect_;
+    }
+    void Actionpoint::setEnemy( ControllableEntity* enemy)
+    {
+        this->enemy_ = enemy;
+    }
+    ControllableEntity* Actionpoint::getEnemy()
+    {
+        return this->enemy_;
+    }
+    void Actionpoint::setTargetPosition(const Vector3& target)
     {
         this->targetPosition_ = target;
     }
-    Vector3 ActionPoint::getTargetPosition ()
+    Vector3 Actionpoint::getTargetPosition ()
     {
         return this->targetPosition_;
Index: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	(revision 10846)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	(revision 10847)
@@ -33,6 +33,6 @@
 */
 
-#ifndef _ActionPoint_H__
-#define _ActionPoint_H__
+#ifndef _Actionpoint_H__
+#define _Actionpoint_H__
 
 #include "OrxonoxPrereqs.h"
@@ -45,9 +45,9 @@
 {
  
-    class _OrxonoxExport ActionPoint : public StaticEntity
+    class _OrxonoxExport Actionpoint : public StaticEntity
     {
         public:
-            ActionPoint(Context* context);
-            virtual ~ActionPoint() {}
+            Actionpoint(Context* context);
+            virtual ~Actionpoint() {}
 
             //----[XML data]----
@@ -87,5 +87,8 @@
                 //----[/FightAll data]----
             //----[/XML data]----
-
+                void setProtect( ControllableEntity* protect);
+                ControllableEntity* getProtect();
+                void setEnemy( ControllableEntity* enemy);
+                ControllableEntity* getEnemy();
             //----["Waypoints" data]----
                 void setTargetPosition(const Vector3& target);
@@ -98,4 +101,7 @@
             std::string protectName_;
             std::string enemyName_;
+            WeakPtr<ControllableEntity> protect_;
+            WeakPtr<ControllableEntity> enemy_;
+
             bool protectMe_;
             bool fightAll_;
@@ -104,3 +110,3 @@
 }
 
-#endif /* _ActionPoint_H__ */
+#endif /* _Actionpoint_H__ */
Index: code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt	(revision 10846)
+++ code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt	(revision 10847)
@@ -12,5 +12,5 @@
   SpawnPoint.cc
   TeamSpawnPoint.cc
-  ActionPoint.cc
+  Actionpoint.cc
 )
 
