[Orxonox-commit 2367] r7082 - code/branches/presentation3/src/orxonox/controllers
landauf at orxonox.net
landauf at orxonox.net
Wed Jun 2 02:26:26 CEST 2010
Author: landauf
Date: 2010-06-02 02:26:25 +0200 (Wed, 02 Jun 2010)
New Revision: 7082
Modified:
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
Log:
fixed a potential bug in DroneController
Modified: code/branches/presentation3/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/presentation3/src/orxonox/controllers/DroneController.cc 2010-06-02 00:18:19 UTC (rev 7081)
+++ code/branches/presentation3/src/orxonox/controllers/DroneController.cc 2010-06-02 00:26:25 UTC (rev 7082)
@@ -62,14 +62,14 @@
void DroneController::setOwner(Pawn* owner){
this->owner_ = owner;
- }
+ }
void DroneController::setDrone(Drone* drone)
{
this->drone_ = drone;
this->setControllableEntity(drone);
}
-
+
void DroneController::action()
{
float random;
@@ -80,7 +80,7 @@
const Vector3& locTargetDir = getDrone()->getOrientation().UnitInverse()*((getDrone()->getWorldPosition())-(target_->getWorldPosition())); //Vector from Drone To target out of drones local coordinate system
distanceToTargetSquared = locTargetDir.squaredLength();
}
-
+
random = rnd(maxrand);
if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
this->searchNewTarget();
@@ -105,25 +105,28 @@
*/
void DroneController::tick(float dt)
{
- 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
+ if (this->getDrone() && this->getOwner())
+ {
+ 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
+ }
+ else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
+ this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
+ }
+ else if(!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);
+ }
}
- else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
- this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
- }
- else if(!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);
- }
-
+
SUPER(AIController, tick, dt);
}
More information about the Orxonox-commit
mailing list