[Orxonox-commit 4040] r8711 - code/branches/ai/src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Wed Jun 22 18:57:17 CEST 2011
Author: jo
Date: 2011-06-22 18:57:16 +0200 (Wed, 22 Jun 2011)
New Revision: 8711
Modified:
code/branches/ai/src/orxonox/controllers/AIController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.h
Log:
Bots are ready for rocket usage. (The hit rate for rockets is just about 60% though.). Note that this is just a proof of concept implementation. The next goal is a more generic implementation that adjusts the AI to any spaceship, not only the assff and similar ones.
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2011-06-18 11:11:04 UTC (rev 8710)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2011-06-22 16:57:16 UTC (rev 8711)
@@ -269,20 +269,26 @@
this->doFire();
}
}//END_OF DEFAULT MODE
- else if (this->mode_ == ROCKET)
+ else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
{
ControllableEntity *controllable = this->getControllableEntity();
if(controllable)
{
- if(controllable->getRocket())//Check wether the bot is controlling the rocket.
- {
- this->follow(); //TODO: CHECK: does follow make the bot crash into the target_ ?
- }
- else
- this->mode_ = DEFAULT;//no rocket -> get out of rocket mode
+ if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over.
+ {
+ this->follow(); //TODO: CHECK: does follow make the bot crash into the target_ ?
+ this->timeout_ -= dt;
+ if((timeout_< 0)||(!target_))//Check if the timeout is over or target died.
+ {
+ controllable->fire(0);//kill the rocket
+ this->setPreviousMode();//get out of rocket mode
+ }
+ }
+ else
+ this->setPreviousMode();//no rocket entity -> get out of rocket mode
}
else
- this->mode_ = DEFAULT;//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
+ this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
}//END_OF ROCKET MODE
SUPER(AIController, tick, dt);
}
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-06-18 11:11:04 UTC (rev 8710)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-06-22 16:57:16 UTC (rev 8711)
@@ -88,6 +88,7 @@
this->numberOfWeapons = 0;
this->botlevel_ = 1.0f;
this->mode_ = DEFAULT;
+ this->timeout_=0;
}
ArtificialController::~ArtificialController()
@@ -1034,21 +1035,29 @@
}
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) )
+ if (this->isCloseAtTarget(130) &&(weapons[1]==1) )
{//LENSFLARE: short range weapon
this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
}
- else if(this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[3]==3)&& this->isCloseAtTarget(260) &&projectiles[3] )*/
+ else if((weapons[3]==3)&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ )
{//ROCKET: mid range weapon
//TODO: Which weapon is the rocket? How many rockets are available?
this->mode_ = ROCKET;
- //TODO: this->rockettimer->start()
this->getControllableEntity()->fire(3);//launch rocket
+ if(this->getControllableEntity()&&this->target_)//after fire(3) getControllableEntity() refers to the rocket!
+ {
+ float speed = this->getControllableEntity()->getVelocity().length() - target_->getVelocity().length();
+ if(!speed) speed = 0.1f;
+ float distance = target_->getPosition().length() - this->getControllableEntity()->getPosition().length();
+ this->timeout_= distance/speed*sgn(speed*distance) + 1.8f;//predicted time of target hit (+ tolerance)
+ }
+ else
+ this->timeout_ = 4.0f;//TODO: find better default value
+
this->projectiles[3]-=1;//decrease ammo !!
}
-
- /*else if ((weapons[0]==0))//LASER: default weapon
- this->getControllableEntity()->fire(0);*/
+ else if ((weapons[0]==0))//LASER: default weapon
+ this->getControllableEntity()->fire(0);
}
}
/**
@@ -1093,6 +1102,11 @@
for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)
it->setBotLevel(level);
}
+
+ void ArtificialController::setPreviousMode()
+ {
+ this->mode_ = DEFAULT;
+ }
}
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h 2011-06-18 11:11:04 UTC (rev 8710)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h 2011-06-22 16:57:16 UTC (rev 8711)
@@ -148,10 +148,12 @@
int numberOfWeapons;//< Used for weapon init function. Displayes number of weapons available for a bot.
int weapons[WeaponSystem::MAX_WEAPON_MODES];
int projectiles[WeaponSystem::MAX_WEAPON_MODES];
- float botlevel_; //< Makes the level of a bot configurable.
+ float botlevel_; //< Makes the level of a bot configurable.
+ float timeout_; //< Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
Mode mode_;
+ void setPreviousMode();
private:
void setupWeapons();
More information about the Orxonox-commit
mailing list