[Orxonox-commit 6193] r10851 - in code/branches/campaignHS15: data/levels src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Tue Nov 24 22:37:28 CET 2015


Author: gania
Date: 2015-11-24 22:37:28 +0100 (Tue, 24 Nov 2015)
New Revision: 10851

Modified:
   code/branches/campaignHS15/data/levels/AITest.oxw
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
Log:
works for the most part, still need to fix Section and Wingman

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-24 21:37:28 UTC (rev 10851)
@@ -61,21 +61,47 @@
         </DivisionController>
       </controller>
     </SpaceShip> -->
-    <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=1 name="ss2">
+    <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1>
+        <DivisionController team=0>
           <actionpoints>
+            <Actionpoint position="-1000,750,-500" action="FLY" />
+            <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
             <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
-            <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
-            <Actionpoint position="-1000,750,-500" action="FLY" />
-            <Actionpoint position="0,0,0" action="FLY" />
           </actionpoints>
         </DivisionController>
       </controller>
     </SpaceShip>
+    <SpaceShip position="-2000, 1800, -1000" lookat="0,0,0" team=0>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=0>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="-2000, 2100, -1000" lookat="0,0,0" team=0>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <WingmanController team=0>
+        </WingmanController>
+      </controller>
+    </SpaceShip>
+    <SpaceShip position="-2000, 2400, -1000" lookat="0,0,0" team=0>
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController team=0>
+        </SectionController>
+      </controller>
+    </SpaceShip>
     <SpaceShip position="0, 0, 0" lookat="0,0,0" team=2 name="ss4">
       <templates>
         <Template link=spaceshipassff />
@@ -86,7 +112,7 @@
         <Template link=spaceshipassff />
       </templates>
     </SpaceShip>
-    <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=1 name="fuck">
+    <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=0 name="fuck">
       <templates>
         <Template link=spaceshipassff />
       </templates>

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-24 21:37:28 UTC (rev 10851)
@@ -25,19 +25,10 @@
  *      Dominik Solenicki
  *
  */
-//bug or feature? Press 4 control keys from {Q,W,E,A,S,D,C} at the same time or 3 keys from {Q,E,A,D}, spaceship goes in free fly mode
 #include "controllers/CommonController.h"
 #include "core/XMLPort.h"
 
-#include "weaponsystem/WeaponMode.h"
-#include "weaponsystem/WeaponPack.h"
-#include "weaponsystem/Weapon.h"
-#include "weaponsystem/WeaponSlot.h"
-#include "weaponsystem/WeaponSlot.h"
-#include "worldentities/pawns/SpaceShip.h"
-
-#include "Scene.h"
-
+//stuff for sameTeam function
 #include "worldentities/pawns/TeamBaseMatchBase.h"
 #include "gametypes/TeamDeathmatch.h"
 #include "gametypes/Dynamicmatch.h"
@@ -55,30 +46,40 @@
     const float SPEED = 0.9f/0.02f;
     const float ROTATEFACTOR = 1.0f/0.02f;
 
+    //Table of content:
+    //Constructor, Destructor & tick
+    //XML methods
+    //World interaction
+    //Helper methods
+    //Flying methods
+    //Fighting methods
+    //Actionpoint methods
+
+
+    //------------------------------------------------------------------------------
+    //------------------------Constructor, Destructor & tick------------------------
+    //------------------------------------------------------------------------------
+    
     CommonController::CommonController( Context* context ): Controller( context )
     {
-        this->squaredaccuracy_ = 500;
+        this->squaredaccuracy_ = 10000;
+        this->bFirstTick_ = true;
+        this->tolerance_ = 65;
         this->action_ = Action::NONE;
         this->stopLookingAtTarget();
-        this->attackRange_ = 800;
+        this->attackRange_ = 2500;
         RegisterObject( CommonController );
     }
-
-
     CommonController::~CommonController() 
     {
-        //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
+        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 CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
-    {
-        SUPER( CommonController, XMLPort, xmlelement, mode );
-        XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
-        XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
-
-    }
-   
     void CommonController::tick(float dt)
     {
         if (this->bHasTargetPosition_)
@@ -93,76 +94,26 @@
         {
             this->doFire();
         }
+        if (this->bFirstTick_)
+        {
+            std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
+            std::reverse(actionpoints_.begin(), actionpoints_.end());
+        }
+        if (this->bFirstTick_)
+            this->bFirstTick_ = false;
         SUPER(CommonController, tick, dt);
     }
 
-    std::string CommonController::getProtectXML ()
+    //------------------------------------------------------------------------------
+    //----------------------------------XML methods---------------------------------
+    //------------------------------------------------------------------------------
+    
+    void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
     {
-        if (!this->getProtect())
-            return "noProtectWasSet";
-        return CommonController::getName (orxonox_cast<Pawn*>(this->getProtect()));
+        SUPER( CommonController, XMLPort, xmlelement, mode );
+        XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
+        XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
     }
-    std::string CommonController::getName(Pawn* 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)
-    {
-        this->protect_ = protect;
-    }
-    ControllableEntity* CommonController::getProtect ()
-    {
-        return this->protect_;
-    }
-  
-    std::string CommonController::getActionXML()
-    {
-        switch ( this->action_ )
-        {
-            case Action::FIGHT:
-            {
-                return "FIGHT";
-                break;
-            }
-            case Action::FLY:
-            {
-                return "FLY";
-                break;
-            }
-            case Action::PROTECT:
-            {
-                return "PROTECT";
-                break;
-            }
-            case Action::NONE:
-            {
-                return "NONE";
-                break;
-            }
-            case Action::FIGHTALL:
-            {
-                return "FIGHTALL";
-                break;
-            }
-            case Action::ATTACK:
-            {
-                return "ATTACK";
-                break;
-            }
-            default:
-                return "NONE";
-                break;
-        }
-    }
     void CommonController::setFormationModeXML( std::string val )
     {
         const std::string valUpper = getUppercase( val );
@@ -177,85 +128,46 @@
         else
             ThrowException( ParseError, std::string( "Attempting to set an unknown FormationMode: '" )+ val + "'." );
         this->setFormationMode( value );
-       
     }
     std::string CommonController::getFormationModeXML() 
     {
         switch ( this->formationMode_ )
         {
             case FormationMode::WALL:
-            {
-                return "WALL";
-                break;
-            }
+            { return "WALL"; break; }
             case FormationMode::FINGER4:
-            {
-                return "FINGER4";
-                break;
-            }
+            { return "FINGER4"; break; }
             case FormationMode::DIAMOND:
-            {
-                return "DIAMOND";
-                break;
-            }
+            { return "DIAMOND"; break; }
             default:
-                return "DIAMOND";
-                break;
-
+                return "DIAMOND"; break;
         }
     }
-    Action::Value CommonController::getAction ()
-    {
-        return this->action_;
+    void CommonController::setFormationMode(FormationMode::Value val)
+    { 
+        this->formationMode_ = val; 
     }
-    void CommonController::setAction (Action::Value action)
-    {
-        this->action_ = action;
+    FormationMode::Value CommonController::getFormationMode() const
+    { 
+        return this->formationMode_; 
     }
-
-    void CommonController::setAction (Action::Value action, ControllableEntity* target)
-    {
-        this->action_ = action;
-        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
-        {   
-            if (target)
-                this->setTarget (target);
-        }
-        else if (action == Action::PROTECT)
-        {
-            if (target)
-                this->setProtect (target);
-        }
+    void CommonController::setRank(Rank::Value val)
+    { 
+        this->rank_ = val; 
     }
-    void CommonController::setAction (Action::Value action, const Vector3& target)
-    {
-        this->action_ = action;
-        if (action == Action::FLY)
-        {
-            this->setTargetPosition (target);
-        }
-        
+    Rank::Value CommonController::getRank() const
+    { 
+        return this->rank_; 
     }
-    void CommonController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
-    {
-        this->action_ = action;
-        if (action == Action::FLY)
-        {
-            this->setTargetPosition (target);
-            this->setTargetOrientation (orient);
-        }
-       
-    }
     void CommonController::addActionpoint(WorldEntity* actionpoint)
     {
         std::string actionName;
         Vector3 position;
         std::string targetName;
-
+        Point p;
         if (static_cast<Actionpoint*> (actionpoint))
         {
             Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
-            
             actionName = ap->getActionXML();
             targetName = ap->getName();
             position = ap->getWorldPosition();
@@ -263,53 +175,29 @@
             Action::Value value;
             
             if ( actionName == "FIGHT" )
-            {
-                value = Action::FIGHT;
-
-            }
+            { value = Action::FIGHT; }
             else if ( actionName == "FLY" )
-            {
-                value = Action::FLY;
-
-            }
+            { value = Action::FLY; }
             else if ( actionName == "PROTECT" )
-            {
-                value = Action::PROTECT;
-
-            }
+            { value = Action::PROTECT; }
             else if ( actionName == "NONE" )
-            {
-                value = Action::NONE;
-
-            }
+            { value = Action::NONE; }
             else if ( actionName == "FIGHTALL" )
-            {
-                value = Action::FIGHTALL;
-
-            }
+            { value = Action::FIGHTALL; }
             else if ( actionName == "ATTACK" )
-            {
-                value = Action::ATTACK;
-
-
-            }
+            { value = Action::ATTACK; }
             else
                 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
-            //this->setAction( value );
-            Point p = { value, targetName, position };
+            p.action = value; p.name = targetName; p.position = position;
             parsedActionpoints_.push_back(p);
-            orxout(internal_error) << "Pushed " << p.action << endl;
         }
         else
         {
-            Point p = { Action::FLY, "", actionpoint->getWorldPosition() };
-            parsedActionpoints_.push_back(p);
+            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition();
         }
+            parsedActionpoints_.push_back(p);
             this->actionpoints_.push_back(actionpoint);
-
-        
     }
-
     WorldEntity* CommonController::getActionpoint(unsigned int index) const
     {
         if (index < this->actionpoints_.size())
@@ -317,428 +205,91 @@
         else
             return 0;
     }
-    void CommonController::setClosestTarget()
-    {
-        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 
-    }
-    Pawn* CommonController::closestTarget()
-    {
-        if (!this->getControllableEntity())
-            return 0;
 
-        Pawn* closestTarget = 0;
-        float minDistance =  std::numeric_limits<float>::infinity();
-        Gametype* gt = this->getGametype();
-        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-        {
-            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
-                continue;
+    //------------------------------------------------------------------------------
+    //-------------------------------World interaction------------------------------
+    //------------------------------------------------------------------------------
 
-            float distance = CommonController::distance (*itP, this->getControllableEntity());
-            if (distance < minDistance)
-            {
-                closestTarget = *itP;
-                minDistance = distance;
-            }
-        }
-        if (closestTarget)
-        {
-           return closestTarget;
-        } 
-        return 0;  
-    }
-    //POST: this starts doing what was asked by the last element of parsedActionpoints_,
-    //if last element was failed to be parsed, next element will be executed.
-    void CommonController::executeActionpoint()
-    {
-        if (!this->parsedActionpoints_.empty())
-        {
-            this->action_ = this->parsedActionpoints_.back().action;
-
-            switch ( this->action_ )
-            {
-                case Action::FIGHT:
-                {                
-                    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;
-
-                    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)
-                        {
-                            orxout(internal_error) << "Attacking" << endl;
-                            this->setTarget (static_cast<ControllableEntity*>(*itP));
-                        }
-                    }
-                    if (!this->getTarget())
-                    {
-                        this->nextActionpoint();
-                        this->executeActionpoint();
-                    }
-                    break;
-                }
-                default:
-                    break;
-            }
-            
-
-        }
-        else
-        {
-            this->setTarget(0);
-            this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
-            this->action_ = Action::NONE;
-        }
-        orxout(internal_error) << "Executing action " << this->getActionXML() << endl;
-    }
-    void CommonController::nextActionpoint()
-    {
-        if (!this->parsedActionpoints_.empty())
-        {
-            this->parsedActionpoints_.pop_back();
-        }
-        this->setAction(Action::NONE);
-    }
-
-    void CommonController::maneuver() 
-    {
-        maneuverCounter_++;
-
-        if (maneuverCounter_ > 5)
-            maneuverCounter_ = 0;
-        if ( this->target_ && this->getControllableEntity())
-        {
-            Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
-            //Quaternion thisOrientation = this->getControllableEntity()->getOrientation();
-
-            this->setPositionOfTarget( getPredictedPosition( 
-                thisPosition, 
-                hardcoded_projectile_speed, 
-                this->target_->getWorldPosition() , 
-                this->target_->getVelocity()  
-                )  );
-            this->setOrientationOfTarget( this->target_->getOrientation() );
-
-
-            Vector3 diffVector = this->positionOfTarget_ - thisPosition;
-            float diffLength = diffVector.length();
-            Vector3 diffUnit = diffVector/diffLength;
-
-
-
-            //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 );
-            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
-            
-
-
-            //too far? well, come closer then
-            if ( diffLength > 3000 )
-            {
-                if (diffLength < 6000)
-                {
-
-                }
-                else
-                {
-                }
-                this->setTargetPosition( this->positionOfTarget_ );
-            }
-            //too close? How do u expect to dodge anything? Just attack!
-            else if ( diffLength < 500 )
-            {   
-                //at this point, just look and shoot
-                if ( diffLength < 250 )
-                {
-                    this->stopMoving();
-                    this->startLookingAtTarget();
-                }
-                else
-                {
-                    this->setTargetPosition( this->positionOfTarget_ );
-                }
-            }
-            //Good distance? Check if target looks at us. It doesn't? Go hunt!
-            else if ( !bTargetIsLookingAtThis )
-            {
-                this->setTargetPosition( this->positionOfTarget_ );
-              /*  if (maneuverCounter_ == 0)
-                {
-                    this->setTargetPosition( this->positionOfTarget_ );   
-                    return;
-                }
-                else
-                {
-                    dodge( thisPosition, diffUnit );
-                }*/
-            }
-            //That's unfortunate, he is looking and probably shooting... try to dodge what we can...  
-            else 
-            {   
-            
-                if (maneuverCounter_ == 0)
-                {
-                    this->setTargetPosition( this->positionOfTarget_ );   
-                    return;
-                }
-                dodge( thisPosition, diffUnit );
-                
-            }
-        }
-        
-        //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
-    }
-    ControllableEntity* CommonController::getTarget()
-    {
-        return this->target_;
-    }
-    void CommonController::dodge(Vector3& thisPosition, Vector3& diffUnit)
-    {
-        float factorX = 0, factorY = 0, factorZ = 0;
-        float rand = randomInRange (0, 1);
-        if (rand <= 0.5)
-        {
-            factorX = 1;
-        }
-        else
-        {
-            factorX = -1;
-        }
-        rand = randomInRange (0, 1);
-        if (rand <= 0.5)
-        {
-            factorY = 1;
-        }
-        else
-        {
-            factorY = -1;
-        }
-        rand = randomInRange (0, 1);
-        if (rand <= 0.5)
-        {
-            factorZ = 1;
-        }
-        else
-        {
-            factorZ = -1;
-        }
-        Vector3 target = ( diffUnit )* 8000.0f;
-        Vector3* randVector = new Vector3( 
-            factorX * randomInRange( 10000, 40000 ), 
-            factorY * randomInRange( 10000, 40000 ), 
-            factorZ * randomInRange( 10000, 40000 ) 
-        );
-        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
-        *randVector -= projection;
-        target += *randVector;
-        this->setTargetPosition( thisPosition + target );
-    }
-    void CommonController::stopMoving()
-    {
-        this->bHasTargetPosition_ = false;
-    }
-    void CommonController::startLookingAtTarget()
-    {
-        this->bLookAtTarget_ = true;
-    }
-    void CommonController::stopLookingAtTarget()
-    {
-        this->bLookAtTarget_ = false;
-    }
-    void CommonController::lookAtTarget(float dt)
-    {
-
-        
-        ControllableEntity* entity = this->getControllableEntity();
-        if ( !entity )
-            return;
-        Vector2 coord = get2DViewCoordinates
-            ( entity->getPosition() , 
-            entity->getOrientation()  * WorldEntity::FRONT, 
-            entity->getOrientation()  * WorldEntity::UP, 
-            positionOfTarget_ );
-
-        //rotates should be in range [-1,+1], clamp cuts off all that is not
-        float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
-        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
-
-        
-   
-        //Yaw and Pitch are enough to start facing the target
-        this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
-        this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
-        
-           
-    }
-   
+    //"Virtual" methods
     bool CommonController::setWingman ( CommonController* wingman )
-    {
-        return false;
-    }
-   
+    { return false; }
     bool CommonController::hasWingman() 
-    {
-        return true;
-    }
-    void CommonController::setTarget( ControllableEntity* target )
-    {
-        this->target_ = target;
-        //orxout ( internal_error ) << " TARGET SET " << endl;
-        
-        if ( this->target_ )
-        {
-            this->setPositionOfTarget( target_->getWorldPosition() );
-
-        }
-    }
+    { return true; }
     bool CommonController::hasTarget() 
     {
         if ( this->target_ )
             return true;
         return false;
     }
-    void CommonController::setPositionOfTarget( const Vector3& target )
+    ControllableEntity* CommonController::getTarget()
     {
-        this->positionOfTarget_ = target;
-        this->bHasPositionOfTarget_ = true;
+        return this->target_;
     }
-    void CommonController::setOrientationOfTarget( const Quaternion& orient )
+    Action::Value CommonController::getAction ()
     {
-        this->orientationOfTarget_=orient;
-        this->bHasOrientationOfTarget_=true;
+        return this->action_;
     }
-
-    void CommonController::setTargetPosition( const Vector3& target )
+    std::string CommonController::getActionName()
     {
-        this->targetPosition_ = target;
-        this->bHasTargetPosition_ = true;
+        switch ( this->action_ )
+        {
+            case Action::FIGHT:
+            { return "FIGHT"; break; }
+            case Action::FLY:
+            { return "FLY"; break; }
+            case Action::PROTECT:
+            { return "PROTECT"; break; }
+            case Action::NONE:
+            { return "NONE"; break; }
+            case Action::FIGHTALL:
+            { return "FIGHTALL"; break; }
+            case Action::ATTACK:
+            { return "ATTACK"; break; }
+            default:
+                return "NONE";
+                break;
+        }
     }
-
-    void CommonController::setTargetOrientation( const Quaternion& orient )
+    void CommonController::setAction (Action::Value action)
     {
-        this->targetOrientation_=orient;
-        this->bHasTargetOrientation_=true;
+        this->action_ = action;
     }
-
-    void CommonController::setTargetOrientation( ControllableEntity* target )
+    void CommonController::setAction (Action::Value action, ControllableEntity* target)
     {
-        if ( target )
-            setTargetOrientation( target->getOrientation() );
-    }
-
-
-
-    //copy the Roll orientation of given Quaternion.
-    void CommonController::copyOrientation( const Quaternion& orient, float dt )
-    {
-        //roll angle difference in radian
-        float diff=orient.getRoll( false ).valueRadians() -( this->getControllableEntity() ->getOrientation() .getRoll( false ).valueRadians() );
-        while( diff>math::twoPi )diff-=math::twoPi;
-        while( diff<-math::twoPi )diff+=math::twoPi;
-        this->getControllableEntity() ->rotateRoll( diff*ROTATEFACTOR * dt );
-    }
-    void CommonController::copyTargetOrientation( float dt )
-    {
-        if ( bHasTargetOrientation_ )
+        this->action_ = action;
+        if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
         {   
-            copyOrientation( targetOrientation_, dt );
+            if (target)
+                this->setTarget (target);
         }
+        else if (action == Action::PROTECT)
+        {
+            if (target)
+                this->setProtect (target);
+        }
     }
-
-
-
-
-    void CommonController::moveToTargetPosition( float dt )
+    void CommonController::setAction (Action::Value action, const Vector3& target)
     {
-        this->moveToPosition( this->targetPosition_, dt );
+        this->action_ = action;
+        if (action == Action::FLY)
+        {
+            this->setTargetPosition (target);
+        }
     }
-    void CommonController::moveToPosition( const Vector3& target, float dt )
+    void CommonController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
     {
-     
-        
-        //100 is ( so far )the smallest tolerance ( empirically found )that can be reached, 
-        //with smaller distance spaceships can't reach position and go circles around it instead
-        int tolerance = 65;
-
-        ControllableEntity* entity = this->getControllableEntity();
-        Vector2 coord = get2DViewCoordinates
-            ( entity->getPosition() , 
-            entity->getOrientation()  * WorldEntity::FRONT, 
-            entity->getOrientation()  * WorldEntity::UP, 
-            target );
-
-        float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
-
-        //rotates should be in range [-1,+1], clamp cuts off all that is not
-        float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
-        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
-
-        
-        if ( distance > tolerance )
+        this->action_ = action;
+        if (action == Action::FLY)
         {
-            //Yaw and Pitch are enough to start facing the target
-            this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
-            this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
+            this->setTargetPosition (target);
+            this->setTargetOrientation (orient);
+        }  
+    }
 
-            //300 works, maybe less is better
-            if ( distance < 400 )
-            {
-                //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
-                //It's important that roll is not changed in the process of changing yaw and pitch
-                //Wingmen won't face same direction as Leaders, but when Leaders start moving
-                //Yaw and Pitch will adapt.
-                if ( bHasTargetOrientation_ )
-                {
-                    copyTargetOrientation( dt );
-                }
-            }
+    //------------------------------------------------------------------------------
+    //--------------------------------Helper methods--------------------------------
+    //------------------------------------------------------------------------------
 
-            this->getControllableEntity() ->moveFrontBack( SPEED * dt );
-        }
-        else
-        {      
-            bHasTargetPosition_ = false;
-            bHasTargetOrientation_ = false;
-        }
-    }
     float CommonController::randomInRange( float a, float b )
     {
         float random = rnd( 1.0f );
@@ -746,139 +297,6 @@
         float r = random * diff;
         return a + r;
     }
-    
-
-    //to be called in action
-    //PRE: relativeTargetPosition is desired position relative to the spaceship,
-    //angleRoll is the angle in degrees of Roll that should be applied by the end of the movement
-    //POST: target orientation and position are set, so that it can be used by MoveAndRoll() 
-    void CommonController::moveToPoint( const Vector3& relativeTargetPosition, float angleRoll )
-    {
-        ControllableEntity* entity = this->getControllableEntity();
-        if ( !entity )
-            return;
-        Quaternion orient = entity->getWorldOrientation();
-        Quaternion rotation = Quaternion( Degree( angleRoll ), Vector3::UNIT_Z );
-
-        Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
-        setTargetPosition( target );
-        orient = orient * rotation;
-        this->setTargetOrientation( orient );
-       
-    }
-    //to be called in tick
-    //PRE: MoveToPoint was called
-    //POST: spaceship changes its yaw and pitch to point towards targetPosition_,
-    //moves towards targetPosition_ by amount depending on dt and its speed,
-    //rolls by amount depending on the difference between angleRoll_ and angleRolled_, dt, and 
-    //angular speed
-    //if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false,
-    //otherwise returns true
-    //dt is normally around 0.02f, which makes it 1/0.02 = 50 frames/sec
-    bool CommonController::moveAndRoll( float dt )
-    {
-        float factor = 1;
-        if ( !this->getControllableEntity() )
-            return false;
-        if ( this->rank_ == Rank::DIVISIONLEADER )
-            factor = 0.8;
-        if ( this->rank_ == Rank::SECTIONLEADER )
-            factor = 0.9;
-        int tolerance = 60;
-        
-        ControllableEntity* entity = this->getControllableEntity();
-        if ( !entity )
-            return true;
-        Vector2 coord = get2DViewCoordinates
-            ( entity->getPosition() , 
-            entity->getOrientation()  * WorldEntity::FRONT, 
-            entity->getOrientation()  * WorldEntity::UP, 
-            targetPosition_ );
-
-        float distance = ( targetPosition_ - this->getControllableEntity() ->getPosition() ).length();
-
-        //rotates should be in range [-1,+1], clamp cuts off all that is not
-        float rotateX = clamp( coord.x * 10, -1.0f, 1.0f );
-        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
-
-        
-        if ( distance > tolerance )
-        {
-            //Yaw and Pitch are enough to start facing the target
-            this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
-            this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
-            
-            //Roll
-            if ( bHasTargetOrientation_ )
-            {
-                copyTargetOrientation( dt );
-            }
-          
-            //Move
-            this->getControllableEntity() ->moveFrontBack( 1.2f * SPEED * factor * dt );
-            //if still moving, return false
-            return false;
-        }
-        else
-        {     
-            
-            //if finished, return true;
-            return true;
-        }
-    }
-
-    float CommonController::squaredDistanceToTarget()  const
-    {
-        if ( !this->getControllableEntity()  )
-            return 0;
-        if ( !this->target_ || !this->getControllableEntity() )
-            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
-        else
-            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
-    }
-    
-    bool CommonController::isLookingAtTarget( float angle )const
-    {
-        if ( !this->getControllableEntity()  || !this->target_ )
-            return false;
-
-        return ( getAngle( this->getControllableEntity() ->getPosition() , 
-            this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->positionOfTarget_ ) < angle );
-    }
-    bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
-    {
-        if ( !entityThatLooks || !entityBeingLookedAt )
-            return false;
-        return ( getAngle( entityThatLooks ->getPosition() , 
-            entityThatLooks->getOrientation()  * WorldEntity::FRONT, 
-            entityBeingLookedAt->getWorldPosition() ) < angle );
-    }
-
-    bool CommonController::canFire() 
-    {
-
-        //no target? why fire?
-        if ( !this->target_ )
-            return false;
-
-        Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , 
-            hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
-        if ( newPositionOfTarget != Vector3::ZERO )
-        {
-            this->setPositionOfTarget( newPositionOfTarget );
-        }
-
-        float squaredDistance = squaredDistanceToTarget();
-
-        if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 20.0f)) {
-            return true;
-        }
-        else
-        {
-            return false;
-        }
-
-    }
     float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2)
     {
         if (!entity1 || !entity2)
@@ -995,6 +413,295 @@
 
         return (team1 == team2 && team1 != -1);
     }
+    bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )
+    {
+        if ( !entityThatLooks || !entityBeingLookedAt )
+            return false;
+        return ( getAngle( entityThatLooks ->getPosition() , 
+            entityThatLooks->getOrientation()  * WorldEntity::FRONT, 
+            entityBeingLookedAt->getWorldPosition() ) < angle );
+    }
+    std::string CommonController::getName(Pawn* 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;
+    }
+    float CommonController::squaredDistanceToTarget()  const
+    {
+        if ( !this->getControllableEntity()  )
+            return 0;
+        if ( !this->target_ || !this->getControllableEntity() )
+            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
+        else
+            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
+    }
+    bool CommonController::isLookingAtTarget( float angle )
+    {
+        if ( !this->getControllableEntity()  || !this->target_ )
+            return false;
+        return this->isLooking(this->getControllableEntity(), this->getTarget(), angle);
+    }
+
+
+    //------------------------------------------------------------------------------
+    //--------------------------------Flying methods--------------------------------
+    //------------------------------------------------------------------------------
+
+    void CommonController::stopMoving()
+    {
+        this->bHasTargetPosition_ = false;
+    }
+    void CommonController::stopLookingAtTarget()
+    {
+        this->bLookAtTarget_ = false;
+    }
+    void CommonController::startLookingAtTarget()
+    {
+        this->bLookAtTarget_ = true;
+    }
+    void CommonController::moveToPosition( const Vector3& target, float dt )
+    {
+        ControllableEntity* entity = this->getControllableEntity();
+        Vector2 coord = get2DViewCoordinates
+            ( entity->getPosition() , 
+            entity->getOrientation()  * WorldEntity::FRONT, 
+            entity->getOrientation()  * WorldEntity::UP, 
+            target );
+
+        float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
+        float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
+        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
+
+        if ( distance > this->tolerance_ )
+        {
+            this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
+            this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
+
+            if ( distance < 300 )
+            {
+                if ( bHasTargetOrientation_ )
+                {
+                    copyTargetOrientation( dt );
+                }
+            }
+            if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))
+                this->getControllableEntity() ->moveFrontBack( SPEED * dt );
+        }
+        else
+        {      
+            bHasTargetPosition_ = false;
+            bHasTargetOrientation_ = false;
+        }
+    }
+    void CommonController::moveToTargetPosition(float dt)
+    {
+        this->moveToPosition (this->targetPosition_, dt);
+    }
+    void CommonController::copyOrientation( const Quaternion& orient, float dt )
+    {
+        //roll angle difference in radian
+        float diff=orient.getRoll(false).valueRadians() -
+                        ( this->getControllableEntity() ->getOrientation() .getRoll( false ).valueRadians() );
+        while( diff>math::twoPi )diff-=math::twoPi;
+        while( diff<-math::twoPi )diff+=math::twoPi;
+        this->getControllableEntity() ->rotateRoll( diff*ROTATEFACTOR * dt );
+    }
+    void CommonController::copyTargetOrientation( float dt )
+    {
+        if ( bHasTargetOrientation_ )
+        {   
+            copyOrientation( targetOrientation_, dt );
+        }
+    }
+    void CommonController::lookAtTarget(float dt)
+    {
+        ControllableEntity* entity = this->getControllableEntity();
+        if ( !entity )
+            return;
+        Vector2 coord = get2DViewCoordinates
+            ( entity->getPosition() , 
+            entity->getOrientation()  * WorldEntity::FRONT, 
+            entity->getOrientation()  * WorldEntity::UP, 
+            positionOfTarget_ );
+
+        //rotates should be in range [-1,+1], clamp cuts off all that is not
+        float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
+        float rotateY = clamp( coord.y * 10, -1.0f, 1.0f ); 
+   
+        //Yaw and Pitch are enough to start facing the target
+        this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
+        this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
+    }
+    void CommonController::setTargetPosition( const Vector3& target )
+    {
+        this->targetPosition_ = target;
+        this->bHasTargetPosition_ = true;
+    }
+
+    void CommonController::setTargetOrientation( const Quaternion& orient )
+    {
+        this->targetOrientation_=orient;
+        this->bHasTargetOrientation_=true;
+    }
+
+    void CommonController::setTargetOrientation( ControllableEntity* target )
+    {
+        if ( target )
+            setTargetOrientation( target->getOrientation() );
+    }
+
+    //------------------------------------------------------------------------------
+    //-------------------------------Fighting methods-------------------------------
+    //------------------------------------------------------------------------------
+
+    void CommonController::setTarget( ControllableEntity* target )
+    {
+        this->target_ = target;        
+        if ( this->target_ )
+        {
+            this->setPositionOfTarget( target_->getWorldPosition() );
+        }
+    }
+    void CommonController::setPositionOfTarget( const Vector3& target )
+    {
+        this->positionOfTarget_ = target;
+        this->bHasPositionOfTarget_ = true;
+    }
+    void CommonController::setOrientationOfTarget( const Quaternion& orient )
+    {
+        this->orientationOfTarget_=orient;
+        this->bHasOrientationOfTarget_=true;
+    }
+    void CommonController::setProtect (ControllableEntity* protect)
+    {
+        this->protect_ = protect;
+    }
+    ControllableEntity* CommonController::getProtect ()
+    {
+        return this->protect_;
+    }
+    void CommonController::maneuver() 
+    {
+        maneuverCounter_++;
+        if (maneuverCounter_ > 5)
+            maneuverCounter_ = 0;
+
+        if ( !this->target_ || !this->getControllableEntity())
+            return;
+        
+        Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
+        this->setPositionOfTarget( getPredictedPosition( 
+            thisPosition, 
+            hardcoded_projectile_speed, 
+            this->target_->getWorldPosition() , 
+            this->target_->getVelocity()  
+            )  );
+        this->setOrientationOfTarget( this->target_->getOrientation() );
+
+        Vector3 diffVector = this->positionOfTarget_ - thisPosition;
+        float diffLength = diffVector.length();
+        Vector3 diffUnit = diffVector/diffLength;
+
+        bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f );
+        
+        //too far? well, come closer then
+        if ( diffLength > this->attackRange_ )
+        {
+            this->setTargetPosition( this->positionOfTarget_ );
+        }
+        //too close? How do u expect to dodge anything? Just attack!
+        else if ( diffLength < 500 )
+        {   
+            //at this point, just look and shoot
+            if ( diffLength < 250 )
+            {
+                this->stopMoving();
+                this->startLookingAtTarget();
+            }
+            else
+            {
+                this->setTargetPosition( this->positionOfTarget_ );
+            }
+        }
+        //Good distance? Check if target looks at us. It doesn't? Go hunt!
+        else if ( !bTargetIsLookingAtThis )
+        {
+            this->setTargetPosition( this->positionOfTarget_ );
+        }
+        //That's unfortunate, he is looking and probably shooting... try to dodge what we can...  
+        else 
+        {   
+            if (maneuverCounter_ == 0)
+            {
+                this->setTargetPosition( this->positionOfTarget_ );   
+                return;
+            }
+            dodge( thisPosition, diffUnit );
+        }
+    }
+    
+    void CommonController::dodge(Vector3& thisPosition, Vector3& diffUnit)
+    {
+        float factorX = 0, factorY = 0, factorZ = 0;
+        float rand = randomInRange (0, 1);
+    
+        if (rand <= 0.5)
+        { factorX = 1; }
+        else
+        { factorX = -1; }
+        rand = randomInRange (0, 1);
+        if (rand <= 0.5)
+        { factorY = 1; }
+        else
+        { factorY = -1; }
+        rand = randomInRange (0, 1);
+        if (rand <= 0.5)
+        { factorZ = 1; }
+        else
+        { factorZ = -1; }
+
+        Vector3 target = ( diffUnit )* 8000.0f;
+        Vector3* randVector = new Vector3( 
+            factorX * randomInRange( 10000, 40000 ), 
+            factorY * randomInRange( 10000, 40000 ), 
+            factorZ * randomInRange( 10000, 40000 ) 
+        );
+        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
+        *randVector -= projection;
+        target += *randVector;
+        this->setTargetPosition( thisPosition + target );
+    }
+    bool CommonController::canFire() 
+    {
+        //no target? why fire?
+        if ( !this->target_ )
+            return false;
+
+        Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , 
+            hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
+        if ( newPositionOfTarget != Vector3::ZERO )
+        {
+            this->setPositionOfTarget( newPositionOfTarget );
+        }
+
+        float squaredDistance = squaredDistanceToTarget();
+
+        if ( squaredDistance < this->attackRange_*this->attackRange_ && this->isLookingAtTarget( math::pi / 20.0f)) 
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
     void CommonController::doFire() 
     {
         if ( !this->target_ || !this->getControllableEntity() )
@@ -1005,11 +712,150 @@
         Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
 
         if ( pawn )
-            //pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition()  + 4000*( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ));
             pawn->setAimPosition( this->positionOfTarget_ );
-    
         this->getControllableEntity() ->fire( 0 );
     }
-   
+    void CommonController::setClosestTarget()
+    {
+        this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 
+    }
+    Pawn* CommonController::closestTarget()
+    {
+        if (!this->getControllableEntity())
+            return 0;
 
+        Pawn* closestTarget = 0;
+        float minDistance =  std::numeric_limits<float>::infinity();
+        Gametype* gt = this->getGametype();
+        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+        {
+            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
+                continue;
+
+            float distance = CommonController::distance (*itP, this->getControllableEntity());
+            if (distance < minDistance)
+            {
+                closestTarget = *itP;
+                minDistance = distance;
+            }
+        }
+        if (closestTarget)
+        {
+           return closestTarget;
+        } 
+        return 0;  
+    }
+    bool CommonController::startAttackingEnemiesThatAreClose()
+    {
+        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
+        {
+            if ( (this->target_ && this->distance (this->getControllableEntity(), this->target_) > this->attackRange_) 
+                || !this->target_ )
+            {
+                Pawn* newTarget = this->closestTarget();
+                if ( newTarget && 
+                    this->distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
+                        <= this->attackRange_ )
+                {
+                    Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO };
+                    this->parsedActionpoints_.push_back(p);
+                    this->executeActionpoint();
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    //------------------------------------------------------------------------------
+    //------------------------------Actionpoint methods-----------------------------
+    //------------------------------------------------------------------------------
+
+    //POST: this starts doing what was asked by the last element of parsedActionpoints_,
+    //if last element was failed to be parsed, next element will be executed.
+    void CommonController::executeActionpoint()
+    {
+        if (!this->parsedActionpoints_.empty())
+        {
+            this->action_ = this->parsedActionpoints_.back().action;
+
+            switch ( this->action_ )
+            {
+                case Action::FIGHT:
+                {                
+                    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;
+
+                    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;
+        }
+    }
+    void CommonController::nextActionpoint()
+    {
+        if (!this->parsedActionpoints_.empty())
+        {
+            this->parsedActionpoints_.pop_back();
+        }
+        this->setAction(Action::NONE);
+    }
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-24 21:37:28 UTC (rev 10851)
@@ -38,6 +38,7 @@
 #include "tools/Timer.h"
 #include "tools/interfaces/Tickable.h"
 #include <limits>
+#include <algorithm>
 #include "worldentities/Actionpoint.h"
 
 namespace orxonox
@@ -89,60 +90,38 @@
 
             virtual void tick(float dt); 
 
-            //----[XML data]----
+            //----[XML methods]----
                 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-                //----[Action data]----
-                    Action::Value getAction ();
-                    void setAction (Action::Value action);
-                    void setAction (Action::Value action, ControllableEntity* target);
-                    void setAction (Action::Value action, const Vector3& target);
-                    void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
-                    void setActionXML( std::string val);
-                    std::string getActionXML();
-                //----[/Action data]----
-                //----[Formation data]----
-                    virtual void setFormationModeXML(std::string val);
-                    virtual std::string getFormationModeXML();
-                    virtual void setFormationMode(FormationMode::Value val)
-                        { this->formationMode_ = val; }
-                    inline FormationMode::Value getFormationMode() const
-                        { return this->formationMode_; }
-                //----[/Formation data]----
-                //----[Rank data]----
-                    virtual void setRank(Rank::Value val)
-                        { this->rank_ = val; }
-                    inline Rank::Value getRank() const
-                        { return this->rank_; }
-                //----[/Rank data]----
-                //----[Protect data]----
-                    void setProtectXML( std::string val );
-                    std::string getProtectXML ();
-                    void setProtect (ControllableEntity* protect);
-                    ControllableEntity* getProtect ();
-                //----[/Protect data]----
-                //----[Actionpoint data]----
+                
+                    void setFormationModeXML(std::string val);
+                    std::string getFormationModeXML();
+                    void setFormationMode(FormationMode::Value val);
+                    FormationMode::Value getFormationMode() const;
+
+                    void setRank(Rank::Value val);
+                    Rank::Value getRank() const;
+               
                     void addActionpoint(WorldEntity* waypoint);
                     WorldEntity* getActionpoint(unsigned int index) const;
-                //----[/Actionpoint data]----
-            //----[/XML data]----
+            //----[/XML methods]----
 
             //----[Interaction with other Controllers]----
                 virtual bool setWingman(CommonController* wingman);
                 virtual bool hasWingman();        
-
-                void setPositionOfTarget(const Vector3& target);
-                void setOrientationOfTarget(const Quaternion& orient);
-
-                void setTarget(ControllableEntity* target);
-                ControllableEntity* getTarget();
+                
                 bool hasTarget();
+                ControllableEntity* getTarget();
+                      
+                Action::Value getAction ();
+                std::string getActionName();
 
-                void setTargetPosition(const Vector3& target);
-                void setTargetOrientation(const Quaternion& orient);
-                void setTargetOrientation(ControllableEntity* target);
+                void setAction (Action::Value action);
+                void setAction (Action::Value action, ControllableEntity* target);
+                void setAction (Action::Value action, const Vector3& target);
+                void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
             //----[/Interaction with other Controllers]----
 
-            //----[Helper functions]----
+            //----[Helper methods]----
                 float randomInRange(float a, float b);
                 static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
                 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
@@ -150,16 +129,26 @@
                 static std::string getName( Pawn* entity ) ;
 
                 float squaredDistanceToTarget() const;
-                bool isLookingAtTarget(float angle) const;
-            //----[/Helper functions]----
+                bool isLookingAtTarget(float angle);
+            //----[/Helper methods]----
 
+             //----[Actionpoint information]----
+
+                std::vector<WeakPtr<WorldEntity> > actionpoints_;
+                float squaredaccuracy_;
+                std::vector<Point > parsedActionpoints_;
+
+            //----[/Actionpoint information]----
+                //----[Actionpoint methods]----
+                void executeActionpoint();
+                void nextActionpoint();
+            //----[Actionpoint methods]----
         protected:
-            //----[Flying functionality]----
+            //----[Flying methods]----
                 void stopMoving();
+                void stopLookingAtTarget();
+                void startLookingAtTarget();
 
-                void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
-                bool moveAndRoll(float dt);
-
                 void moveToPosition(const Vector3& target, float dt);
                 void moveToTargetPosition(float dt);
 
@@ -167,32 +156,39 @@
                 void copyTargetOrientation(float dt);
 
                 void lookAtTarget(float dt);
-                void stopLookingAtTarget();
-                void startLookingAtTarget();
 
-                bool bLookAtTarget_;        
-            //----[/Flying functionality]----
+                void setTargetPosition(const Vector3& target);
+                void setTargetOrientation(const Quaternion& orient);
+                void setTargetOrientation(ControllableEntity* target);
+
+
+            //----[/Flying methods]----
             
-            //----[Fighting functionality]----
+            //----[Fighting methods]----
+                void setTarget(ControllableEntity* target);
+
+                void setPositionOfTarget(const Vector3& target);
+                void setOrientationOfTarget(const Quaternion& orient);
+
+                void setProtect (ControllableEntity* protect);
+                ControllableEntity* getProtect (); 
+
                 void maneuver();
                 void dodge(Vector3& thisPosition, Vector3& diffUnit);
-                void aimAtTarget();           
                 bool canFire();
                 void doFire();
                 void setClosestTarget();
                 Pawn* closestTarget();
-
-                bool bShooting_;
-                int maneuverCounter_;         
-            //----[/Fighting functionality]----            
+                bool startAttackingEnemiesThatAreClose();
+            //----[/Fighting methods]----            
             
             //----[where-to-fly information]----
+                
                 bool bHasTargetPosition_;
                 Vector3 targetPosition_;
                 bool bHasTargetOrientation_;
                 Quaternion targetOrientation_;
                 
-               
             //----[/where-to-fly information]----
             //----[protect information]----
                 WeakPtr<ControllableEntity> protect_;
@@ -206,14 +202,7 @@
                 Quaternion orientationOfTarget_;
             //----[/who-to-kill information]----
 
-            //----[Actionpoint information]----
-                std::vector<WeakPtr<WorldEntity> > actionpoints_;
-                float squaredaccuracy_;
-                Point  currentActionpoint_;
-                std::vector<Point > parsedActionpoints_;
-                void executeActionpoint();
-                void nextActionpoint();
-            //----[/Actionpoint information]----
+           
             //----["Private" variables]----
                 FormationMode::Value formationMode_;
                 Rank::Value rank_;
@@ -221,7 +210,11 @@
                 std::string targetName_;
                 Action::Value action_;
                 int attackRange_;
-                
+                bool bLookAtTarget_;        
+                bool bShooting_;
+                int maneuverCounter_;
+                int tolerance_; 
+                bool bFirstTick_;                        
             //----[/"Private" variables]----               
     };
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-24 21:37:28 UTC (rev 10851)
@@ -45,8 +45,6 @@
         this->myWingman_ = 0;
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
         this->rank_ = Rank::DIVISIONLEADER;
-
-
     }
 
     DivisionController::~DivisionController()
@@ -59,54 +57,32 @@
 
         //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);
     }
-
-    
     void DivisionController::tick(float dt)
     {   
-
         if (!this->isActive())
             return;
-        
-        
         SUPER(DivisionController, tick, dt);
-
     }
     void DivisionController::action()
-    {
-        //----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->startAttackingEnemiesThatAreClose())
         {
-            if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 
-                || !this->target_ )
+            Point p = { Action::FIGHT, "", Vector3::ZERO };
+            
+            if (this->myWingman_)
             {
-                Pawn* newTarget = this->closestTarget();
-                if ( newTarget && 
-                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
-                        <= this->attackRange_ )
-                {
-                    // this->backupAction();
-                    // this->setAction (Action::FIGHT, newTarget);
-                    Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO };
-                    this->parsedActionpoints_.push_back(p);
-                    this->executeActionpoint();
-                }
+                this->myWingman_->parsedActionpoints_.push_back(p);
             }
+            if (this->myFollower_)
+            {
+                this->myFollower_->parsedActionpoints_.push_back(p);
+            }
         }
 
-        //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)
         {
             this->executeActionpoint();
         }
-
-
-        //this->action_ is what I am actually executing, this->target_ is what I am 
-        //actually attacking, etc.
-
-        //after action is finished, .pop_back() is to be called.
         if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
         {
             if (!this->hasTarget())
@@ -115,13 +91,22 @@
                 ControllableEntity* newTarget = this->closestTarget();
                 if (this->action_ == Action::FIGHT)
                 {
-                    if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                    if (newTarget && 
+                            CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
                     {
                         this->setAction (Action::FIGHT, newTarget);
                     }
                     else
                     {
                         this->nextActionpoint();
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->nextActionpoint();
+                        }
+                        if (this->myFollower_)
+                        {
+                            this->myFollower_->nextActionpoint();
+                        }
                         return;
                     }
                 }
@@ -134,6 +119,14 @@
                     else
                     {
                         this->nextActionpoint();
+                        if (this->myWingman_)
+                        {
+                            this->myWingman_->nextActionpoint();
+                        }
+                        if (this->myFollower_)
+                        {
+                            this->myFollower_->nextActionpoint();
+                        }
                         return;
                     }
                 }
@@ -143,13 +136,20 @@
             {
                 //----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();
+                        }
+                        if (this->myFollower_)
+                        {
+                            this->myFollower_->nextActionpoint();
+                        }
                         return;
                     }
                     else
@@ -157,39 +157,34 @@
                         this->setTargetPositionOfWingman();
                         this->setTargetPositionOfFollower();                    
                     }
-
                 }
                 else
                 {
                     //----wingmans shall support the fire of their leaders----
                     if (this->myWingman_)
                     {
-                        this->myWingman_->setAction (this->action_, this->target_);     
+                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
                     }
                     if (this->myFollower_)
                     {
-                        this->myFollower_->setAction (this->action_);                                    
+                        this->myFollower_->setAction (Action::FIGHT);                                    
                     }
-
                 }
-                
             }
-            if (this->hasTarget())
-            {
-                //----choose where to go----
-                this->maneuver();
-                //----fire if you can----
-                this->bShooting_ = this->canFire();                
-            }
-
         }
         else if (this->action_ == Action::FLY)
         {
-
             if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
             {
-                orxout(internal_error) << "arrived";
                 this->nextActionpoint();
+                if (this->myWingman_)
+                {
+                    this->myWingman_->nextActionpoint();
+                }
+                if (this->myFollower_)
+                {
+                    this->myFollower_->nextActionpoint();
+                }
                 return;
             }
             this->setTargetPositionOfWingman();
@@ -200,16 +195,20 @@
             if (!this->getProtect())
             {
                 this->nextActionpoint();
+                if (this->myWingman_)
+                {
+                    this->myWingman_->nextActionpoint();
+                }
+                if (this->myFollower_)
+                {
+                    this->myFollower_->nextActionpoint();
+                }
                 return;
             }
-           /* if (this->myWingman_)
-                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
-            if (this->myFollower_)
-                this->myFollower_->setAction (Action::PROTECT, this->getProtect());
-            */
+
             Vector3* targetRelativePosition;
                 
-            targetRelativePosition = new Vector3 (0, 0, 500);  
+            targetRelativePosition = new Vector3 (0, 300, 300);  
  
             Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
                 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
@@ -224,6 +223,14 @@
             if (!this->hasTarget())
             {
                 this->nextActionpoint();
+                if (this->myWingman_)
+                {
+                    this->myWingman_->nextActionpoint();
+                }
+                if (this->myFollower_)
+                {
+                    this->myFollower_->nextActionpoint();
+                }
                 return;
             }
             //----fly in formation if far enough----
@@ -238,25 +245,23 @@
                 //----wingmans shall support the fire of their leaders----
                 if (this->myWingman_)
                 {
-                    this->myWingman_->setAction (this->action_, this->target_);     
+                    this->myWingman_->setAction (Action::FIGHT, this->target_);     
                 }
                 if (this->myFollower_)
                 {
-                    this->myFollower_->setAction (this->action_);                                    
+                    this->myFollower_->setAction (Action::FIGHT);                                    
                 }
-
-            }
-            
+            }          
+        }
+        if (this->hasTarget())
+        {
             //----choose where to go----
             this->maneuver();
             //----fire if you can----
             this->bShooting_ = this->canFire();                
         }
-
     }
-
     
-
     void DivisionController::setTargetPositionOfWingman()
     {
         if (!this->myWingman_)
@@ -320,8 +325,6 @@
         
         myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );       
     }
-
-
     bool DivisionController::setWingman(CommonController* cwingman)
     {
 
@@ -335,7 +338,6 @@
         {
             return false;
         }
-    
     }
     bool DivisionController::setFollower(LeaderController* myFollower)
     {
@@ -363,9 +365,4 @@
         else
             return false;
     }
-
-
-    
-   
-
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-24 21:37:28 UTC (rev 10851)
@@ -43,7 +43,7 @@
         this->myWingman_ = 0;
         this->myDivisionLeader_ = 0;
         this->rank_ = Rank::SECTIONLEADER;
-
+        this->bFirstAction_ = true;
         //orxout(internal_error) << this << "Was created" << endl;
 
     }
@@ -71,6 +71,7 @@
 
     void SectionController::action()
     {
+
         //----If no leader, find one----  
         if (!myDivisionLeader_)
         {
@@ -82,38 +83,157 @@
         else
         {
         }
-
-        //----action was set to fight----
-        if (this->action_ == Action::FIGHT)
+        if (!myDivisionLeader_)
         {
-            if (!this->hasTarget())
+            if (this->startAttackingEnemiesThatAreClose())
             {
-                if (this->myDivisionLeader_)
+                Point p = { Action::FIGHT, "", Vector3::ZERO };
+                
+                if (this->myWingman_)
                 {
-                    this->chooseTarget();                
+                    this->myWingman_->parsedActionpoints_.push_back(p);
                 }
-                else
+            }
+            if (this->action_ == Action::NONE)
+            {
+                this->executeActionpoint();
+            }
+            if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
+            {
+                if (!this->hasTarget())
                 {
-                    this->setClosestTarget(); 
+                    //----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
+            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() > 3000)
+                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_);                    
+                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
                     }
-                }
+      
+                }          
             }
             if (this->hasTarget())
             {
@@ -123,24 +243,59 @@
                 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();
+            //----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));
+                }
+            }       
         }
-
-        //----action was set to protect----
-        else if (this->action_ == Action::PROTECT)
+        if (this->bFirstAction_ && this->myDivisionLeader_)
         {
-           /* if (this->myWingman_)
-                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
-*/
-            this->setTargetPositionOfWingman();
-
+            this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_;
+            this->bFirstAction_ = false;
         }
-                
-
     }
     //PRE: myDivisionLeader_ != 0 && myDivisionLeader_->action_ == Action::FIGHT
     //POST: this->target_ is set unless division leader doesn't have one
@@ -266,7 +421,6 @@
                 return closestLeader;
         }
         return 0;
-
     }
     bool SectionController::setWingman(CommonController* cwingman)
     {
@@ -290,9 +444,4 @@
         else
             return false;
     }
-
-    
-    
-   
-
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-11-24 21:37:28 UTC (rev 10851)
@@ -66,6 +66,7 @@
         private:
             //----private variables-----
                 Timer actionTimer_; //<! Regularly calls action().
+                bool bFirstAction_;
             
 
     };

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-24 21:37:28 UTC (rev 10851)
@@ -41,6 +41,8 @@
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
         this->myLeader_ = 0;
         this->rank_ = Rank::WINGMAN;
+        this->bFirstAction_ = true;
+
     }
 
     WingmanController::~WingmanController()
@@ -68,6 +70,7 @@
     //----action for hard calculations----
     void WingmanController::action()
     {
+
         //----If no leader, find one----
         if (!this->myLeader_)
         {
@@ -78,18 +81,99 @@
         //----If have leader, he will deal with logic----
         else
         {
-            this->action_ = this->myLeader_->getAction();
+
         }
+        if (!this->myLeader_)
+        {
+            bool b = this->startAttackingEnemiesThatAreClose();
 
+            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();
+                            return;
+                        }
+                    }
+                    else if (this->action_ == Action::FIGHTALL)
+                    {
+                        if (newTarget && newTarget->getController())
+                        {
+                            this->setAction (Action::FIGHTALL, newTarget);
+                        }
+                        else
+                        {
+                            this->nextActionpoint();
+                            return;
+                        }
+                    }
 
-        //----action was set to fight----
-        if (this->action_ == Action::FIGHT)
-        {
-            //----If no leader found, attack someone----
-            if (!this->hasTarget() && !this->myLeader_)
+                }
+                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();
+                            return;
+                        }
+                    }
+                }
+            }
+            else if (this->action_ == Action::FLY)
             {
-                this->setClosestTarget(); 
+                if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                {
+                    this->nextActionpoint();
+                    return;
+                }
             }
+            else if (this->action_ == Action::PROTECT)
+            {
+                if (!this->getProtect())
+                {
+                    this->nextActionpoint();
+                    return;
+                }
+
+                Vector3* targetRelativePosition;
+                    
+                targetRelativePosition = new Vector3 (0, 300, 300);  
+     
+                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
+                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
+                this->setTargetPosition(targetAbsolutePosition);
+                
+
+            }
+            else if (this->action_ == Action::ATTACK)
+            {   
+                if (!this->hasTarget())
+                {
+                    this->nextActionpoint();
+                    return;
+                }
+                        
+            }
             if (this->hasTarget())
             {
                 //----choose where to go----
@@ -98,17 +182,35 @@
                 this->bShooting_ = this->canFire();                
             }
         }
-        //----action was set to fly, leader handles the logic----
-        else if (this->action_ == Action::FLY)
+        else
         {
+            //----action was set to fight----
+            if (this->action_ == Action::FIGHT)
+            {
+                //----If no leader found, attack someone----
+                if (!this->hasTarget())
+                {
+                    this->setClosestTarget(); 
+                }
+                if (this->hasTarget())
+                {
+                    //----choose where to go----
+                    this->maneuver();
+                    //----fire if you can----
+                    this->bShooting_ = this->canFire();                
+                }
+            }
+            //----action was set to fly, leader handles the logic----
+            else if (this->action_ == Action::FLY)
+            {
 
-        }
-        //----gani-TODO: implement protect----
-        else if (this->action_ == Action::PROTECT)
+            }
+        } 
+        if (this->bFirstAction_ && this->myLeader_)
         {
-
+            this->parsedActionpoints_ = this->myLeader_->parsedActionpoints_;
+            this->bFirstAction_ = false;
         }
-          
     }
      
    

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-24 16:52:43 UTC (rev 10850)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-11-24 21:37:28 UTC (rev 10851)
@@ -62,7 +62,8 @@
             //----private variables-----
                 WeakPtr<CommonController> myLeader_;
                 Timer actionTimer_; //<! Regularly calls action().
-               
+                bool bFirstAction_;
+
     };
 }
 




More information about the Orxonox-commit mailing list