Index: code/trunk/src/modules/pong/Pong.cc
===================================================================
--- code/trunk/src/modules/pong/Pong.cc	(revision 7911)
+++ code/trunk/src/modules/pong/Pong.cc	(revision 8108)
@@ -27,4 +27,9 @@
  */
 
+/**
+    @file Pong.cc
+    @brief Implementation of the Pong class.
+*/
+
 #include "Pong.h"
 
@@ -32,4 +37,7 @@
 #include "core/EventIncludes.h"
 #include "core/command/Executor.h"
+
+#include "gamestates/GSLevel.h"
+
 #include "PongCenterpoint.h"
 #include "PongBall.h"
@@ -40,4 +48,5 @@
 namespace orxonox
 {
+    // Events to allow to react to scoring of a player, in the level-file.
     CreateEventName(PongCenterpoint, right);
     CreateEventName(PongCenterpoint, left);
@@ -45,4 +54,8 @@
     CreateUnloadableFactory(Pong);
 
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    */
     Pong::Pong(BaseObject* creator) : Deathmatch(creator)
     {
@@ -56,10 +69,16 @@
         this->setHUDTemplate("PongHUD");
 
+        // Pre-set the timer, but don't start it yet.
         this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Pong::startBall, this)));
         this->starttimer_.stopTimer();
 
+        // Set the type of Bots for this particular Gametype.
         this->botclass_ = Class(PongBot);
     }
 
+    /**
+    @brief
+        Destructor. Cleans up, if initialized.
+    */
     Pong::~Pong()
     {
@@ -68,7 +87,11 @@
     }
 
+    /**
+    @brief
+        Cleans up the Gametype by destroying the ball and the bats.
+    */
     void Pong::cleanup()
     {
-        if (this->ball_)
+        if (this->ball_ != NULL) // Destroy the ball, if present.
         {
             this->ball_->destroy();
@@ -76,7 +99,8 @@
         }
 
+        // Destroy both bats, if present.
         for (size_t i = 0; i < 2; ++i)
         {
-            if (this->bat_[0])
+            if (this->bat_[0] != NULL)
             {
                 this->bat_[0]->destroy();
@@ -86,14 +110,20 @@
     }
 
+    /**
+    @brief
+        Starts the Pong minigame.
+    */
     void Pong::start()
     {
-        if (this->center_)
-        {
-            if (!this->ball_)
+        if (this->center_ != NULL) // There needs to be a PongCenterpoint, i.e. the area the game takes place.
+        {
+            if (this->ball_ == NULL) // If there is no ball, create a new ball.
             {
                 this->ball_ = new PongBall(this->center_);
+                // Apply the template for the ball specified by the centerpoint.
                 this->ball_->addTemplate(this->center_->getBalltemplate());
             }
 
+            // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to.
             this->center_->attach(this->ball_);
             this->ball_->setPosition(0, 0, 0);
@@ -103,15 +133,15 @@
             this->ball_->setBatLength(this->center_->getBatLength());
 
-            if (!this->bat_[0])
+            // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint.
+            for (size_t i = 0; i < 2; ++i)
             {
-                this->bat_[0] = new PongBat(this->center_);
-                this->bat_[0]->addTemplate(this->center_->getBattemplate());
+                if (this->bat_[i] == NULL)
+                {
+                    this->bat_[i] = new PongBat(this->center_);
+                    this->bat_[i]->addTemplate(this->center_->getBattemplate());
+                }
             }
-            if (!this->bat_[1])
-            {
-                this->bat_[1] = new PongBat(this->center_);
-                this->bat_[1]->addTemplate(this->center_->getBattemplate());
-            }
-
+
+            // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to.
             this->center_->attach(this->bat_[0]);
             this->center_->attach(this->bat_[1]);
@@ -127,29 +157,44 @@
             this->bat_[1]->setLength(this->center_->getBatLength());
 
+            // Set the bats for the ball.
             this->ball_->setBats(this->bat_);
         }
-        else
+        else // If no centerpoint was specified, an error is thrown and the level is exited.
         {
             COUT(1) << "Error: No Centerpoint specified." << std::endl;
-        }
-
+            GSLevel::startMainMenu();
+            return;
+        }
+
+        // Start the timer. After it has expired the ball is started.
         this->starttimer_.startTimer();
 
-
+        // Set variable to temporarily force the player to spawn.
         bool temp = this->bForceSpawn_;
         this->bForceSpawn_ = true;
 
+        // Call start for the parent class.
         Deathmatch::start();
 
+        // Reset the variable.
         this->bForceSpawn_ = temp;
     }
 
+    /**
+    @brief
+        Ends the Pong minigame.
+    */
     void Pong::end()
     {
         this->cleanup();
 
+        // Call end for the parent class.
         Deathmatch::end();
     }
 
+    /**
+    @brief
+        Spawns players, and fills the rest up with bots.
+    */
     void Pong::spawnPlayersIfRequested()
     {
@@ -164,20 +209,32 @@
     }
 
+    /**
+    @brief
+        Spawns the input player.
+    @param player
+        The player to be spawned.
+    */
     void Pong::spawnPlayer(PlayerInfo* player)
     {
-        if (!this->bat_[0]->getPlayer())
+        assert(player);
+
+        // If the first (left) bat has no player.
+        if (this->bat_[0]->getPlayer() == NULL)
         {
             player->startControl(this->bat_[0]);
             this->players_[player].state_ = PlayerState::Alive;
         }
-        else if (!this->bat_[1]->getPlayer())
+        // If the second (right) bat has no player.
+        else if (this->bat_[1]->getPlayer() == NULL)
         {
             player->startControl(this->bat_[1]);
             this->players_[player].state_ = PlayerState::Alive;
         }
+        // If both bats are taken.
         else
             return;
 
-        if (player && player->getController() && player->getController()->isA(Class(PongAI)))
+        // If the player is an AI, it receives a pointer to the ball.
+        if (player->getController() != NULL && player->getController()->isA(Class(PongAI)))
         {
             PongAI* ai = orxonox_cast<PongAI*>(player->getController());
@@ -186,10 +243,15 @@
     }
 
+    /**
+    @brief
+        Is called when the player scored.
+    */
     void Pong::playerScored(PlayerInfo* player)
     {
         Deathmatch::playerScored(player);
 
-        if (this->center_)
-        {
+        if (this->center_ != NULL) // If there is a centerpoint.
+        {
+            // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks.
             if (player == this->getRightPlayer())
                 this->center_->fireEvent(FireEventName(PongCenterpoint, right));
@@ -197,9 +259,11 @@
                 this->center_->fireEvent(FireEventName(PongCenterpoint, left));
 
-            if (player)
+            // Also announce, that the player has scored.
+            if (player != NULL)
                 this->gtinfo_->sendAnnounceMessage(player->getName() + " scored");
         }
 
-        if (this->ball_)
+        // If there is a ball present, reset its position, velocity and acceleration.
+        if (this->ball_ != NULL)
         {
             this->ball_->setPosition(Vector3::ZERO);
@@ -209,5 +273,6 @@
         }
 
-        if (this->bat_[0] && this->bat_[1])
+        // If there are bats reset them to the middle position.
+        if (this->bat_[0] != NULL && this->bat_[1] != NULL)
         {
             this->bat_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0);
@@ -215,16 +280,27 @@
         }
 
+        // Restart the timer to start the ball.
         this->starttimer_.startTimer();
     }
 
+    /**
+    @brief
+        Starts the ball with some default speed.
+    */
     void Pong::startBall()
     {
-        if (this->ball_ && this->center_)
+        if (this->ball_ != NULL && this->center_ != NULL)
             this->ball_->setSpeed(this->center_->getBallSpeed());
     }
 
+    /**
+    @brief
+        Get the left player.
+    @return
+        Returns a pointer to the player playing on the left. If there is no left player, NULL is returned.
+    */
     PlayerInfo* Pong::getLeftPlayer() const
     {
-        if (this->bat_ && this->bat_[0])
+        if (this->bat_ != NULL && this->bat_[0] != NULL)
             return this->bat_[0]->getPlayer();
         else
@@ -232,7 +308,13 @@
     }
 
+    /**
+    @brief
+        Get the right player.
+    @return
+        Returns a pointer to the player playing on the right. If there is no right player, NULL is returned.
+    */
     PlayerInfo* Pong::getRightPlayer() const
     {
-        if (this->bat_ && this->bat_[1])
+        if (this->bat_ != NULL && this->bat_[1] != NULL)
             return this->bat_[1]->getPlayer();
         else
