[Orxonox-commit 201] r2872 - in trunk/src: orxonox/objects/controllers orxonox/objects/gametypes util
landauf at orxonox.net
landauf at orxonox.net
Tue Mar 31 01:15:53 CEST 2009
Author: landauf
Date: 2009-03-30 23:15:52 +0000 (Mon, 30 Mar 2009)
New Revision: 2872
Modified:
trunk/src/orxonox/objects/controllers/HumanController.cc
trunk/src/orxonox/objects/controllers/PongAI.cc
trunk/src/orxonox/objects/controllers/PongAI.h
trunk/src/orxonox/objects/gametypes/Pong.cc
trunk/src/util/Math.h
Log:
some small adjustments in PongAI and related classes
Modified: trunk/src/orxonox/objects/controllers/HumanController.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/HumanController.cc 2009-03-30 21:42:30 UTC (rev 2871)
+++ trunk/src/orxonox/objects/controllers/HumanController.cc 2009-03-30 23:15:52 UTC (rev 2872)
@@ -34,6 +34,7 @@
#include "objects/worldentities/ControllableEntity.h"
#include "objects/worldentities/pawns/Pawn.h"
#include "objects/gametypes/Gametype.h"
+#include "objects/infos/PlayerInfo.h"
namespace orxonox
{
@@ -156,6 +157,8 @@
Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_);
if (pawn)
pawn->kill();
+ else if (HumanController::localController_s->player_)
+ HumanController::localController_s->player_->stopControl(HumanController::localController_s->controllableEntity_);
}
}
Modified: trunk/src/orxonox/objects/controllers/PongAI.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/PongAI.cc 2009-03-30 21:42:30 UTC (rev 2871)
+++ trunk/src/orxonox/objects/controllers/PongAI.cc 2009-03-30 23:15:52 UTC (rev 2872)
@@ -54,11 +54,6 @@
this->movement_ = 0;
this->setConfigValues();
-
-// this->randomOffsetTimer_.setTimer(MAX_REACTION_TIME * (1 - this->strength_), false, this, createExecutor(createFunctor(&PongAI::calculateRandomOffset)));
-// this->ballEndPositionTimer_.setTimer(MAX_REACTION_TIME * (1 - this->strength_), false, this, createExecutor(createFunctor(&PongAI::calculateBallEndPosition)));
-// this->randomOffsetTimer_.stopTimer();
-// this->ballEndPositionTimer_.stopTimer();
}
PongAI::~PongAI()
@@ -87,10 +82,11 @@
// Check in which direction the ball is flying
if ((mypos.x > 0 && ballvel.x < 0) || (mypos.x < 0 && ballvel.x > 0))
{
- // Ball is flying away
+ // The ball is flying away
this->ballDirection_.x = -1;
this->ballDirection_.y = 0;
+ // Move to the middle
if (mypos.z > hysteresisOffset)
move = 1;
else if (mypos.z < -hysteresisOffset)
@@ -98,15 +94,16 @@
}
else if (ballvel.x == 0)
{
- // Ball is standing still
+ // The ball is standing still
this->ballDirection_.x = 0;
this->ballDirection_.y = 0;
}
else
{
- // Ball is approaching
+ // The ball is approaching
if (this->ballDirection_.x != 1)
{
+ // The ball just startet to approach, initialize all values
this->ballDirection_.x = 1;
this->ballDirection_.y = sgn(ballvel.z);
this->ballEndPosition_ = 0;
@@ -114,21 +111,18 @@
this->calculateRandomOffset();
this->calculateBallEndPosition();
- //this->randomOffsetTimer_.setInterval(MAX_REACTION_TIME * (1 - this->strength_));
- //this->ballEndPositionTimer_.setInterval(MAX_REACTION_TIME * (1 - this->strength_));
- //this->randomOffsetTimer_.startTimer();
- //this->ballEndPositionTimer_.startTimer();
}
if (this->ballDirection_.y != sgn(ballvel.z))
{
+ // The ball just bounced from a bound, recalculate the predicted end position
this->ballDirection_.y = sgn(ballvel.z);
this->calculateBallEndPosition();
- //this->ballEndPositionTimer_.startTimer();
}
- float desiredZValue = /*((1 - this->strength_) * ballpos.z) + */(/*this->strength_ * */this->ballEndPosition_) + this->randomOffset_;
+ // Move to the predicted end position with an additional offset (to hit the ball with the side of the bat)
+ float desiredZValue = this->ballEndPosition_ + this->randomOffset_;
if (mypos.z > desiredZValue + hysteresisOffset * (this->randomOffset_ < 0))
move = 1;
@@ -155,7 +149,7 @@
position *= 0.48;
// Both sides are equally probable
- position *= sgn(rnd(-1,1));
+ position *= rndsgn();
// Calculate the offset in world units
this->randomOffset_ = position * this->ball_->getBatLength() * this->ball_->getFieldDimension().y;
@@ -173,16 +167,21 @@
// Calculate bounces
for (float limit = 0.35; limit < this->strength_ || this->strength_ > 0.99; limit += 0.4)
{
+ // Bounce from the upper bound
if (this->ballEndPosition_ > dimension.y / 2)
{
+ // Mirror the predicted position at the upper bound and add some random error
this->ballEndPosition_ = dimension.y - this->ballEndPosition_ + (rnd(-1, 1) * dimension.y * (1 - this->strength_));
continue;
}
+ // Bounce from the upper bound
if (this->ballEndPosition_ < -dimension.y / 2)
{
+ // Mirror the predicted position at the lower bound and add some random error
this->ballEndPosition_ = -dimension.y - this->ballEndPosition_ + (rnd(-1, 1) * dimension.y * (1 - this->strength_));
continue;
}
+ // No bounce - break
break;
}
}
@@ -215,8 +214,10 @@
void PongAI::delayedMove()
{
+ // Get the new movement direction from the timer list
this->movement_ = this->reactionTimers_.front().second;
+ // Destroy the timer and remove it from the list
Timer<PongAI>* timer = this->reactionTimers_.front().first;
delete timer;
Modified: trunk/src/orxonox/objects/controllers/PongAI.h
===================================================================
--- trunk/src/orxonox/objects/controllers/PongAI.h 2009-03-30 21:42:30 UTC (rev 2871)
+++ trunk/src/orxonox/objects/controllers/PongAI.h 2009-03-30 23:15:52 UTC (rev 2872)
@@ -65,8 +65,6 @@
float relHysteresisOffset_;
float strength_;
-// Timer<PongAI> randomOffsetTimer_;
-// Timer<PongAI> ballEndPositionTimer_;
std::list<std::pair<Timer<PongAI>*, char> > reactionTimers_;
char movement_;
};
Modified: trunk/src/orxonox/objects/gametypes/Pong.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/Pong.cc 2009-03-30 21:42:30 UTC (rev 2871)
+++ trunk/src/orxonox/objects/gametypes/Pong.cc 2009-03-30 23:15:52 UTC (rev 2872)
@@ -150,6 +150,11 @@
{
Deathmatch::playerScored(player);
+ if (this->center_)
+ {
+ this->center_->fireEvent();
+ }
+
if (this->ball_)
{
this->ball_->setPosition(Vector3::ZERO);
Modified: trunk/src/util/Math.h
===================================================================
--- trunk/src/util/Math.h 2009-03-30 21:42:30 UTC (rev 2871)
+++ trunk/src/util/Math.h 2009-03-30 23:15:52 UTC (rev 2872)
@@ -269,6 +269,14 @@
return rnd(max - min) + min;
}
+ /**
+ @brief Returns randomly 1 or -1 with equal probability.
+ */
+ inline float rndsgn()
+ {
+ return ((rand() & 0x2) - 1); // rand() & 0x2 is either 2 or 0
+ }
+
_UtilExport unsigned long getUniqueNumber();
class IntVector2
More information about the Orxonox-commit
mailing list