[Orxonox-commit 6145] r10803 - in code/branches/AI_HS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Sat Nov 14 22:09:42 CET 2015
Author: gania
Date: 2015-11-14 22:09:41 +0100 (Sat, 14 Nov 2015)
New Revision: 10803
Modified:
code/branches/AI_HS15/data/levels/AITest.oxw
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
Log:
Works for DivisionController for now. Almost balanced AI! Dodges bullets (still killable, which is good), but goes crazy when close. So to be destroyed when far away. TODO: implement formation flight when not in fight
Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw 2015-11-14 15:31:10 UTC (rev 10802)
+++ code/branches/AI_HS15/data/levels/AITest.oxw 2015-11-14 21:09:41 UTC (rev 10803)
@@ -75,7 +75,7 @@
?>
- <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
+ <SpaceShip position="<?4000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
<templates>
<Template link=spaceshipassff />
</templates>
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-14 15:31:10 UTC (rev 10802)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-14 21:09:41 UTC (rev 10803)
@@ -46,7 +46,7 @@
RegisterClass( CommonController );
float SPEED = 0.9f/0.02f;
- float ROTATEFACTOR = 0.5f/0.02f;
+ float ROTATEFACTOR = 1.0f/0.02f;
CommonController::CommonController( Context* context ): Controller( context )
{
@@ -54,7 +54,7 @@
this->executingManeuver_ = false;
this->executingMoveToPoint_ = false;
-
+ this->stopLookingAtTarget();
this->maneuverType_ = ManeuverType::NONE;
RegisterObject( CommonController );
}
@@ -119,19 +119,21 @@
}
void CommonController::maneuver()
{
+ counter++;
- if ( this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity() )
+ if (counter > 5)
+ counter = 0;
+ if ( this->target_ && this->getControllableEntity())
{
- Vector3 thisPosition = this->getControllableEntity() ->getWorldPosition();
- Quaternion thisOrientation = this->getControllableEntity() ->getOrientation();
+ Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
+ //Quaternion thisOrientation = this->getControllableEntity()->getOrientation();
- /*this->setPositionOfTarget( getPredictedPosition(
+ this->setPositionOfTarget( getPredictedPosition(
thisPosition,
hardcoded_projectile_speed,
this->target_->getWorldPosition() ,
this->target_->getVelocity()
- ) );*/
- this->setPositionOfTarget( this->target_->getWorldPosition() );
+ ) );
this->setOrientationOfTarget( this->target_->getOrientation() );
@@ -139,208 +141,157 @@
float diffLength = diffVector.length();
Vector3 diffUnit = diffVector/diffLength;
- Vector3 thisForwardVector = thisOrientation * WorldEntity::FRONT;
- float thisDotProduct = diffVector.dotProduct( thisForwardVector );
- Vector3 targetForwardVector = this->orientationOfTarget_ * WorldEntity::FRONT;
- float targetDotProduct = diffVector.dotProduct( targetForwardVector );
- float thisAngle = getAngle( thisPosition, thisForwardVector, this->positionOfTarget_ );
- float targetAngle = getAngle( this->positionOfTarget_, targetForwardVector, thisPosition );
-
-
- bool bThisIsLookingAtTarget = ( thisAngle/( diffLength*diffLength ) < math::pi/8000000.0f );
- bool bTargetIsLookingAtThis = ( targetAngle/( diffLength*diffLength ) < math::pi/8000000.0f );
+ //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 );
+ bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/8.0f );
- float angleDiff = targetAngle - thisAngle;
- //if his angle is bigger than mine
- if ( angleDiff > 0 )
+
+ //too far? well, come closer then
+ if ( diffLength > 5000 )
{
- //if diff is insignificant
- if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis )
+ if (diffLength < 6000)
{
- //no way to dodge
- if ( diffLength < 400 )
- {
- Vector3* target = new Vector3 ( 0, -200, -200 );
- this->setTargetPosition( this->positionOfTarget_ );
-
-
- }
- //do scissors
- else
- {
- Vector3 target = ( diffUnit )* 150.0f;
- Vector3* randVector = new Vector3(
- randomInRange( -300, 300 ),
- randomInRange( -300, 300 ),
- randomInRange( -300, 300 )
- );
- Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
- *randVector -= projection;
- target += *randVector;
- this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target );
-
- }
+ this->bEngaging_ = true;
}
- //this has advantage
else
{
- //if too close
- if ( diffLength < 300 )
- {
- this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() );
- }
- //move closer
- else
- {
- this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector );
- }
+ this->bEngaging_ = false;
}
+ this->setTargetPosition( this->positionOfTarget_ );
}
- else
- {
- //if diff is insignificant
- if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis )
+ //too close? How do u expect to dodge anything? Just attack!
+ else if ( diffLength < 600 )
+ {
+ //at this point, just look and shoot
+ if ( diffLength < 300 )
{
- //no way to dodge
- if ( diffLength < 400 )
- {
- Vector3* target = new Vector3 ( 0, -200, -200 );
- this->setTargetPosition( this->positionOfTarget_ );
-
- }
- //do scissors
- else
- {
- Vector3 target = ( diffUnit )* 150.0f;
- Vector3* randVector = new Vector3(
- randomInRange( -300, 300 ),
- randomInRange( -300, 300 ),
- randomInRange( -300, 300 )
- );
- Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
- *randVector -= projection;
- target += *randVector;
- this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target );
-
- }
+ this->stopMoving();
+ this->startLookingAtTarget();
}
- //target has advantage
else
{
- //if too close
- if ( diffLength < 300 )
- {
- this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() );
- }
- //move closer
- else
- {
- this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector );
- }
+ this->setTargetPosition( this->positionOfTarget_ );
}
}
- this->bShooting_ = true;
-
- }
- if ( this->getControllableEntity() && !this->target_ )
- {
- this->maneuverType_ = ManeuverType::NONE;
- }
- orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
- }
- void CommonController::chooseManeuverType()
- {
-
- if ( this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity() )
- {
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
- Vector3 thisForwardVector = this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT;
- float thisDotProduct = diffVector.dotProduct( thisForwardVector );
-
- Vector3 targetForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
- float targetDotProduct = diffVector.dotProduct( targetForwardVector );
-
-
- switch ( ( thisDotProduct > 0 )- ( thisDotProduct < 0 ))
+ //Good distance? Check if target looks at us. It doesn't? Go hunt!
+ else if ( !bTargetIsLookingAtThis )
{
- case 1:
+ this->setTargetPosition( this->positionOfTarget_ );
+ /* if (counter == 0)
{
- switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
- {
- case 1:
- {
- this->maneuverType_ = ManeuverType::OFFENSIVE;
- break;
- }
- case 0:
- {
- this->maneuverType_ = ManeuverType::OFFENSIVE;
- break;
- }
- case -1:
- {
- this->maneuverType_ = ManeuverType::NEUTRAL;
- break;
- }
- }
- break;
+ this->setTargetPosition( this->positionOfTarget_ );
+ return;
}
- case 0:
+ else
{
- switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 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:
+ dodge( thisPosition, diffUnit );
+ }*/
+ }
+ //That's unfortunate, he is looking and probably shooting... try to dodge what we can...
+ else
+ {
+
+ if (counter == 0)
{
- switch ( ( targetDotProduct > 0 )- ( targetDotProduct < 0 ))
- {
- case 1:
- {
- this->maneuverType_ = ManeuverType::NEUTRAL;
- break;
- }
- case 0:
- {
- this->maneuverType_ = ManeuverType::DEFENCIVE;
- break;
- }
- case -1:
- {
- this->maneuverType_ = ManeuverType::DEFENCIVE;
- break;
- }
- }
- break;
+ this->setTargetPosition( this->positionOfTarget_ );
+ return;
}
+ dodge( thisPosition, diffUnit );
+
}
}
if ( this->getControllableEntity() && !this->target_ )
{
+ this->bEngaging_ = false;
this->maneuverType_ = ManeuverType::NONE;
}
orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
}
+ ControllableEntity* CommonController::getTarget()
+ {
+ return this->target_;
+ }
+ void CommonController::dodge(Vector3& thisPosition, Vector3& diffUnit)
+ {
+ float factorX = 0, factorY = 0, factorZ = 0;
+ float rand = randomInRange (0, 1);
+ if (rand <= 0.5)
+ {
+ factorX = 1;
+ }
+ else
+ {
+ factorX = -1;
+ }
+ rand = randomInRange (0, 1);
+ if (rand <= 0.5)
+ {
+ factorY = 1;
+ }
+ else
+ {
+ factorY = -1;
+ }
+ rand = randomInRange (0, 1);
+ if (rand <= 0.5)
+ {
+ factorZ = 1;
+ }
+ else
+ {
+ factorZ = -1;
+ }
+ Vector3 target = ( diffUnit )* 8000.0f;
+ Vector3* randVector = new Vector3(
+ factorX * randomInRange( 10000, 40000 ),
+ factorY * randomInRange( 10000, 40000 ),
+ factorZ * randomInRange( 10000, 40000 )
+ );
+ Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
+ *randVector -= projection;
+ target += *randVector;
+ this->setTargetPosition( thisPosition + target );
+ }
+ void CommonController::stopMoving()
+ {
+ this->bHasTargetPosition_ = false;
+ }
+ void CommonController::startLookingAtTarget()
+ {
+ this->bLookAtTarget_ = true;
+ }
+ void CommonController::stopLookingAtTarget()
+ {
+ this->bLookAtTarget_ = false;
+ }
+ void CommonController::lookAtTarget(float dt)
+ {
+
+
+ ControllableEntity* entity = this->getControllableEntity();
+ if ( !entity )
+ return;
+ Vector2 coord = get2DViewCoordinates
+ ( entity->getPosition() ,
+ entity->getOrientation() * WorldEntity::FRONT,
+ entity->getOrientation() * WorldEntity::UP,
+ positionOfTarget_ );
+
+ //rotates should be in range [-1,+1], clamp cuts off all that is not
+ float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
+ float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
+
+
+
+ //Yaw and Pitch are enough to start facing the target
+ this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
+ this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
+
+
+ }
+
bool CommonController::setWingman ( CommonController* wingman )
{
return false;
@@ -396,23 +347,8 @@
setTargetOrientation( target->getOrientation() );
}
- /*void CommonController::spin()
- {
- this->moveToTargetPosition();
- this->getControllableEntity() ->rotateRoll( 8.0f );
- }
- void CommonController::turn180()
- {
- Vector2 coord = get2DViewdirection( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->getControllableEntity() ->getOrientation() * WorldEntity::UP, this->targetPosition_ );
- this->getControllableEntity() ->rotateYaw( -2.0f * sgn( coord.x )* coord.x*coord.x );
- this->getControllableEntity() ->rotatePitch( 2.0f * sgn( coord.y )* coord.y*coord.y );
- this->getControllableEntity() ->moveFrontBack( SPEED );
- }*/
-
-
-
//copy the Roll orientation of given Quaternion.
void CommonController::copyOrientation( const Quaternion& orient, float dt )
{
@@ -443,13 +379,13 @@
if ( !this->getControllableEntity() )
return;
if ( this->rank_ == Rank::DIVISIONLEADER )
- factor = 0.8;
- if ( this->rank_ == Rank::SECTIONLEADER )
factor = 0.9;
+ if ( this->rank_ == Rank::SECTIONLEADER )
+ factor = 0.95;
//100 is ( so far )the smallest tolerance ( empirically found )that can be reached,
//with smaller distance spaceships can't reach position and go circles around it instead
- int tolerance = 60;
+ int tolerance = 65;
ControllableEntity* entity = this->getControllableEntity();
Vector2 coord = get2DViewCoordinates
@@ -461,15 +397,15 @@
float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
//rotates should be in range [-1,+1], clamp cuts off all that is not
- float rotateX = clamp( coord.x * 10, -1.0f, 1.0f );
+ float rotateX = -clamp( coord.x * 10, -1.0f, 1.0f );
float rotateY = clamp( coord.y * 10, -1.0f, 1.0f );
if ( distance > tolerance )
{
//Yaw and Pitch are enough to start facing the target
- this->getControllableEntity() ->rotateYaw( -2.0f * ROTATEFACTOR * rotateX * dt );
- this->getControllableEntity() ->rotatePitch( 2.0f * ROTATEFACTOR * rotateY * dt );
+ this->getControllableEntity() ->rotateYaw( ROTATEFACTOR * rotateX * dt );
+ this->getControllableEntity() ->rotatePitch( ROTATEFACTOR * rotateY * dt );
//300 works, maybe less is better
if ( distance < 400 )
@@ -484,7 +420,7 @@
}
}
- this->getControllableEntity() ->moveFrontBack( 1.2f*SPEED*factor * dt );
+ this->getControllableEntity() ->moveFrontBack( SPEED*factor * dt );
}
else
{
@@ -499,192 +435,8 @@
float r = random * diff;
return a + r;
}
- void CommonController::attack()
- {
- if ( !this->getControllableEntity() )
- return;
- if ( this->target_ )
- {
- this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity() ->getWorldPosition() ,
- hardcoded_projectile_speed,
- this->target_->getWorldPosition() ,
- this->target_->getVelocity()
- );
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
- float diffLength = diffVector.length();
- if ( diffLength < 100 )
- {
- Vector3* targetPosition;
- targetPosition = new Vector3 (
- //randomInRange( 200, 300 ),
- 0,
- //randomInRange( -300, -200 ),
- 0,
- randomInRange( -300, -400 )
- );
- Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ).getRotationTo( diffVector );
- Vector3 target = rotationToTarget * ( *targetPosition );
- moveToPoint(
- target,
- randomInRange( 45, 180 )
- );
- executingMoveToPoint_ = true;
- return;
- }
- this->bShooting_ = true;
- this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity() ->getWorldPosition() ,
- hardcoded_projectile_speed,
- this->target_->getWorldPosition() ,
- this->target_->getVelocity()
- );
- this->targetPosition_ = positionOfTarget_;
+
- }
- else
- {
- this->chooseManeuverType();
- }
- }
- void CommonController::scissors()
- {
- if ( !this->getControllableEntity() )
- return;
- if ( this->target_ )
- {
- this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity() ->getWorldPosition() ,
- hardcoded_projectile_speed,
- this->target_->getWorldPosition() ,
- this->target_->getVelocity()
- );
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
- float diffLength = diffVector.length();
- Vector3 targetForwardVector = this->target_->getOrientation() * WorldEntity::FRONT;
- float targetDotProduct = diffVector.dotProduct( targetForwardVector );
-
- int f = ( int )rnd( 100.0f );
- f = ( f % 2 == 0 ? 1 : -1 );
-
- if( !this->executingMoveToPoint_ )
- {
- Vector3* targetPosition;
- if ( diffLength < 100 )
- {
- targetPosition = new Vector3 (
- //f * randomInRange( 200, 300 ),
- 0,
- //f * randomInRange( -300, -200 ),
- 0,
- //randomInRange( -300, -400 )
- 0
- );
- }
- else
- {
- if ( targetDotProduct < 0 )
- {
- targetPosition = new Vector3 (
- //f * randomInRange( 200, 300 ),
- 0,
- //f * randomInRange( -300, -200 ),
- 0,
- //randomInRange( -300, -400 )
- -300
- );
- }
- else
- {
- targetPosition = new Vector3 (
- //f * randomInRange( 200, 300 ),
- 0,
- //f * randomInRange( -300, -200 ),
- 0,
- //randomInRange( -300, -400 )
- 300
- );
- }
- }
- Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ).getRotationTo( diffVector );
- Vector3 target = rotationToTarget * ( *targetPosition );
- moveToPoint(
- target,
- randomInRange( 45, 180 )
- );
- executingMoveToPoint_ = true;
- }
- }
-
- else
- {
- this->chooseManeuverType();
- }
- }
- void CommonController::gunsD()
- {
- if ( !this->getControllableEntity() )
- return;
- if ( this->target_ )
- {
- this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity() ->getWorldPosition() ,
- hardcoded_projectile_speed,
- this->target_->getWorldPosition() ,
- this->target_->getVelocity()
- );
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity() ->getWorldPosition();
- float diffLength = diffVector.length();
- if( !this->executingMoveToPoint_ )
- {
- Vector3* targetPosition;
- if ( diffLength < 200 )
- {
- targetPosition = new Vector3 (
- //f * randomInRange( 200, 300 ),
- 0,
- //f * randomInRange( -300, -200 ),
- 0,
- //randomInRange( -300, -400 )
- 0
- );
- }
- else if ( diffLength < 500 )
- {
- targetPosition = new Vector3 (
- //randomInRange( 100, 200 ),
- 0,
- //randomInRange( -200, -100 ),
- 0,
- //randomInRange( -400, -600 )
- 500
- );
- }
- else
- {
- targetPosition = new Vector3 (
- //randomInRange( 200, 300 ),
- 0,
- //randomInRange( -300, -200 ),
- 0,
- //randomInRange( -400, -600 )
- 500
- );
- }
- Quaternion rotationToTarget = ( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT ).getRotationTo( diffVector );
- Vector3 target = rotationToTarget * ( *targetPosition );
- moveToPoint(
- target,
- randomInRange( 45, 180 )
- );
- executingMoveToPoint_ = true;
- }
- }
- else
- {
- this->chooseManeuverType();
- }
- }
//to be called in action
//PRE: relativeTargetPosition is desired position relative to the spaceship,
//angleRoll is the angle in degrees of Roll that should be applied by the end of the movement
@@ -768,7 +520,7 @@
{
if ( !this->getControllableEntity() )
return 0;
- if ( !this->target_ )
+ if ( !this->target_ || !this->getControllableEntity() )
return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
else
return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
@@ -776,19 +528,38 @@
bool CommonController::isLookingAtTarget( float angle )const
{
- if ( !this->getControllableEntity() )
+ if ( !this->getControllableEntity() || !this->target_ )
return false;
- return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->positionOfTarget_ ) < angle );
+ return ( getAngle( this->getControllableEntity() ->getPosition() ,
+ this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->positionOfTarget_ ) < angle );
}
+ bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const
+ {
+ if ( !entityThatLooks || !entityBeingLookedAt )
+ return false;
+ return ( getAngle( entityThatLooks ->getPosition() ,
+ entityThatLooks->getOrientation() * WorldEntity::FRONT,
+ entityBeingLookedAt->getWorldPosition() ) < angle );
+ }
bool CommonController::canFire()
{
- float squaredDistance = squaredDistanceToTarget();
- this->setPositionOfTarget( this->target_->getPosition() );
- if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget( math::pi /( 0.0002f*squaredDistance )) )
+ //no target? why fire?
+ if ( !this->target_ )
+ return false;
+
+ Vector3 newPositionOfTarget = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() ,
+ hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
+ if ( newPositionOfTarget != Vector3::ZERO )
{
+ this->setPositionOfTarget( newPositionOfTarget );
+ }
+
+ float squaredDistance = squaredDistanceToTarget();
+
+ if ( squaredDistance < 25000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {
return true;
}
else
@@ -800,12 +571,12 @@
void CommonController::doFire()
{
if ( !this->target_ || !this->getControllableEntity() )
+ {
return;
- static const float hardcoded_projectile_speed = 750;
+ }
+
- this->positionOfTarget_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
- this->bHasPositionOfTarget_ = ( this->positionOfTarget_ != Vector3::ZERO );
-
+
Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
if ( pawn )
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-14 15:31:10 UTC (rev 10802)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-11-14 21:09:41 UTC (rev 10803)
@@ -80,9 +80,9 @@
{
public:
- static const float hardcoded_projectile_speed = 750;
+ static const float hardcoded_projectile_speed = 750;
- static const float ACTION_INTERVAL = 2.0f;
+ static const float ACTION_INTERVAL = 1.0f;
CommonController(Context* context);
@@ -113,6 +113,7 @@
void setTarget(ControllableEntity* target);
bool hasTarget();
+ ControllableEntity* getTarget();
void setTargetOrientation(const Quaternion& orient);
void setTargetOrientation(ControllableEntity* target);
void setTargetPosition(const Vector3& target);
@@ -122,7 +123,8 @@
protected:
-
+ void dodge(Vector3& thisPosition, Vector3& diffUnit);
+ int counter;
void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
bool moveAndRoll(float dt);
@@ -138,6 +140,7 @@
void doFire();
void aimAtTarget();
bool isLookingAtTarget(float angle) const;
+ bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const;
//checks if spaceship points at enemy and if there are allies inbetween
bool canFire();
@@ -154,6 +157,7 @@
bool bHasTargetOrientation_;
Quaternion targetOrientation_;
+ void stopMoving();
void setPositionOfTarget(const Vector3& target);
void setOrientationOfTarget(const Quaternion& orient);
bool bHasPositionOfTarget_;
@@ -163,9 +167,16 @@
WeakPtr<ControllableEntity> target_;
+ //WeakPtr<ControllableEntity> thisEntity_;
+
+ bool bEngaging_;
bool bShooting_;
WeakPtr<ControllableEntity> objectiveTarget_;
+ void lookAtTarget(float dt);
+ void stopLookingAtTarget();
+ void startLookingAtTarget();
+ bool bLookAtTarget_;
void maneuver();
void chooseManeuverType();
void gunsD();
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-14 15:31:10 UTC (rev 10802)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-11-14 21:09:41 UTC (rev 10803)
@@ -55,142 +55,31 @@
void DivisionController::tick(float dt)
- {
- if (this->target_ )
- {
- this->setPositionOfTarget(target_->getWorldPosition());
-
- }
- /*if (this->target_)
- {
- this->aimAtTarget();
- this->doFire();
- this->bShooting_ = true;
- }*/
-
+ {
+ if (!this->isActive())
+ return;
if (this->bHasTargetPosition_)
{
this->moveToTargetPosition(dt);
}
- /* if (executingMoveToPoint_)
+ else if (this->bLookAtTarget_)
{
- executingMoveToPoint_ = !this->moveAndRoll(dt);
+ this->lookAtTarget(dt);
}
- else
+ if (bShooting_)
{
- if (this->target_)
- {
- this->positionOfTarget_ = getPredictedPosition(
- this->getControllableEntity()->getWorldPosition(),
- hardcoded_projectile_speed,
- this->target_->getWorldPosition(),
- this->target_->getVelocity()
- );
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
- float diffLength = diffVector.length();
- Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
- Vector3* targetPosition = new Vector3 ( 0, 0, -200 );
- Vector3 target = rotationToTarget * (*targetPosition);
- if (diffLength > 200)
- this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector);
-
- else
- this->setTargetPosition( this->getControllableEntity()->getWorldPosition() );
- executingMoveToPoint_ = true;
- }
-
-
- if (this->maneuverType_ == ManeuverType::OFFENSIVE)
- {
- this->attack();
- this->moveAndRoll(dt);
- }
- }*/
- if (this->bShooting_ && this->canFire())
- doFire();
+ this->doFire();
+ }
+
SUPER(DivisionController, tick, dt);
}
void DivisionController::action()
{
-/*
- Vector3* pos = new Vector3(4000,1000,2000);
- this->setTargetPosition(*pos);*/
-
-/* if (!this->target_)
- {
+ this->maneuver();
+ this->bShooting_ = this->canFire();
+
- 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();
- this->maneuver();
-
- switch (this->maneuverType_)
- {
- case ManeuverType::NONE:
- {
- setTargetPositionOfFollower();
- setTargetPositionOfWingman();
- break;
- }
- case ManeuverType::DEFENCIVE:
- {
- this->gunsD();
- break;
- }
- case ManeuverType::OFFENSIVE:
- {
- this->attack();
- break;
- }
- case ManeuverType::NEUTRAL:
- {
- this->scissors();
- }
- default:
- {
- this->gunsD();
- break;
- }
- }
-
- /*if (!executingMoveToPoint_)
- {
- Vector3* targetPosition = new Vector3 (0, 0, -2000);
- moveToPoint(*targetPosition, 180);
- executingMoveToPoint_ = true;
- }
- */
- // if (this->myFollower_ && this->target_)
- // this->myFollower_->setTarget(this->target_);
- // if (this->target_ && this->myWingman_)
- // this->myWingman_->setTarget(this->target_);
- /*
- for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
- {
- if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
- {
- this->setTargetPosition(it->getControllableEntity()->getWorldPosition());
-
- break;
- }
- }
- */
- if (canFire())
- this->bShooting_ = true;
- else
- this->bShooting_ = false;
}
More information about the Orxonox-commit
mailing list