Index: code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.cc
===================================================================
--- code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.cc	(revision 7699)
+++ code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.cc	(revision 7890)
@@ -43,128 +43,24 @@
     LastTeamStanding::LastTeamStanding(BaseObject* creator) : TeamDeathmatch(creator)
     {
-        RegisterObject(LastTeamStanding);
-        this->bForceSpawn_=true;
-        this->lives=4;
-        this->teamsAlive=0;
-        this->timeRemaining=15.0f;
-        this->respawnDelay=4.0f;
-        this->bNoPunishment=false;
-        this->bHardPunishment=false;
-        this->punishDamageRate=0.4f;
-        this->setHUDTemplate("LastTeamStandingHUD");//tolowercase:-)
-        this->eachTeamsPlayers = new int[teams_];
-        this->bMinPlayersReached = false;
+        this->bForceSpawn_ = true;
+        this->lives = 1;//4
+        this->eachTeamsPlayers.reserve(teams_);
+        this->teamsAlive = 0;
+        this->bMinTeamsReached = false;
+        this->bNoPunishment = false;
+        this->bHardPunishment = false;
+        this->punishDamageRate = 0.4f;
+        this->timeRemaining = 15.0f;
+        this->respawnDelay = 4.0f;
     }
     
     LastTeamStanding::~LastTeamStanding()
     {
-        delete[] this->eachTeamsPlayers;
+        this->playerLives_.clear();
+        this->eachTeamsPlayers.clear();
+        this->timeToAct_.clear();
+        this->playerDelayTime_.clear();
+        this->inGame_.clear();
     }   
-
-    void LastTeamStanding::spawnDeadPlayersIfRequested()
-    {
-        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
-            if (it->second.state_ == PlayerState::Dead)
-            {
-                bool alive = (0<playerLives_[it->first]&&(inGame_[it->first]));
-                if (alive&&(it->first->isReadyToSpawn() || this->bForceSpawn_))
-                {
-                    this->spawnPlayer(it->first);
-                }
-            }
-    }
-
-
-    void LastTeamStanding::setConfigValues()
-    {
-        SetConfigValue(lives, 4);
-        SetConfigValue(timeRemaining, 15.0f);
-        SetConfigValue(respawnDelay, 4.0f);
-        SetConfigValue(bNoPunishment, false);
-        SetConfigValue(bHardPunishment, false);
-    }
-
-    bool LastTeamStanding::allowPawnDamage(Pawn* victim, Pawn* originator)
-    {
-        bool allow = TeamDeathmatch::allowPawnDamage(victim, originator);
-        if(!allow) {return allow;}
-        if (originator && originator->getPlayer())// only for safety
-        {
-            this->timeToAct_[originator->getPlayer()]=timeRemaining;
-
-            std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
-            if (it != this->players_.end())
-            {
-                if (it->first->getClientID()== CLIENTID_UNKNOWN)
-                    return true;
-                const std::string& message = ""; // resets Camper-Warning-message
-                this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
-            }    
-        }
-        return allow;
-    }
-
-    bool LastTeamStanding::allowPawnDeath(Pawn* victim, Pawn* originator)
-    {
-        if (!victim||!victim->getPlayer())// only for safety
-            return true;
-        bool allow =TeamDeathmatch::allowPawnDeath(victim, originator);
-        if(!allow) {return allow;}
-        playerLives_[victim->getPlayer()]=playerLives_[victim->getPlayer()]-1;
-        this->inGame_[victim->getPlayer()]=false;//if player dies he, isn't allowed to respawn immediately
-        if (playerLives_[victim->getPlayer()]<=0)//if player lost all lives
-        {
-            this->eachTeamsPlayers[getTeam(victim->getPlayer())]--;
-            if(eachTeamsPlayers[getTeam(victim->getPlayer())]==0)//last team member died
-                this->teamsAlive--;
-            const std::string& message = victim->getPlayer()->getName() + " has lost all lives";
-            COUT(0) << message << std::endl;
-            Host::Broadcast(message);
-        }
-
-        return allow;
-    }
-
-    int LastTeamStanding::getMinLives()
-    {
-        int min=lives;
-        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
-        {
-            if (it->second<=0)
-                continue;
-            if (it->second<lives)
-                min=it->second;
-        }
-        return min;
-    }
-
-    void LastTeamStanding::end()//TODO!
-    {
-        Gametype::end();
-        
-        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
-        {
-            if (it->first->getClientID() == CLIENTID_UNKNOWN)
-                continue;
-
-            if (it->second > 0)
-                this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
-            else
-                this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
-        }
-    }
-
-    int LastTeamStanding::playerGetLives(PlayerInfo* player)
-    {
-        if (player)
-            return  playerLives_[player];
-        else
-            return 0;
-    }
-    
-    int LastTeamStanding::getNumTeamsAlive() const
-    {
-        return this->teamsAlive;
-    }
 
     void LastTeamStanding::playerEntered(PlayerInfo* player)
@@ -177,13 +73,14 @@
         else
             playerLives_[player]=getMinLives();//new players only get minimum of lives
-            
-        if(this->eachTeamsPlayers[getTeam(player)]==0)
+        
+        if(this->eachTeamsPlayers[getTeam(player)]==0) //if a player is the first in his group, a new team is alive
             this->teamsAlive++;
-        this->eachTeamsPlayers[getTeam(player)]++;
+        this->eachTeamsPlayers[getTeam(player)]++; //the number of player in this team is increased
+
         if (teamsAlive>1) // Now the game is allowed to end, since there are at least two teams.
-            bMinPlayersReached=true;
-        this->timeToAct_[player]=timeRemaining;
-        this->playerDelayTime_[player]=respawnDelay;
-        this->inGame_[player]=true;
+            bMinTeamsReached = true; // since there are at least two teams, the game is allowed to end
+        this->timeToAct_[player] = timeRemaining;
+        this->playerDelayTime_[player] = respawnDelay;
+        this->inGame_[player] = true;
     }
 
@@ -193,14 +90,70 @@
         if (valid_player)
         {
-            this->eachTeamsPlayers[getTeam(player)]--;
-            if(this->eachTeamsPlayers[getTeam(player)]==0)
+            this->eachTeamsPlayers[getTeam(player)]--;       // a player left the team
+            if(this->eachTeamsPlayers[getTeam(player)] == 0) // if it was the last player a team died
                  this->teamsAlive--;
-            this->playerLives_.erase (player);
-            this->playerDelayTime_.erase (player);
-            this->inGame_.erase (player);
+            this->playerLives_.erase(player);
+            this->eachTeamsPlayers.clear();
             this->timeToAct_.erase(player);
+            this->playerDelayTime_.erase(player);
+            this->inGame_.erase(player);
         }
 
         return valid_player;
+    }
+
+    bool LastTeamStanding::allowPawnDeath(Pawn* victim, Pawn* originator)
+    {
+        if (!victim||!victim->getPlayer())// only for safety
+            return true;
+        bool allow = TeamDeathmatch::allowPawnDeath(victim, originator);
+        if(!allow) {return allow;}
+        
+        playerLives_[victim->getPlayer()] = playerLives_[victim->getPlayer()] - 1; //player lost a live
+        this->inGame_[victim->getPlayer()] = false; //if player dies, he isn't allowed to respawn immediately
+        if (playerLives_[victim->getPlayer()]<=0) //if player lost all lives
+        {
+            this->eachTeamsPlayers[getTeam(victim->getPlayer())]--;
+            if(eachTeamsPlayers[getTeam(victim->getPlayer())] == 0) //last team member died
+                this->teamsAlive--;
+            const std::string& message = victim->getPlayer()->getName() + " has lost all lives";
+            COUT(0) << message << std::endl;
+            Host::Broadcast(message);
+        }
+
+        return allow;
+    }
+
+    bool LastTeamStanding::allowPawnDamage(Pawn* victim, Pawn* originator)
+    {
+        bool allow = TeamDeathmatch::allowPawnDamage(victim, originator);
+        if(!allow) {return allow;}
+        if (originator && originator->getPlayer())// only for safety
+        {
+            this->timeToAct_[originator->getPlayer()] = timeRemaining;
+
+            std::map<PlayerInfo*, Player>::iterator it = this->players_.find(originator->getPlayer());
+            if (it != this->players_.end())
+            {
+                if (it->first->getClientID()== CLIENTID_UNKNOWN)
+                    return true;
+                const std::string& message = ""; // resets Camper-Warning-message
+                this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
+            }    
+        }
+        return allow;
+    }
+
+    void LastTeamStanding::spawnDeadPlayersIfRequested()
+    {
+        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+            if (it->second.state_ == PlayerState::Dead)
+            {
+                bool alive = (0 < playerLives_[it->first]&&(inGame_[it->first]));
+                if (alive&&(it->first->isReadyToSpawn() || this->bForceSpawn_))
+                {
+                    this->spawnPlayer(it->first);
+                }
+            }
     }
 
@@ -211,6 +164,6 @@
         TeamDeathmatch::playerStartsControllingPawn(player,pawn);
         
-        this->timeToAct_[player]=timeRemaining+3.0f+respawnDelay;//reset timer
-        this->playerDelayTime_[player]=respawnDelay;
+        this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer
+        this->playerDelayTime_[player] = respawnDelay;
         
         std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
@@ -222,4 +175,89 @@
             this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
         }  
+    }
+
+    void LastTeamStanding::tick(float dt)
+    {
+        SUPER(LastTeamStanding, tick, dt);
+        if(this->hasStarted()&&(!this->hasEnded()))
+        {
+            if (bMinTeamsReached &&(this->hasStarted()&&(teamsAlive<=1)))//last team remaining -> game will end
+            {
+                this->end();
+            }
+            for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
+            {   
+                if (playerGetLives(it->first) <= 0)//Players without lives shouldn't be affected by time.
+                    continue;     
+                it->second -= dt;//Decreases punishment time.
+                if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 
+                {
+                    playerDelayTime_[it->first] -= dt;
+                    if (playerDelayTime_[it->first] <= 0)
+                    this->inGame_[it->first] = true;
+
+                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
+                        continue;
+                    int output = 1 + playerDelayTime_[it->first];
+                    const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
+                    this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
+                }
+                else if (it->second < 0.0f)
+                {
+                    it->second = timeRemaining + 3.0f;//reset punishment-timer
+                    if (playerGetLives(it->first) > 0)
+                    {
+                        this->punishPlayer(it->first);
+                        if (it->first->getClientID() == CLIENTID_UNKNOWN)
+                            return;
+                        const std::string& message = ""; // resets Camper-Warning-message
+                        this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
+                    }
+                }
+                else if (it->second < timeRemaining/5)//Warning message
+                {
+                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
+                        continue;
+                    const std::string& message = "Camper Warning! Don't forget to shoot.";
+                    this->gtinfo_->sendFadingMessage(message, it->first->getClientID());
+                }
+            }
+        }
+    }
+
+    void LastTeamStanding::end()//TODO: Send the message to the whole team
+    {
+        Gametype::end();
+        
+        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
+        {
+            if (it->first->getClientID() == CLIENTID_UNKNOWN)
+                continue;
+
+            if (it->second > 0)
+                this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
+            else
+                this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+        /*//erase maps:
+            this->playerLives_.erase(it->first);
+            this->playerDelayTime_.erase (it->first);
+            this->inGame_.erase (it->first);
+            this->timeToAct_.erase(it->first);*/
+        }
+
+    }
+
+
+    int LastTeamStanding::getMinLives()
+    {
+        int min = lives;
+        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
+        {
+            if (it->second <= 0)
+                continue;
+            if (it->second < lives)
+                min = it->second;
+        }
+        return min;
     }
 
@@ -241,63 +279,30 @@
             {
                 pawn->kill();
-                this->timeToAct_[player]=timeRemaining+3.0f+respawnDelay;//reset timer
+                this->timeToAct_[player] = timeRemaining + 3.0f + respawnDelay;//reset timer
             }
             else
             {
-                float damage=pawn->getMaxHealth()*punishDamageRate*0.5;//TODO: Factor 0.5 is hard coded. Where is the ratio between MaxHealth actually defined?
+                float damage = pawn->getMaxHealth()*punishDamageRate*0.5;//TODO: Factor 0.5 is hard coded. Where is the ratio between MaxHealth actually defined?
                 pawn->removeHealth(damage);
-                this->timeToAct_[player]=timeRemaining;//reset timer
-            }
-        }
-    }
-
-    void LastTeamStanding::tick(float dt)
-    {
-        SUPER(LastTeamStanding, tick, dt);
-        if(this->hasStarted()&&(!this->hasEnded()))
-        {
-            if (bMinPlayersReached &&(this->hasStarted()&&(teamsAlive<=1)))//last team remaining
-            {
-                this->end();
-            }
-            for (std::map<PlayerInfo*, float>::iterator it = this->timeToAct_.begin(); it != this->timeToAct_.end(); ++it)
-            {   
-                if (playerGetLives(it->first)<=0)//Players without lives shouldn't be affected by time.
-                    continue;     
-                it->second-=dt;//Decreases punishment time.
-                if (!inGame_[it->first])//Manages respawn delay - player is forced to respawn after the delaytime is used up. 
-                {
-                    playerDelayTime_[it->first]-=dt;
-                    if (playerDelayTime_[it->first]<=0)
-                    this->inGame_[it->first]=true;
-
-                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
-                        continue;
-                    int output=1+playerDelayTime_[it->first];
-                    const std::string& message = "Respawn in " +multi_cast<std::string>(output)+ " seconds." ;//Countdown
-                    this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
-                }
-                else if (it->second<0.0f)
-                {
-                    it->second=timeRemaining+3.0f;//reset punishment-timer
-                    if (playerGetLives(it->first)>0)
-                    {
-                        this->punishPlayer(it->first);
-                        if (it->first->getClientID()== CLIENTID_UNKNOWN)
-                            return;
-                        const std::string& message = ""; // resets Camper-Warning-message
-                        this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
-                    }
-                }
-                else if (it->second<timeRemaining/5)//Warning message
-                {
-                    if (it->first->getClientID()== CLIENTID_UNKNOWN)
-                        continue;
-                    const std::string& message = "Camper Warning! Don't forget to shoot.";
-                    this->gtinfo_->sendFadingMessage(message,it->first->getClientID());
-                }
-            }
-        }
-    }
-
+                this->timeToAct_[player] = timeRemaining;//reset timer
+            }
+        }
+    }
+
+    int LastTeamStanding::playerGetLives(PlayerInfo* player)
+    {
+        if (player)
+            return  playerLives_[player];
+        else
+            return 0;
+    }
+    
+    void LastTeamStanding::setConfigValues()
+    {
+        SetConfigValue(lives, 4);
+        SetConfigValue(timeRemaining, 15.0f);
+        SetConfigValue(respawnDelay, 4.0f);
+        SetConfigValue(bNoPunishment, false);
+        SetConfigValue(bHardPunishment, false);
+    }
 }
Index: code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.h
===================================================================
--- code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.h	(revision 7699)
+++ code/branches/lastmanstanding2/src/orxonox/gametypes/LastTeamStanding.h	(revision 7890)
@@ -54,35 +54,40 @@
             int lives; //!< Standard amount of lives. Each player starts a game with so many lives.
             std::map< PlayerInfo*, int > playerLives_; //!< Each player's lives are stored here.
+            std::vector<int> eachTeamsPlayers; //!<Number of players in each team.
             int teamsAlive; //!< Counter counting teams with more than one player remaining.
+//Data for CamperPunishment
             float timeRemaining; //!< Each player has a certain time where he or she has to hit an opponent or will be punished.
             std::map<PlayerInfo*, float> timeToAct_; //!< Each player's time till she/he will be punished is stored here.
+            bool bNoPunishment; //!< Config value to switch off Punishment function if it is set to true.
+            bool bHardPunishment; //!< Switches between damage and death as punishment.
+            float punishDamageRate; //!< Makes Damage adjustable.
+//Data for RespawnDelay
             float respawnDelay; //!<Time in seconds when a player will respawn after death.
             std::map<PlayerInfo*, float> playerDelayTime_; //!< Stores each Player's delay time.
             std::map<PlayerInfo*, bool> inGame_; //!< Indicates each Player's state.
-            bool bNoPunishment; //!< Config value to switch off Punishment function if it is set to true.
-            bool bHardPunishment; //!< Switches between damage and death as punishment.
-            float punishDamageRate; //!< Makes Damage adjustable.
+
+            bool bMinTeamsReached; //!< Lock. Game shouldn't end right at the beginning.
+
             virtual void spawnDeadPlayersIfRequested(); //!< Prevents dead players to respawn.
             virtual int getMinLives(); //!< Returns minimum of each player's lives; players with 0 lives are skipped;
-            int * eachTeamsPlayers; //!<Each teams player's alive.
-            bool bMinPlayersReached;
 
         public:
             LastTeamStanding(BaseObject* creator); //!< Default Constructor.
             virtual ~LastTeamStanding(); //!< Default Destructor.
+
+            virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
+            virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
+
+            virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); //!< Manages each player's lost lives.
+            virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); //!< If a player shoot's an opponent, his punishment countdown will be resetted.
+            virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn); //!< Resets punishment time and respawn delay.
+            void tick (float dt); //!< used to end the game
+            virtual void end(); //!< Sends an end message.
+            void punishPlayer(PlayerInfo* player); //!< Function in order to kill a player. Punishment for hiding longer than "timeRemaining".
+            int playerGetLives(PlayerInfo* player); //!< getFunction for the map "playerLives_".
+            inline int getNumTeamsAlive() const//!< Returns the number of players that are still alive.
+            {return this->teamsAlive;}
             void setConfigValues(); //!< Makes values configurable.
 
-            virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0); //!< If a player shoot's an opponent, his punishment countdown will be resetted.
-            virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0); //!< Manages each players lives.
-
-            virtual void end(); //!< Sends an end message.
-            int playerGetLives(PlayerInfo* player); //!< getFunction for the map "playerLives_".
-            int getNumTeamsAlive() const; //!< Returns the number of players that are still alive.
-            virtual void playerEntered(PlayerInfo* player); //!< Initializes values.
-            virtual bool playerLeft(PlayerInfo* player); //!< Manages all local variables.
-            virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn); //!< Resets punishment time and respawn delay.
-
-            void punishPlayer(PlayerInfo* player); //!< Function in order to kill a player. Punishment for hiding longer than "timeRemaining".
-            void tick (float dt); //!< used to end the game
     };
 }
