[Orxonox-commit 6190] r10848 - in code/branches/campaignHS15/src/orxonox: controllers worldentities

gania at orxonox.net gania at orxonox.net
Tue Nov 24 13:47:44 CET 2015


Author: gania
Date: 2015-11-24 13:47:43 +0100 (Tue, 24 Nov 2015)
New Revision: 10848

Modified:
   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/worldentities/ActionPoint.h
Log:
still not compilable

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-24 10:54:47 UTC (rev 10847)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-24 12:47:43 UTC (rev 10848)
@@ -121,7 +121,7 @@
             return "noProtectWasSet";
         return CommonController::getName (this->getProtect());
     }
-    std::string CommonController::getName(ControllableEntity* entity)
+    std::string CommonController::getName(Pawn* entity)
     {
         std::string name = entity->getName();
         if (name == "")
@@ -290,52 +290,60 @@
         std::string actionName;
         Vector3 position;
         std::string targetName;
-        this->actionpoints_.push_back(actionpoint);
+
         if (static_cast<Actionpoint*> (actionpoint))
         {
             Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
+            
             actionName = ap->getActionXML();
-            targetName = ap->get
+            targetName = ap->getName();
+            position = ap->getWorldPosition();
+
             Action::Value value;
             
-            if ( valUpper == "FIGHT" )
+            if ( actionName == "FIGHT" )
             {
                 value = Action::FIGHT;
 
             }
-            else if ( valUpper == "FLY" )
+            else if ( actionName == "FLY" )
             {
                 value = Action::FLY;
 
             }
-            else if ( valUpper == "PROTECT" )
+            else if ( actionName == "PROTECT" )
             {
                 value = Action::PROTECT;
 
             }
-            else if ( valUpper == "NONE" )
+            else if ( actionName == "NONE" )
             {
                 value = Action::NONE;
 
             }
-            else if ( valUpper == "FIGHTALL" )
+            else if ( actionName == "FIGHTALL" )
             {
                 value = Action::FIGHTALL;
 
             }
-            else if ( valUpper == "ATTACK" )
+            else if ( actionName == "ATTACK" )
             {
                 value = Action::ATTACK;
 
+
             }
             else
                 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
-            this->setAction( value );
+            //this->setAction( value );
+            parsedActionpoints_.push_back( std::make_tuple (value, targetName, position) );
         }
         else
         {
-            actionName = "FLY";
+            parsedActionpoints_.push_back( 
+                std::make_tuple (Action::FLY, "", actionpoint->getWorldPosition()) );
         }
+            this->actionpoints_.push_back(actionpoint);
+
         
     }
 
@@ -376,6 +384,96 @@
         } 
         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_ = std::get<0>( this->parsedActionpoints_.back() );
+
+            switch ( this->action_ )
+            {
+                case Action::FIGHT:
+                {                
+                    break;
+                }
+                case Action::FLY:
+                {
+                    this->setTargetPosition(std::get<2>( this->parsedActionpoints_.back() ));
+                    if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                    {
+                        this->nextActionpoint();
+                        this->executeActionpoint();
+                    }
+                    break;
+                }
+                case Action::PROTECT:
+                {
+                    std::string protectName = std::get<1>( this->parsedActionpoints_.back() );
+
+                    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 = std::get<1>( this->parsedActionpoints_.back() );
+
+                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    {
+                        if (CommonController::getName(*itP) == targetName)
+                        {
+                            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;
+        }
+    }
+    void CommonController::nextActionpoint()
+    {
+        if (!this->parsedActionpoints_.empty())
+        {
+            this->parsedActionpoints_.pop_back();
+        }
+        this->setAction(Action::NONE);
+    }
+
     void CommonController::maneuver() 
     {
         maneuverCounter_++;

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-24 10:54:47 UTC (rev 10847)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-24 12:47:43 UTC (rev 10848)
@@ -137,7 +137,7 @@
                 static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
                 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
                 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
-                static std::string getName( ControllableEntity* entity ) ;
+                static std::string getName( Pawn* entity ) ;
 
                 float squaredDistanceToTarget() const;
                 bool isLookingAtTarget(float angle) const;
@@ -206,6 +206,7 @@
                 FormationMode::Value formationMode_;
                 Rank::Value rank_;
                 std::string protectName_;
+                std::string targetName_;
                 Action::Value action_;
                 int attackRange_;
                 

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-24 10:54:47 UTC (rev 10847)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-24 12:47:43 UTC (rev 10848)
@@ -96,46 +96,60 @@
              !this->target_)
             {
                 ControllableEntity* newTarget = this->closestTarget();
-                if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                if ( newTarget && 
+                    CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ )
                 {
-                    this->backupAction();
-                    this->setAction (Action::FIGHT, newTarget);
+                    // this->backupAction();
+                    // this->setAction (Action::FIGHT, newTarget);
+                    this->parsedActionpoints_.push_back(
+                        std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) );
                 }
             }
         }
+
         //action is NONE whenever ships finishes current action, 
         //if it was fighting before because enemies were close, resume what it was doing
         //otherwise try to execute next action
         if (this->action_ == Action::NONE)
         {
-            if (this->bBackuped_)
-            {
-                this->restoreAction();
-            } else if (!this->actionpoints_.empty())
-            {
-                this->popAction();
-            }
+
         }
+
+        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())
             {
                 //----find a target----
+                ControllableEntity* newTarget = this->closestTarget();
                 if (this->action_ == Action::FIGHT)
                 {
-                    ControllableEntity* newTarget = this->closestTarget();
                     if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
                     {
                         this->setAction (Action::FIGHT, newTarget);
                     }
                     else
                     {
-                        this->setAction (Action::NONE);
+                        this->nextActionpoint();
+                        return;
                     }
                 }
                 else if (this->action_ == Action::FIGHTALL)
                 {
-                    this->setClosestTarget();                     
+                    if (newTarget)
+                    {
+                        this->setAction (Action::FIGHTALL, newTarget);
+                    }
+                    else
+                    {
+                        this->nextActionpoint();
+                        return;
+                    }
                 }
 
             }
@@ -145,19 +159,28 @@
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
                 if (diffVector.length() > this->attackRange_)
                 {
-                    this->setTargetPositionOfWingman();
-                    this->setTargetPositionOfFollower();                    
+                    if (this->action_ == Action::FIGHT)
+                    {
+                        this->nextActionpoint();
+                        return;
+                    }
+                    else
+                    {
+                        this->setTargetPositionOfWingman();
+                        this->setTargetPositionOfFollower();                    
+                    }
+
                 }
                 else
                 {
                     //----wingmans shall support the fire of their leaders----
                     if (this->myWingman_)
                     {
-                        this->myWingman_->setAction (Action::FIGHT, this->target_);     
+                        this->myWingman_->setAction (this->action_, this->target_);     
                     }
                     if (this->myFollower_)
                     {
-                        this->myFollower_->setAction (Action::FIGHT);                                    
+                        this->myFollower_->setAction (this->action_);                                    
                     }
 
                 }
@@ -179,39 +202,55 @@
         }
         else if (this->action_ == Action::PROTECT)
         {
-            if (!this->getProtect())
+           /* 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);  
+ 
+            Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
+                (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
+            this->setTargetPosition(targetAbsolutePosition);
+            
+            this->setTargetPositionOfWingman();
+            this->setTargetPositionOfFollower();
+        }
+        else if (this->action_ == Action::ATTACK)
+        {   
+            if (this->hasTarget())
             {
-                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                //----fly in formation if far enough----
+                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
+                if (diffVector.length() > this->attackRange_)
                 {
-                    if ((*itP)->getName() == this->protectName_)
+                    this->setTargetPositionOfWingman();
+                    this->setTargetPositionOfFollower();                    
+                }
+                else
+                {
+                    //----wingmans shall support the fire of their leaders----
+                    if (this->myWingman_)
                     {
-                        this->setProtect (static_cast<ControllableEntity*>(*itP));
+                        this->myWingman_->setAction (this->action_, this->target_);     
                     }
+                    if (this->myFollower_)
+                    {
+                        this->myFollower_->setAction (this->action_);                                    
+                    }
+
                 }
-                if (!this->getProtect())
-                {
-                    this->setAction (Action::NONE);
-                }
+                
             }
-            else
+            if (this->hasTarget())
             {
-               /* 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);  
-     
-                Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
-                    (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
-                this->setTargetPosition(targetAbsolutePosition);
-                
-                this->setTargetPositionOfWingman();
-                this->setTargetPositionOfFollower();
-            }            
-
+                //----choose where to go----
+                this->maneuver();
+                //----fire if you can----
+                this->bShooting_ = this->canFire();                
+            }
         }
 
     }

Modified: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	2015-11-24 10:54:47 UTC (rev 10847)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	2015-11-24 12:47:43 UTC (rev 10848)
@@ -90,6 +90,17 @@
                 ControllableEntity* getProtect();
                 void setEnemy( ControllableEntity* enemy);
                 ControllableEntity* getEnemy();
+                std::string getName()
+                {
+                    if (actionName_ != "")
+                        return actionName_;
+                    else if (protectName_ != "")
+                        return protectName_;
+                    else if (enemyName_ != "")
+                        return enemyName_;
+                    else
+                        return "";
+                }
             //----["Waypoints" data]----
                 void setTargetPosition(const Vector3& target);
                 Vector3 getTargetPosition ();




More information about the Orxonox-commit mailing list