Index: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10851)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	(revision 10854)
@@ -51,5 +51,11 @@
     SectionController::~SectionController()
     {
-       
+       for (size_t i = 0; i < this->actionpoints_.size(); ++i)
+        {
+            if(this->actionpoints_[i])
+                this->actionpoints_[i]->destroy();
+        }
+        this->parsedActionpoints_.clear();
+        this->actionpoints_.clear();
     }
     void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -86,214 +92,75 @@
         if (!myDivisionLeader_)
         {
-            if (this->startAttackingEnemiesThatAreClose())
-            {
-                Point p = { Action::FIGHT, "", Vector3::ZERO };
-                
-                if (this->myWingman_)
+            CommonController::action();
+        }
+        else if (myDivisionLeader_)
+        {
+            switch (myDivisionLeader_->getAction())
+            {
+                // case Action::FLY:
+                // {
+                //     // Vector3 targetRelativePosition = getFormationPosition();
+                //     // Quaternion orient = 
+                //     //     this->myDivisionLeader_->getControllableEntity()->getWorldOrientation();
+                //     // Vector3 targetAbsolutePosition = 
+                //     //     ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) + 
+                //     //         (orient* (targetRelativePosition)));
+                //     // this->setAction (Action::FLY, targetAbsolutePosition, orient);
+                //     break;
+                // }
+                // case Action::FIGHT:
+                // {
+
+                //     // this->setAction (Action::FLY, targetAbsolutePosition, orient);
+                //     break;
+                // }
+                default:
                 {
-                    this->myWingman_->parsedActionpoints_.push_back(p);
+                    ControllableEntity* myEntity = this->getControllableEntity();
+                    Vector3 myPosition = myEntity->getWorldPosition();
+                    if (!this->myDivisionLeader_)
+                    {
+                        return;
+                    }
+                    ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
+                    Quaternion orient = leaderEntity->getWorldOrientation();
+                    Vector3 leaderPosition = leaderEntity->getWorldPosition();
+
+                    Vector3 targetRelativePosition = getFormationPosition();
+                    if (!this->myDivisionLeader_)
+                    {
+                        return;
+                    }
+                    Vector3 targetAbsolutePosition = 
+                        (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
+                         + (orient* (targetRelativePosition)));
+               
+                    this->setAction (Action::FLY, targetAbsolutePosition, orient);
+                    if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
+                    {
+                        this->boostControl();
+                    }
+                    else
+                    {
+                       this->getControllableEntity()->boost(false);
+                    }
                 }
             }
-            if (this->action_ == Action::NONE)
-            {
-                this->executeActionpoint();
-            }
-            if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
-            {
-                if (!this->hasTarget())
-                {
-                    //----find a target----
-                    ControllableEntity* newTarget = this->closestTarget();
-                    if (this->action_ == Action::FIGHT)
-                    {
-                        if (newTarget && 
-                                CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
-                        {
-                            this->setAction (Action::FIGHT, newTarget);
-                        }
-                        else
-                        {
-                            this->nextActionpoint();
-                            if (this->myWingman_)
-                            {
-                                this->myWingman_->nextActionpoint();
-                            }
-                
-                            return;
-                        }
-                    }
-                    else if (this->action_ == Action::FIGHTALL)
-                    {
-                        if (newTarget && newTarget->getController())
-                        {
-                            this->setAction (Action::FIGHTALL, newTarget);
-                        }
-                        else
-                        {
-                            this->nextActionpoint();
-                            if (this->myWingman_)
-                            {
-                                this->myWingman_->nextActionpoint();
-                            }
-                            return;
-                        }
-                    }
-
-                }
-                else if (this->hasTarget())
-                {
-                    //----fly in formation if far enough----
-                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                        
-                    if (diffVector.length() > this->attackRange_)
-                    {
-                        if (this->action_ == Action::FIGHT)
-                        {
-                            this->nextActionpoint();
-                            if (this->myWingman_)
-                            {
-                                this->myWingman_->nextActionpoint();
-                            }
-                            return;
-                        }
-                        else
-                        {
-                            this->setTargetPositionOfWingman();
-                        }
-                    }
-                    else
-                    {
-                        //----wingmans shall support the fire of their leaders----
-                        if (this->myWingman_)
-                        {
-                            this->myWingman_->setAction (Action::FIGHT, this->target_);     
-                        }
-                        
-                    }
-                }
-            }
-            else if (this->action_ == Action::FLY)
-            {
-                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
-                {
-                    this->nextActionpoint();
-                    if (this->myWingman_)
-                    {
-                        this->myWingman_->nextActionpoint();
-                    }
-                    return;
-                }
-                this->setTargetPositionOfWingman();
-            }
-            else if (this->action_ == Action::PROTECT)
-            {
-                if (!this->getProtect())
-                {
-                    this->nextActionpoint();
-                    if (this->myWingman_)
-                    {
-                        this->myWingman_->nextActionpoint();
-                    }
-                    return;
-                }
-
-                Vector3* targetRelativePosition;
-                    
-                targetRelativePosition = new Vector3 (0, 300, 300);  
+        }
      
-                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
-                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
-                this->setTargetPosition(targetAbsolutePosition);
-                
-                this->setTargetPositionOfWingman();
-
-            }
-            else if (this->action_ == Action::ATTACK)
-            {   
-                if (!this->hasTarget())
-                {
-                    this->nextActionpoint();
-                    if (this->myWingman_)
-                    {
-                        this->myWingman_->nextActionpoint();
-                    }
-                    return;
-                }
-                //----fly in formation if far enough----
-                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                if (diffVector.length() > this->attackRange_)
-                {
-                    this->setTargetPositionOfWingman();
-                }
-                else
-                {
-                    //----wingmans shall support the fire of their leaders----
-                    if (this->myWingman_)
-                    {
-                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
-                    }
-      
-                }          
-            }
-            if (this->hasTarget())
-            {
-                //----choose where to go----
-                this->maneuver();
-                //----fire if you can----
-                this->bShooting_ = this->canFire();                
-            }
-        }
-        //----If have leader----
-        else
-        {
-            //----action was set to fight----
-            if (this->action_ == Action::FIGHT)
-            {
-                if (!this->hasTarget())
-                {
-                    this->chooseTarget();
-                }
-                else
-                {
-                    //----fly in formation if far enough----
-                    Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                    if (diffVector.length() > this->attackRange_)
-                    {
-                        this->setTargetPositionOfWingman();
-                    }   
-                    else
-                    {
-                        //----wingmans shall support the fire of their leaders----
-                        if (this->myWingman_)
-                        {
-                            this->myWingman_->setAction (Action::FIGHT, this->target_);                    
-                        }
-                    }
-                }
-                if (this->hasTarget())
-                {
-                    //----choose where to go----
-                    this->maneuver();
-                    //----fire if you can----
-                    this->bShooting_ = this->canFire();                
-                }
-            }
-
-            //----action was set to fly----
-            else if (this->action_ == Action::FLY)
-            {
-                this->setTargetPositionOfWingman();
-                Pawn* newTarget = this->closestTarget();
-                if ( newTarget &&  this->distance (this->getControllableEntity(), 
-                                                    static_cast<ControllableEntity*>(newTarget)) <= this->attackRange_ )
-                {
-                    this->setAction (Action::FIGHT, static_cast<ControllableEntity*>(newTarget));
-                }
-            }       
-        }
-        if (this->bFirstAction_ && this->myDivisionLeader_)
-        {
-            this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_;
-            this->bFirstAction_ = false;
+    }
+
+    void SectionController::boostControl()
+    {
+        SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
+        if(ship == NULL) return;
+        if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
+        {
+
+            this->getControllableEntity()->boost(true);
+        }
+        else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
+        {
+           this->getControllableEntity()->boost(false);
         }
     }
@@ -303,5 +170,8 @@
     {
         //----If division leader fights, cover him by fighting emenies close to his target----
-        if (this->myDivisionLeader_->getAction() == Action::FIGHT)
+        Action::Value action = this->myDivisionLeader_->getAction();
+        
+        Pawn* target;
+        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
         {
             //----if he has a target----
@@ -327,5 +197,5 @@
                         {
                             foundTarget = true;
-                            this->setAction(Action::FIGHT, (*itP));
+                            target =  (*itP);
                             //orxout(internal_error) << "Found target" << endl;
                             break; 
@@ -335,5 +205,5 @@
                     if (!foundTarget)
                     {
-                        this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+                        target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget());
                     }
                 }
@@ -341,5 +211,5 @@
                 else
                 {
-                    this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+                    target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget());
                 }
             }
@@ -349,5 +219,33 @@
 
             }
+            this->setAction (Action::FIGHT, orxonox_cast<ControllableEntity*>(target));
+        }
+        else
+        {
         } 
+    }
+    Vector3 SectionController::getFormationPosition ()
+    {
+        this->setFormationMode( this->myDivisionLeader_->getFormationMode() );
+        Vector3* targetRelativePosition;
+        switch (this->formationMode_){
+            case FormationMode::WALL:
+            {
+                targetRelativePosition = new Vector3 (-400, 0, 0);   
+                break;
+            }
+            case FormationMode::FINGER4: 
+            {
+                targetRelativePosition = new Vector3 (-400, 0, 200);   
+                break;
+            }
+            
+            case FormationMode::DIAMOND: 
+            {
+                targetRelativePosition = new Vector3 (-400, 0, 200);                   
+                break;
+            }
+        }
+        return *targetRelativePosition;
     }
 
