Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2872


Ignore:
Timestamp:
Mar 31, 2009, 1:15:52 AM (15 years ago)
Author:
landauf
Message:

some small adjustments in PongAI and related classes

Location:
code/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/controllers/HumanController.cc

    r2662 r2872  
    3535#include "objects/worldentities/pawns/Pawn.h"
    3636#include "objects/gametypes/Gametype.h"
     37#include "objects/infos/PlayerInfo.h"
    3738
    3839namespace orxonox
     
    157158            if (pawn)
    158159                pawn->kill();
     160            else if (HumanController::localController_s->player_)
     161                HumanController::localController_s->player_->stopControl(HumanController::localController_s->controllableEntity_);
    159162        }
    160163    }
  • code/trunk/src/orxonox/objects/controllers/PongAI.cc

    r2860 r2872  
    5555
    5656        this->setConfigValues();
    57 
    58 //        this->randomOffsetTimer_.setTimer(MAX_REACTION_TIME * (1 - this->strength_), false, this, createExecutor(createFunctor(&PongAI::calculateRandomOffset)));
    59 //        this->ballEndPositionTimer_.setTimer(MAX_REACTION_TIME * (1 - this->strength_), false, this, createExecutor(createFunctor(&PongAI::calculateBallEndPosition)));
    60 //        this->randomOffsetTimer_.stopTimer();
    61 //        this->ballEndPositionTimer_.stopTimer();
    6257    }
    6358
     
    8883        if ((mypos.x > 0 && ballvel.x < 0) || (mypos.x < 0 && ballvel.x > 0))
    8984        {
    90             // Ball is flying away
     85            // The ball is flying away
    9186            this->ballDirection_.x = -1;
    9287            this->ballDirection_.y = 0;
    9388
     89            // Move to the middle
    9490            if (mypos.z > hysteresisOffset)
    9591                move = 1;
     
    9995        else if (ballvel.x == 0)
    10096        {
    101             // Ball is standing still
     97            // The ball is standing still
    10298            this->ballDirection_.x = 0;
    10399            this->ballDirection_.y = 0;
     
    105101        else
    106102        {
    107             // Ball is approaching
     103            // The ball is approaching
    108104            if (this->ballDirection_.x != 1)
    109105            {
     106                // The ball just startet to approach, initialize all values
    110107                this->ballDirection_.x = 1;
    111108                this->ballDirection_.y = sgn(ballvel.z);
     
    115112                this->calculateRandomOffset();
    116113                this->calculateBallEndPosition();
    117                 //this->randomOffsetTimer_.setInterval(MAX_REACTION_TIME * (1 - this->strength_));
    118                 //this->ballEndPositionTimer_.setInterval(MAX_REACTION_TIME * (1 - this->strength_));
    119                 //this->randomOffsetTimer_.startTimer();
    120                 //this->ballEndPositionTimer_.startTimer();
    121114            }
    122115
    123116            if (this->ballDirection_.y != sgn(ballvel.z))
    124117            {
     118                // The ball just bounced from a bound, recalculate the predicted end position
    125119                this->ballDirection_.y = sgn(ballvel.z);
    126120
    127121                this->calculateBallEndPosition();
    128                 //this->ballEndPositionTimer_.startTimer();
    129             }
    130 
    131             float desiredZValue = /*((1 - this->strength_) * ballpos.z) + */(/*this->strength_ * */this->ballEndPosition_) + this->randomOffset_;
     122            }
     123
     124            // Move to the predicted end position with an additional offset (to hit the ball with the side of the bat)
     125            float desiredZValue = this->ballEndPosition_ + this->randomOffset_;
    132126
    133127            if (mypos.z > desiredZValue + hysteresisOffset * (this->randomOffset_ < 0))
     
    156150
    157151        // Both sides are equally probable
    158         position *= sgn(rnd(-1,1));
     152        position *= rndsgn();
    159153
    160154        // Calculate the offset in world units
     
    174168        for (float limit = 0.35; limit < this->strength_ || this->strength_ > 0.99; limit += 0.4)
    175169        {
     170            // Bounce from the upper bound
    176171            if (this->ballEndPosition_ > dimension.y / 2)
    177172            {
     173                // Mirror the predicted position at the upper bound and add some random error
    178174                this->ballEndPosition_ = dimension.y - this->ballEndPosition_ + (rnd(-1, 1) * dimension.y * (1 - this->strength_));
    179175                continue;
    180176            }
     177            // Bounce from the upper bound
    181178            if (this->ballEndPosition_ < -dimension.y / 2)
    182179            {
     180                // Mirror the predicted position at the lower bound and add some random error
    183181                this->ballEndPosition_ = -dimension.y - this->ballEndPosition_ + (rnd(-1, 1) * dimension.y * (1 - this->strength_));
    184182                continue;
    185183            }
     184            // No bounce - break
    186185            break;
    187186        }
     
    216215    void PongAI::delayedMove()
    217216    {
     217        // Get the new movement direction from the timer list
    218218        this->movement_ = this->reactionTimers_.front().second;
    219219
     220        // Destroy the timer and remove it from the list
    220221        Timer<PongAI>* timer = this->reactionTimers_.front().first;
    221222        delete timer;
  • code/trunk/src/orxonox/objects/controllers/PongAI.h

    r2860 r2872  
    6666            float strength_;
    6767
    68 //            Timer<PongAI> randomOffsetTimer_;
    69 //            Timer<PongAI> ballEndPositionTimer_;
    7068            std::list<std::pair<Timer<PongAI>*, char> > reactionTimers_;
    7169            char movement_;
  • code/trunk/src/orxonox/objects/gametypes/Pong.cc

    r2839 r2872  
    151151        Deathmatch::playerScored(player);
    152152
     153        if (this->center_)
     154        {
     155            this->center_->fireEvent();
     156        }
     157
    153158        if (this->ball_)
    154159        {
  • code/trunk/src/util/Math.h

    r2756 r2872  
    270270    }
    271271
     272    /**
     273        @brief Returns randomly 1 or -1 with equal probability.
     274    */
     275    inline float rndsgn()
     276    {
     277        return ((rand() & 0x2) - 1); // rand() & 0x2 is either 2 or 0
     278    }
     279
    272280    _UtilExport unsigned long getUniqueNumber();
    273281
Note: See TracChangeset for help on using the changeset viewer.