Changeset 6991 for code/branches/ai
- Timestamp:
- May 27, 2010, 10:16:08 PM (14 years ago)
- Location:
- code/branches/ai
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/data/levels/templates/pickup_representation_templates.oxt
r6918 r6991 110 110 111 111 <Template name=droneTemplate> 112 <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.99999 99"primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>112 <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=50 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50> 113 113 <attached> 114 114 <Model scale="1" mesh="drone.mesh"/> -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6986 r6991 762 762 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 763 763 return true; 764 DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController()); 765 DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController()); 766 if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner()) 767 return true; 764 768 765 769 return (team1 == team2 && team1 != -1); -
code/branches/ai/src/orxonox/controllers/DroneController.cc
r6918 r6991 80 80 81 81 const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(ownerPosition-dronePosition); //Vector from Drone To Owner out of drones local coordinate system 82 /* 83 int distance_square = (ownerPosition.x-dronePosition.x)*(ownerPosition.x-dronePosition.x) 84 + (ownerPosition.y-dronePosition.y)*(ownerPosition.y-dronePosition.y) 85 + (ownerPosition.z-dronePosition.z)*(ownerPosition.z-dronePosition.z); //distance to Owner squared 86 */ 82 87 83 random = rnd(maxrand); 88 84 if ( random < 30 && (!this->target_)) 89 85 this->searchNewTarget(); 90 /* 91 //face target 92 drone_->rotateYaw(-targetPosition_.x); 93 drone_->rotatePitch(targetPosition_.y); 94 */ 95 if (this->target_) 86 87 if (random < 50 && this->target_) 96 88 { 89 this->isShooting_ = true; 97 90 this->aimAtTarget(); 91 drone_->rotateYaw(targetPosition_.x); //face target 92 drone_->rotatePitch(targetPosition_.y); 98 93 drone_->fire(0); 94 this->isShooting_ = false; 99 95 } 100 101 96 102 103 /*104 COUT(0) << "Drone: " << dronePosition << endl;105 COUT(0) << "Distance: " << distance << endl;106 COUT(0) << "locDrone: " << locOwnerDir << endl;107 COUT(0) << "target: " << targetPosition_ << endl;108 COUT(0) << "Owner: " << ownerPosition << endl;109 COUT(0) << "Rand: " << random << endl;110 */111 /*112 // search enemy113 random = rnd(maxrand);114 if (random < 15 && (!this->target_))115 this->searchNewTarget();116 117 // forget enemy118 random = rnd(maxrand);119 if (random < 5 && (this->target_))120 this->forgetTarget();121 122 // next enemy123 random = rnd(maxrand);124 if (random < 10 && (this->target_))125 this->searchNewTarget();126 127 //fly somewhere128 random = rnd(maxrand);129 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))130 this->searchRandomTargetPosition();131 132 // stop flying133 random = rnd(maxrand);134 if (random < 10 && (this->bHasTargetPosition_ && !this->target_))135 this->bHasTargetPosition_ = false;136 137 // fly somewhere else138 random = rnd(maxrand);139 if (random < 30 && (this->bHasTargetPosition_ && !this->target_))140 this->searchRandomTargetPosition();141 142 // shoot143 random = rnd(maxrand);144 if (random < 75 && (this->target_ && !this->bShooting_))145 this->bShooting_ = true;146 147 // stop shooting148 random = rnd(maxrand);149 if (random < 25 && (this->bShooting_))150 this->bShooting_ = false; */151 97 } 152 98 153 154 /** 99 /* 155 100 @brief 156 101 The controlling happens here. This method defines what the controller has to do each tick. … … 163 108 164 109 Drone *myDrone = static_cast<Drone*>(this->getControllableEntity()); 165 166 if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > 150*150) { //TODO: variable implementation of maxdistance 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) { 167 113 this->moveToPosition(this->getOwner()->getWorldPosition()); 168 169 114 } 170 115 else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) { 116 this->moveToPosition(-this->getOwner()->getWorldPosition()); 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 } 171 128 SUPER(AIController, tick, dt); 172 129 -
code/branches/ai/src/orxonox/controllers/DroneController.h
r6918 r6991 66 66 virtual void action(); 67 67 void ownerDied(); 68 bool isShooting_; 68 69 69 70 private: -
code/branches/ai/src/orxonox/worldentities/Drone.cc
r6918 r6991 40 40 namespace orxonox 41 41 { 42 // put your code in here:43 // create the factory for the drone44 42 CreateFactory(Drone); 45 43 /** … … 49 47 Drone::Drone(BaseObject* creator) : Pawn(creator) 50 48 { 51 // put your code in here:52 // - register the drone class to the core53 49 RegisterObject(Drone); 54 50 … … 57 53 this->localLinearAcceleration_.setValue(0, 0, 0); 58 54 this->localAngularAcceleration_.setValue(0, 0, 0); 59 this->primaryThrust_ = 100; 60 this->auxilaryThrust_ = 100; 61 this->rotationThrust_ = 10; 62 55 this->setRadarVisibility(false); 63 56 this->setCollisionType(WorldEntity::Dynamic); 64 57 … … 85 78 void Drone::XMLPort(Element& xmlelement, XMLPort::Mode mode) 86 79 { 87 // this calls the XMLPort function of the parent class88 80 SUPER(Drone, XMLPort, xmlelement, mode); 89 81 90 // put your code in here:91 // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport92 // make sure that the set- and get-functions exist.93 // variables can be added by the following command94 // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)95 82 XMLPortParam(Drone, "primaryThrust_", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); 96 83 XMLPortParam(Drone, "auxilaryThrust_", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode); 97 84 XMLPortParam(Drone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode); 98 99 85 XMLPortParam(Drone, "maxDistanceToOwner_", setMaxDistanceToOwner, getMaxDistanceToOwner, xmlelement, mode); 86 XMLPortParam(Drone, "minDistanceToOwner_", setMinDistanceToOwner, getMinDistanceToOwner, xmlelement, mode); 100 87 } 101 88 -
code/branches/ai/src/orxonox/worldentities/Drone.h
r6832 r6991 110 110 inline void setRotationThrust( float thrust ) 111 111 { this->rotationThrust_=thrust; } 112 inline void setMaxDistanceToOwner( float distance) 113 { this->maxDistanceToOwner_=distance; } 114 inline void setMinDistanceToOwner( float distance) 115 { this->minDistanceToOwner_=distance; } 112 116 113 117 … … 118 122 inline float getPrimaryThrust() 119 123 { return this->primaryThrust_; } 120 121 inline float getAuxilaryThrust() 124 inline float getAuxilaryThrust() 122 125 { return this->auxilaryThrust_; } 123 inline float getRotationThrust()126 inline float getRotationThrust() 124 127 { return this->rotationThrust_; } 128 inline float getMaxDistanceToOwner() 129 { return this->maxDistanceToOwner_; } 130 inline float getMinDistanceToOwner() 131 { return this->minDistanceToOwner_; } 125 132 126 133 private: … … 132 139 float auxilaryThrust_; //!< The amount of auxilary thrust. Used for all other movements (except for rotations). 133 140 float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only. 141 float maxDistanceToOwner_; //Maximum Distance to owner 142 float minDistanceToOwner_; //Minimum Distance to owner 134 143 }; 135 144
Note: See TracChangeset
for help on using the changeset viewer.