Index: trunk/src/util/multiplayer_team_deathmatch.cc
===================================================================
--- trunk/src/util/multiplayer_team_deathmatch.cc	(revision 9494)
+++ trunk/src/util/multiplayer_team_deathmatch.cc	(revision 9656)
@@ -138,8 +138,7 @@
   if ( currentGameState == GAMESTATE_PRE_GAME || currentGameState == GAMESTATE_GAME )
   {
-    if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
-         && box == NULL
-         &&  (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM
-         || bShowTeamChange )
+    if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) &&
+         box == NULL &&
+         (PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM || bShowTeamChange )
 
        )
@@ -193,8 +192,14 @@
   }
 
-  if ( box != NULL
-       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
-       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM
-       && !bShowTeamChange
+//   if( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) )
+//   {
+//     PRINTF(0)("prefered team id: %i, noteam: %i\n", PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId(), TEAM_NOTEAM);
+//   }
+
+  // check if the menu should be removed and the game state should be entered
+  if ( box != NULL &&
+       PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) &&
+       PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM &&
+       !bShowTeamChange
      )
   {
@@ -310,4 +315,5 @@
   assert( false );
 }
+
 
 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId )
@@ -442,4 +448,7 @@
 }
 
+/**
+ *  this handles team changes but only on the master server
+ */
 void MultiplayerTeamDeathmatch::handleTeamChanges( )
 {
@@ -458,5 +467,5 @@
       if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() >= 0 && stats.getPreferedTeamId() < numTeams ) )
       {
-        teamChange( stats.getUserId() );
+        teamChange( stats.getAssignedUserId() );
       }
     }
@@ -473,5 +482,5 @@
       {
         stats.setPreferedTeamId( getRandomTeam() );
-        teamChange( stats.getUserId() );
+        teamChange( stats.getAssignedUserId() );
       }
     }
@@ -479,4 +488,10 @@
 }
 
+
+
+/**
+ * changes the team
+ * @param userId the user changing team (userId)
+ */
 void MultiplayerTeamDeathmatch::teamChange( int userId )
 {
@@ -489,8 +504,8 @@
 
 
-  ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() );
-  std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId );
-  std::string playableTexture = getPlayableModelTextureFileName( userId, stats.getPreferedTeamId(), playableClassId );
-  float       playableScale = getPlayableScale( userId, stats.getPreferedTeamId(), playableClassId );
+  ClassID       playableClassId  = getPlayableClassId( userId, stats.getPreferedTeamId() );
+  std::string   playableModel    = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId );
+  std::string   playableTexture  = getPlayableModelTextureFileName( userId, stats.getPreferedTeamId(), playableClassId );
+  float         playableScale    = getPlayableScale( userId, stats.getPreferedTeamId(), playableClassId );
 
   BaseObject * bo = Factory::fabricate( playableClassId );
@@ -507,8 +522,11 @@
   playable.setSynchronized( true );
 
-  stats.setTeamId( stats.getPreferedTeamId() );
   stats.setPlayableClassId( playableClassId );
   stats.setPlayableUniqueId( playable.getUniqueID() );
   stats.setModelFileName( playableModel );
+  stats.setTeamId( stats.getPreferedTeamId() );
+
+  playable.setTeam(stats.getPreferedTeamId());
+
 
   this->respawnPlayable( &playable, stats.getPreferedTeamId(), 0.0f );
@@ -516,9 +534,8 @@
   if ( oldPlayable )
   {
-    //if ( userId == SharedNetworkData::getInstance()->getHostID() )
-    //  State::getPlayer()->setPlayable( NULL );
     delete oldPlayable;
   }
 }
+
 
 void MultiplayerTeamDeathmatch::onButtonExit( )
@@ -558,9 +575,10 @@
 }
 
-  /**
-   * function that processes events from the handler
-   * @param event: the event
-   * @todo replace SDLK_o with something from KeyMapper
-   */
+
+/**
+ * function that processes events from the handler
+ * @param event: the event
+ * @todo replace SDLK_o with something from KeyMapper
+ */
 void MultiplayerTeamDeathmatch::process( const Event & event )
 {
@@ -573,10 +591,10 @@
     if ( this->statsBox && !this->bLocalPlayerDead && event.bPressed )
     {
-      PRINTF(0)("hide stats\n");
+      PRINTF(5)("hide stats\n");
       this->hideStats();
     }
     else if ( !this->statsBox && event.bPressed )
     {
-      PRINTF(0)("show stats\n");
+      PRINTF(5)("show stats\n");
       this->showStats();
     }
@@ -740,7 +758,7 @@
   PlayerStats & killerStats = *PlayerStats::getStats( killerUserId );
 
-  if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim )
-  {
-    PRINTF(0)("killerStats.getPlayable() != killer || victimStats.getPlayable() != victim\n");
+  if ( killerStats.getPlayable() == NULL || victimStats.getPlayable() == NULL)
+  {
+    PRINTF(0)("killerStats.getPlayable() != NULL || victimStats.getPlayable() != NULL\n");
     PRINTF(0)("%x %x %x %x\n", killerStats.getPlayable(), killer, victimStats.getPlayable(), victim );
     PRINTF(0)("%d %d %d %d\n", killerStats.getPlayable()->getUniqueID(), killer->getUniqueID(), victimStats.getPlayable()->getUniqueID(), victim->getUniqueID() );
@@ -796,4 +814,10 @@
 
 
+/**
+ * respawns a playable in the world via spawning points
+ * @param playable the playable to respawn
+ * @param teamId the teamId to use
+ * @param delay time delay for delayed spawning
+ */
 void MultiplayerTeamDeathmatch::respawnPlayable( Playable * playable, int teamId, float delay )
 {
