Index: trunk/src/util/multiplayer_team_deathmatch.cc
===================================================================
--- trunk/src/util/multiplayer_team_deathmatch.cc	(revision 8145)
+++ trunk/src/util/multiplayer_team_deathmatch.cc	(revision 8147)
@@ -37,4 +37,10 @@
 
 #include "network_game_manager.h"
+
+#include "event_handler.h"
+
+#include "glgui.h"
+
+#include "story_entity.h"
 
 
@@ -59,4 +65,6 @@
   this->currentGameState = GAMESTATE_PRE_GAME;
   this->gameStateTimer = 10.0f;
+  
+  this->box = NULL;
 
   this->deathScreen = new ImagePlane();
@@ -138,9 +146,71 @@
 void MultiplayerTeamDeathmatch::tick(float dt)
 {
+  //on client side hostId is -1 until hanshake finished
+  if ( SharedNetworkData::getInstance()->getHostID() < 0 )
+    return;
+  
+  if ( currentGameState == GAMESTATE_PRE_GAME )
+  {
+    if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
+         && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() == TEAM_NOTEAM 
+         && box == NULL
+       )
+    {
+      EventHandler::getInstance()->pushState( ES_MENU );
+      
+      OrxGui::GLGuiHandler::getInstance()->activateCursor();
+      
+      box = new OrxGui::GLGuiBox();
+      box->setAbsCoor2D( 300, 100 );
+      
+      OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator");
+      box->pack( buttonSpectator );
+      buttonSpectator->connect(SIGNAL(buttonSpectator, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonSpectator));
+      
+      OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random");
+      box->pack( buttonRandom );
+      buttonRandom->connect(SIGNAL(buttonRandom, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonRandom));
+      
+      OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team");
+      box->pack( buttonTeam0 );
+      buttonTeam0->connect(SIGNAL(buttonTeam0, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam0));
+      
+      OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team");
+      box->pack( buttonTeam1 );
+      buttonTeam1->connect(SIGNAL(buttonTeam1, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonTeam1));
+      
+      OrxGui::GLGuiPushButton * buttonExit = new OrxGui::GLGuiPushButton("Exit");
+      box->pack( buttonExit );
+      buttonExit->connect(SIGNAL(buttonExit, released), this, SLOT(MultiplayerTeamDeathmatch, onButtonExit));
+      
+      box->showAll();
+    }
+  }
+
+  if ( box != NULL
+       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )
+       && PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPreferedTeamId() != TEAM_NOTEAM 
+     )
+  {
+    delete box;
+    box = NULL;
+      
+    OrxGui::GLGuiHandler::getInstance()->deactivateCursor( true );
+      
+    EventHandler::getInstance()->popState();
+  }
+  
+  if ( box != NULL )
+  {
+    OrxGui::GLGuiHandler::getInstance()->tick( dt );
+  }
+  
+  assignPlayable();
+  
   if ( !SharedNetworkData::getInstance()->isGameServer() )
     return;
   
   gameStateTimer -= dt;
-  PRINTF(0)("TICK %f\n", gameStateTimer);
+  //PRINTF(0)("TICK %f\n", gameStateTimer);
   
   if ( currentGameState != GAMESTATE_GAME && gameStateTimer < 0 )
@@ -210,17 +280,28 @@
  * @return group id
  */
-int MultiplayerTeamDeathmatch::getTeamForNewUser( )
+int MultiplayerTeamDeathmatch::getTeamForNewUser()
 {
   return TEAM_NOTEAM;
 }
 
-ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int team )
-{
-  return CL_SPECTATOR;
-}
-
-std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int team, ClassID classId )
-{
-  return "";
+ClassID MultiplayerTeamDeathmatch::getPlayableClassId( int userId, int team )
+{
+  if ( team == TEAM_NOTEAM || team == TEAM_SPECTATOR )
+    return CL_SPECTATOR;
+  
+  if ( team == 0 || team == 1 )
+    return CL_SPACE_SHIP;
+  
+  assert( false );
+}
+
+std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId )
+{
+  if ( team == 0 )
+    return "models/ships/reap_#.obj";
+  else if ( team == 1 )
+    return "models/ships/fighter.obj";
+  else
+    return "";
 }
 
@@ -334,5 +415,5 @@
     if ( stats.getTeamId() != stats.getPreferedTeamId() )
     {
-      if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() <= 0 && stats.getPreferedTeamId() < numTeams ) )
+      if ( stats.getPreferedTeamId() == TEAM_SPECTATOR || ( stats.getPreferedTeamId() >= 0 && stats.getPreferedTeamId() < numTeams ) )
       {
         teamChange( stats.getUserId() );
@@ -350,5 +431,5 @@
       if ( stats.getPreferedTeamId() == TEAM_RANDOM )
       {
-        stats.setPreferedTeamId( getTeamForNewUser() );
+        stats.setPreferedTeamId( getRandomTeam() );
         teamChange( stats.getUserId() );
       }
@@ -362,10 +443,71 @@
   PlayerStats & stats = *(PlayerStats::getStats( userId ));
   
-  assert(false);
-}
-
-
-
-
-
-
+  stats.setTeamId( stats.getPreferedTeamId() );
+  
+  Playable * oldPlayable = stats.getPlayable();
+  
+  
+  ClassID playableClassId = getPlayableClassId( userId, stats.getPreferedTeamId() );
+  std::string playableModel = getPlayableModelFileName( userId, stats.getPreferedTeamId(), playableClassId );
+  
+  BaseObject * bo = Factory::fabricate( playableClassId );
+  
+  assert( bo != NULL );
+  assert( bo->isA( CL_PLAYABLE ) );
+  
+  Playable & playable = *(dynamic_cast<Playable*>(bo));
+  
+  playable.loadModel( playableModel );
+  playable.setOwner( userId );
+  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
+  playable.setSynchronized( true );
+  
+  stats.setTeamId( stats.getPreferedTeamId() );
+  stats.setPlayableClassId( playableClassId );
+  stats.setPlayableUniqueId( playable.getUniqueID() );
+  stats.setModelFileName( playableModel );
+  
+  if ( oldPlayable )
+  {
+    //if ( userId == SharedNetworkData::getInstance()->getHostID() )
+    //  State::getPlayer()->setPlayable( NULL );
+    delete oldPlayable;
+  }
+}
+
+void MultiplayerTeamDeathmatch::onButtonExit( )
+{
+  State::getCurrentStoryEntity()->stop();
+}
+
+void MultiplayerTeamDeathmatch::onButtonRandom( )
+{
+  NetworkGameManager::getInstance()->prefereTeam( TEAM_RANDOM );
+}
+
+void MultiplayerTeamDeathmatch::onButtonTeam0( )
+{
+  NetworkGameManager::getInstance()->prefereTeam( 0 );
+}
+
+void MultiplayerTeamDeathmatch::onButtonTeam1( )
+{
+  NetworkGameManager::getInstance()->prefereTeam( 1 );
+}
+
+void MultiplayerTeamDeathmatch::onButtonSpectator( )
+{
+  NetworkGameManager::getInstance()->prefereTeam( TEAM_SPECTATOR );
+}
+
+void MultiplayerTeamDeathmatch::assignPlayable( )
+{
+  if ( PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() ) )
+    PlayerStats::getStats( SharedNetworkData::getInstance()->getHostID() )->getPlayable();
+}
+
+
+
+
+
+
Index: trunk/src/util/multiplayer_team_deathmatch.h
===================================================================
--- trunk/src/util/multiplayer_team_deathmatch.h	(revision 8145)
+++ trunk/src/util/multiplayer_team_deathmatch.h	(revision 8147)
@@ -12,4 +12,5 @@
 #include "network_game_rules.h"
 
+#include "glgui_box.h"
 
 class TiXmlElement;
@@ -36,6 +37,6 @@
 
     virtual int getTeamForNewUser();
-    virtual ClassID getPlayableClassId( int team );
-    virtual std::string getPlayableModelFileName( int team, ClassID classId );
+    virtual ClassID getPlayableClassId( int userId, int team );
+    virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId );
 
     virtual void onPlayerSpawn();
@@ -73,8 +74,18 @@
     float              gameStateTimer;             //!< if less than 0 -> change game state
 
+    OrxGui::GLGuiBox* box;
+
+
     void calculateTeamScore();
     void nextGameState();
     void handleTeamChanges();
     void teamChange( int userId );
+    void assignPlayable();
+    
+    void onButtonSpectator();
+    void onButtonRandom();
+    void onButtonTeam0();
+    void onButtonTeam1();
+    void onButtonExit();
 };
 
Index: trunk/src/util/network_game_rules.cc
===================================================================
--- trunk/src/util/network_game_rules.cc	(revision 8145)
+++ trunk/src/util/network_game_rules.cc	(revision 8147)
@@ -38,10 +38,10 @@
 }
 
-std::string NetworkGameRules::getPlayableModelFileName( int team, ClassID classId )
+std::string NetworkGameRules::getPlayableModelFileName( int uesrId, int team, ClassID classId )
 {
   return "models/ships/reap_#.obj";
 }
 
-ClassID NetworkGameRules::getPlayableClassId( int team )
+ClassID NetworkGameRules::getPlayableClassId( int userId, int team )
 {
   return CL_SPACE_SHIP;
Index: trunk/src/util/network_game_rules.h
===================================================================
--- trunk/src/util/network_game_rules.h	(revision 8145)
+++ trunk/src/util/network_game_rules.h	(revision 8147)
@@ -21,6 +21,6 @@
     
     virtual int getTeamForNewUser();
-    virtual ClassID getPlayableClassId( int team );
-    virtual std::string getPlayableModelFileName( int team, ClassID classId );
+    virtual ClassID getPlayableClassId( int userId, int team );
+    virtual std::string getPlayableModelFileName( int userId, int team, ClassID classId );
     
     virtual PlayerStats * getNewPlayerStats( int userId ){ return new PlayerStats( userId ); }
