ServerState.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 <engine/GameState.h>
00022 #include <engine/ActionController.h>
00023 #include <server/ServerState.h>
00024 #include <server/ServerNewGameState.h>
00025 #include <server/ServerNextRoundState.h>
00026 #include <server/ServerNextTurnState.h>
00027 #include <server/ServerNextShotState.h>
00028 #include <server/ServerReadyState.h>
00029 #include <server/ServerResetState.h>
00030 #include <server/ServerTooFewPlayersStimulus.h>
00031 #include <server/ServerStateTooFewPlayersState.h>
00032 #include <server/ServerPlayingState.h>
00033 #include <server/ServerStartingState.h>
00034 #include <server/ServerShotState.h>
00035 #include <server/ServerShotFinishedState.h>
00036 #include <server/ScorchedServer.h>
00037 
00038 void ServerState::setupStates(GameState &gameState)
00039 {
00040         static class DummyLoop : public GameStateI
00041         {
00042         public:
00043                 DummyLoop() : GameStateI("DummyLoop") {}
00044         } dummyLoop_;
00045 
00046         gameState.clear();
00047 
00048         // ServerStateTooFewPlayers (Start State)
00049         ServerStateTooFewPlayersState *serverTooFewPlayers = 
00050                 new ServerStateTooFewPlayersState();
00051         gameState.addStateEntry(ServerStateTooFewPlayers,
00052                 serverTooFewPlayers);
00053         gameState.addStateStimulus(ServerStateTooFewPlayers, 
00054                 serverTooFewPlayers, ServerStateStarting);
00055 
00056         // ServerStateStarting
00057         ServerStartingState *serverStarting = 
00058                 new ServerStartingState();
00059         gameState.addStateEntry(ServerStateStarting,
00060                 serverStarting);
00061         gameState.addStateStimulus(ServerStateStarting, 
00062                 ServerStimulusStarting, ServerStateStarting);   
00063         gameState.addStateStimulus(ServerStateStarting, 
00064                 ServerTooFewPlayersStimulus::instance(), ServerStateTooFewPlayers);     
00065         gameState.addStateStimulus(ServerStateStarting, 
00066                 serverStarting, ServerStateReset);
00067 
00068         // ServerStateReset 
00069         ServerResetState *serverReset = new ServerResetState();
00070         gameState.addStateEntry(ServerStateReset,
00071                 serverReset);
00072         gameState.addStateStimulus(ServerStateReset, 
00073                 ServerStimulusNewGame, ServerStateNewGame);
00074 
00075         // ServerStateNewGame
00076         ServerNewGameState *serverNewGame = new ServerNewGameState;
00077         gameState.addStateEntry(ServerStateNewGame,
00078                 serverNewGame);
00079         gameState.addStateStimulus(ServerStateNewGame, 
00080                 ServerStimulusNewGameReady, ServerStateNewGameReady);
00081 
00082         // ServerStateNewGameReady
00083         ServerReadyState *serverNewGameReady = new ServerReadyState();
00084 #ifdef S3D_SERVER
00085         // Only required on the server.
00086         // For client games, there will only be one client waiting
00087         // so the server and client will start simulating in sync anyway
00088         // The server starts simulating after this state (and will exit this
00089         // state as soon as the only client is ready).
00090         gameState.addStateLoop(ServerStateNewGameReady, &dummyLoop_, 
00091                 &ScorchedServer::instance()->getActionController());
00092 #endif
00093         gameState.addStateEntry(ServerStateNewGameReady,
00094                 serverNewGameReady);
00095         gameState.addStateStimulus(ServerStateNewGameReady, 
00096                 serverNewGameReady, ServerStateNextRound);
00097 
00098         // ServerStateNextRound
00099         ServerNextRoundState *serverNextRound = new ServerNextRoundState();
00100         gameState.addStateLoop(ServerStateNextRound, &dummyLoop_, 
00101                 &ScorchedServer::instance()->getActionController());
00102         gameState.addStateEntry(ServerStateNextRound,
00103                 serverNextRound);
00104         gameState.addStateStimulus(ServerStateNextRound, 
00105                 ServerStimulusNextShot, ServerStateNextShot);
00106 
00107         // ServerStateNextShot
00108         ServerNextShotState *serverNextShot = new ServerNextShotState;
00109         gameState.addStateLoop(ServerStateNextShot, &dummyLoop_, 
00110                 &ScorchedServer::instance()->getActionController());
00111         gameState.addStateEntry(ServerStateNextShot,
00112                 serverNextShot);
00113         gameState.addStateStimulus(ServerStateNextShot, 
00114                 ServerStimulusNextTurn, ServerStateNextTurn);
00115         gameState.addStateStimulus(ServerStateNextShot,
00116                 ServerStimulusNewGame, ServerStateNewGame);     
00117         gameState.addStateStimulus(ServerStateNextShot,
00118                 ServerStimulusStarting, ServerStateStarting);   
00119         gameState.addStateStimulus(ServerStateNextShot, 
00120                 ServerStimulusNextRound, ServerStateNextRound);
00121 
00122         // ServerStateNextTurn
00123         ServerNextTurnState *serverNextTurn = new ServerNextTurnState;
00124         gameState.addStateLoop(ServerStateNextTurn, &dummyLoop_, 
00125                 &ScorchedServer::instance()->getActionController());
00126         gameState.addStateEntry(ServerStateNextTurn,
00127                 serverNextTurn);
00128         gameState.addStateStimulus(ServerStateNextTurn,
00129                 ServerStimulusBuying, ServerStateBuying);       
00130         gameState.addStateStimulus(ServerStateNextTurn,
00131                 ServerStimulusPlaying, ServerStatePlaying);     
00132         gameState.addStateStimulus(ServerStateNextTurn,
00133                 ServerStimulusShot, ServerStateShot);   
00134 
00135         // ServerStatePlaying
00136         ServerPlayingState *serverPlaying = new ServerPlayingState;
00137         gameState.addStateLoop(ServerStatePlaying, &dummyLoop_, 
00138                 &ScorchedServer::instance()->getActionController());
00139         gameState.addStateEntry(ServerStatePlaying,
00140                 serverPlaying);
00141         gameState.addStateStimulus(ServerStatePlaying,
00142                 ServerTooFewPlayersStimulus::instance(), ServerStateShot);      
00143         gameState.addStateStimulus(ServerStatePlaying,
00144                 serverPlaying, ServerStateNextTurn);
00145 
00146         // ServerStateBuying
00147         ServerPlayingState *serverBuying = new ServerPlayingState;
00148         gameState.addStateLoop(ServerStateBuying, &dummyLoop_, 
00149                 &ScorchedServer::instance()->getActionController());
00150         gameState.addStateEntry(ServerStateBuying,
00151                 serverBuying);
00152         gameState.addStateStimulus(ServerStateBuying,
00153                 ServerTooFewPlayersStimulus::instance(), ServerStateShot);      
00154         gameState.addStateStimulus(ServerStateBuying,
00155                 serverBuying, ServerStateNextTurn);
00156 
00157         // ServerStateShot
00158         ServerShotState *serverShot = new ServerShotState();
00159         gameState.addStateLoop(ServerStateShot, &dummyLoop_, 
00160                 &ScorchedServer::instance()->getActionController());
00161         gameState.addStateEntry(ServerStateShot,
00162                 serverShot);
00163         gameState.addStateStimulus(ServerStateShot,
00164                 serverShot, ServerStateShotReady);
00165 
00166         // ServerStateShotReady
00167         ServerReadyState *serverShotReady = new ServerReadyState();
00168         gameState.addStateLoop(ServerStateShotReady, &dummyLoop_, 
00169                 &ScorchedServer::instance()->getActionController());
00170         gameState.addStateEntry(ServerStateShotReady,
00171                 serverShotReady);
00172         gameState.addStateStimulus(ServerStateShotReady, 
00173                 serverShotReady, ServerStateShotFinished);
00174 
00175         // ServerStateShotFinished
00176         ServerShotFinishedState *serverShotFinished = new ServerShotFinishedState(serverShot);
00177         gameState.addStateLoop(ServerStateShotFinished, &dummyLoop_, 
00178                 &ScorchedServer::instance()->getActionController());
00179         gameState.addStateEntry(ServerStateShotFinished,
00180                 serverShotFinished);
00181         gameState.addStateStimulus(ServerStateShotFinished, 
00182                 ServerStimulusTooFewPlayers, ServerStateTooFewPlayers);
00183         gameState.addStateStimulus(ServerStateShotFinished, 
00184                 serverShotFinished, ServerStateNextShot);
00185 
00186         // Set the start state
00187         gameState.setState(ServerStateTooFewPlayers);
00188 }

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