[Orxonox-commit 6197] r10855 - in code/branches/campaignHS15: data/levels src/orxonox/controllers src/orxonox/worldentities

gania at orxonox.net gania at orxonox.net
Wed Nov 25 13:51:11 CET 2015


Author: gania
Date: 2015-11-25 13:51:10 +0100 (Wed, 25 Nov 2015)
New Revision: 10855

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/worldentities/ActionPoint.cc
   code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
Log:
introduced loops

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-25 11:07:22 UTC (rev 10854)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-25 12:51:10 UTC (rev 10855)
@@ -61,6 +61,20 @@
         </DivisionController>
       </controller>
     </SpaceShip> -->
+    <SpaceShip position="-1500, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=0 formationMode="finger4">
+          <actionpoints>
+            <Actionpoint position="-1000,1000,-1000" action="FLY" loopStart=true />
+            <Actionpoint position="-1250,1250,-500" action="FLY" />
+            <Actionpoint position="-1500,1500,-1000" action="FLY" loopEnd=true />
+          </actionpoints>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
     <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
       <templates>
         <Template link=spaceshipassff />

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-25 11:07:22 UTC (rev 10854)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-25 12:51:10 UTC (rev 10855)
@@ -68,6 +68,8 @@
         this->action_ = Action::NONE;
         this->stopLookingAtTarget();
         this->attackRange_ = 2500;
+        this->bInLoop_ = false;
+        this->bLoop_ = false;
         RegisterObject( CommonController );
     }
     CommonController::~CommonController() 
@@ -158,6 +160,7 @@
         std::string actionName;
         Vector3 position;
         std::string targetName;
+        bool inLoop;
         Point p;
         if (static_cast<Actionpoint*> (actionpoint))
         {
@@ -166,6 +169,16 @@
             targetName = ap->getName();
             position = ap->getWorldPosition();
 
+            if (!this->bInLoop_ && ap->getStartLoop())
+            {
+                this->bInLoop_ = true;
+            }
+            if (this->bInLoop_ && ap->getEndLoop())
+            {
+                this->bInLoop_ = false;
+            }
+            inLoop = this->bInLoop_;
+
             Action::Value value;
             
             if ( actionName == "FIGHT" )
@@ -182,12 +195,12 @@
             { value = Action::ATTACK; }
             else
                 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
-            p.action = value; p.name = targetName; p.position = position;
+            p.action = value; p.name = targetName; p.position = position; p.inLoop = inLoop;
             parsedActionpoints_.push_back(p);
         }
         else
         {
-            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition();
+            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); p.inLoop = inLoop;
         }
             parsedActionpoints_.push_back(p);
             this->actionpoints_.push_back(actionpoint);
@@ -751,7 +764,7 @@
                     this->distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
                         <= this->attackRange_ )
                 {
-                    Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO };
+                    Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO, false };
                     this->parsedActionpoints_.push_back(p);
                     this->executeActionpoint();
                 }
@@ -767,92 +780,189 @@
     //if last element was failed to be parsed, next element will be executed.
     void CommonController::executeActionpoint()
     {
-        if (!this->parsedActionpoints_.empty())
+        if (this->bLoop_)
         {
-            this->action_ = this->parsedActionpoints_.back().action;
-
-            switch ( this->action_ )
+            if (!this->loopActionpoints_.empty())
             {
-                case Action::FIGHT:
+                this->action_ = this->loopActionpoints_.back().action;
+                switch ( this->action_ )
                 {
-                    std::string targetName = this->parsedActionpoints_.back().name;
-                    if (targetName == "")
+                    case Action::FIGHT:
                     {
+                        std::string targetName = this->loopActionpoints_.back().name;
+                        if (targetName == "")
+                        {
+                            break;
+                        }
+                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                        {
+                            if (CommonController::getName(*itP) == targetName)
+                            {
+                                this->setTarget (static_cast<ControllableEntity*>(*itP));
+                            }
+                        }          
                         break;
                     }
-                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    case Action::FLY:
                     {
-                        if (CommonController::getName(*itP) == targetName)
+                        this->setTargetPosition( this->loopActionpoints_.back().position );
+                        if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
                         {
-                            this->setTarget (static_cast<ControllableEntity*>(*itP));
+                            this->nextActionpoint();
+                            this->executeActionpoint();
                         }
-                    }          
-                    break;
-                }
-                case Action::FLY:
-                {
-                    this->setTargetPosition( this->parsedActionpoints_.back().position );
-                    if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                        break;
+                    }
+                    case Action::PROTECT:
                     {
-                        this->nextActionpoint();
-                        this->executeActionpoint();
-                    }
-                    break;
-                }
-                case Action::PROTECT:
-                {
-                    std::string protectName = this->parsedActionpoints_.back().name;
+                        std::string protectName = this->loopActionpoints_.back().name;
 
-                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
-                    {
-                        if (CommonController::getName(*itP) == protectName)
+                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
                         {
-                            this->setProtect (static_cast<ControllableEntity*>(*itP));
+                            if (CommonController::getName(*itP) == protectName)
+                            {
+                                this->setProtect (static_cast<ControllableEntity*>(*itP));
+                            }
                         }
+                        if (!this->getProtect())
+                        {
+                            this->nextActionpoint();
+                            this->executeActionpoint();
+                        }
+                        break;
                     }
-                    if (!this->getProtect())
+                    case Action::NONE:
                     {
-                        this->nextActionpoint();
-                        this->executeActionpoint();
+                        break;
                     }
-                    break;
+                    case Action::FIGHTALL:
+                    {
+                        break;
+                    }
+                    case Action::ATTACK:
+                    {
+                        std::string targetName = this->loopActionpoints_.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;
                 }
-                case Action::NONE:
+            }
+            else
+            {
+                this->bLoop_ = false;
+            }
+        }
+        else
+        {
+            if (!this->parsedActionpoints_.empty())
+            {
+                if (this->parsedActionpoints_.back().inLoop)
                 {
-                    break;
+                    //MOVES all points that are in loop to a loop vector
+                    this->fillLoop();
+                    this->bLoop_ = true;
+                    executeActionpoint();
+                    return;
                 }
-                case Action::FIGHTALL:
+                this->action_ = this->parsedActionpoints_.back().action;
+                switch ( this->action_ )
                 {
-                    break;
-                }
-                case Action::ATTACK:
-                {
-                    std::string targetName = this->parsedActionpoints_.back().name;
-
-                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                    case Action::FIGHT:
                     {
-                        if (CommonController::getName(*itP) == targetName)
+                        std::string targetName = this->parsedActionpoints_.back().name;
+                        if (targetName == "")
                         {
-                            this->setTarget (static_cast<ControllableEntity*>(*itP));
+                            break;
                         }
+                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+                        {
+                            if (CommonController::getName(*itP) == targetName)
+                            {
+                                this->setTarget (static_cast<ControllableEntity*>(*itP));
+                            }
+                        }          
+                        break;
                     }
-                    if (!this->hasTarget())
+                    case Action::FLY:
                     {
-                        this->nextActionpoint();
-                        this->executeActionpoint();
+                        this->setTargetPosition( this->parsedActionpoints_.back().position );
+                        if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+                        {
+                            this->nextActionpoint();
+                            this->executeActionpoint();
+                        }
+                        break;
                     }
-                    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;
                 }
-                default:
-                    break;
             }
+            else
+            {
+                this->setTarget(0);
+                this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
+                this->action_ = Action::NONE;
+            }
         }
-        else
-        {
-            this->setTarget(0);
-            this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
-            this->action_ = Action::NONE;
-        }
+
     }
     void CommonController::stayNearProtect()
     {
@@ -864,12 +974,48 @@
     }
     void CommonController::nextActionpoint()
     {
-        if (!this->parsedActionpoints_.empty())
+        if (this->bLoop_)
         {
-            this->parsedActionpoints_.pop_back();
+            if (!this->loopActionpoints_.empty())
+            {
+                this->moveBackToTop();
+            }
         }
+        else
+        {
+            if (!this->parsedActionpoints_.empty())
+            {
+                this->parsedActionpoints_.pop_back();
+            }            
+        }
         this->setAction(Action::NONE);
     }
+    void CommonController::moveBackToTop()
+    {
+        Point temp = loopActionpoints_.back();
+        loopActionpoints_.pop_back();
+        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
+        loopActionpoints_.push_back(temp);
+        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
+    }
+    void CommonController::fillLoop()
+    {
+        loopActionpoints_.clear();
+        fillLoopReversed();
+        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
+    }
+    void CommonController::fillLoopReversed()
+    {
+        if (parsedActionpoints_.back().inLoop)
+        {
+            loopActionpoints_.push_back(parsedActionpoints_.back());
+            parsedActionpoints_.pop_back();
+        }
+        if (parsedActionpoints_.back().inLoop)
+        {
+            fillLoopReversed();
+        }
+    }
     void CommonController::action()
     {
         this->startAttackingEnemiesThatAreClose();

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-25 11:07:22 UTC (rev 10854)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-25 12:51:10 UTC (rev 10855)
@@ -73,6 +73,7 @@
         Action::Value action;
         std::string name;
         Vector3 position;
+        bool inLoop;
     } ;
 
 
@@ -201,11 +202,15 @@
                 std::vector<WeakPtr<WorldEntity> > actionpoints_;
                 float squaredaccuracy_;
                 std::vector<Point > parsedActionpoints_;
+                std::vector<Point > loopActionpoints_;
 
             //----[/Actionpoint information]----
             //----[Actionpoint methods]----
                 void executeActionpoint();
                 void nextActionpoint();
+                void fillLoop();
+                void fillLoopReversed();
+                void moveBackToTop();
             //----[Actionpoint methods]----
             //----["Private" variables]----
                 FormationMode::Value formationMode_;
@@ -218,7 +223,9 @@
                 bool bShooting_;
                 int maneuverCounter_;
                 int tolerance_; 
-                bool bFirstTick_;                        
+                bool bFirstTick_; 
+                bool bInLoop_;
+                bool bLoop_;                   
             //----[/"Private" variables]----               
     };
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-25 11:07:22 UTC (rev 10854)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-25 12:51:10 UTC (rev 10855)
@@ -77,7 +77,6 @@
     void DivisionController::action()
     {   
         CommonController::action();
-        
     }
     void DivisionController::stayNearProtect()
     {

Modified: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc	2015-11-25 11:07:22 UTC (rev 10854)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc	2015-11-25 12:51:10 UTC (rev 10855)
@@ -71,6 +71,8 @@
         XMLPortParam( Actionpoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
         XMLPortParam( Actionpoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
         XMLPortParam( Actionpoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
+        XMLPortParam( Actionpoint, "loopStart", setLoopStart, getLoopStart,  xmlelement, mode ).defaultValues(false);
+        XMLPortParam( Actionpoint, "loopEnd", setLoopEnd, getLoopEnd,  xmlelement, mode ).defaultValues(false);
 
     }
     void Actionpoint::setActionXML( std::string val)

Modified: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	2015-11-25 11:07:22 UTC (rev 10854)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	2015-11-25 12:51:10 UTC (rev 10855)
@@ -67,22 +67,22 @@
                 //----[ProtectMe data]----
                     inline void setProtectMeXML(bool c)
                     {
-                        this->protectMe_ = c;
+                        this->bProtectMe_ = c;
                     }
                     inline bool getProtectMeXML ()
                     {
-                        return this->protectMe_;
+                        return this->bProtectMe_;
                     }
 
                 //----[/ProtectMe data]----
                 //----[FightAll data]----
                     inline void setFightAllXML(bool c)
                     {
-                        this->fightAll_ = c;
+                        this->bFightAll_ = c;
                     }
                     inline bool getFightAllXML ()
                     {
-                        return this->fightAll_;
+                        return this->bFightAll_;
                     }
                 //----[/FightAll data]----
             //----[/XML data]----
@@ -101,11 +101,27 @@
                     else
                         return "";
                 }
+                void setLoopStart(bool value)
+                {
+                    this->bLoopStart_ = value;
+                }
+                void setLoopEnd (bool value)
+                {
+                    this->bLoopEnd_ = value;
+                }
             //----["Waypoints" data]----
                 void setTargetPosition(const Vector3& target);
                 Vector3 getTargetPosition ();
             //----[/"Waypoints" data]----
 
+            bool getLoopStart()
+            {
+                return this->bLoopStart_;
+            }
+            bool getLoopEnd();
+            {
+                return this->bLoopEnd_;
+            }
         private:
             
             std::string actionName_;
@@ -114,8 +130,10 @@
             WeakPtr<ControllableEntity> protect_;
             WeakPtr<ControllableEntity> enemy_;
 
-            bool protectMe_;
-            bool fightAll_;
+            bool bLoopStart_;
+            bool bLoopEnd_;
+            bool bProtectMe_;
+            bool bFightAll_;
             Vector3 targetPosition_;
     };
 }




More information about the Orxonox-commit mailing list