[Orxonox-commit 6079] r10737 - code/branches/AI_HS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Sun Nov 1 09:10:09 CET 2015
Author: gania
Date: 2015-11-01 09:10:08 +0100 (Sun, 01 Nov 2015)
New Revision: 10737
Modified:
code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
Log:
nothing really changed
Modified: code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc 2015-10-31 22:50:17 UTC (rev 10736)
+++ code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc 2015-11-01 08:10:08 UTC (rev 10737)
@@ -81,6 +81,8 @@
*/
void ArtificialController::changedControllableEntity()
{
+ FormationController::changedControllableEntity(); // super
+
if (!this->getControllableEntity())
this->removeFromFormation();
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-10-31 22:50:17 UTC (rev 10736)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-01 08:10:08 UTC (rev 10737)
@@ -26,6 +26,14 @@
*
*/
#include "controllers/CommonController.h"
+/*
+#include "weaponsystem/WeaponMode.h"
+#include "weaponsystem/WeaponPack.h"
+#include "weaponsystem/Weapon.h"
+#include "weaponsystem/WeaponSlot.h"
+#include "weaponsystem/WeaponSlot.h"
+#include "worldentities/pawns/SpaceShip.h"
+*/
namespace orxonox
{
@@ -36,6 +44,7 @@
CommonController::CommonController(Context* context) : Controller(context)
{
+ //this->bSetupWorked = false;
RegisterObject(CommonController);
}
@@ -169,10 +178,74 @@
bHasTargetOrientation_ = false;
}
}
+
+/*
+ int CommonController::getFiremode(std::string name)
+ {
+ for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
+ {
+ if (it->first == name)
+ return it->second;
+ }
+ return -1;
+ }
+ bool CommonController::isCloseAtTarget(float distance) const
+ {
+ if (!this->getControllableEntity())
+ return false;
+
+ if (!this->target_)
+ return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
+ else
+ return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
+ }
+ void CommonController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
+ {
+ this->bSetupWorked = false;
+ if(this->getControllableEntity())
+ {
+ Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+ if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip
+ {
+ this->weaponModes_.clear(); // reset previous weapon information
+ WeaponSlot* wSlot = 0;
+ for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
+ {
+ WeaponMode* wMode = 0;
+ for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
+ {
+ std::string wName = wMode->getIdentifier()->getName();
+ if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new"
+ weaponModes_[wName] = wMode->getMode();
+ }
+ }
+ if(weaponModes_.size())//at least one weapon detected
+ this->bSetupWorked = true;
+ }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
+ }
+ }
void CommonController::doFire()
{
- if (this->isLookingAtTarget(math::pi / 20.0f))
- this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target
+ if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
+ {
+ this->setupWeapons();
+ }
+ else if(this->getControllableEntity() &&
+ weaponModes_.size()&&
+ this->bShooting_ &&
+ this->isCloseAtTarget((3)*1000) &&
+ this->isLookingAtTarget(math::pi / 20.0f))
+ {
+ int firemode;
+ float random = rnd(1);//
+ if (this->isCloseAtTarget(130) && (firemode = getFiremode("LightningGun")) > -1 )
+ {//LENSFLARE: short range weapon
+ this->getControllableEntity()->fire(firemode); //ai uses lens flare if they're close enough to the target
+ }
+
+ else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon
+ this->getControllableEntity()->fire(firemode);
+ }
}
bool CommonController::isLookingAtTarget(float angle) const
{
@@ -195,7 +268,7 @@
Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
if (pawn)
pawn->setAimPosition(aimPosition);
- }
+ }*/
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-10-31 22:50:17 UTC (rev 10736)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-01 08:10:08 UTC (rev 10737)
@@ -32,9 +32,9 @@
#include "controllers/Controller.h"
#include "worldentities/ControllableEntity.h"
-#include "worldentities/pawns/Pawn.h"
+/*#include "worldentities/pawns/Pawn.h"
+*/
-
namespace orxonox
{
class _OrxonoxExport CommonController : public Controller
@@ -80,15 +80,26 @@
void moveToPosition(const Vector3& target);
void moveToTargetPosition();
+ //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes
-
+ //Mode mode_;
void copyOrientation(const Quaternion& orient);
void copyTargetOrientation();
+ /* bool isCloseAtTarget(float distance) const;
void doFire();
void aimAtTarget();
bool isLookingAtTarget(float angle) const;
+
+ std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
+ //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
+ float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
+ void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
+ bool bSetupWorked; //<! If false, setupWeapons() is called.
+ int getFiremode(std::string name);
+*/
+
bool bHasTargetPosition_;
Vector3 targetPosition_;
bool bHasTargetOrientation_;
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-10-31 22:50:17 UTC (rev 10736)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-01 08:10:08 UTC (rev 10737)
@@ -59,8 +59,9 @@
{
if (this->target_)
{
- this->aimAtTarget();
- this->doFire();
+ //this->aimAtTarget();
+ //this->doFire();
+ //this->bShooting_ = true;
}
if (this->bHasTargetPosition_)
@@ -75,7 +76,7 @@
{
setTargetPositionOfFollower();
setTargetPositionOfWingman();
-
+/*
for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
{
if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
@@ -84,7 +85,7 @@
this->setTargetPosition(this->target_->getWorldPosition());
break;
}
- }
+ }*/
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc 2015-10-31 22:50:17 UTC (rev 10736)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc 2015-11-01 08:10:08 UTC (rev 10737)
@@ -1086,4 +1086,12 @@
}
}
+ void FormationController::changedControllableEntity()
+ {
+ Controller::changedControllableEntity(); // super
+
+ // when changing the controllable entity, ensure that the controller does not use the new entity as target
+ if (this->target_ && this->getControllableEntity() == static_cast<ControllableEntity*>(this->target_))
+ this->forgetTarget();
+ }
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.h 2015-10-31 22:50:17 UTC (rev 10736)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.h 2015-11-01 08:10:08 UTC (rev 10737)
@@ -98,6 +98,8 @@
FormationController* getController( void ) { return this; }
FormationController* getSlave( void ) { return this->slaves_.back(); }
+ virtual void changedControllableEntity();
+
protected:
bool formationFlight_;
bool passive_;
More information about the Orxonox-commit
mailing list