ServerStateTooFewPlayersState.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <server/ServerStateTooFewPlayersState.h>
00022 #include <server/ServerTooFewPlayersStimulus.h>
00023 #include <server/ServerChannelManager.h>
00024 #include <server/ScorchedServer.h>
00025 #include <server/ServerNewGameState.h>
00026 #include <server/ServerState.h>
00027 #include <server/ServerCommon.h>
00028 #include <tank/TankContainer.h>
00029 #include <coms/ComsGameStoppedMessage.h>
00030 #include <coms/ComsMessageSender.h>
00031 #include <common/OptionsScorched.h>
00032 #include <common/Logger.h>
00033 
00034 ServerStateTooFewPlayersState::ServerStateTooFewPlayersState() :
00035         GameStateI("ServerStateTooFewPlayersState"),
00036         totalTime_(0.0f)
00037         
00038 {
00039 }
00040 
00041 ServerStateTooFewPlayersState::~ServerStateTooFewPlayersState()
00042 {
00043 }
00044 
00045 void ServerStateTooFewPlayersState::enterState(const unsigned state)
00046 {
00047         // Make sure all tanks are dead
00048         ScorchedServer::instance()->getTankContainer().setAllDead();
00049 
00050         // Tell any clients why the game has been abandonded
00051         ComsGameStoppedMessage gameStopped;
00052         ComsMessageSender::sendToAllPlayingClients(gameStopped);
00053 
00054         ServerChannelManager::instance()->sendText(
00055                 ChannelText("info", 
00056                         "TOO_FEW_PLAYERS", 
00057                         "Too few players, stopping play"),
00058                 true);
00059 }
00060 
00061 bool ServerStateTooFewPlayersState::acceptStateChange(const unsigned state, 
00062                 const unsigned nextState,
00063                 float frameTime)
00064 {
00065         bool readyToPlay = !ServerTooFewPlayersStimulus::instance()->
00066                 acceptStateChange(state, nextState, frameTime);
00067         if (readyToPlay) return true;
00068 
00069         // Check if the game options have changed
00070         totalTime_ += frameTime;
00071         if (totalTime_ > 1.0f)
00072         {
00073                 totalTime_ = 0.0f;
00074                 if (ScorchedServer::instance()->getOptionsGame().commitChanges())
00075                 {
00076                         ServerChannelManager::instance()->sendText(
00077                                 ChannelText("info", 
00078                                         "GAME_OPTIONS_CHANGED", 
00079                                         "Game options have been changed!"),
00080                                 true);
00081                 }       
00082         }
00083 
00084         // Check settings
00085 #ifndef S3D_SERVER
00086         {
00087                 if (ScorchedServer::instance()->getTankContainer().getNoOfNonSpectatorTanks() ==
00088                         ScorchedServer::instance()->getOptionsGame().getNoMinPlayers())
00089                 {
00090                         // Something has gone wrong
00091                         // We are playing a single player game.
00092                         // We have enough players but have not started
00093                         S3D::dialogExit("Scorched3D",
00094                                 "Incorrect players added for current game settings."
00095                                 "Is this a team game with un-even teams?");
00096                 }
00097         }
00098 #endif // S3D_SERVER
00099 
00100         return false;
00101 }

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3