Changeset 8238 for code/branches/ai/src
- Timestamp:
- Apr 12, 2011, 9:41:33 PM (14 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r7843 r8238 66 66 if (this->freedomCount_ == 1) 67 67 { 68 this->state_ = SLAVE;69 this->freedomCount_ = 0;68 this->state_ = SLAVE; 69 this->freedomCount_ = 0; 70 70 } 71 71 … … 82 82 // forget enemy 83 83 random = rnd(maxrand); 84 if (random < ((1-botlevel_)* 5) && (this->target_))84 if (random < ((1-botlevel_)*6) && (this->target_)) 85 85 this->forgetTarget(); 86 86 87 87 // next enemy 88 88 random = rnd(maxrand); 89 if (random < ( (1-botlevel_)*10) && (this->target_))89 if (random < (botlevel_*20) && (this->target_)) 90 90 this->searchNewTarget(); 91 91 … … 220 220 { 221 221 this->aimAtTarget(); 222 223 222 random = rnd(maxrand); 223 if(this->botlevel_*100 > random) 224 224 this->follow();//If a bot is shooting a player, it shouldn't let him go away easily. 225 225 } … … 254 254 this->forgetTarget(); 255 255 else 256 257 258 259 256 { 257 this->aimAtTarget(); 258 random = rnd(maxrand); 259 if(this->botlevel_*100 > random) 260 260 this->follow();//If a bot is shooting a player, it shouldn't let him go away easily. 261 261 } 262 262 } 263 263 -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r7843 r8238 1026 1026 void ArtificialController::doFire() 1027 1027 { 1028 if(ArtificialController::friendlyFire()) return;//catch if the bot would do friendlyFire 1028 1029 if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ... 1029 1030 { … … 1065 1066 } 1066 1067 } 1068 1067 1069 1068 1070 void ArtificialController::setBotLevel(float level) -
code/branches/ai/src/orxonox/controllers/DroneController.cc
r7284 r8238 103 103 this->isShooting_ = true; 104 104 this->aimAtTarget(); 105 this->getDrone()->fire(0); 105 if(!this->friendlyFire()) 106 this->getDrone()->fire(0); 106 107 } 107 108 } … … 147 148 this->destroy(); 148 149 } 150 151 bool DroneController::friendlyFire() 152 { ControllableEntity* droneEntity_ = this->getControllableEntity(); 153 if (!droneEntity_) return false; 154 if(!owner_) return false; 155 if(this->bHasTargetPosition_) 156 { 157 Vector3 ownerPosition_ = owner_->getPosition(); 158 Vector3 toOwner_ = owner_->getPosition() - droneEntity_->getPosition(); 159 Vector3 toTarget_ = targetPosition_ - droneEntity_->getPosition(); 160 if(toTarget_.length() < toOwner_.length()) return false; //owner is far away = in safty 161 float angleToOwner = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, ownerPosition_); 162 float angleToTarget = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, targetPosition_); 163 float angle = angleToOwner - angleToTarget;//angle between target and owner, observed by the drone 164 if(std::sin(angle)*toOwner_.length() < 5.0f)//calculate owner's distance to shooting line 165 return true; 166 } 167 return false;//Default return value: Usually there is no friendlyFire 168 } 149 169 } -
code/branches/ai/src/orxonox/controllers/DroneController.h
r7163 r8238 66 66 virtual void action(); 67 67 void ownerDied(); 68 bool friendlyFire(); //< returns true if the owner_ would be hit. 68 69 bool isShooting_; 69 70
Note: See TracChangeset
for help on using the changeset viewer.