1 /*============================================================================= 2 Blobby Volley 2 3 Copyright (C) 2006 Jonathan Sieber (jonathan_sieber@yahoo.de) 4 Copyright (C) 2006 Daniel Knobe (daniel-knobe@web.de) 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 =============================================================================*/ 20 21 #pragma once 22 23 #include "GameState.h" 24 #include "NetworkMessage.h" 25 #include "PlayerIdentity.h" 26 27 #include <vector> 28 #include <boost/scoped_ptr.hpp> 29 #include <boost/shared_ptr.hpp> 30 31 class RakClient; 32 class RakServer; 33 class DuelMatch; 34 class InputSource; 35 class NetworkGame; 36 class PlayerIdentity; 37 class DedicatedServer; 38 39 /*! \class NetworkGameState 40 \brief State for Network Game 41 \details state which is responsible for presenting a network game, sending player input to the 42 server, managing chat etc. 43 */ 44 class NetworkGameState : public GameState 45 { 46 public: 47 /// create a NetworkGameState with connection to a certain server 48 /// \param client A client which has an established connection to the server we want to start the game on. 49 NetworkGameState(boost::shared_ptr<RakClient> client); 50 51 virtual ~NetworkGameState(); 52 virtual void step_impl(); 53 virtual const char* getStateName() const; 54 55 private: 56 enum 57 { 58 WAITING_FOR_OPPONENT, 59 OPPONENT_DISCONNECTED, 60 DISCONNECTED, 61 SERVER_FULL, 62 PLAYING, 63 PLAYER_WON, 64 PAUSING 65 } mNetworkState; 66 67 // these are pointers to mLeftPlayer or mRightPlayer respectively, so we don't need a smart pointer here 68 PlayerIdentity* mLocalPlayer; 69 PlayerIdentity* mRemotePlayer; 70 71 bool mUseRemoteColor; 72 73 boost::scoped_ptr<InputSource> mLocalInput; 74 75 bool mWaitingForReplay; 76 77 boost::shared_ptr<RakClient> mClient; 78 PlayerSide mOwnSide; 79 PlayerSide mWinningPlayer; 80 81 // Chat Vars 82 std::vector<std::string> mChatlog; 83 std::vector<bool > mChatOrigin; 84 unsigned mSelectedChatmessage; 85 unsigned mChatCursorPosition; 86 std::string mChattext; 87 }; 88 89 90 /*! \class NetworkHostState 91 \brief state for hosting a game locally 92 \details 93 This class is a wrapper for NetworkGameState to run an instance 94 of NetworkGame 95 \todo this construction seems like a big hack ;) 96 */ 97 class NetworkHostState : public State 98 { 99 public: 100 NetworkHostState(); 101 virtual ~NetworkHostState(); 102 103 virtual void step_impl(); 104 virtual const char* getStateName() const; 105 106 private: 107 boost::scoped_ptr<DedicatedServer> mServer; 108 boost::shared_ptr<RakClient> mClient; 109 NetworkGameState* mGameState; 110 111 PlayerIdentity mLocalPlayer; 112 unsigned int mLobbyCounter; 113 114 }; 115 116