Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2839


Ignore:
Timestamp:
Mar 25, 2009, 3:26:06 AM (15 years ago)
Author:
landauf
Message:

added AI for the Pong gametype
improved Pong gameplay

Location:
code/trunk/src/orxonox
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r2826 r2839  
    192192    class AIController;
    193193    class ScriptController;
     194    class PongAI;
    194195
    195196    class Info;
     
    197198    class HumanPlayer;
    198199    class Bot;
     200    class PongBot;
    199201    class GametypeInfo;
    200202
  • code/trunk/src/orxonox/objects/controllers/CMakeLists.txt

    r2710 r2839  
    55  AIController.cc
    66  ScriptController.cc
     7  PongAI.cc
    78)
  • code/trunk/src/orxonox/objects/gametypes/Gametype.cc

    r2826 r2839  
    200200                // Reward killer
    201201                if (killer)
    202                     this->playerScored(killer->getPlayer());
     202                {
     203                    std::map<PlayerInfo*, Player>::iterator it = this->players_.find(killer->getPlayer());
     204                    if (it != this->players_.end())
     205                        it->second.frags_++;
     206                }
    203207
    204208                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
     
    348352    {
    349353        for (unsigned int i = 0; i < amount; ++i)
    350             new Bot(this);
     354            this->botclass_.fabricate(this);
    351355    }
    352356
  • code/trunk/src/orxonox/objects/gametypes/Gametype.h

    r2826 r2839  
    142142            float initialStartCountdown_;
    143143            unsigned int numberOfBots_;
     144            SubclassIdentifier<Bot> botclass_;
    144145
    145146            std::map<PlayerInfo*, Player> players_;
  • code/trunk/src/orxonox/objects/gametypes/Pong.cc

    r2826 r2839  
    3737#include "objects/worldentities/PongBall.h"
    3838#include "objects/worldentities/PongBat.h"
    39 #include "objects/infos/PlayerInfo.h"
     39#include "objects/infos/HumanPlayer.h"
     40#include "objects/infos/PongBot.h"
     41#include "objects/controllers/PongAI.h"
    4042
    4143namespace orxonox
     
    5658        this->starttimer_.setTimer(1.0, false, this, createExecutor(createFunctor(&Pong::startBall)));
    5759        this->starttimer_.stopTimer();
     60
     61        this->botclass_ = Class(PongBot);
    5862    }
    5963
     
    133137            this->players_[player].state_ = PlayerState::Alive;
    134138        }
     139        else
     140            return;
     141
     142        if (player && player->getController() && player->getController()->isA(Class(PongAI)))
     143        {
     144            PongAI* ai = dynamic_cast<PongAI*>(player->getController());
     145            ai->setPongBall(this->ball_);
     146        }
    135147    }
    136148
  • code/trunk/src/orxonox/objects/infos/CMakeLists.txt

    r2710 r2839  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    22  Bot.cc
     3  PongBot.cc
    34  Info.cc
    45  PlayerInfo.cc
  • code/trunk/src/orxonox/objects/infos/PlayerInfo.cc

    r2826 r2839  
    110110    void PlayerInfo::createController()
    111111    {
     112        if (this->controller_)
     113        {
     114            delete this->controller_;
     115            this->controller_ = 0;
     116        }
    112117        this->controller_ = this->defaultController_.fabricate(this);
    113118        assert(this->controller_);
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2826 r2839  
    251251            }
    252252        }
     253
     254        this->changedPlayer();
    253255    }
    254256
     
    263265        this->bHasHumanController_ = false;
    264266        this->setObjectMode(objectDirection::toclient);
     267
     268        this->changedPlayer();
    265269
    266270        if (this->bDestroyWhenPlayerLeft_)
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h

    r2662 r2839  
    4949
    5050            virtual void changedGametype();
     51            virtual void changedPlayer() {}
    5152
    5253            virtual void setPlayer(PlayerInfo* player);
  • code/trunk/src/orxonox/objects/worldentities/PongBall.cc

    r2826 r2839  
    4444        this->speed_ = 0;
    4545        this->bat_ = 0;
     46        this->relMercyOffset_ = 0.05;
    4647    }
    4748
     
    6768            if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
    6869            {
    69                 velocity.x = -velocity.x;
    7070                float distance = 0;
    7171
    72                 if (position.x > this->fieldWidth_ / 2)
     72                if (this->bat_)
    7373                {
    74                     position.x = this->fieldWidth_ / 2;
    75                     if (this->bat_ && this->bat_[1])
     74                    if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
    7675                    {
    77                         distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
    78                         if (this->getGametype() && this->bat_[0] && fabs(distance) > 1)
     76                        distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     77                        if (fabs(distance) <= 1)
    7978                        {
    80                             this->getGametype()->playerScored(this->bat_[0]->getPlayer());
    81                             return;
     79                            position.x = this->fieldWidth_ / 2;
     80                            velocity.x = -velocity.x;
     81                            velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
     82                        }
     83                        else if (position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     84                        {
     85                            if (this->getGametype() && this->bat_[0])
     86                            {
     87                                this->getGametype()->playerScored(this->bat_[0]->getPlayer());
     88                                return;
     89                            }
     90                        }
     91                    }
     92                    if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     93                    {
     94                        distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     95                        if (fabs(distance) <= 1)
     96                        {
     97                            position.x = -this->fieldWidth_ / 2;
     98                            velocity.x = -velocity.x;
     99                            velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
     100                        }
     101                        else if (position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))
     102                        {
     103                            if (this->getGametype() && this->bat_[1])
     104                            {
     105                                this->getGametype()->playerScored(this->bat_[1]->getPlayer());
     106                                return;
     107                            }
    82108                        }
    83109                    }
    84110                }
    85                 if (position.x < -this->fieldWidth_ / 2)
    86                 {
    87                     position.x = -this->fieldWidth_ / 2;
    88                     if (this->bat_ && this->bat_[0])
    89                     {
    90                         distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * this->batlength_ / 2);
    91                         if (this->getGametype() && this->bat_[1] && fabs(distance) > 1)
    92                         {
    93                             this->getGametype()->playerScored(this->bat_[1]->getPlayer());
    94                             return;
    95                         }
    96                     }
    97                 }
    98 
    99                 velocity.z = distance * distance * sgn(distance) * 1.5 * this->speed_;
    100111            }
    101112
  • code/trunk/src/orxonox/objects/worldentities/PongBall.h

    r2826 r2839  
    4848            void setFieldDimension(const Vector2& dimension)
    4949                { this->setFieldDimension(dimension.x, dimension.y); }
     50            Vector2 getFieldDimension() const
     51                { return Vector2(this->fieldWidth_, this->fieldHeight_); }
    5052
    5153            void setSpeed(float speed);
     
    6769            float batlength_;
    6870            PongBat** bat_;
     71            float relMercyOffset_;
    6972    };
    7073}
  • code/trunk/src/orxonox/objects/worldentities/PongBat.cc

    r2826 r2839  
    4646        this->length_ = 0.25;
    4747        this->fieldHeight_ = 100;
     48        this->bSteadiedPosition_ = false;
    4849
    4950        this->registerVariables();
     
    6162        if (this->hasLocalController())
    6263        {
    63             this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
     64            if (this->movement_ != 0)
     65            {
     66                this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_;
    6467
    65             if (this->bMoveLocal_)
    66                 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
    67             else
    68                 this->setVelocity(0, 0, this->movement_);
     68                if (this->bMoveLocal_)
     69                    this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0));
     70                else
     71                    this->setVelocity(0, 0, this->movement_);
    6972
    70             this->movement_ = 0;
     73                this->movement_ = 0;
     74                this->bSteadiedPosition_ = false;
     75            }
     76            else if (!this->bSteadiedPosition_)
     77            {
     78                // To ensure network synchronicity
     79                this->setVelocity(0, 0, 0);
     80                this->setPosition(this->getPosition());
     81                this->bSteadiedPosition_ = true;
     82            }
    7183        }
    7284
    7385        SUPER(PongBat, tick, dt);
    7486
    75         if (this->hasLocalController())
    76         {
    77             Vector3 position = this->getPosition();
    78 
    79             if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
    80                 position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
    81             if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
    82                 position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
    83 
    84             if (position != this->getPosition())
    85                 this->setPosition(position);
    86         }
     87        Vector3 position = this->getPosition();
     88        if (position.z > this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2)
     89            position.z = this->fieldHeight_ / 2 - this->fieldHeight_ * this->length_ / 2;
     90        if (position.z < -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2)
     91            position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
     92        if (position != this->getPosition())
     93            this->setPosition(position);
    8794    }
    8895
     
    98105        this->movement_ = value.x;
    99106    }
     107
     108    void PongBat::changedPlayer()
     109    {
     110        this->setVelocity(0, 0, 0);
     111    }
    100112}
  • code/trunk/src/orxonox/objects/worldentities/PongBat.h

    r2826 r2839  
    4848            virtual void moveRightLeft(const Vector2& value);
    4949
     50            virtual void changedPlayer();
     51
    5052            void setSpeed(float speed)
    5153                { this->speed_ = speed; }
     
    6971            float length_;
    7072            float fieldHeight_;
     73            bool bSteadiedPosition_;
    7174    };
    7275}
Note: See TracChangeset for help on using the changeset viewer.