[Orxonox-commit 6105] r10763 - code/branches/AI_HS15/src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Tue Nov 3 17:06:06 CET 2015


Author: gania
Date: 2015-11-03 17:06:05 +0100 (Tue, 03 Nov 2015)
New Revision: 10763

Modified:
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
   code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
Log:
fixed a bug

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-03 14:56:41 UTC (rev 10762)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-03 16:06:05 UTC (rev 10763)
@@ -189,12 +189,13 @@
     }
     void CommonController::moveToPosition(const Vector3& target)
     {
+        float factor = 1;
         if (!this->getControllableEntity())
             return;
         if (this->rank_ == Rank::DIVISIONLEADER)
-            SPEED *= 0.8;
+            factor = 0.8;
         if (this->rank_ == Rank::SECTIONLEADER)
-            SPEED *= 0.9;
+            factor = 0.9;
         
         //100 is (so far) the smallest tolerance (empirically found) that can be reached, 
         //with smaller distance spaceships can't reach position and go circles around it instead
@@ -232,7 +233,9 @@
                     copyTargetOrientation();
                 }
             }
-            this->getControllableEntity()->moveFrontBack(1.2f*SPEED);
+                    orxout (internal_error) << "MOVING" <<endl ;
+
+            this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor);
         }
         else
         {      
@@ -256,15 +259,15 @@
     bool CommonController::canFire()
     {
         //check pointers
-        if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity())
+        if (!this->getControllableEntity() || !this->target_)
             return false;
-        
+
         //check if this points in the direction of target_
 
         Vector3 myPosition = this->getControllableEntity()->getWorldPosition();
-        Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition();
+        Vector3 targetPosition = this->target_->getWorldPosition();
         Vector3 differenceVector = targetPosition - myPosition;
-        float scalarProduct = differenceVector * WorldEntity::FRONT;
+        float scalarProduct = differenceVector.dotProduct(WorldEntity::FRONT);
         Vector3 projection = scalarProduct * WorldEntity::FRONT;
         if ((differenceVector - projection).length() > 50)
             return false;
@@ -281,7 +284,7 @@
             {
                 allyPosition = it->getControllableEntity()->getWorldPosition();
                 allyDifference = allyPosition - myPosition;
-                allyScalarProduct = allyDifference * WorldEntity::FRONT;
+                allyScalarProduct = allyDifference.dotProduct(WorldEntity::FRONT);
                 allyProjection = allyScalarProduct * WorldEntity::FRONT;
                 if (allyScalarProduct < 0 || allyScalarProduct > scalarProduct)
                     continue;
@@ -290,6 +293,10 @@
             } 
         }
 
+        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+        if (pawn)
+            pawn->setAimPosition(WorldEntity::FRONT);
+    
         return true;
 
     }

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-03 14:56:41 UTC (rev 10762)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-03 16:06:05 UTC (rev 10763)
@@ -108,7 +108,7 @@
             virtual bool hasWingman();
 
             void setTarget(ControllableEntity* target);
-
+            
             void setTargetOrientation(const Quaternion& orient);
             void setTargetOrientation(ControllableEntity* target);
             void setTargetPosition(const Vector3& target);

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-03 14:56:41 UTC (rev 10762)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-03 16:06:05 UTC (rev 10763)
@@ -39,14 +39,12 @@
         RegisterObject(DivisionController);
         
         this->setFormationMode(FormationMode::DIAMOND);
-
+        this->target_ = 0;
         this->myFollower_ = 0;
         this->myWingman_ = 0;
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
         this->rank_ = Rank::DIVISIONLEADER;
 
-        Vector3* pos = new Vector3(-4000,-1000,-2000);
-        this->setTargetPosition(*pos);
 
     }
 
@@ -75,6 +73,10 @@
     }
     void DivisionController::action()
     {
+/*
+        Vector3* pos = new Vector3(4000,1000,2000);
+        this->setTargetPosition(*pos);*/
+
         setTargetPositionOfFollower();
         setTargetPositionOfWingman();
 

Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-11-03 14:56:41 UTC (rev 10762)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc	2015-11-03 16:06:05 UTC (rev 10763)
@@ -57,23 +57,28 @@
     {
         this->divisions_.clear();
         
-        /*for (ObjectList<DivisionController>::iterator it = ObjectList<DivisionController>::begin(); it; ++it)
+        for (ObjectList<DivisionController>::iterator it = ObjectList<DivisionController>::begin(); it; ++it)
         {
             if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
             {
                 this->divisions_.push_back(*(it));
             } 
         }
+        /*for(std::vector<WeakPtr<DivisionController> >::iterator it2 = divisions_.begin(); it2 != divisions_.end(); ++it2) 
+        {
+            (*it2)->setTargetPosition(this->getControllableEntity()->getWorldPosition());   
+        }*/ 
         for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
         {
-            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
+            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() == 0)
             {
                 for(std::vector<WeakPtr<DivisionController> >::iterator it2 = divisions_.begin(); it2 != divisions_.end(); ++it2) {
                     (*it2)->setTarget(it->getControllableEntity());   
+                    (*it2)->setTargetPosition(it->getControllableEntity()->getWorldPosition());
                 }               
                 break;
             } 
-        }*/
+        }
 
     }
     void FleetController::tick(float dt)




More information about the Orxonox-commit mailing list