Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 2, 2010, 2:26:25 AM (14 years ago)
Author:
landauf
Message:

fixed a potential bug in DroneController

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/orxonox/controllers/DroneController.cc

    r7060 r7082  
    6363    void DroneController::setOwner(Pawn* owner){
    6464        this->owner_ = owner;
    65     } 
     65    }
    6666
    6767    void DroneController::setDrone(Drone* drone)
     
    7070        this->setControllableEntity(drone);
    7171    }
    72    
     72
    7373    void DroneController::action()
    7474    {
     
    8181            distanceToTargetSquared = locTargetDir.squaredLength();
    8282        }
    83          
     83
    8484        random = rnd(maxrand);
    8585        if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
     
    106106    void DroneController::tick(float dt)
    107107    {
    108         float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
    109         float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
    110         if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared) {
    111             this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
     108        if (this->getDrone() && this->getOwner())
     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                this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
     114            }
     115            else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
     116                this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
     117            }
     118            else if(!isShooting_) {
     119                float random = rnd(2.0f);
     120                float randomSelection = rnd(6.0f);
     121                if((int)randomSelection==0) drone_->moveUpDown(random);
     122                else if((int)randomSelection==1) drone_->moveRightLeft(random);
     123                else if((int)randomSelection==2) drone_->moveFrontBack(random);
     124                else if((int)randomSelection==3) drone_->rotateYaw(random);
     125                else if((int)randomSelection==4) drone_->rotatePitch(random);
     126                else if((int)randomSelection==5) drone_->rotateRoll(random);
     127            }
    112128        }
    113         else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
    114             this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
    115         }
    116         else if(!isShooting_) {
    117             float random = rnd(2.0f);
    118             float randomSelection = rnd(6.0f);
    119             if((int)randomSelection==0) drone_->moveUpDown(random);
    120             else if((int)randomSelection==1) drone_->moveRightLeft(random);
    121             else if((int)randomSelection==2) drone_->moveFrontBack(random);
    122             else if((int)randomSelection==3) drone_->rotateYaw(random);
    123             else if((int)randomSelection==4) drone_->rotatePitch(random);
    124             else if((int)randomSelection==5) drone_->rotateRoll(random);
    125         }
    126        
     129
    127130        SUPER(AIController, tick, dt);
    128131
Note: See TracChangeset for help on using the changeset viewer.