[Orxonox-commit 6298] r10955 - code/branches/campaignHS15/src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Mon Dec 7 22:24:20 CET 2015


Author: gania
Date: 2015-12-07 22:24:20 +0100 (Mon, 07 Dec 2015)
New Revision: 10955

Modified:
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
   code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
   code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc
   code/branches/campaignHS15/src/orxonox/controllers/MasterController.h
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
Log:
cleaned up a bit

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-07 21:24:20 UTC (rev 10955)
@@ -77,24 +77,22 @@
         if (!this || !this->getControllableEntity() || !this->isActive() || this->stop_)
             return;
 
+        //count ticks, ticks_ is unsigned, so overflow is not a problem
         ++this->ticks_;
         if (this->ticks_ == 1)
         {
+            //those vectors are in reversed order after being set by XML.
             std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end());
             std::reverse(actionpoints_.begin(), actionpoints_.end());
-            if (this->parsedActionpoints_.empty())
-            {
-                this->action_ = Action::FIGHTALL;
-            }
         }
 
         if (!this || !this->getControllableEntity())
             return;
-        
+        //fly
         if (this->bHasTargetPosition_)
         {
             this->moveToTargetPosition(dt);
-        }
+        }//or just rotate
         else if (this->bLookAtTarget_)
         {
             this->lookAtTarget(dt);
@@ -103,7 +101,7 @@
 
         if (!this || !this->getControllableEntity())
             return;
-
+        //don't fire rocket each tick
         if (timeout_ <= 0)
         {    
             this->bFiredRocket_ = false;
@@ -115,7 +113,7 @@
 
         if (!this || !this->getControllableEntity())
             return;
-
+        //sometimes dodge, sometimes attack
         if (this->ticks_ % 80 <= 10)
         {
             this->bDodge_ = false;
@@ -127,7 +125,7 @@
 
         if (!this || !this->getControllableEntity())
             return;
-     
+        //fire if you can
         if (this->bShooting_)
         {
             this->doFire();
@@ -135,15 +133,21 @@
         SUPER(ActionpointController, tick, dt);
     }
      
+    /**
+    @brief
+        action() manages the state machine.
+    */
 
-
     void ActionpointController::action()
     {
         if (!this || !this->getControllableEntity() || !this->isActive())
             return;
 
+        //deltaHp is used to know if this got attacked
         this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
         this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
+
+        //look out for enemies
         if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE))
         {
             this->startAttackingEnemiesThatAreClose();
@@ -154,6 +158,7 @@
         //No action -> pop one from stack
         if (this->action_ == Action::NONE || this->bTakenOver_)
         {
+            //if default behaviour is fighting all, push it onto the stack
             if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_)
             {
                 if (!this || !this->getControllableEntity())
@@ -295,6 +300,10 @@
 
 
     }
+    /**
+    @brief
+        if action is protect, this follows protect_ and fights enemies that are close
+    */
     void ActionpointController::setProtect (ControllableEntity* protect)
     {
 
@@ -305,6 +314,7 @@
 
         return this->protect_;
     }
+    //XML method
     void ActionpointController::addActionpoint(WorldEntity* actionpoint)
     {
         std::string actionName;
@@ -359,6 +369,7 @@
             parsedActionpoints_.push_back(p);
             this->actionpoints_.push_back(actionpoint);
     }
+    //XML method
     WorldEntity* ActionpointController::getActionpoint(unsigned int index) const
     {
         if (index < this->actionpoints_.size())
@@ -366,11 +377,12 @@
         else
             return 0;
     }
-
+    //XML method
     Action::Value ActionpointController::getAction ()
     {
         return this->action_;
     }
+    //XML method
     std::string ActionpointController::getActionName()
     {
         switch ( this->action_ )
@@ -392,10 +404,12 @@
                 break;
         }
     }
+    //XML method
     void ActionpointController::setAction (Action::Value action)
     {
         this->action_ = action;
     }
+    //set action and target/protect
     void ActionpointController::setAction (Action::Value action, ControllableEntity* target)
     {
         if (!this || !this->getControllableEntity())
@@ -412,6 +426,7 @@
                 this->setProtect (target);
         }
     }
+    //set action and target position
     void ActionpointController::setAction (Action::Value action, const Vector3& target)
     {
         if (!this || !this->getControllableEntity())
@@ -422,6 +437,7 @@
             this->setTargetPosition (target);
         }
     }
+    //set action and target position and orientation
     void ActionpointController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
     {
         if (!this || !this->getControllableEntity())
@@ -589,7 +605,7 @@
         }   
     }
 
-    
+    //calculate where in world coordinates this ship has to be, so that it keeps distance to protect_, and fly there
     void ActionpointController::stayNearProtect()
     {
         if (!this || !this->getControllableEntity())
@@ -611,6 +627,7 @@
         }  
         this->setTargetOrientation(this->getProtect()->getWorldOrientation());
     }
+    //remove current point from the stack
     void ActionpointController::nextActionpoint()
     {
         if (!this || !this->getControllableEntity())
@@ -637,6 +654,7 @@
         this->setAction(Action::NONE);
         this->bHasTargetPosition_ = false;
     }
+    //if looping, instead of erasing point, move it to the top (back is what gets executed, so it's kinda reversed stack)
     void ActionpointController::moveBackToTop()
     {
         if (!this || !this->getControllableEntity())
@@ -648,6 +666,7 @@
         loopActionpoints_.push_back(temp);
         std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
     }
+    //POST: moves all consecutive points that are in loop to the loop stack
     void ActionpointController::fillLoop()
     {
         loopActionpoints_.clear();
@@ -666,7 +685,7 @@
             fillLoopReversed();
         }
     }
-    
+    //copy other ship's stacks so that if it dies, this can finish that ship's actions
     void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b)
     {
         if (!this || !this->getControllableEntity())
@@ -678,10 +697,12 @@
         this->bLoop_ = b;
         this->bTakenOver_ = true;
     }
+    //attack closest target
     void ActionpointController::setClosestTarget()
     {
         this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 
     }
+    //find closest target
     Pawn* ActionpointController::closestTarget()
     {
         if (!this || !this->getControllableEntity())
@@ -710,6 +731,7 @@
         } 
         return 0;  
     }
+    //push action FIGHT to the stack and set target to the closest enemy
     void ActionpointController::startAttackingEnemiesThatAreClose()
     {
         if (!this || !this->getControllableEntity())

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -60,6 +60,8 @@
 
         In XML one has to attack Actionpoints in order to achieve any complex behaviour, but in Controller all actionpoints are effectively 
         being stored in an array of type Point::Value.
+    @note
+        ActionpointController will not work, if there is no MasterController in the level!
     */
     namespace Action
     {  
@@ -92,9 +94,14 @@
             virtual ~ActionpointController();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);          
                
-            virtual void tick(float dt);
             /**
             @brief
+                tick is called every tick by Game (?).
+                In tick ship flies and fires.
+            */
+            virtual void tick(float dt);   
+            /**
+            @brief
                 XML method, example XML usage:
                 <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
                   <templates>
@@ -174,7 +181,7 @@
                
 
             virtual void stayNearProtect();
-            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
+            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. Only gets called by MasterController
             virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b);
 
             virtual Action::Value getAction ();

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -48,7 +48,6 @@
 
             CommonController(Context* context);
             virtual ~CommonController();
-            virtual void action(){}; //<! action() is called in regular intervals managing the bot's behaviour.
             static float randomInRange(float a, float b);
             static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);
             static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -35,6 +35,10 @@
 
 namespace orxonox
 {
+    /**
+        @note
+        ActionpointController will not work, if there is no MasterController in the level!
+    */
     class _OrxonoxExport DivisionController : public ActionpointController
     {
         public:

Modified: code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/FightingController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -38,6 +38,9 @@
     @brief
         FightingController stores all the fighting methods and member variables of AI.
         Main methods here are maneuver() and dodge().
+    
+    @note
+        ActionpointController will not work, if there is no MasterController in the level!
     */
     class _OrxonoxExport FightingController : public FlyingController
     {
@@ -58,7 +61,7 @@
                              //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
             bool bShooting_;
             bool canFire(); //<! check if target_ is in radius and if this is looking at target_
-
+            virtual void action(){};//<! action() is called in regular intervals managing the bot's behaviour. Only gets called by MasterController, is implemented in ActionpointController
         protected:
             void setTarget(ControllableEntity* target); //set a target to shoot at
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc	2015-12-07 21:24:20 UTC (rev 10955)
@@ -57,6 +57,7 @@
         //orxout(internal_error) << "Tick = " << this->ticks_ << endl;
         if (this->ticks_ == 1)
         {
+            //fill the vector in the first tick
             for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)
             {
                 //----0ptr?----
@@ -68,13 +69,16 @@
         }
         else
         {
+
             if (this->controllers_.empty())
                 return;
 
+            //iterate over vecotr with the index, keep index in boundaries 
             if (this->indexOfCurrentController_ >= this->controllers_.size())
             {
                 this->indexOfCurrentController_ = 0;
             }
+            //each 9 ticks index is incremented
             if (this->numberOfTicksPassedSinceLastActionCall_ >= 9)
             {
                 this->numberOfTicksPassedSinceLastActionCall_ = 0;
@@ -82,6 +86,7 @@
 
             if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
             {
+                //call maneuver for current index
                 if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
                 {
                     if (!this->controllers_.at(this->indexOfCurrentController_))
@@ -94,6 +99,7 @@
                 }
                 else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
                 {
+                    //call canFire for current index
                     if (!this->controllers_.at(this->indexOfCurrentController_))
                     {
                         this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
@@ -106,6 +112,7 @@
             }
             else
             {
+                //call action for current index
                 if (!this->controllers_.at(this->indexOfCurrentController_))
                 {
                     this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);

Modified: code/branches/campaignHS15/src/orxonox/controllers/MasterController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/MasterController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/MasterController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -36,6 +36,19 @@
 
 namespace orxonox
 {
+    /**
+    @brief
+      calles action(), maneuver() and canFire() methods of all the ActionpointControllers in level.
+      Only one instance of MasterController is to be placed in level.
+      If no MasterController is initialized, none of ActionpointControllers will work.
+      Example:
+      <Pawn position = "100000, 100000, 100000">
+        <controller>
+          <MasterController>
+          </MasterController>
+        </controller>
+      </Pawn>
+    */
     class _OrxonoxExport MasterController : public FightingController, public Tickable
     {
         public:
@@ -53,10 +66,10 @@
         protected:
           
         private:
-            std::vector<WeakPtr<FightingController> > controllers_;
-            size_t indexOfCurrentController_;
+            std::vector<WeakPtr<FightingController> > controllers_;  //<! vector of controllers, which action(), canFire() and maneuver() methods are to be called
+            size_t indexOfCurrentController_;                        //<! index of current controller
             unsigned int numberOfTicksPassedSinceLastActionCall_;
-            unsigned int ticks_;     //<! local tick counter            
+            unsigned int ticks_;                                     //<! local tick counter            
 
     };
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -34,6 +34,10 @@
 
 namespace orxonox
 {
+    /**
+        @note
+        ActionpointController will not work, if there is no MasterController in the level!
+    */
     class _OrxonoxExport SectionController : public ActionpointController
     {
         public:

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-12-07 19:45:07 UTC (rev 10954)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-12-07 21:24:20 UTC (rev 10955)
@@ -35,6 +35,10 @@
 
 namespace orxonox
 {
+    /**
+        @note
+        ActionpointController will not work, if there is no MasterController in the level!
+    */
     class _OrxonoxExport WingmanController : public ActionpointController
     {
         public:




More information about the Orxonox-commit mailing list