[Orxonox-commit 4174] r8845 - code/branches/ai2/src/orxonox/controllers

jo at orxonox.net jo at orxonox.net
Sun Aug 14 22:58:07 CEST 2011


Author: jo
Date: 2011-08-14 22:58:07 +0200 (Sun, 14 Aug 2011)
New Revision: 8845

Modified:
   code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
   code/branches/ai2/src/orxonox/controllers/ArtificialController.h
   code/branches/ai2/src/orxonox/controllers/DroneController.cc
   code/branches/ai2/src/orxonox/controllers/DroneController.h
Log:
QUICK&DIRTY: drone uses portals.

Modified: code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/ArtificialController.cc	2011-08-14 20:47:05 UTC (rev 8844)
+++ code/branches/ai2/src/orxonox/controllers/ArtificialController.cc	2011-08-14 20:58:07 UTC (rev 8845)
@@ -404,6 +404,31 @@
         }
     }
 
+    void ArtificialController::absoluteMoveToPosition(const Vector3& target)
+    {
+        float minDistance = 40.0f;
+        if (!this->getControllableEntity())
+            return;
+
+        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        float distance = (target - this->getControllableEntity()->getPosition()).length();
+
+            if (this->target_ || distance > minDistance)
+            {
+                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
+                this->getControllableEntity()->moveFrontBack(SPEED_FREE);
+            }
+
+
+        if (distance < minDistance)
+        {
+            this->positionReached();
+        }
+    }
+
+
     void ArtificialController::moveToTargetPosition()
     {
         this->moveToPosition(this->targetPosition_);

Modified: code/branches/ai2/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai2/src/orxonox/controllers/ArtificialController.h	2011-08-14 20:47:05 UTC (rev 8844)
+++ code/branches/ai2/src/orxonox/controllers/ArtificialController.h	2011-08-14 20:58:07 UTC (rev 8845)
@@ -112,6 +112,7 @@
 
             void moveToPosition(const Vector3& target);
             void moveToTargetPosition();
+            void absoluteMoveToPosition(const Vector3& target);
 
             virtual void positionReached() {}
 

Modified: code/branches/ai2/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/DroneController.cc	2011-08-14 20:47:05 UTC (rev 8844)
+++ code/branches/ai2/src/orxonox/controllers/DroneController.cc	2011-08-14 20:58:07 UTC (rev 8845)
@@ -51,6 +51,8 @@
         this->owner_ = 0;
         this->drone_ = 0;
         this->isShooting_ = false;
+        //this->criticalDistance_ = 1000.0f;
+        this->setAccuracy(10);
 
         this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this)));
 
@@ -91,49 +93,78 @@
     @param dt
         The duration of the tick.
     */
+    /* PORTALS workaround:
+    if the owner uses a portal -> distance between owner and drone is huge -> is detected by drone
+    -> drone searches for portal -> drone adds portal as waypoint -> drone flies towards portal //ignores owner
+    -> if the drone used a portal, then the distance to the owner is small -> remove waypoint // back to normal mode
+
+    */
     void DroneController::tick(float dt)
     {
         if (this->getDrone() && this->getOwner())
         {
-            if (this->target_)
-            {
-                float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
-                if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
+            if (this->waypoints_.size() > 0 ) //Waypoint functionality: Drone should follow it's master through portals
+            {// Idea: after using the the portal, the master is far away.
+                WorldEntity* wPoint = this->waypoints_[this->waypoints_.size()-1];
+                if(wPoint)
                 {
-                    this->isShooting_ = true;
-                    this->aimAtTarget();
-		    if(!this->friendlyFire())
-                        this->getDrone()->fire(0);
+                    float distanceToOwnerSquared = (this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength();
+                    this->absoluteMoveToPosition(wPoint->getWorldPosition()); //simplified function - needs WORKAROUND
+                    if (distanceToOwnerSquared <= 90000.0f) //WORKAROUND: if the Drone is again near its owner, the portal has been used correctly.
+                    {
+                        this->waypoints_.pop_back(); // if goal is reached, remove it from the list
+                        this->positionReached(); //needed??
+                    }
+
                 }
+                else
+                    this->waypoints_.pop_back(); // remove invalid waypoints
             }
+            else
+            {
+                if (this->target_)
+                {
+                    float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
+                    if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
+                    {
+                       this->isShooting_ = true;
+                       this->aimAtTarget();
+                       if(!this->friendlyFire())
+                           this->getDrone()->fire(0);
+                    }
+               }
 
-            float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
-            float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
-            if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared)
-            {
-                this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
+
+                float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
+                float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
+                if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > 20.0f*maxDistanceSquared)
+                {//FIX: if the drone's owner uses portal, the drone searches for the portal & adds it as a waypoint.
+                    this->updatePointsOfInterest("PortalEndPoint", 500.0f); //possible conflict: speed-pickup
+                }
+                if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared)
+                {
+                    this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
+                }
+                else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
+                {
+                    this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
+                }
+                else if (!this->isShooting_)
+                {
+                    float random = rnd(2.0f);
+                    float randomSelection = rnd(6.0f);
+                    if((int)randomSelection==0) drone_->moveUpDown(random);
+                    else if((int)randomSelection==1) drone_->moveRightLeft(random);
+                    else if((int)randomSelection==2) drone_->moveFrontBack(random);
+                    else if((int)randomSelection==3) drone_->rotateYaw(random);
+                    else if((int)randomSelection==4) drone_->rotatePitch(random);
+                    else if((int)randomSelection==5) drone_->rotateRoll(random);
+                }
+
+                this->isShooting_ = false;
             }
-            else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
-            {
-                this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
-            }
-            else if (!this->isShooting_)
-            {
-                float random = rnd(2.0f);
-                float randomSelection = rnd(6.0f);
-                if((int)randomSelection==0) drone_->moveUpDown(random);
-                else if((int)randomSelection==1) drone_->moveRightLeft(random);
-                else if((int)randomSelection==2) drone_->moveFrontBack(random);
-                else if((int)randomSelection==3) drone_->rotateYaw(random);
-                else if((int)randomSelection==4) drone_->rotatePitch(random);
-                else if((int)randomSelection==5) drone_->rotateRoll(random);
-            }
-
-            this->isShooting_ = false;
         }
-
         SUPER(AIController, tick, dt);
-
     }
 
     void DroneController::ownerDied()

Modified: code/branches/ai2/src/orxonox/controllers/DroneController.h
===================================================================
--- code/branches/ai2/src/orxonox/controllers/DroneController.h	2011-08-14 20:47:05 UTC (rev 8844)
+++ code/branches/ai2/src/orxonox/controllers/DroneController.h	2011-08-14 20:58:07 UTC (rev 8845)
@@ -65,7 +65,7 @@
         protected:
             virtual void action();
             void ownerDied();
-	    bool friendlyFire(); //< returns true if the owner_ would be hit.
+            bool friendlyFire(); //<! returns true if the owner_ would be hit.
             bool isShooting_;
 
         private:




More information about the Orxonox-commit mailing list