[Orxonox-commit 2242] r6958 - code/branches/ai/src/orxonox/controllers

solex at orxonox.net solex at orxonox.net
Fri May 21 15:19:42 CEST 2010


Author: solex
Date: 2010-05-21 15:19:42 +0200 (Fri, 21 May 2010)
New Revision: 6958

Modified:
   code/branches/ai/src/orxonox/controllers/ArtificialController.cc
   code/branches/ai/src/orxonox/controllers/ArtificialController.h
Log:
ai: introduced masteraction and console commands

Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc	2010-05-21 12:11:47 UTC (rev 6957)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc	2010-05-21 13:19:42 UTC (rev 6958)
@@ -37,9 +37,12 @@
 #include "controllers/WaypointPatrolController.h"
 #include "controllers/DroneController.h"
 #include "util/Math.h"
+#include "core/ConsoleCommand.h"
 
 namespace orxonox
 {
+    SetConsoleCommand(ArtificialController, formationflight, true);//.defaultValues(0, true);
+    SetConsoleCommand(ArtificialController, masteraction, true);
 
     static const unsigned int MAX_FORMATION_SIZE = 7;
     static const int FORMATION_LENGTH =  10;
@@ -55,7 +58,7 @@
         RegisterObject(ArtificialController);
 
         this->target_ = 0;
-        this->formationFlight_  =  true;
+        this->formationFlight_ = true;
         this->myMaster_ = 0;
         this->freedomCount_ = 0;
 	this->team_ = -1;
@@ -78,9 +81,42 @@
         SUPER(ArtificialController, XMLPort, xmlelement, mode);
 
         XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1);
-//         XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true);
+        XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true);
     }
 
+    //activate/deactivate formationflight
+    void ArtificialController::formationflight(bool form)
+    {
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            if (!it->getController())
+                continue;
+
+            ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
+
+            if(aiController)
+            {
+                aiController->formationFlight_ = form;
+            }
+        }
+    }
+    //get all masters to do this action
+    void ArtificialController::masteraction(int action) 
+    {
+        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+        {
+            if (!it->getController())
+                continue;
+
+            ArtificialController *aiController = static_cast<ArtificialController*>(it->getController());
+
+            if(aiController || aiController->state_ == MASTER)
+            {
+                aiController->specificMasterAction_ = TURN180;
+            }
+        }
+    }
+
 // gets called when Bot dies
     void ArtificialController::changedControllableEntity()
     {
@@ -124,8 +160,15 @@
         {
             if (this->target_ || distance > 10)
             {
+                if (this->specificMasterAction_ == NONE)
+                {
                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+                } else if (this->specificMasterAction_ == TURN180)
+                {
+                this->getControllableEntity()->rotateYaw(-1.0f * sgn(coord.x) * coord.x*coord.x);
+                this->getControllableEntity()->rotatePitch(sgn(coord.y) * coord.y*coord.y);
+                }
 
             }
 
@@ -143,10 +186,6 @@
            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
 
-
-
-
-
             if (distance < 300)
             {
                 if (distance < 40)
@@ -176,7 +215,6 @@
             std::vector<ArtificialController*>::iterator it = std::find(myMaster_->slaves_.begin(), myMaster_->slaves_.end(), this);
             if( it != myMaster_->slaves_.end() )
                 myMaster_->slaves_.erase(it);
-// COUT(0) << "~unregister slave" << std::endl;
         }
     }
 
@@ -344,13 +382,24 @@
 
     void ArtificialController::specificMasterActionHold()
     {
-        if (specificMasterActionHoldCount_ == 0) this->specificMasterAction_ = NONE;
+        if (specificMasterActionHoldCount_ == 0) 
+         {
+            this->specificMasterAction_ = NONE;
+            this->searchNewTarget();
+            COUT(0) << "~action end" << std::endl;
+         }
         else specificMasterActionHoldCount_--;
     }
 
     void ArtificialController::turn180()
     {
-        this->specificMasterAction_  =  NONE;
+        COUT(0) << "~turn" << std::endl;
+
+        Quaternion orient = this->getControllableEntity()->getOrientation();
+
+        this->setTargetPosition(this->getControllableEntity()->getPosition() + 500.0f*orient*WorldEntity::BACK);
+        this->specificMasterActionHoldCount_ = 2;
+        this->specificMasterAction_  =  HOLD;
     }
 
     void ArtificialController::spin()
@@ -381,7 +430,6 @@
 
     void ArtificialController::searchNewTarget()
     {
-COUT(0) << "search new target - start" << std::endl;
         if (!this->getControllableEntity())
             return;
 
@@ -406,7 +454,6 @@
                 }
             }
         }
-COUT(0) << "search new target - end: " << this->target_ << std::endl;
     }
 
     void ArtificialController::forgetTarget()
@@ -543,7 +590,7 @@
         droneController = orxonox_cast<DroneController*>(entity2->getController());
         if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
             return true;
-            
+
         return (team1 == team2 && team1 != -1);
     }
 }

Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h	2010-05-21 12:11:47 UTC (rev 6957)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h	2010-05-21 13:19:42 UTC (rev 6958)
@@ -58,6 +58,8 @@
                 { return this->formationFlight_; }
             virtual void changedControllableEntity();
 
+            static void formationflight(bool form);
+            static void masteraction(int action);
 
         protected:
 




More information about the Orxonox-commit mailing list