[Orxonox-commit 6135] r10793 - code/branches/AI_HS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Tue Nov 10 16:37:35 CET 2015
Author: gania
Date: 2015-11-10 16:37:34 +0100 (Tue, 10 Nov 2015)
New Revision: 10793
Modified:
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/FleetController.cc
Log:
added choose maneuver type functionality
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-09 16:56:56 UTC (rev 10792)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-10 15:37:34 UTC (rev 10793)
@@ -54,6 +54,7 @@
this->executingManeuver_ = false;
this->executingMoveToPoint_ = false;
+ this->maneuverType_ = ManeuverType::NONE;
RegisterObject(CommonController);
}
@@ -115,7 +116,96 @@
}
}
+ void CommonController::chooseManeuverType()
+ {
+ if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity())
+ {
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+ Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
+ float myDotProduct = diffVector.dotProduct(myForwardVector);
+
+ Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
+ float opponentDotProduct = diffVector.dotProduct(opponentForwardVector);
+
+
+ switch ((myDotProduct > 0) - (myDotProduct < 0))
+ {
+ case 1:
+ {
+ switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+ {
+ case 1:
+ {
+ this->maneuverType_ = ManeuverType::OFFENSIVE;
+ break;
+ }
+ case 0:
+ {
+ this->maneuverType_ = ManeuverType::OFFENSIVE;
+ break;
+ }
+ case -1:
+ {
+ this->maneuverType_ = ManeuverType::NEUTRAL;
+ break;
+ }
+ }
+ break;
+ }
+ case 0:
+ {
+ switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+ {
+ case 1:
+ {
+ this->maneuverType_ = ManeuverType::OFFENSIVE;
+ break;
+ }
+ case 0:
+ {
+ this->maneuverType_ = ManeuverType::NEUTRAL;
+ break;
+ }
+ case -1:
+ {
+ this->maneuverType_ = ManeuverType::DEFENCIVE;
+ break;
+ }
+ }
+
+ break;
+ }
+ case -1:
+ {
+ switch ((opponentDotProduct > 0) - (opponentDotProduct < 0))
+ {
+ case 1:
+ {
+ this->maneuverType_ = ManeuverType::NEUTRAL;
+ break;
+ }
+ case 0:
+ {
+ this->maneuverType_ = ManeuverType::DEFENCIVE;
+ break;
+ }
+ case -1:
+ {
+ this->maneuverType_ = ManeuverType::DEFENCIVE;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ if (this->getControllableEntity() && !this->target_)
+ {
+ this->maneuverType_ = ManeuverType::NONE;
+ }
+ orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl;
+ }
bool CommonController::setWingman (CommonController* wingman)
{
return false;
@@ -129,12 +219,30 @@
{
this->target_ = target;
orxout (internal_error) << " TARGET SET " << endl;
- if (target)
- this->targetPosition_ = target->getPosition();
+
+ if (this->target_ )
+ {
+ this->setPositionOfTarget(target_->getWorldPosition());
+
+ }
}
+ bool CommonController::hasTarget()
+ {
+ if (this->target_)
+ return true;
+ return false;
+ }
+ void CommonController::setPositionOfTarget(const Vector3& target)
+ {
+ this->positionOfTarget_ = target;
+ this->bHasPositionOfTarget_ = true;
+ }
+ void CommonController::setOrientationOfTarget(const Quaternion& orient)
+ {
+ this->orientationOfTarget_=orient;
+ this->bHasOrientationOfTarget_=true;
+ }
-
-
void CommonController::setTargetPosition(const Vector3& target)
{
this->targetPosition_ = target;
@@ -369,8 +477,10 @@
this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
+
if (pawn)
- pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
+ //pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
+ pawn->setAimPosition(this->targetPosition_);
this->getControllableEntity()->fire(0);
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-09 16:56:56 UTC (rev 10792)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-10 15:37:34 UTC (rev 10793)
@@ -110,7 +110,7 @@
virtual bool hasWingman();
void setTarget(ControllableEntity* target);
-
+ bool hasTarget();
void setTargetOrientation(const Quaternion& orient);
void setTargetOrientation(ControllableEntity* target);
void setTargetPosition(const Vector3& target);
@@ -152,7 +152,8 @@
bool bHasTargetOrientation_;
Quaternion targetOrientation_;
-
+ void setPositionOfTarget(const Vector3& target);
+ void setOrientationOfTarget(const Quaternion& orient);
bool bHasPositionOfTarget_;
Vector3 positionOfTarget_;
bool bHasOrientationOfTarget_;
@@ -164,6 +165,7 @@
WeakPtr<ControllableEntity> objectiveTarget_;
+ void chooseManeuverType();
FormationMode::Value formationMode_;
Rank::Value rank_;
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-09 16:56:56 UTC (rev 10792)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-10 15:37:34 UTC (rev 10793)
@@ -56,6 +56,11 @@
void DivisionController::tick(float dt)
{
+ if (this->target_ )
+ {
+ this->setPositionOfTarget(target_->getWorldPosition());
+
+ }
/*if (this->target_)
{
this->aimAtTarget();
@@ -81,9 +86,42 @@
/*
Vector3* pos = new Vector3(4000,1000,2000);
this->setTargetPosition(*pos);*/
+
+/* if (!this->target_)
+ {
- setTargetPositionOfFollower();
- setTargetPositionOfWingman();
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*it)->getTeam())
+ continue;
+
+
+
+ if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
+ {
+ this->setTarget(*it);
+ }
+ }
+ }*/
+ this->chooseManeuverType();
+ switch (this->maneuverType_)
+ {
+ case ManeuverType::NONE:
+ {
+ setTargetPositionOfFollower();
+ setTargetPositionOfWingman();
+ break;
+ }
+ case ManeuverType::DEFENSIVE:
+ {
+ this->gunsD();
+ }
+ case ManeuverType::OFFENSIVE:
+ {
+ this->attack();
+ }
+ }
+
if (!executingMoveToPoint_)
{
Vector3* targetPosition = new Vector3 (0, 0, -2000);
Modified: code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc 2015-11-09 16:56:56 UTC (rev 10792)
+++ code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc 2015-11-10 15:37:34 UTC (rev 10793)
@@ -79,7 +79,22 @@
break;
}
}*/
+ for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+ {
+ if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
+ continue;
+ for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it)
+ {
+ if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget())
+ {
+ (*it)->setTarget(*itP);
+ }
+
+ }
+
+ }
+
}
void FleetController::tick(float dt)
{
More information about the Orxonox-commit
mailing list