[Orxonox-commit 3552] r8238 - code/branches/ai/src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Tue Apr 12 21:41:33 CEST 2011
Author: jo
Date: 2011-04-12 21:41:33 +0200 (Tue, 12 Apr 2011)
New Revision: 8238
Modified:
code/branches/ai/src/orxonox/controllers/AIController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
code/branches/ai/src/orxonox/controllers/DroneController.cc
code/branches/ai/src/orxonox/controllers/DroneController.h
Log:
Drone (almost) doesn't shoot at it's owner anymore.
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2011-04-12 17:54:36 UTC (rev 8237)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2011-04-12 19:41:33 UTC (rev 8238)
@@ -65,8 +65,8 @@
// return to Master after being forced free
if (this->freedomCount_ == 1)
{
- this->state_ = SLAVE;
- this->freedomCount_ = 0;
+ this->state_ = SLAVE;
+ this->freedomCount_ = 0;
}
random = rnd(maxrand);
@@ -81,12 +81,12 @@
// forget enemy
random = rnd(maxrand);
- if (random < ((1-botlevel_)*5) && (this->target_))
+ if (random < ((1-botlevel_)*6) && (this->target_))
this->forgetTarget();
// next enemy
random = rnd(maxrand);
- if (random < ((1-botlevel_)*10) && (this->target_))
+ if (random < (botlevel_*20) && (this->target_))
this->searchNewTarget();
// fly somewhere
@@ -219,8 +219,8 @@
else
{
this->aimAtTarget();
- random = rnd(maxrand);
- if(this->botlevel_*100 > random)
+ random = rnd(maxrand);
+ if(this->botlevel_*100 > random)
this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
}
}
@@ -253,12 +253,12 @@
if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
this->forgetTarget();
else
- {
- this->aimAtTarget();
- random = rnd(maxrand);
- if(this->botlevel_*100 > random)
+ {
+ this->aimAtTarget();
+ random = rnd(maxrand);
+ if(this->botlevel_*100 > random)
this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
- }
+ }
}
if (this->bHasTargetPosition_)
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-04-12 17:54:36 UTC (rev 8237)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-04-12 19:41:33 UTC (rev 8238)
@@ -1025,6 +1025,7 @@
*/
void ArtificialController::doFire()
{
+ if(ArtificialController::friendlyFire()) return;//catch if the bot would do friendlyFire
if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
{
this->setupWeapons();
@@ -1064,6 +1065,7 @@
}
}
}
+
void ArtificialController::setBotLevel(float level)
{
Modified: code/branches/ai/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/DroneController.cc 2011-04-12 17:54:36 UTC (rev 8237)
+++ code/branches/ai/src/orxonox/controllers/DroneController.cc 2011-04-12 19:41:33 UTC (rev 8238)
@@ -102,7 +102,8 @@
{
this->isShooting_ = true;
this->aimAtTarget();
- this->getDrone()->fire(0);
+ if(!this->friendlyFire())
+ this->getDrone()->fire(0);
}
}
@@ -146,4 +147,23 @@
else
this->destroy();
}
+
+ bool DroneController::friendlyFire()
+ { ControllableEntity* droneEntity_ = this->getControllableEntity();
+ if (!droneEntity_) return false;
+ if(!owner_) return false;
+ if(this->bHasTargetPosition_)
+ {
+ Vector3 ownerPosition_ = owner_->getPosition();
+ Vector3 toOwner_ = owner_->getPosition() - droneEntity_->getPosition();
+ Vector3 toTarget_ = targetPosition_ - droneEntity_->getPosition();
+ if(toTarget_.length() < toOwner_.length()) return false; //owner is far away = in safty
+ float angleToOwner = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, ownerPosition_);
+ float angleToTarget = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, targetPosition_);
+ float angle = angleToOwner - angleToTarget;//angle between target and owner, observed by the drone
+ if(std::sin(angle)*toOwner_.length() < 5.0f)//calculate owner's distance to shooting line
+ return true;
+ }
+ return false;//Default return value: Usually there is no friendlyFire
+ }
}
Modified: code/branches/ai/src/orxonox/controllers/DroneController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/DroneController.h 2011-04-12 17:54:36 UTC (rev 8237)
+++ code/branches/ai/src/orxonox/controllers/DroneController.h 2011-04-12 19:41:33 UTC (rev 8238)
@@ -65,6 +65,7 @@
protected:
virtual void action();
void ownerDied();
+ bool friendlyFire(); //< returns true if the owner_ would be hit.
bool isShooting_;
private:
More information about the Orxonox-commit
mailing list