[Orxonox-commit 6147] r10805 - in code/branches/AI_HS15: data/levels src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Sun Nov 15 16:47:35 CET 2015


Author: gania
Date: 2015-11-15 16:47:35 +0100 (Sun, 15 Nov 2015)
New Revision: 10805

Modified:
   code/branches/AI_HS15/data/levels/AITest.oxw
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
   code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
   code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
Log:
Finished groundwork: AI fights enemies like I want it to. TODO: implement all the functionality of old AI, like Waypoints, XMLPort

Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/data/levels/AITest.oxw	2015-11-15 15:47:35 UTC (rev 10805)
@@ -1,6 +1,6 @@
 <LevelInfo
- name = "AI testing level"
- description = "A level with two opposing AI teams"
+ name = "New AI testing level"
+ description = "A level with two opposing new AI teams"
  tags = "test"
  screenshot = "emptylevel.png"
 />
@@ -32,50 +32,26 @@
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
     <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
-    <!-->
-
+    >
+<!-- 
     <?lua
       for i = 0, 5, 1 do
     ?>
 
-    <StaticEntity position="0,-10000,0" direction="0,-1,0" >
-     <controller>
-        <FleetController team=1>
-        </FleetController>
-      </controller>
-    </StaticEntity>
-    <StaticEntity position="0,10000,0" direction="0,-1,0" >
-     <controller>
-        <FleetController team=2>
-        </FleetController>
-      </controller>
-    </StaticEntity>
-    <SpaceShip position="<?lua print(1600+i*200) ?>,<?lua print(3000-i*500) ?>, -1500 ?>" lookat="0,0,0">
+    
+    <SpaceShip position="<?lua print(-1600+i*200) ?>,<?lua print(-3000-i*500) ?>, -1500 ?>" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <AIController accuracy=10 team=1>
+        <AIController accuracy=10 team=2>
         </AIController>
       </controller>
     </SpaceShip>
-    <?lua end ?>
-  </!-->
-    <SpaceShip position="0,-10000,0" direction="0,-1,0" >
-     <templates>
-        <Template link=spaceshipassff />
-      </templates>
-     <controller>
-        <FleetController team=1>
-        </FleetController>
-      </controller>
-    </SpaceShip>
-    <?lua
-      for i = 0, 0, 1 do
-    ?>
-
+    <?lua end ?> -->
+ 
     
-    <SpaceShip position="<?4000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -84,7 +60,7 @@
         </DivisionController>
       </controller>
     </SpaceShip>
-    <!-- <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
+    <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -93,7 +69,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -2200" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -102,7 +78,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0">
+    <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -110,132 +86,92 @@
         <SectionController team=1>
         </SectionController>
       </controller>
-    </SpaceShip> -->
-    <?lua end ?>
-   <!--  <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
+    </SpaceShip>
+    <SpaceShip position="6000, 1500, -1000" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=2>
-        </WingmanController>
-      </controller>
-    </SpaceShip> -->
-<!-- 
-    <?lua
-      for i = 0, 0, 1 do
-    ?>
-
-    <StaticEntity position="1000,-10000,0" direction="0,-1,0" >
-     <controller>
-        <FleetController team=2>
-        </FleetController>
-      </controller>
-    </StaticEntity>
-    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <DivisionController team=2>
+        <DivisionController team=1 formationMode="DIAMOND">
         </DivisionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
+    <SpaceShip position="6000 ,1500, -1600 " lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=2>
+        <WingmanController team=1>
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0">
+    <SpaceShip position="6000, 1500, -2200" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=2>
+        <WingmanController team=1>
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0">
+    <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <SectionController team=2>
+        <SectionController team=1>
         </SectionController>
       </controller>
     </SpaceShip>
-    <?lua end ?> -->
-
-<!-- 
-
-    <StaticEntity position = "-1000, -1000, -1000">
- 
-      <controller>
-        <FleetController accuracy=10 team=1 >
-        </FleetController>
-      </controller>
-    </StaticEntity>
+  
     
-    <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
+    <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1>
+        <DivisionController team=2 formationMode="FINGER4">
         </DivisionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1500, -1300 ?>" lookat="0,0,0">
+    <SpaceShip position="-4000 , 1500, -5600" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=1>
+        <WingmanController team=2>
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1500, -1700 ?>" lookat="0,0,0">
+    <SpaceShip position="-4000, 1500, -6200" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=1>
+        <WingmanController team=2>
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
+    <SpaceShip position="-4000, 1500, -6800 " lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <SectionController team=1>
+        <SectionController team=2>
         </SectionController>
       </controller>
     </SpaceShip>
 
-
-      <StaticEntity position = "-1000, -1000, -2000">
- 
-      <controller>
-        <FleetController accuracy=10 team=2 >
-        </FleetController>
-      </controller>
-    </StaticEntity>
-    
-    <SpaceShip position="4000, 1000, -1300 ?>" lookat="0,0,0">
+       <SpaceShip position="-6000, 1500, -5000" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=2>
+        <DivisionController team=2 formationMode="FINGER4">
         </DivisionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
+    <SpaceShip position="-6000 , 1500, -5600" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -244,7 +180,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1500, -1700 ?>" lookat="0,0,0">
+    <SpaceShip position="-6000, 1500, -6200" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -253,7 +189,7 @@
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1000, -1900 ?>" lookat="0,0,0">
+    <SpaceShip position="-6000, 1500, -6800 " lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -261,24 +197,11 @@
         <SectionController team=2>
         </SectionController>
       </controller>
-    </SpaceShip> -->
+    </SpaceShip>
 
+
+    
    
-    <!-->
-    <?lua
-      for i = 0, 5, 1 do
-    ?>
-    <SpaceShip position="<?lua print(1600+i*200) ?>,3000, 6000 ?>" lookat="0,0,0">
-      <templates>
-        <Template link=spaceshipassff />
-      </templates>
-      <controller>
-        <AIController accuracy=10 team=2>
-        </AIController>
-      </controller>
-    </SpaceShip>
-    <?lua end ?>
-    </!-->
 
   </Scene>
 </Level>

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-15 15:47:35 UTC (rev 10805)
@@ -54,6 +54,7 @@
 
         this->executingManeuver_ = false;
         this->executingMoveToPoint_ = false;
+        this->action_ = Action::FLY;
         this->stopLookingAtTarget();
         this->maneuverType_ = ManeuverType::NONE;
         RegisterObject( CommonController );
@@ -62,6 +63,7 @@
 
     CommonController::~CommonController() 
     {
+        orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
     }
 
     void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
@@ -117,6 +119,48 @@
 
         }
     }
+    Action::Value CommonController::getAction ()
+    {
+        return this->action_;
+    }
+
+    void CommonController::setAction (Action::Value action, ControllableEntity* target)
+    {
+        this->action_ = action;
+        if (action == Action::FIGHT)
+        {   
+            if (target)
+                this->setTarget (target);
+        }
+        else if (action == Action::PROTECT)
+        {
+        }
+    }
+    void CommonController::setAction (Action::Value action, const Vector3& target)
+    {
+        this->action_ = action;
+        if (action == Action::FLY)
+        {
+            this->setTargetPosition (target);
+        }
+        else if (action == Action::PROTECT)
+        {
+
+        }
+    }
+    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);
+        }
+        else if (action == Action::PROTECT)
+        {
+            
+        }
+    }
     void CommonController::maneuver() 
     {
         counter++;
@@ -144,28 +188,27 @@
 
 
             //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 );
-            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/8.0f );
+            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/5.0f );
             
 
 
             //too far? well, come closer then
-            if ( diffLength > 5000 )
+            if ( diffLength > 3000 )
             {
                 if (diffLength < 6000)
                 {
-                    this->bEngaging_ = true;
+
                 }
                 else
                 {
-                    this->bEngaging_ = false;
                 }
                 this->setTargetPosition( this->positionOfTarget_ );
             }
             //too close? How do u expect to dodge anything? Just attack!
-            else if ( diffLength < 600 )
+            else if ( diffLength < 500 )
             {   
                 //at this point, just look and shoot
-                if ( diffLength < 300 )
+                if ( diffLength < 250 )
                 {
                     this->stopMoving();
                     this->startLookingAtTarget();
@@ -204,10 +247,10 @@
         }
         if ( this->getControllableEntity()  && !this->target_ )
         {
-            this->bEngaging_ = false;
+
             this->maneuverType_ = ManeuverType::NONE;
         }
-        orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
+        //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
     }
     ControllableEntity* CommonController::getTarget()
     {
@@ -304,7 +347,7 @@
     void CommonController::setTarget( ControllableEntity* target )
     {
         this->target_ = target;
-        orxout ( internal_error ) << " TARGET SET " << endl;
+        //orxout ( internal_error ) << " TARGET SET " << endl;
         
         if ( this->target_ )
         {
@@ -375,13 +418,7 @@
     }
     void CommonController::moveToPosition( const Vector3& target, float dt )
     {
-        float factor = 1;
-        if ( !this->getControllableEntity() )
-            return;
-        if ( this->rank_ == Rank::DIVISIONLEADER )
-            factor = 0.9;
-        if ( this->rank_ == Rank::SECTIONLEADER )
-            factor = 0.95;
+     
         
         //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
@@ -420,7 +457,7 @@
                 }
             }
 
-            this->getControllableEntity() ->moveFrontBack( SPEED*factor * dt );
+            this->getControllableEntity() ->moveFrontBack( SPEED * dt );
         }
         else
         {      
@@ -559,7 +596,7 @@
 
         float squaredDistance = squaredDistanceToTarget();
 
-        if ( squaredDistance < 25000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {
+        if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {
             return true;
         }
         else

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-15 15:47:35 UTC (rev 10805)
@@ -65,6 +65,13 @@
         };
 
     }
+    namespace Action
+    {  
+        enum Value
+        {
+            FLY, FIGHT, PROTECT
+        };
+    }
     //none for a formation flight
     namespace Maneuver
     {
@@ -120,8 +127,11 @@
 
             /*void spin();
             void turn180();*/
+            Action::Value getAction ();
+            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 );
 
-
         protected:
             void dodge(Vector3& thisPosition, Vector3& diffUnit);
             int counter;
@@ -157,6 +167,10 @@
             bool bHasTargetOrientation_;
             Quaternion targetOrientation_;
 
+            Vector3 destination_;
+            bool bHasDestination;
+
+
             void stopMoving();
             void setPositionOfTarget(const Vector3& target);
             void setOrientationOfTarget(const Quaternion& orient);
@@ -169,6 +183,9 @@
             WeakPtr<ControllableEntity> target_;
             //WeakPtr<ControllableEntity> thisEntity_;
 
+           
+
+            Action::Value action_;
             bool bEngaging_;
             bool bShooting_;
             WeakPtr<ControllableEntity> objectiveTarget_;

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-15 15:47:35 UTC (rev 10805)
@@ -50,7 +50,6 @@
 
     DivisionController::~DivisionController()
     {
-      
     } 
 
     
@@ -76,10 +75,51 @@
     }
     void DivisionController::action()
     {
-        this->maneuver();
-        this->bShooting_ = this->canFire();
+        if (!this->target_)
+        {
+            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+            {
+                if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+                    continue;           
+
+                
+                if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() && !(this)->hasTarget()
+                    && ((*itP)->getWorldPosition() - (this)->getControllableEntity()->getWorldPosition()).length() < 10000)
+                {
+                    (this)->setAction(Action::FIGHT, *itP);
+                }   
+            }
+        }
         
+        if (this->action_ == Action::FIGHT)
+        {
+            this->maneuver();
+            this->bShooting_ = this->canFire();
+            if (this->target_)
+            {
+                if (this->myWingman_)
+                {
+                    this->myWingman_->setAction (Action::FIGHT, this->target_);                    
+                }
+                
+                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                if (diffVector.length() > 3000)
+                {
+                    this->setTargetPositionOfWingman();
+                    //this->setTargetPositionOfFollower();                    
+                }   
+            }
+        }
+        else if (this->action_ == Action::FLY)
+        {
+            this->setTargetPositionOfWingman();
+            this->setTargetPositionOfFollower();
+        }
+        else if (this->action_ == Action::PROTECT)
+        {
 
+        }
+
     }
 
     
@@ -115,8 +155,7 @@
         Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
         (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
         
-        myWingman_->setTargetOrientation(orient);
-        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
+        myWingman_->setAction( Action::FLY, targetAbsolutePositionOfWingman, orient);
        
     }
     void DivisionController::setTargetPositionOfFollower()
@@ -152,9 +191,7 @@
         Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 
         (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
         
-        myFollower_->setTargetOrientation(orient);
-        myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
-       
+        myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );       
     }
 
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-11-15 15:47:35 UTC (rev 10805)
@@ -86,15 +86,21 @@
 
             for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 
             {
-                if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget())
+                if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget()
+                    && ((*itP)->getWorldPosition() - (*it)->getControllableEntity()->getWorldPosition()).length() < 10000)
                 {
-                    (*it)->setTarget(*itP);
+                    (*it)->setAction(Action::FIGHT, *itP);
                 }
                 
             }   
            
         }
-
+        /*for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 
+        {
+            Vector3* target = new Vector3 (0, 0, 2000);
+            (*it)->setAction (Action::FLY, *target);           
+        }   
+*/
     }
     void FleetController::tick(float dt)
     {

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-11-15 15:47:35 UTC (rev 10805)
@@ -54,16 +54,20 @@
 
     void SectionController::tick(float dt)
     {
-        if (!this->isActive())
+         if (!this->isActive())
             return;
-        
-        
         if (this->bHasTargetPosition_)
         {
             this->moveToTargetPosition(dt);
         }
-        if (this->bShooting_)
-            doFire();
+        else if (this->bLookAtTarget_)
+        {
+            this->lookAtTarget(dt);
+        }
+        if (bShooting_)
+        {
+            this->doFire();
+        }
         
         SUPER(SectionController, tick, dt);
     }
@@ -79,17 +83,81 @@
                 orxout(internal_error) << "new DivisionLeader set" << endl;
             else
             {
-                
+                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                {
+                    if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+                        continue;           
+
+                    if (!this->myDivisionLeader_)
+                    {
+                        this->setAction(Action::FIGHT, (*itP));
+                        break;
+                    }
+                   
+                }
             }
 
         }
-        setTargetPositionOfWingman();
-        if (this->target_ && this->myWingman_)
-            this->myWingman_->setTarget(this->target_);
-        if (canFire())
-           this->bShooting_ = true;
         else
-            this->bShooting_ = false;
+        {
+            if (this->myDivisionLeader_->getAction() == Action::FIGHT)
+            {
+                if (this->myDivisionLeader_->hasTarget())
+                {
+                    if (this->myDivisionLeader_->hasWingman() && (!this->hasTarget() || this->getTarget() == this->myDivisionLeader_->getTarget()))
+                    {
+                        bool foundTarget = false;
+                        Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
+                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                        {
+                            if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+                                continue;           
+
+                            if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
+                                ((*itP)->getWorldPosition() - divisionTargetPosition).length() > 1000 && 
+                                (*itP) != this->myDivisionLeader_->getTarget())
+                            {
+                                foundTarget = true;
+                                this->setAction(Action::FIGHT, (*itP));
+                                orxout(internal_error) << "Found target" << endl;
+                                break; 
+                            }
+                        }
+                        if (!foundTarget)
+                        {
+                            this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+                        }
+
+                    }
+                }
+            }   
+        }
+        
+        if (this->action_ == Action::FIGHT)
+        {
+            this->maneuver();
+            this->bShooting_ = this->canFire();
+            if (this->target_)
+            {
+                if (this->myWingman_)
+                {
+                    this->myWingman_->setAction (Action::FIGHT, this->target_);                    
+                }
+                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                if (diffVector.length() > 3000)
+                {
+                    this->setTargetPositionOfWingman();
+                }   
+            }
+        }
+        else if (this->action_ == Action::FLY)
+        {
+            this->setTargetPositionOfWingman();
+        }
+        else if (this->action_ == Action::PROTECT)
+        {
+
+        }
                 
 
     }
@@ -125,8 +193,7 @@
         Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 
         (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
         
-        myWingman_->setTargetOrientation(orient);
-        myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
+        myWingman_->setAction (Action::FLY, targetAbsolutePositionOfWingman, orient);
        
     }
     LeaderController* SectionController::findNewDivisionLeader()

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-11-14 23:05:48 UTC (rev 10804)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-11-15 15:47:35 UTC (rev 10805)
@@ -110,26 +110,21 @@
 
     void WingmanController::tick(float dt)
     {   
-       
-        
         if (!this->isActive())
             return;
-        if (!this->target_)
+        if (this->bHasTargetPosition_)
         {
-            //stay in formation
+            this->moveToTargetPosition(dt);
         }
-        else
+        else if (this->bLookAtTarget_)
         {
-
+            this->lookAtTarget(dt);
         }
-        if (this->bHasTargetPosition_)
+        if (bShooting_)
         {
-            this->moveToTargetPosition(dt);
-        } 
+            this->doFire();
+        }
         
-        if (this->bShooting_)
-            doFire();
-        
         SUPER(WingmanController, tick, dt);
     }
     
@@ -143,8 +138,15 @@
                 orxout(internal_error) << "new Leader set" << endl;
             else
             {
-                //orxout(internal_error) << "0 leader" << endl;
-                
+                if (!this->target_){
+                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    {
+                        if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+                            continue;   
+                        this->setAction(Action::FIGHT, (*itP));
+                        break;
+                    }
+                }
             }
 
         }
@@ -152,10 +154,28 @@
         {
 
         }
-        if (canFire())
-           this->bShooting_ = true;
-        else
-            this->bShooting_ = false;
+        
+        if (this->action_ == Action::FIGHT)
+        {
+            this->maneuver();
+            this->bShooting_ = this->canFire();
+            if (this->target_)
+            {
+                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                if (diffVector.length() > 5000)
+                {
+                  
+                }   
+            }
+        }
+        else if (this->action_ == Action::FLY)
+        {
+
+        }
+        else if (this->action_ == Action::PROTECT)
+        {
+
+        }
           
     }
      




More information about the Orxonox-commit mailing list