ServerNextRoundState.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/ServerNextRoundState.h>
00022 #include <server/ServerState.h>
00023 #include <server/ServerShotHolder.h>
00024 #include <server/ScorchedServer.h>
00025 #include <server/TurnController.h>
00026 #include <tank/TankContainer.h>
00027 #include <engine/ActionController.h>
00028 #include <coms/ComsMessageSender.h>
00029 #include <coms/ComsGameStateMessage.h>
00030 #include <common/Logger.h>
00031 #include <common/OptionsScorched.h>
00032 #include <common/OptionsTransient.h>
00033 #include <common/StatsLogger.h>
00034 #include <lua/LUAScriptHook.h>
00035 
00036 ServerNextRoundState::ServerNextRoundState() :
00037         GameStateI("ServerNextRoundState")
00038 {
00039         ScorchedServer::instance()->getLUAScriptHook().addHookProvider("server_newround");
00040 }
00041 
00042 ServerNextRoundState::~ServerNextRoundState()
00043 {
00044 }
00045 
00046 void ServerNextRoundState::enterState(const unsigned state)
00047 {
00048         // Move all tanks into the next round
00049         // Load the set of options for this next player
00050         ScorchedServer::instance()->getContext().getOptionsTransient().nextRound();
00051 
00052         // Tell the stats about the start of a new round
00053         bool weaponBuy = 
00054                 (ScorchedServer::instance()->getOptionsTransient().getCurrentGameNo() == 0);
00055         if (!weaponBuy)
00056         {
00057                 std::list<Tank *> currentTanks;
00058                 std::map<unsigned int, Tank *> &playingTanks =
00059                         ScorchedServer::instance()->getTankContainer().getPlayingTanks();
00060                 std::map<unsigned int, Tank *>::iterator playingTanksItor;
00061                 for (playingTanksItor = playingTanks.begin();
00062                         playingTanksItor != playingTanks.end();
00063                         playingTanksItor++)
00064                 {
00065                         Tank *tank = (*playingTanksItor).second;
00066                         currentTanks.push_back(tank);
00067                 }
00068                 StatsLogger::instance()->roundStart(currentTanks);
00069         }
00070 
00071         // Setup this list of players that need to move before this round is over
00072         TurnController::instance()->nextRound();
00073 
00074         // Notify scripts of a new game starting
00075         ScorchedServer::instance()->getLUAScriptHook().callHook("server_newround");
00076 
00077         // Make sure all clients have the correct game settings
00078         ComsGameStateMessage message;
00079         ComsMessageSender::sendToAllPlayingClients(message);    
00080 
00081         // Move into the ready state
00082         ScorchedServer::instance()->getGameState().stimulate(ServerState::ServerStimulusNextShot);
00083 }

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