[Orxonox-commit 6311] r10968 - code/branches/campaignHS15/src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Fri Dec 11 15:16:48 CET 2015


Author: gania
Date: 2015-12-11 15:16:48 +0100 (Fri, 11 Dec 2015)
New Revision: 10968

Modified:
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
   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/MasterController.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:
a little clean up

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-12-11 14:16:48 UTC (rev 10968)
@@ -52,7 +52,6 @@
         this->bStartedDodging_ = false;
         this->bDefaultPatrol_ = true;
         this->bDefaultFightAll_ = true;
-        this->stop_ = false;
         RegisterObject(ActionpointController);
 
     }
@@ -74,7 +73,7 @@
     }
     void ActionpointController::tick(float dt)
     {
-        if (!this || !this->getControllableEntity() || !this->isActive() || this->stop_)
+        if (!this || !this->getControllableEntity() || !this->isActive())
             return;
 
         //count ticks, ticks_ is unsigned, so overflow is not a problem
@@ -732,35 +731,31 @@
     {
         if (!this || !this->getControllableEntity())
             return;
-
-        //if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
+        
+        if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
         {
-            if (!this->target_ || (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_))
+            if (!this || !this->getControllableEntity())
+                return;
+            Pawn* newTarget = this->closestTarget();
+            if ( newTarget && 
+                CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
+                    <= this->attackRange_ )
             {
                 if (!this || !this->getControllableEntity())
                     return;
-                Pawn* newTarget = this->closestTarget();
-                if ( newTarget && 
-                    CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget))
-                        <= this->attackRange_ )
+                this->setTarget(newTarget);
+                if (this->bLoop_ && !this->bPatrolling_)
                 {
-                    if (!this || !this->getControllableEntity())
-                        return;
-                    this->setTarget(newTarget);
-                    if (this->bLoop_ && !this->bPatrolling_)
-                    {
-                        Point p = { Action::FIGHT, "", Vector3::ZERO, true };
-                        this->loopActionpoints_.push_back(p);
-                    }
-                    else if (!this->bPatrolling_)
-                    {
-                        //orxout (internal_error) << "found new target " << CommonController::getName(newTarget) <<endl;
-                        Point p = { Action::FIGHT, "", Vector3::ZERO, false };
-                        this->parsedActionpoints_.push_back(p);
-                    }
-                    this->bPatrolling_ = true;
-                    this->executeActionpoint();
+                    Point p = { Action::FIGHT, "", Vector3::ZERO, true };
+                    this->loopActionpoints_.push_back(p);
                 }
+                else if (!this->bPatrolling_)
+                {
+                    Point p = { Action::FIGHT, "", Vector3::ZERO, false };
+                    this->parsedActionpoints_.push_back(p);
+                }
+                this->bPatrolling_ = true;
+                this->executeActionpoint();
             }
         }
     }

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h	2015-12-11 14:16:48 UTC (rev 10968)
@@ -215,9 +215,9 @@
                 float squaredaccuracy_;
                 std::vector<Point > parsedActionpoints_;//<! actionpoints as they are stored here after being parsed from XML
                 std::vector<Point > loopActionpoints_;  //<! actionpoints that are to be looped
-                bool bInLoop_;
+                bool bInLoop_;                          //<! variable for addActionpoint method
                 bool bLoop_;                            //<! is state machine looping?
-                bool bEndLoop_;                    
+                bool bEndLoop_;                         //<! variable for addActionpoint method
                 bool bTakenOver_;                       //<! are actionpoints taken over from the leader when he died? if yes, top actionpoint 
                                                         //<! is to be executed for the state machine to start working
             //----[/Actionpoint information]----
@@ -249,13 +249,11 @@
                 void nextActionpoint();                 
             //----[Actionpoint methods]----          
 
-                bool bDefaultFightAll_;
+                bool bDefaultFightAll_;     //<! if true, when no action set, this will fight all
 
-                bool bPatrolling_;
-                bool bDefaultPatrol_;
-                bool stop_;
+                bool bPatrolling_;        //<! true if current action_ is FIGHT because this found enemies that are close, need this to correctly go back to looping if was looping
+                bool bDefaultPatrol_;       //<! if true, this will look out for enemies that are close if this is just flying or doing nothing
                 unsigned int ticks_;     //<! local tick counter            
-
     };
 }
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-12-11 14:16:48 UTC (rev 10968)
@@ -22,7 +22,7 @@
  *   Author:
  *      Gani Aliguzhinov
  *   Co-authors:
- *      Dominik Solenicki
+ *      ...
  *
  */
 #include "controllers/CommonController.h"
@@ -72,10 +72,7 @@
     */    
     bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     {
-        //uncomment following code if functions stops working due to being a hack
-        /*if (!entity1 || !entity2)
-            return false;
-        return entity1->getTeam() == entity2->getTeam();*/
+        
         if (!entity1 || !entity2)
             return false;
         if (entity1 == entity2)

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-12-11 14:16:48 UTC (rev 10968)
@@ -22,7 +22,7 @@
  *   Author:
  *      Gani Aliguzhinov
  *   Co-authors:
- *      Dominik Solenicki
+ *      ...
  *
  */
 
@@ -48,11 +48,11 @@
 
             CommonController(Context* context);
             virtual ~CommonController();
-            static float randomInRange(float a, float b);
-            static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);
+            static float randomInRange(float a, float b);   //<! returns random number from a to b
+            static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2);    //<! returns distance between arguments
             static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
-            static bool isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle ) ;
-            static std::string getName(const Pawn* entity ) ;           
+            static bool isLooking(const ControllableEntity* entityThatLooks, const ControllableEntity* entityBeingLookedAt, float angle) ;
+            static std::string getName(const Pawn* entity) ;           
     };
 }
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-12-11 14:16:48 UTC (rev 10968)
@@ -78,6 +78,7 @@
             return;
         if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()))
         {
+            //when this dies, its follower will execute all its actionpoints, if follower dies before this, wingman will do this
             if (this->myFollower_)
             {
                 this->myFollower_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);

Modified: code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc	2015-12-11 14:16:48 UTC (rev 10968)
@@ -37,8 +37,6 @@
     MasterController::MasterController(Context* context) : Controller(context)
     {
         RegisterObject(MasterController);
-        // orxout(internal_error) << "MasterController was created" << endl;
-
         this->controllers_.clear();
         this->numberOfTicksPassedSinceLastActionCall_ = 0;
         this->indexOfCurrentController_ = 0;
@@ -49,12 +47,13 @@
     {
         this->controllers_.clear();
     } 
+    /*HACK*/
+    //the whole idea is a hack
     void MasterController::tick(float dt)
     {   
         if (!this->isActive())
             return;  
         ++this->ticks_;
-        //orxout(internal_error) << "Tick = " << this->ticks_ << endl;
         if (this->ticks_ == 1)
         {
             //fill the vector in the first tick
@@ -65,11 +64,9 @@
                     continue;
                 this->controllers_.push_back(*it);
             }
-            //orxout(internal_error) << "I got " << this->controllers_.size() << " controllers" << endl;
         }
         else
         {
-
             if (this->controllers_.empty())
                 return;
 
@@ -86,40 +83,41 @@
 
             if (this->numberOfTicksPassedSinceLastActionCall_ > 0)
             {
-                //call maneuver for current index
                 if (this->numberOfTicksPassedSinceLastActionCall_ == 3)
                 {
+                    //check if 0ptr
                     if (!this->controllers_.at(this->indexOfCurrentController_))
                     {
                         this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
                         return;
                     }
-                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
+                    //call maneuver for current index
                     this->controllers_.at(this->indexOfCurrentController_)->maneuver();
                 }
                 else if (this->numberOfTicksPassedSinceLastActionCall_ == 6)
                 {
-                    //call canFire for current index
+                    //check if 0ptr
                     if (!this->controllers_.at(this->indexOfCurrentController_))
                     {
                         this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
                         return;
                     }
-                    //orxout (internal_error) << "Executing maneuver of Controller # " << this->indexOfCurrentController_ << endl;
+                    //call canFire for current index
                     this->controllers_.at(this->indexOfCurrentController_)->bShooting_ = this->controllers_.at(this->indexOfCurrentController_)->canFire();   
                 }
                 ++this->numberOfTicksPassedSinceLastActionCall_;
             }
             else
             {
-                //call action for current index
+                //check if 0ptr
                 if (!this->controllers_.at(this->indexOfCurrentController_))
                 {
                     this->controllers_.erase(this->controllers_.begin() + this->indexOfCurrentController_);
                     return;
                 }
-                //orxout (internal_error) << "Executing action of Controller # " << this->indexOfCurrentController_ << endl;
-                this->controllers_.at(this->indexOfCurrentController_)->action();    
+                //call action for current index
+                this->controllers_.at(this->indexOfCurrentController_)->action();   
+                 
                 //bCopyOrientation makes ship oscillate like crazy if set to true all the time.s
                 this->controllers_.at(this->indexOfCurrentController_)->bCopyOrientation_ = this->ticks_ % 3 == 0;
 

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-12-11 14:16:48 UTC (rev 10968)
@@ -83,8 +83,6 @@
                 return;
 
             this->myDivisionLeader_ = newDivisionLeader;
-            //spread copyOrientation called equally among the division
-
         }
         //----If have leader----
         else
@@ -110,8 +108,6 @@
                 || this->myDivisionLeader_->getAction() == Action::ATTACK))
             {
                 this->keepFormation();
-                //orxout (internal_error) << "Keeping formation" << endl;
-
             }
             else if (!this->myDivisionLeader_->bKeepFormation_)
             {
@@ -161,7 +157,6 @@
                         {
                             foundTarget = true;
                             target =  (*itP);
-                            //orxout(internal_error) << "Found target" << endl;
                             break; 
                         }
                     }

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h	2015-12-11 14:16:48 UTC (rev 10968)
@@ -65,7 +65,7 @@
 
         protected:       
             //----action must only be managed by this----     
-                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
+                virtual void action(); //<! action() is called in regular intervals by MasterController managing the bot's behaviour.
                 Vector3 getFormationPosition ();
                 void keepFormation();
         private:

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-12-11 14:16:48 UTC (rev 10968)
@@ -98,7 +98,8 @@
         }
         else if (this->myLeader_)
         {
-            if (this->myLeader_->bKeepFormation_ || !(this->myLeader_->getAction() == Action::FIGHT || this->myLeader_->getAction() == Action::FIGHTALL
+            if (this->myLeader_->bKeepFormation_ || !(this->myLeader_->getAction() == Action::FIGHT 
+                || this->myLeader_->getAction() == Action::FIGHTALL
                 || this->myLeader_->getAction() == Action::ATTACK))
             {
                 this->keepFormation();
@@ -147,7 +148,6 @@
         }
         else
         {
-
             switch (this->formationMode_){
                 case FormationMode::WALL:
                 {
@@ -214,16 +214,10 @@
         if (closestLeader)
         {
             //----Racing conditions----
+            /*TODO: racing condition check is wrong and redundant, as there is no multithreading here, ticks get called one after another,
+            so it can be simplified to a check of whether leader got a wingman*/
             if (closestLeader->setWingman(orxonox_cast<ActionpointController*>(this)))
             {
-                if (closestLeader->getIdentifier()->getName() == "SectionController")
-                {
-                    this->actionTime_ = 1.6f;
-                }
-                else
-                {
-                    this->actionTime_ = 2.0f;
-                }
                 return closestLeader;
             }
         }

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-12-11 13:21:20 UTC (rev 10967)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h	2015-12-11 14:16:48 UTC (rev 10968)
@@ -72,7 +72,6 @@
             //----private variables-----
                 WeakPtr<ActionpointController> myLeader_;
                 bool bFirstAction_;
-                float actionTime_;
 
 
     };




More information about the Orxonox-commit mailing list