[Orxonox-commit 3150] r7843 - code/branches/ai/src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Thu Feb 3 17:46:31 CET 2011
Author: jo
Date: 2011-02-03 17:46:31 +0100 (Thu, 03 Feb 2011)
New Revision: 7843
Modified:
code/branches/ai/src/orxonox/controllers/AIController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
Log:
Little feature added: Bot's are following their victims. So that they can't get out of reach easily.
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2011-01-31 22:36:18 UTC (rev 7842)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2011-02-03 16:46:31 UTC (rev 7843)
@@ -25,7 +25,7 @@
* Dominik Solenicki
*
*/
-//TODO: intended behaviour: when a bot has a target_ it shouldn't move away.
+
#include "AIController.h"
#include "util/Math.h"
@@ -34,6 +34,7 @@
#include "worldentities/ControllableEntity.h"
#include "worldentities/pawns/Pawn.h"
+//Todo: Bot soll pickupspawner besuchen können, falls Pickup vorhanden
namespace orxonox
{
static const float ACTION_INTERVAL = 1.0f;
@@ -85,7 +86,7 @@
// next enemy
random = rnd(maxrand);
- if (random < ((1+ botlevel_)*10) && (this->target_))
+ if (random < ((1-botlevel_)*10) && (this->target_))
this->searchNewTarget();
// fly somewhere
@@ -158,12 +159,12 @@
// search enemy
random = rnd(maxrand);
- if (random < 15 && (!this->target_))
+ if (random < (botlevel_)*25 && (!this->target_))
this->searchNewTarget();
// forget enemy
random = rnd(maxrand);
- if (random < 5 && (this->target_))
+ if (random < (1-botlevel_)*6 && (this->target_))
this->forgetTarget();
// next enemy
@@ -183,10 +184,10 @@
// shoot
random = rnd(maxrand);
- if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
+ if (!(this->passive_) && random < 25*(botlevel_)+1 && (this->target_ && !this->bShooting_))
{
- this->bShooting_ = true;
- this->forceFreeSlaves();
+ this->bShooting_ = true;
+ this->forceFreeSlaves();
}
// stop shooting
@@ -201,6 +202,9 @@
void AIController::tick(float dt)
{
+ float random;
+ float maxrand = 100.0f / ACTION_INTERVAL;
+
if (!this->isActive())
return;
@@ -212,7 +216,13 @@
{
if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
this->forgetTarget();
- else this->aimAtTarget();
+ else
+ {
+ 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_)
@@ -232,10 +242,8 @@
if (this->state_ == SLAVE)
{
-
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
-
}
if (this->state_ == FREE)
@@ -244,7 +252,13 @@
{
if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
this->forgetTarget();
- else this->aimAtTarget();
+ else
+ {
+ 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-01-31 22:36:18 UTC (rev 7842)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-02-03 16:46:31 UTC (rev 7843)
@@ -52,7 +52,6 @@
SetConsoleCommand("ArtificialController", "passivebehaviour", &ArtificialController::passivebehaviour);
SetConsoleCommand("ArtificialController", "formationsize", &ArtificialController::formationsize);
SetConsoleCommand("ArtificialController", "setbotlevel", &ArtificialController::setAllBotLevel);
-
static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
@@ -130,7 +129,7 @@
XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
- XMLPortParam(ArtificialController, "level", setBotLevel, getBotLevel, xmlelement, mode).defaultValues(1.0f);
+ //XMLPortParam(ArtificialController, "level", setBotLevel, getBotLevel, xmlelement, mode).defaultValues(0.0f);
}
// Documentation only here to get a faster overview for creating a useful documentation...
@@ -1032,7 +1031,7 @@
if(numberOfWeapons>0)
bSetupWorked=true;
}
- else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000 + botlevel_*200) && this->isLookingAtTarget(math::pi / 20.0f))
+ else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
{
if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
More information about the Orxonox-commit
mailing list