1 /* 2 * Hedgewars, a free turn based strategy game 3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef GAME_H 20 #define GAME_H 21 22 #include <QString> 23 #include "team.h" 24 #include "namegen.h" 25 26 #include "tcpBase.h" 27 28 class GameUIConfig; 29 class GameCFGWidget; 30 class TeamSelWidget; 31 32 enum GameType 33 { 34 gtNone = 0, 35 gtLocal = 1, 36 gtQLocal = 2, 37 gtDemo = 3, 38 gtNet = 4, 39 gtTraining = 5, 40 gtCampaign = 6, 41 gtSave = 7, 42 }; 43 44 enum GameState 45 { 46 gsNotStarted = 0, 47 gsStarted = 1, 48 gsInterrupted = 2, 49 gsFinished = 3, 50 gsStopped = 4, 51 gsDestroyed = 5, 52 gsHalted = 6 53 }; 54 55 enum RecordType 56 { 57 rtDemo, 58 rtSave, 59 rtNeither, 60 }; 61 62 bool checkForDir(const QString & dir); 63 64 // last game info 65 extern QList<QVariant> lastGameStartArgs; 66 extern GameType lastGameType; 67 extern GameCFGWidget * lastGameCfg; 68 extern QString lastGameAmmo; 69 extern TeamSelWidget * lastGameTeamSel; 70 71 class HWGame : public TCPBase 72 { 73 Q_OBJECT 74 public: 75 HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget = 0); 76 virtual ~HWGame(); 77 void AddTeam(const QString & team); 78 void PlayDemo(const QString & demofilename, bool isSave); 79 void PlayOfficialServerDemo(); 80 void StartLocal(); 81 void StartQuick(); 82 void StartNet(); 83 void StartTraining(const QString & file, const QString & subFolder, const QString & trainTeam); 84 void StartCampaign(const QString & camp, const QString & campScript, const QString & campTeam); 85 void abort(); 86 GameState gameState; 87 bool netSuspend; 88 89 protected: 90 virtual QStringList getArguments(); 91 virtual void onClientRead(); 92 virtual void onClientDisconnect(); 93 94 signals: 95 void SendNet(const QByteArray & msg); 96 void SendChat(const QString & msg); 97 void SendTeamMessage(const QString & msg); 98 void GameStateChanged(GameState gameState); 99 void DemoPresenceChanged(bool hasDemo); 100 void GameStats(char type, const QString & info); 101 void HaveRecord(RecordType type, const QByteArray & record); 102 void ErrorMessage(const QString &); 103 void CampStateChanged(int); 104 void TrainingStateChanged(int); 105 void SendConsoleCommand(const QString & command); 106 107 public slots: 108 void FromNet(const QByteArray & msg); 109 void FromNetChat(const QString & msg); 110 void FromNetWarning(const QString & msg); 111 void FromNetError(const QString & msg); 112 113 private: 114 char msgbuf[MAXMSGCHARS]; 115 QString ammostr; 116 GameUIConfig * config; 117 GameCFGWidget * gamecfg; 118 TeamSelWidget* m_pTeamSelWidget; 119 GameType gameType; 120 QByteArray m_netSendBuffer; 121 122 void commonConfig(); 123 void SendConfig(); 124 void SendQuickConfig(); 125 void SendNetConfig(); 126 void SendTrainingConfig(); 127 void SendCampaignConfig(); 128 void ParseMessage(const QByteArray & msg); 129 void SetGameState(GameState state); 130 void SetDemoPresence(bool hasDemo); 131 void sendCampaignVar(const QByteArray & varToSend); 132 void writeCampaignVar(const QByteArray &varVal); 133 void sendMissionVar(const QByteArray & varToSend); 134 void writeMissionVar(const QByteArray &varVal); 135 void flushNetBuffer(); 136 }; 137 138 #endif 139