Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8845


Ignore:
Timestamp:
Aug 14, 2011, 10:58:07 PM (13 years ago)
Author:
jo
Message:

QUICK&DIRTY: drone uses portals.

Location:
code/branches/ai2/src/orxonox/controllers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.cc

    r8800 r8845  
    405405    }
    406406
     407    void ArtificialController::absoluteMoveToPosition(const Vector3& target)
     408    {
     409        float minDistance = 40.0f;
     410        if (!this->getControllableEntity())
     411            return;
     412
     413        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     414        float distance = (target - this->getControllableEntity()->getPosition()).length();
     415
     416            if (this->target_ || distance > minDistance)
     417            {
     418                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
     419                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
     420                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
     421                this->getControllableEntity()->moveFrontBack(SPEED_FREE);
     422            }
     423
     424
     425        if (distance < minDistance)
     426        {
     427            this->positionReached();
     428        }
     429    }
     430
     431
    407432    void ArtificialController::moveToTargetPosition()
    408433    {
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8792 r8845  
    113113            void moveToPosition(const Vector3& target);
    114114            void moveToTargetPosition();
     115            void absoluteMoveToPosition(const Vector3& target);
    115116
    116117            virtual void positionReached() {}
  • code/branches/ai2/src/orxonox/controllers/DroneController.cc

    r8723 r8845  
    5252        this->drone_ = 0;
    5353        this->isShooting_ = false;
     54        //this->criticalDistance_ = 1000.0f;
     55        this->setAccuracy(10);
    5456
    5557        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this)));
     
    9294        The duration of the tick.
    9395    */
     96    /* PORTALS workaround:
     97    if the owner uses a portal -> distance between owner and drone is huge -> is detected by drone
     98    -> drone searches for portal -> drone adds portal as waypoint -> drone flies towards portal //ignores owner
     99    -> if the drone used a portal, then the distance to the owner is small -> remove waypoint // back to normal mode
     100
     101    */
    94102    void DroneController::tick(float dt)
    95103    {
    96104        if (this->getDrone() && this->getOwner())
    97105        {
    98             if (this->target_)
     106            if (this->waypoints_.size() > 0 ) //Waypoint functionality: Drone should follow it's master through portals
     107            {// Idea: after using the the portal, the master is far away.
     108                WorldEntity* wPoint = this->waypoints_[this->waypoints_.size()-1];
     109                if(wPoint)
     110                {
     111                    float distanceToOwnerSquared = (this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength();
     112                    this->absoluteMoveToPosition(wPoint->getWorldPosition()); //simplified function - needs WORKAROUND
     113                    if (distanceToOwnerSquared <= 90000.0f) //WORKAROUND: if the Drone is again near its owner, the portal has been used correctly.
     114                    {
     115                        this->waypoints_.pop_back(); // if goal is reached, remove it from the list
     116                        this->positionReached(); //needed??
     117                    }
     118
     119                }
     120                else
     121                    this->waypoints_.pop_back(); // remove invalid waypoints
     122            }
     123            else
    99124            {
    100                 float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
    101                 if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
    102                 {
    103                     this->isShooting_ = true;
    104                     this->aimAtTarget();
    105                     if(!this->friendlyFire())
    106                         this->getDrone()->fire(0);
    107                 }
     125                if (this->target_)
     126                {
     127                    float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
     128                    if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
     129                    {
     130                       this->isShooting_ = true;
     131                       this->aimAtTarget();
     132                       if(!this->friendlyFire())
     133                           this->getDrone()->fire(0);
     134                    }
     135               }
     136
     137
     138                float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
     139                float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
     140                if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > 20.0f*maxDistanceSquared)
     141                {//FIX: if the drone's owner uses portal, the drone searches for the portal & adds it as a waypoint.
     142                    this->updatePointsOfInterest("PortalEndPoint", 500.0f); //possible conflict: speed-pickup
     143                }
     144                if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared)
     145                {
     146                    this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
     147                }
     148                else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
     149                {
     150                    this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
     151                }
     152                else if (!this->isShooting_)
     153                {
     154                    float random = rnd(2.0f);
     155                    float randomSelection = rnd(6.0f);
     156                    if((int)randomSelection==0) drone_->moveUpDown(random);
     157                    else if((int)randomSelection==1) drone_->moveRightLeft(random);
     158                    else if((int)randomSelection==2) drone_->moveFrontBack(random);
     159                    else if((int)randomSelection==3) drone_->rotateYaw(random);
     160                    else if((int)randomSelection==4) drone_->rotatePitch(random);
     161                    else if((int)randomSelection==5) drone_->rotateRoll(random);
     162                }
     163
     164                this->isShooting_ = false;
    108165            }
    109 
    110             float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
    111             float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
    112             if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared)
    113             {
    114                 this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
    115             }
    116             else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
    117             {
    118                 this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
    119             }
    120             else if (!this->isShooting_)
    121             {
    122                 float random = rnd(2.0f);
    123                 float randomSelection = rnd(6.0f);
    124                 if((int)randomSelection==0) drone_->moveUpDown(random);
    125                 else if((int)randomSelection==1) drone_->moveRightLeft(random);
    126                 else if((int)randomSelection==2) drone_->moveFrontBack(random);
    127                 else if((int)randomSelection==3) drone_->rotateYaw(random);
    128                 else if((int)randomSelection==4) drone_->rotatePitch(random);
    129                 else if((int)randomSelection==5) drone_->rotateRoll(random);
    130             }
    131 
    132             this->isShooting_ = false;
    133166        }
    134 
    135167        SUPER(AIController, tick, dt);
    136 
    137168    }
    138169
  • code/branches/ai2/src/orxonox/controllers/DroneController.h

    r8723 r8845  
    6666            virtual void action();
    6767            void ownerDied();
    68             bool friendlyFire(); //< returns true if the owner_ would be hit.
     68            bool friendlyFire(); //<! returns true if the owner_ would be hit.
    6969            bool isShooting_;
    7070
Note: See TracChangeset for help on using the changeset viewer.