[Orxonox-commit 2275] r6991 - in code/branches/ai: data/levels/templates src/orxonox/controllers src/orxonox/worldentities
gasserlu at orxonox.net
gasserlu at orxonox.net
Thu May 27 22:16:08 CEST 2010
Author: gasserlu
Date: 2010-05-27 22:16:08 +0200 (Thu, 27 May 2010)
New Revision: 6991
Modified:
code/branches/ai/data/levels/templates/pickup_representation_templates.oxt
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
code/branches/ai/src/orxonox/controllers/DroneController.cc
code/branches/ai/src/orxonox/controllers/DroneController.h
code/branches/ai/src/orxonox/worldentities/Drone.cc
code/branches/ai/src/orxonox/worldentities/Drone.h
Log:
drone smooth flight mode & minmaxDistance, multiple drones possible
Modified: code/branches/ai/data/levels/templates/pickup_representation_templates.oxt
===================================================================
--- code/branches/ai/data/levels/templates/pickup_representation_templates.oxt 2010-05-27 19:23:07 UTC (rev 6990)
+++ code/branches/ai/data/levels/templates/pickup_representation_templates.oxt 2010-05-27 20:16:08 UTC (rev 6991)
@@ -109,7 +109,7 @@
<Template name=droneTemplate>
- <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.9999999" primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>
+ <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=50 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>
<attached>
<Model scale="1" mesh="drone.mesh"/>
</attached>
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-05-27 19:23:07 UTC (rev 6990)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-05-27 20:16:08 UTC (rev 6991)
@@ -761,6 +761,10 @@
droneController = orxonox_cast<DroneController*>(entity2->getController());
if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
return true;
+ DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+ DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+ if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+ return true;
return (team1 == team2 && team1 != -1);
}
Modified: code/branches/ai/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/DroneController.cc 2010-05-27 19:23:07 UTC (rev 6990)
+++ code/branches/ai/src/orxonox/controllers/DroneController.cc 2010-05-27 20:16:08 UTC (rev 6991)
@@ -79,79 +79,24 @@
const Vector3& dronePosition = getDrone()->getWorldPosition();
const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(ownerPosition-dronePosition); //Vector from Drone To Owner out of drones local coordinate system
-/*
- int distance_square = (ownerPosition.x-dronePosition.x)*(ownerPosition.x-dronePosition.x)
- + (ownerPosition.y-dronePosition.y)*(ownerPosition.y-dronePosition.y)
- + (ownerPosition.z-dronePosition.z)*(ownerPosition.z-dronePosition.z); //distance to Owner squared
-*/
+
random = rnd(maxrand);
if ( random < 30 && (!this->target_))
this->searchNewTarget();
-/*
- //face target
- drone_->rotateYaw(-targetPosition_.x);
- drone_->rotatePitch(targetPosition_.y);
- */
- if (this->target_)
+
+ if (random < 50 && this->target_)
{
+ this->isShooting_ = true;
this->aimAtTarget();
+ drone_->rotateYaw(targetPosition_.x); //face target
+ drone_->rotatePitch(targetPosition_.y);
drone_->fire(0);
+ this->isShooting_ = false;
}
-
-
-/*
- COUT(0) << "Drone: " << dronePosition << endl;
- COUT(0) << "Distance: " << distance << endl;
- COUT(0) << "locDrone: " << locOwnerDir << endl;
- COUT(0) << "target: " << targetPosition_ << endl;
- COUT(0) << "Owner: " << ownerPosition << endl;
- COUT(0) << "Rand: " << random << endl;
-*/
-/*
- // search enemy
- random = rnd(maxrand);
- if (random < 15 && (!this->target_))
- this->searchNewTarget();
-
- // forget enemy
- random = rnd(maxrand);
- if (random < 5 && (this->target_))
- this->forgetTarget();
-
- // next enemy
- random = rnd(maxrand);
- if (random < 10 && (this->target_))
- this->searchNewTarget();
-
- //fly somewhere
- random = rnd(maxrand);
- if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
- this->searchRandomTargetPosition();
-
- // stop flying
- random = rnd(maxrand);
- if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
- this->bHasTargetPosition_ = false;
-
- // fly somewhere else
- random = rnd(maxrand);
- if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
- this->searchRandomTargetPosition();
-
- // shoot
- random = rnd(maxrand);
- if (random < 75 && (this->target_ && !this->bShooting_))
- this->bShooting_ = true;
-
- // stop shooting
- random = rnd(maxrand);
- if (random < 25 && (this->bShooting_))
- this->bShooting_ = false; */
}
-
- /**
+ /*
@brief
The controlling happens here. This method defines what the controller has to do each tick.
@param dt
@@ -162,12 +107,24 @@
Drone *myDrone = static_cast<Drone*>(this->getControllableEntity());
-
- if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > 150*150) { //TODO: variable implementation of maxdistance
+ 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());
-
}
-
+ else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
+ this->moveToPosition(-this->getOwner()->getWorldPosition());
+ }
+ 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);
}
Modified: code/branches/ai/src/orxonox/controllers/DroneController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/DroneController.h 2010-05-27 19:23:07 UTC (rev 6990)
+++ code/branches/ai/src/orxonox/controllers/DroneController.h 2010-05-27 20:16:08 UTC (rev 6991)
@@ -65,6 +65,7 @@
protected:
virtual void action();
void ownerDied();
+ bool isShooting_;
private:
Timer actionTimer_;
Modified: code/branches/ai/src/orxonox/worldentities/Drone.cc
===================================================================
--- code/branches/ai/src/orxonox/worldentities/Drone.cc 2010-05-27 19:23:07 UTC (rev 6990)
+++ code/branches/ai/src/orxonox/worldentities/Drone.cc 2010-05-27 20:16:08 UTC (rev 6991)
@@ -39,8 +39,6 @@
namespace orxonox
{
- // put your code in here:
- // create the factory for the drone
CreateFactory(Drone);
/**
@brief
@@ -48,18 +46,13 @@
*/
Drone::Drone(BaseObject* creator) : Pawn(creator)
{
- // put your code in here:
- // - register the drone class to the core
RegisterObject(Drone);
this->myController_ = 0;
this->localLinearAcceleration_.setValue(0, 0, 0);
this->localAngularAcceleration_.setValue(0, 0, 0);
- this->primaryThrust_ = 100;
- this->auxilaryThrust_ = 100;
- this->rotationThrust_ = 10;
-
+ this->setRadarVisibility(false);
this->setCollisionType(WorldEntity::Dynamic);
myController_ = new DroneController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator.
@@ -84,19 +77,13 @@
*/
void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
- // this calls the XMLPort function of the parent class
SUPER(Drone, XMLPort, xmlelement, mode);
- // put your code in here:
- // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport
- // make sure that the set- and get-functions exist.
- // variables can be added by the following command
- // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
XMLPortParam(Drone, "primaryThrust_", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
XMLPortParam(Drone, "auxilaryThrust_", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode);
XMLPortParam(Drone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode);
-
-
+ XMLPortParam(Drone, "maxDistanceToOwner_", setMaxDistanceToOwner, getMaxDistanceToOwner, xmlelement, mode);
+ XMLPortParam(Drone, "minDistanceToOwner_", setMinDistanceToOwner, getMinDistanceToOwner, xmlelement, mode);
}
Modified: code/branches/ai/src/orxonox/worldentities/Drone.h
===================================================================
--- code/branches/ai/src/orxonox/worldentities/Drone.h 2010-05-27 19:23:07 UTC (rev 6990)
+++ code/branches/ai/src/orxonox/worldentities/Drone.h 2010-05-27 20:16:08 UTC (rev 6991)
@@ -109,6 +109,10 @@
{ this->auxilaryThrust_=thrust; }
inline void setRotationThrust( float thrust )
{ this->rotationThrust_=thrust; }
+ inline void setMaxDistanceToOwner( float distance)
+ { this->maxDistanceToOwner_=distance; }
+ inline void setMinDistanceToOwner( float distance)
+ { this->minDistanceToOwner_=distance; }
/**
@@ -117,11 +121,14 @@
*/
inline float getPrimaryThrust()
{ return this->primaryThrust_; }
-
- inline float getAuxilaryThrust()
+ inline float getAuxilaryThrust()
{ return this->auxilaryThrust_; }
- inline float getRotationThrust()
+ inline float getRotationThrust()
{ return this->rotationThrust_; }
+ inline float getMaxDistanceToOwner()
+ { return this->maxDistanceToOwner_; }
+ inline float getMinDistanceToOwner()
+ { return this->minDistanceToOwner_; }
private:
DroneController *myController_; //!< The controller of the Drone.
@@ -131,6 +138,8 @@
float primaryThrust_; //!< The amount of primary thrust. This is just used, when moving forward.
float auxilaryThrust_; //!< The amount of auxilary thrust. Used for all other movements (except for rotations).
float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.
+ float maxDistanceToOwner_; //Maximum Distance to owner
+ float minDistanceToOwner_; //Minimum Distance to owner
};
}
More information about the Orxonox-commit
mailing list