| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file game.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created OpenJazz.h |
| 10 | * - 2nd March 2009: Created network.h from parts of OpenJazz.h |
| 11 | * - 9th February 2009: Renamed network.h to game.h |
| 12 | * - 2nd August 2009: Created gamemode.h from parts of game.h |
| 13 | * |
| 14 | * @par Licence: |
| 15 | * Copyright (c) 2005-2017 AJ Thomson |
| 16 | * |
| 17 | * OpenJazz is distributed under the terms of |
| 18 | * the GNU General Public License, version 2.0 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #ifndef _GAME_H |
| 24 | #define _GAME_Hcxx . . $ `src/game/game.h:24:9`! |
| 25 | |
| 26 | |
| 27 | #include "gamemode.h"cxx . . $ `<file>/src/game/gamemode.h`/ |
| 28 | |
| 29 | #include "io/network.h"cxx . . $ `<file>/src/io/network.h`/ |
| 30 | #include "level/level.h"cxx . . $ `<file>/src/level/level.h`/ |
| 31 | |
| 32 | |
| 33 | // Constants |
| 34 | |
| 35 | // Time intervals |
| 36 | #define T_SSENDcxx . . $ `src/game/game.h:36:9`! 20 |
| 37 | #define T_SCHECKcxx . . $ `src/game/game.h:37:9`! 1000 |
| 38 | #define T_CSENDcxx . . $ `src/game/game.h:38:9`! 10 |
| 39 | #define T_CCHECKcxx . . $ `src/game/game.h:39:9`! 1000 |
| 40 | |
| 41 | // Message categories and types |
| 42 | #define MCMASKcxx . . $ `src/game/game.h:42:9`! 0xF0 |
| 43 | #define MC_GAMEcxx . . $ `src/game/game.h:43:9`! 0x00 |
| 44 | #define MC_LEVELcxx . . $ `src/game/game.h:44:9`! 0x10 |
| 45 | #define MC_PLAYERcxx . . $ `src/game/game.h:45:9`! 0x20 |
| 46 | |
| 47 | #define MT_G_PROPScxx . . $ `src/game/game.h:47:9`! 0x00 /* Game properties */ |
| 48 | #define MT_G_PJOINcxx . . $ `src/game/game.h:48:9`! 0x01 /* New player joined */ |
| 49 | #define MT_G_PQUITcxx . . $ `src/game/game.h:49:9`! 0x02 /* Player left */ |
| 50 | #define MT_G_LEVELcxx . . $ `src/game/game.h:50:9`! 0x03 /* Level data */ |
| 51 | #define MT_G_CHECKcxx . . $ `src/game/game.h:51:9`! 0x04 |
| 52 | #define MT_G_SCOREcxx . . $ `src/game/game.h:52:9`! 0x05 /* Team scored a roast/lap/etc. */ |
| 53 | #define MT_G_LTYPEcxx . . $ `src/game/game.h:53:9`! 0x06 /* Level type */ |
| 54 | |
| 55 | #define MT_L_PROPcxx . . $ `src/game/game.h:55:9`! 0x10 /* Level property */ |
| 56 | #define MT_L_GRIDcxx . . $ `src/game/game.h:56:9`! 0x11 /* Change to gridElement */ |
| 57 | #define MT_L_STAGEcxx . . $ `src/game/game.h:57:9`! 0x12 /* Change in level stage */ |
| 58 | |
| 59 | #define MT_P_ANIMScxx . . $ `src/game/game.h:59:9`! 0x20 /* Player animations */ |
| 60 | #define MT_P_TEMPcxx . . $ `src/game/game.h:60:9`! 0x21 /* Temporary player properties, e.g. position */ |
| 61 | |
| 62 | // Minimum message lengths, including header |
| 63 | #define MTL_G_PROPScxx . . $ `src/game/game.h:63:9`! 8 |
| 64 | #define MTL_G_PJOINcxx . . $ `src/game/game.h:64:9`! 10 |
| 65 | #define MTL_G_PQUITcxx . . $ `src/game/game.h:65:9`! 3 |
| 66 | #define MTL_G_LEVELcxx . . $ `src/game/game.h:66:9`! 4 /* + amount of level data */ |
| 67 | #define MTL_G_CHECKcxx . . $ `src/game/game.h:67:9`! 6 |
| 68 | #define MTL_G_SCOREcxx . . $ `src/game/game.h:68:9`! 3 |
| 69 | #define MTL_G_LTYPEcxx . . $ `src/game/game.h:69:9`! 3 |
| 70 | |
| 71 | #define MTL_L_PROPcxx . . $ `src/game/game.h:71:9`! 5 |
| 72 | #define MTL_L_GRIDcxx . . $ `src/game/game.h:72:9`! 8 |
| 73 | #define MTL_L_STAGEcxx . . $ `src/game/game.h:73:9`! 3 |
| 74 | |
| 75 | #define MTL_P_ANIMScxx . . $ `src/game/game.h:75:9`! 3 /* + PANIMS, BPANIMS, or 1 (for JJ2) */ |
| 76 | #define MTL_P_TEMPcxx . . $ `src/game/game.h:76:9`! 46 |
| 77 | |
| 78 | #define BUFFER_LENGTHcxx . . $ `src/game/game.h:78:9`! 255 /* Should always be big enough to hold any message */ |
| 79 | |
| 80 | |
| 81 | // Classes |
| 82 | |
| 83 | class Animcxx . . $ Anim#; |
| 84 | class Filecxx . . $ File#; |
| 85 | |
| 86 | /// Base class for game handling classes |
| 87 | class Gamecxx . . $ Game# { |
| 88 | |
| 89 | private: |
| 90 | int planetIdcxx . . $ Game#planetId.; ///< ID of last planet approach sequence |
| 91 | |
| 92 | bool isFileTypecxx . . $ Game#isFileType(f827cee075336303). (const char *fileName, const char *type, int typeLength); |
| 93 | |
| 94 | protected: |
| 95 | GameModecxx . . $ GameMode#* modecxx . . $ Game#mode.; ///< Mode-specific management |
| 96 | Levelcxx . . $ Level#* baseLevelcxx . . $ Game#baseLevel.; ///< Current level |
| 97 | char* levelFilecxx . . $ Game#levelFile.; ///< Current level's file name |
| 98 | LevelTypecxx . . $ LevelType# levelTypecxx . . $ Game#levelType.; ///< Current level's type |
| 99 | difficultyTypecxx . . $ difficultyType# difficultycxx . . $ Game#difficulty.; ///< Difficulty setting (easy, medium, hard, turbo (hard in JJ2 levels)) |
| 100 | unsigned int sendTimecxx . . $ Game#sendTime.; ///< The next time data will be sent |
| 101 | unsigned int checkTimecxx . . $ Game#checkTime.; ///< The next time a connection/disconnection will be dealt with |
| 102 | short int checkXcxx . . $ Game#checkX.; ///< X-coordinate of the level checkpoint |
| 103 | short int checkYcxx . . $ Game#checkY.; ///< Y-coordinate of the level checkpoint |
| 104 | |
| 105 | Gamecxx . . $ Game#Game(49f6e7a06ebc5aa8). (); |
| 106 | |
| 107 | GameModecxx . . $ GameMode#* createModecxx . . $ Game#createMode(14876a996d2f6cf). (GameModeTypecxx . . $ GameModeType# modeType); |
| 108 | |
| 109 | LevelTypecxx . . $ LevelType# getLevelTypecxx . . $ Game#getLevelType(b61afb7421387496). (const char* fileName); |
| 110 | int playLevelcxx . . $ Game#playLevel(cbb24b081db01e54). (char *fileName, bool intro, bool checkpoint); |
| 111 | |
| 112 | void addLevelPlayercxx . . $ Game#addLevelPlayer(34e2c302b1f0e5dd). (Playercxx . . $ Player# *player); |
| 113 | |
| 114 | public: |
| 115 | virtual ~cxx . . $ Game#`~Game`(49f6e7a06ebc5aa8).Gamecxx . . $ Game# (); |
| 116 | |
| 117 | GameModecxx . . $ GameMode#* getModecxx . . $ Game#getMode(b2ac8a9286443acb). (); |
| 118 | difficultyTypecxx . . $ difficultyType# getDifficultycxx . . $ Game#getDifficulty(601dbc13202031c0). (); |
| 119 | void setDifficultycxx . . $ Game#setDifficulty(7b65cd849eaf05fb). (difficultyTypecxx . . $ difficultyType# diff); |
| 120 | int playLevelcxx . . $ Game#playLevel(1ef8e6ec083aabb9). (char *fileName); |
| 121 | virtual int setLevelcxx . . $ Game#setLevel(1ef8e6ec083aabb9). (char *fileName) = 0; |
| 122 | int playcxx . . $ Game#play(b126dc7c1de90089). (); |
| 123 | void viewcxx . . $ Game#view(d4f767463ce0a6b3). (int change); |
| 124 | virtual void sendcxx . . $ Game#send(f25546b61a629de7). (unsigned char *buffer) = 0; |
| 125 | virtual int stepcxx . . $ Game#step(4c679297bf94b9eb). (unsigned int ticks) = 0; |
| 126 | virtual void scorecxx . . $ Game#score(ac50b47256ae7414). (unsigned char team) = 0; |
| 127 | virtual void setCheckpointcxx . . $ Game#setCheckpoint(3e454b8ccf442868). (int gridX, int gridY) = 0; |
| 128 | void resetPlayercxx . . $ Game#resetPlayer(34e2c302b1f0e5dd). (Playercxx . . $ Player# *player); |
| 129 | |
| 130 | }; |
| 131 | |
| 132 | |
| 133 | /// Game handling for single-player local play |
| 134 | class LocalGamecxx . . $ LocalGame# : public Gamecxx . . $ Game# { |
| 135 | |
| 136 | public: |
| 137 | LocalGamecxx . . $ LocalGame#LocalGame(d100a742d84345dc). (const char *firstLevel, difficultyTypecxx . . $ difficultyType# gameDifficulty); |
| 138 | ~cxx . . $ LocalGame#`~LocalGame`(49f6e7a06ebc5aa8).LocalGamecxx . . $ LocalGame# () override; |
| 139 | |
| 140 | int setLevelcxx . . $ LocalGame#setLevel(1ef8e6ec083aabb9). (char *fileName) override; |
| 141 | void sendcxx . . $ LocalGame#send(f25546b61a629de7). (unsigned char *buffer) override; |
| 142 | int stepcxx . . $ LocalGame#step(4c679297bf94b9eb). (unsigned int ticks) override; |
| 143 | void scorecxx . . $ LocalGame#score(ac50b47256ae7414). (unsigned char team) override; |
| 144 | void setCheckpointcxx . . $ LocalGame#setCheckpoint(3e454b8ccf442868). (int gridX, int gridY) override; |
| 145 | |
| 146 | }; |
| 147 | |
| 148 | |
| 149 | /// Game handling for multiplayer servers |
| 150 | class ServerGamecxx . . $ ServerGame# : public Gamecxx . . $ Game# { |
| 151 | |
| 152 | private: |
| 153 | int clientStatuscxx . . $ ServerGame#clientStatus.[MAX_CLIENTScxx . . $ `src/io/network.h:44:9`!]; /**< Array of client statuses |
| 154 | -2: Connected and operational |
| 155 | -1: Not connected |
| 156 | >=0: Number of bytes of the level that have been sent */ |
| 157 | int clientPlayercxx . . $ ServerGame#clientPlayer.[MAX_CLIENTScxx . . $ `src/io/network.h:44:9`!]; ///< Array of client player indexes |
| 158 | int clientSockcxx . . $ ServerGame#clientSock.[MAX_CLIENTScxx . . $ `src/io/network.h:44:9`!]; ///< Array of client sockets |
| 159 | unsigned char recvBufferscxx . . $ ServerGame#recvBuffers.[MAX_CLIENTScxx . . $ `src/io/network.h:44:9`!][BUFFER_LENGTHcxx . . $ `src/game/game.h:78:9`!]; ///< Array of buffers containing data received from clients |
| 160 | int receivedcxx . . $ ServerGame#received.[MAX_CLIENTScxx . . $ `src/io/network.h:44:9`!]; ///< Array containing the amount of data received from each client |
| 161 | unsigned char *levelDatacxx . . $ ServerGame#levelData.; ///< Contents of the current level file |
| 162 | int levelSizecxx . . $ ServerGame#levelSize.; ///< Size of the current level file |
| 163 | int sockcxx . . $ ServerGame#sock.; ///< Server socket |
| 164 | |
| 165 | public: |
| 166 | ServerGamecxx . . $ ServerGame#ServerGame(b6c1c4f70c1ea4fa). (GameModeTypecxx . . $ GameModeType# mode, char *firstLevel, difficultyTypecxx . . $ difficultyType# gameDifficulty); |
| 167 | ~cxx . . $ ServerGame#`~ServerGame`(49f6e7a06ebc5aa8).ServerGamecxx . . $ ServerGame# () override; |
| 168 | |
| 169 | int setLevelcxx . . $ ServerGame#setLevel(1ef8e6ec083aabb9). (char *fileName) override; |
| 170 | void sendcxx . . $ ServerGame#send(f25546b61a629de7). (unsigned char *buffer) override; |
| 171 | int stepcxx . . $ ServerGame#step(4c679297bf94b9eb). (unsigned int ticks) override; |
| 172 | void scorecxx . . $ ServerGame#score(ac50b47256ae7414). (unsigned char team) override; |
| 173 | void setCheckpointcxx . . $ ServerGame#setCheckpoint(3e454b8ccf442868). (int gridX, int gridY) override; |
| 174 | |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | /// Game handling for multiplayer clients |
| 179 | class ClientGamecxx . . $ ClientGame# : public Gamecxx . . $ Game# { |
| 180 | |
| 181 | private: |
| 182 | Filecxx . . $ File# *filecxx . . $ ClientGame#file.; ///< File to which the incoming level will be written |
| 183 | unsigned char recvBuffercxx . . $ ClientGame#recvBuffer.[BUFFER_LENGTHcxx . . $ `src/game/game.h:78:9`!]; ///< Buffer containing data received from server |
| 184 | int receivedcxx . . $ ClientGame#received.; ///< Amount of data received from server |
| 185 | int clientIDcxx . . $ ClientGame#clientID.; ///< Client's index on the server |
| 186 | int maxPlayerscxx . . $ ClientGame#maxPlayers.; ///< The maximum number of players in the game |
| 187 | int sockcxx . . $ ClientGame#sock.; ///< Client socket |
| 188 | |
| 189 | public: |
| 190 | explicit ClientGamecxx . . $ ClientGame#ClientGame(fda57c8427c60377).(char *address); |
| 191 | ~cxx . . $ ClientGame#`~ClientGame`(49f6e7a06ebc5aa8).ClientGamecxx . . $ ClientGame#() override; |
| 192 | |
| 193 | int setLevelcxx . . $ ClientGame#setLevel(1ef8e6ec083aabb9). (char *fileName) override; |
| 194 | void sendcxx . . $ ClientGame#send(f25546b61a629de7). (unsigned char *buffer) override; |
| 195 | int stepcxx . . $ ClientGame#step(4c679297bf94b9eb). (unsigned int ticks) override; |
| 196 | void scorecxx . . $ ClientGame#score(ac50b47256ae7414). (unsigned char team) override; |
| 197 | void setCheckpointcxx . . $ ClientGame#setCheckpoint(3e454b8ccf442868). (int gridX, int gridY) override; |
| 198 | |
| 199 | }; |
| 200 | |
| 201 | #endif |
| 202 |