[Orxonox-commit 3139] r7832 - code/branches/ai/src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Thu Jan 27 15:58:04 CET 2011
Author: jo
Date: 2011-01-27 15:58:04 +0100 (Thu, 27 Jan 2011)
New Revision: 7832
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:
Now the ai use lensflare if the weapon is on board and if they are close enough to the target. Hardcoded version!
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2011-01-17 19:51:15 UTC (rev 7831)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2011-01-27 14:58:04 UTC (rev 7832)
@@ -219,8 +219,7 @@
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
- this->getControllableEntity()->fire(0);
+ this->doFire();
}
if (this->specificMasterAction_ == TURN180)
@@ -240,7 +239,7 @@
}
- if (this->state_ == FREE)
+ if (this->state_ == FREE)
{
if (this->target_)
{
@@ -252,8 +251,7 @@
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
- this->getControllableEntity()->fire(0);
+ this->doFire();
}
SUPER(AIController, tick, dt);
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-01-17 19:51:15 UTC (rev 7831)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2011-01-27 14:58:04 UTC (rev 7832)
@@ -83,6 +83,8 @@
this->targetPosition_ = Vector3::ZERO;
this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
+ this->bSetupWorked = false;
+ this->numberOfWeapons = 0;
}
ArtificialController::~ArtificialController()
@@ -1015,4 +1017,43 @@
return (team1 == team2 && team1 != -1);
}
+
+ void ArtificialController::doFire()
+ {
+ if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
+ {
+ this->setupWeapons();
+ if(numberOfWeapons>0)
+ bSetupWorked=true;
+ }
+ else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
+ {
+ if (this->isCloseAtTarget(140) && 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
+
+ //default fire (laser)
+ else if ((weapons[0]==0))
+ this->getControllableEntity()->fire(0);
+ }
+ }
+ void ArtificialController::setupWeapons()
+ {
+ if(this->getControllableEntity())
+ {
+ Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+ if(pawn)
+ {
+ for(unsigned int i=0; i<WeaponSystem::MAX_WEAPON_MODES; i++)
+ {
+ if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
+ {
+ weapons[i]=i;
+ numberOfWeapons++;
+ }
+ else
+ weapons[i]=-1;
+ }
+ }
+ }
+ }
}
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h 2011-01-17 19:51:15 UTC (rev 7831)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h 2011-01-27 14:58:04 UTC (rev 7832)
@@ -36,6 +36,7 @@
#include "util/Math.h"
#include "Controller.h"
#include "controllers/NewHumanController.h"
+#include "weaponsystem/WeaponSystem.h"
namespace orxonox
{
@@ -76,6 +77,8 @@
static void followme();
static void passivebehaviour(const bool passive);
static void formationsize(const int size);
+
+ virtual void doFire();
protected:
@@ -137,8 +140,13 @@
Vector3 targetPosition_;
WeakPtr<Pawn> target_;
bool bShooting_;
+
+ int numberOfWeapons;
+ int weapons[WeaponSystem::MAX_WEAPON_MODES];
private:
+ void setupWeapons();
+ bool bSetupWorked;
};
}
More information about the Orxonox-commit
mailing list