[Orxonox-commit 4064] r8735 - in code/branches/ai2/src/orxonox: controllers worldentities/pawns
jo at orxonox.net
jo at orxonox.net
Thu Jul 7 15:59:55 CEST 2011
Author: jo
Date: 2011-07-07 15:59:54 +0200 (Thu, 07 Jul 2011)
New Revision: 8735
Modified:
code/branches/ai2/src/orxonox/controllers/AIController.cc
code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
code/branches/ai2/src/orxonox/controllers/ArtificialController.h
code/branches/ai2/src/orxonox/controllers/Controller.cc
code/branches/ai2/src/orxonox/controllers/Controller.h
code/branches/ai2/src/orxonox/worldentities/pawns/Pawn.cc
Log:
Adjust weapon behaviour if bot dies and is respawned with a different weaponsetting than before.
Modified: code/branches/ai2/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/AIController.cc 2011-07-06 20:50:18 UTC (rev 8734)
+++ code/branches/ai2/src/orxonox/controllers/AIController.cc 2011-07-07 13:59:54 UTC (rev 8735)
@@ -204,7 +204,12 @@
{
if (!this->isActive())
return;
-
+ if(this->bDeathFlag_)//If a bot died recently, make him check his weaponsystem.
+ {
+ this->bSetupWorked = false;
+ this->numberOfWeapons = 0;
+ this->resetDeathFlag();
+ }
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
if(this->mode_ == DEFAULT)
Modified: code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/ArtificialController.cc 2011-07-06 20:50:18 UTC (rev 8734)
+++ code/branches/ai2/src/orxonox/controllers/ArtificialController.cc 2011-07-07 13:59:54 UTC (rev 8735)
@@ -89,7 +89,7 @@
this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
this->bSetupWorked = false;
this->numberOfWeapons = 0;
- this->botlevel_ = 1.0f;
+ this->botlevel_ = 0.5f;
this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
this->timeout_=0;
}
@@ -1042,15 +1042,15 @@
}
else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
{
- if (this->isCloseAtTarget(130) &&(weapons[1]==1) )
+ if (this->isCloseAtTarget(130) &&weapons[1] )
{//LENSFLARE: short range weapon
this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
}
- else if((weapons[3]==3)&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ )
+ else if(weapons[3]&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ )
{//ROCKET: mid range weapon
//TODO: How many rockets are available?
this->mode_ = ROCKET;//Vector-implementation: mode_.push_back(ROCKET);
- this->getControllableEntity()->fire(3);//launch rocket BUG IS TRIGGERED HERE.
+ 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();
@@ -1063,7 +1063,7 @@
this->projectiles[3]-=1;//decrease ammo !!
}
- else if ((weapons[0]==0))//LASER: default weapon
+ else if (weapons[0])//LASER: default weapon
this->getControllableEntity()->fire(0);
}
}
@@ -1082,24 +1082,26 @@
{
//const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
/*if(wpn=="")
- weapons[i]=-1;
+ weapons[i]=false;
else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-(
- weapons[0]=0;
+ weapons[0]=true;
else if(wpn=="FusionMunition")
- weapons[1]=1;
+ weapons[1]=true;
else if(wpn=="TargetSeeking Rockets")
- weapons[2]=2;
- else if(wpn=="ROCKET")//TODO: insert right munition name
- weapons[3]=3;
+ weapons[2]=true;
+ else if(wpn=="RocketMunition")
+ weapons[3]=true;
+ else
+ COUT(1)<< wpn << + << " has to be added in ArtificialController.cc as new weapon." << std::endl;
*/
if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
{
- weapons[i]=i;
+ weapons[i]=true;
projectiles[i]=1;//TODO: how to express infinite ammo? how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user)
numberOfWeapons++;
}
else
- weapons[i]=-1;
+ weapons[i]=-false;
}
//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
}
Modified: code/branches/ai2/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai2/src/orxonox/controllers/ArtificialController.h 2011-07-06 20:50:18 UTC (rev 8734)
+++ code/branches/ai2/src/orxonox/controllers/ArtificialController.h 2011-07-07 13:59:54 UTC (rev 8735)
@@ -148,19 +148,17 @@
bool bShooting_;
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];
+ bool weapons[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays if a weapon is available - managed by setupWeapons()
+ int projectiles[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays amount of projectiles. - managed by setupWeapons()
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_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
- void setPreviousMode();
-
- private:
- void setupWeapons();
- const std::string& getWeaponname(int i, Pawn* pawn);
- bool bSetupWorked;
+ void setPreviousMode();
+ void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
+ const std::string& getWeaponname(int i, Pawn* pawn); //<! Function that links a weapon's firemode to its name.
+ bool bSetupWorked; //<! If false, setupWeapons() is called.
};
}
Modified: code/branches/ai2/src/orxonox/controllers/Controller.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/Controller.cc 2011-07-06 20:50:18 UTC (rev 8734)
+++ code/branches/ai2/src/orxonox/controllers/Controller.cc 2011-07-07 13:59:54 UTC (rev 8735)
@@ -41,6 +41,7 @@
this->player_ = 0;
this->controllableEntity_ = 0;
this->bGodMode_ = false;
+ this->bDeathFlag_ = false;
}
Controller::~Controller()
Modified: code/branches/ai2/src/orxonox/controllers/Controller.h
===================================================================
--- code/branches/ai2/src/orxonox/controllers/Controller.h 2011-07-06 20:50:18 UTC (rev 8734)
+++ code/branches/ai2/src/orxonox/controllers/Controller.h 2011-07-07 13:59:54 UTC (rev 8735)
@@ -62,6 +62,10 @@
inline ControllableEntity* getControllableEntity() const
{ return this->controllableEntity_; }
+ inline void setDeathFlag()
+ { this->bDeathFlag_ = true; }
+ inline void resetDeathFlag()
+ { this->bDeathFlag_ = false; }
virtual void changedControllableEntity() {}
protected:
@@ -78,6 +82,7 @@
protected:
PlayerInfo* player_;
ControllableEntity* controllableEntity_;
+ bool bDeathFlag_; //<! Signal, when a controlled entity died. Flag is set in Pawn.cc and used in AIController.
private:
bool bGodMode_;
};
Modified: code/branches/ai2/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/ai2/src/orxonox/worldentities/pawns/Pawn.cc 2011-07-06 20:50:18 UTC (rev 8734)
+++ code/branches/ai2/src/orxonox/worldentities/pawns/Pawn.cc 2011-07-07 13:59:54 UTC (rev 8735)
@@ -303,6 +303,10 @@
this->setHealth(1);
if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
{
+ if ( this->getController()&& (!this->isHumanShip_) ) //announce death to the ai
+ {
+ this->getController()->setDeathFlag();
+ }
// Set bAlive_ to false and wait for PawnManager to do the destruction
this->bAlive_ = false;
More information about the Orxonox-commit
mailing list