1 /*************************************************************************** 2 * Mechanized Assault and Exploration Reloaded Projectfile * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 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 * 16 * Free Software Foundation, Inc., * 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 ***************************************************************************/ 19 20 #ifndef game_logic_servereventsH 21 #define game_logic_servereventsH 22 23 #include <string> 24 #include "defines.h" 25 #include "main.h" // for sID 26 #include "game/logic/movejobs.h" 27 #include "game/logic/upgradecalculator.h" // cResearch::ResearchArea 28 #include "network.h" 29 30 class cBuilding; 31 class cHud; 32 class cMap; 33 class cNetMessage; 34 class cResearch; 35 class cUnit; 36 class cSavedReport; 37 class cGameGuiState; 38 struct sSubBase; 39 40 enum SERVER_EVENT_TYPES 41 { 42 // Types between FIRST_SERVER_MESSAGE and FIRST_CLIENT_MESSAGE are for the server 43 GAME_EV_CHAT_CLIENT = FIRST_SERVER_MESSAGE, // a chat message from client to server 44 GAME_EV_WANT_TO_END_TURN, // a client wants to end the turn 45 GAME_EV_WANT_START_WORK, // a client wants to start a building 46 GAME_EV_WANT_STOP_WORK, // a client wants to stop a building 47 GAME_EV_MOVE_JOB_CLIENT, // a message with all waypoints 48 GAME_EV_WANT_STOP_MOVE, // a client wants to stop a moving vehicle 49 GAME_EV_MOVEJOB_RESUME, // a client wants a paused movejob to be resumed 50 GAME_EV_WANT_ATTACK, // a client wants to attack an other unit 51 GAME_EV_MINELAYERSTATUS, // a minelayer changes his laying status 52 GAME_EV_WANT_BUILD, // a vehicle wants to start building a building 53 GAME_EV_END_BUILDING, // a vehicle has finished building and will leave the building lot now 54 GAME_EV_WANT_STOP_BUILDING, // a vehicle wants to stop building 55 GAME_EV_WANT_TRANSFER, // information about a resource transfer 56 GAME_EV_WANT_BUILDLIST, // a building wants his buildlist to be verified by the server and start work 57 GAME_EV_WANT_EXIT_FIN_VEH, // a client wants to exit a finished vehicle out of a building 58 GAME_EV_CHANGE_RESOURCES, // a client wants to change his resource production 59 GAME_EV_WANT_CHANGE_MANUAL_FIRE,// a client wants to change the manual fire status of a unit 60 GAME_EV_WANT_CHANGE_SENTRY, // a client wants to change the sentry status of a unit 61 GAME_EV_WANT_MARK_LOG, // marks a position in the log file 62 GAME_EV_WANT_SUPPLY, // a client wants to rearm or repair a unit 63 GAME_EV_WANT_VEHICLE_UPGRADE, // a client wants to upgrade a vehicle in a building to the newest version 64 GAME_EV_WANT_START_CLEAR, // a bulldowzer wants to start clearing the field under his position 65 GAME_EV_WANT_STOP_CLEAR, // a bulldowzer wants to stop the clearing 66 GAME_EV_ABORT_WAITING, // the player wants to abort waiting for the reconnect of a disconnected player 67 GAME_EV_IDENTIFICATION, // a message with the name of the player who wants to reconnect 68 GAME_EV_RECON_SUCCESS, // a client has reconnected successfully and is ready to receive his game data 69 GAME_EV_WANT_LOAD, // a client wants to load a unit into another 70 GAME_EV_WANT_EXIT, // a client wants to exit a stored unit 71 GAME_EV_REQUEST_RESYNC, // requests the server to resync a client 72 GAME_EV_WANT_BUY_UPGRADES, // a client wants to buy gold upgrades for units 73 GAME_EV_WANT_BUILDING_UPGRADE, // a client wants to upgrade one or more buildings to the newest version 74 GAME_EV_WANT_RESEARCH_CHANGE, // a client wants to change the research assignments of his research centers 75 GAME_EV_AUTOMOVE_STATUS, // a unit has been set to automoving 76 GAME_EV_SAVE_HUD_INFO, // the current hud settings 77 GAME_EV_SAVE_REPORT_INFO, // a saved report 78 GAME_EV_FIN_SEND_SAVE_INFO, // 79 GAME_EV_WANT_COM_ACTION, // an infiltrator wants to steal or disable another unit 80 GAME_EV_WANT_SELFDESTROY, 81 GAME_EV_WANT_CHANGE_UNIT_NAME, // the player wants to change the name of an unit 82 GAME_EV_END_MOVE_ACTION, // specifies an action, which will be executed at the end of a movejob 83 84 GAME_EV_WANT_KICK_PLAYER, 85 GAME_EV_REQ_RECON_IDENT, // a server of a running game requests an identification of a player who wants to reconnect 86 GAME_EV_RECONNECT_ANSWER, // a server returns an answer for the reconnect 87 88 // Preparation room 89 MU_MSG_CLAN, // a player sends his clan 90 MU_MSG_LANDING_VEHICLES, // the list of purchased vehicles 91 MU_MSG_UPGRADES, // data of upgraded units 92 MU_MSG_LANDING_COORDS, // the selected landing coords of a client 93 MU_MSG_READY_TO_START, // the client is ready and wants the server to start the game 94 95 // DEDICATED_SERVER 96 GAME_EV_WANT_DISCONNECT, // the player wants to disconnect (but later reconnect to the dedicated server) 97 GAME_EV_REQUEST_CASUALTIES_REPORT, // a client wants to have the current casualties data 98 NET_GAME_TIME_CLIENT, //reports the current gametime of the client to server 99 }; 100 101 /** 102 * Sends an event to a player that a new unit has to be added 103 *@author alzi alias DoctorDeath 104 *@param position The position of the unit 105 *@param bVehicle True if the unit is an vehicle 106 *@param iUnitNum The typ number of the unit 107 *@param player The player who should receive this event and get the new unit 108 *@param bInit True if this is called by game initialisation 109 */ 110 void sendAddUnit (cServer& server, const cPosition& position, int iID, bool bVehicle, sID UnitID, const cPlayer& player, bool bInit, bool bAddToMap = true); 111 /** 112 * Sends an event to a player that a unit has to be deleted 113 *@param unit unit that has to be deleted 114 *@param receiver The player who should receive this event. 115 * Null for all player who can see the unit 116 */ 117 void sendDeleteUnit (cServer& server, const cUnit& unit, const cPlayer* receiver); 118 void sendDeleteUnitMessage (cServer& server, const cUnit& unit, const cPlayer& receiver); 119 /** 120 * adds a rubble object to the client 121 */ 122 void sendAddRubble (cServer& server, const cBuilding& building, const cPlayer& receiver); 123 /** 124 * Sends an event to a player that he has detected 125 * an enemy unit and should add it 126 *@author alzi alias DoctorDeath 127 *@param unit The unit that should be added by the player 128 *@param player The player who should receive this event 129 */ 130 void sendAddEnemyUnit (cServer& server, const cUnit& unit, const cPlayer& receiver); 131 132 void sendMakeTurnEnd (cServer& server, const cPlayer* receiver = nullptr); 133 134 void sendTurnFinished (cServer& server, const cPlayer& playerWhoEndedTurn, const cPlayer* nextPlayer, const cPlayer* receiver = nullptr); 135 136 void sendTurnStartTime (cServer& server, unsigned int gameTime); 137 138 void sendTurnEndDeadlineStartTime (cServer& server, unsigned int gameTime); 139 140 /** 141 * Sends the data values of this unit to the client 142 * 143 * @param unit The unit from which the data should be taken 144 * @param player The player who should receive this message 145 */ 146 void sendUnitData (cServer& server, const cUnit& unit, const cPlayer& receiver); 147 /** 148 * Sends the unit data to the owner of the unit (if there is one) and to 149 * all players that can see the unit. 150 * 151 * @param unit The unit from which the data should be taken 152 */ 153 void sendUnitData (cServer& server, const cUnit& unit); 154 155 void sendSpecificUnitData (cServer& server, const cVehicle& Vehicle); 156 157 /** 158 * sends all necessary information to all clients to start the building 159 *@ author Eiko 160 */ 161 void sendDoStartWork (cServer& server, const cBuilding& building); 162 163 /** 164 * sends all necessary information to all clients to stop the building 165 *@ author Eiko 166 */ 167 void sendDoStopWork (cServer& server, const cBuilding& building); 168 169 /** 170 * sends information about the move to the next field of a client 171 *@author alzi alias DoctorDeath 172 */ 173 void sendNextMove (cServer& server, const cVehicle& vehicle, int iType, int iSavedSpeed = -1); 174 175 /** 176 * sends all waypoints of a movejob to a client. 177 * If the movejob is already running, 178 * the sourceoffset will be changed to the actual position of the vehicle 179 *@author alzi alias DoctorDeath 180 */ 181 void sendMoveJobServer (cServer& server, const cServerMoveJob& MoveJob, const cPlayer& receiver); 182 /** 183 * sends the resourcedata of new scaned fields around the unit to a client 184 *@author alzi alias DoctorDeath 185 */ 186 void sendVehicleResources (cServer& server, const cVehicle& vehicle); 187 void sendResources (cServer& server, const cPlayer& player); 188 /** 189 * sends an answer to a client wheter and how he has to build. 190 *@author alzi alias DoctorDeath 191 */ 192 void sendBuildAnswer (cServer& server, bool bOK, const cVehicle& vehicle); 193 /** 194 * sends that a vehicle has to stop building 195 *@author alzi alias DoctorDeath 196 */ 197 void sendStopBuild (cServer& server, int iVehicleID, const cPosition& newPosition, const cPlayer& receiver); 198 /** 199 * send the values if a subbase. 200 *@author alzi alias DoctorDeath 201 *@param subbase the subbase which values should be send 202 */ 203 void sendSubbaseValues (cServer& server, const sSubBase& subbase, const cPlayer& receiver); 204 /** 205 * sends a list with all units which are wanted to be produced by the building 206 *@author alzi alias DoctorDeath 207 *@param building the building which buildlist should be send 208 */ 209 void sendBuildList (cServer& server, const cBuilding& building); 210 /** 211 * send the new values of resource production of a building 212 *@author alzi alias DoctorDeath 213 *@param building the building which producevalues should be send 214 */ 215 void sendProduceValues (cServer& server, const cBuilding& building); 216 /** 217 * sends that a unit has to be rearmed or repaired 218 *@author alzi alias DoctorDeath 219 *@param iDestID the ID of the destination unit 220 *@param bDestVehicle true if the destination unit is a vehicle 221 *@param iValue the new ammo or hitpoint value to be set 222 *@param iType SUPPLY_TYPE_REARM or SUPPLY_TYPE_REPAIR 223 *@param receiver The player, who will receive the message 224 */ 225 void sendSupply (cServer& server, int iDestID, bool bDestVehicle, int iValue, int iType, const cPlayer& receiver); 226 /** 227 * informs the owner of the vehicle whether the vehicle has been detected 228 * by another player. 229 * this is used by the client for correct drawing of the unit 230 */ 231 void sendDetectionState (cServer& server, const cVehicle& vehicle); 232 233 /** 234 * sends whether and how the unit has to clean the field 235 *@author alzi alias DoctorDeath 236 */ 237 void sendClearAnswer (cServer& server, int answertype, const cVehicle& vehicle, int turns, const cPosition& bigPosition, const cPlayer* player); 238 /** 239 * sends that a unit has to stop clearing 240 *@author alzi alias DoctorDeath 241 */ 242 void sendStopClear (cServer& server, const cVehicle& vehicle, const cPosition& bigPosition, const cPlayer& player); 243 /** 244 * sends that the player has to set his hole ScanMap to 1 245 *@author alzi alias DoctorDeath 246 */ 247 void sendNoFog (cServer& server, const cPlayer& receiver); 248 /** 249 * sends that a player has been defeated 250 *@author alzi alias DoctorDeath 251 */ 252 void sendDefeated (cServer& server, const cPlayer& player, const cPlayer* receiver = nullptr); 253 /** 254 * sends that a client has to wait until he will be defrezzed 255 *@param waitForPlayer tells the client, for which other player he is waiting 256 */ 257 void sendFreeze (cServer& server, eFreezeMode mode, int waitForPlayer); 258 /** 259 * sends that the client can abort waiting 260 */ 261 void sendUnfreeze (cServer& server, eFreezeMode mode); 262 /** 263 * sends that a client has to wait for another player to end his turn 264 *@author alzi alias DoctorDeath 265 */ 266 void sendWaitFor (cServer& server, const cPlayer& player, const cPlayer* receiver); 267 /** 268 * sends that a player has to be deleted 269 *@author alzi alias DoctorDeath 270 */ 271 void sendDeletePlayer (cServer& server, const cPlayer& player, const cPlayer* receiver); 272 /** 273 * the server wants to get an identification of the new connected player 274 *@author alzi alias DoctorDeath 275 */ 276 void sendRequestIdentification (cTCP& network, int iSocket); 277 /** 278 * the server gives its ok to the reconnection 279 *@author alzi alias DoctorDeath 280 */ 281 void sendReconnectAnswer (cServer& server, int socketNumber); 282 void sendReconnectAnswer (cServer& server, int socketNumber, const cPlayer& player); 283 284 void sendTurn (cServer& server, int turn, const cPlayer& receiver); 285 void sendGameGuiState (cServer& server, const cGameGuiState& state, const cPlayer& player); 286 void sendStoreVehicle (cServer& server, int unitid, bool vehicle, int storedunitid, const cPlayer& receiver); 287 void sendActivateVehicle (cServer& server, int unitid, bool vehicle, int activatunitid, const cPosition& position, const cPlayer& receiver); 288 void sendDeleteEverything (cServer& server, const cPlayer& receiver); 289 void sendUnitUpgrades (cServer& server, const sUnitData& Data, const cPlayer& receiver); 290 void sendCredits (cServer& server, int newCredits, const cPlayer& receiver); 291 void sendUpgradeBuildings (cServer& server, const std::vector<cBuilding*>& upgradedBuildings, int totalCosts, const cPlayer& receiver); 292 void sendUpgradeVehicles (cServer& server, const std::vector<cVehicle*>& upgradedVehicles, int totalCosts, unsigned int storingBuildingID, const cPlayer& receiver); 293 void sendResearchSettings (cServer& server, const std::vector<cBuilding*>& researchCentersToChangeArea, const std::vector<cResearch::ResearchArea>& newAreasForResearchCenters, const cPlayer& receiver); 294 void sendResearchLevel (cServer& server, const cResearch& researchLevel, const cPlayer& receiver); 295 void sendFinishedResearchAreas (cServer& server, const std::vector<int>& areas, const cPlayer& receiver); 296 void sendRefreshResearchCount (cServer& server, const cPlayer& receiver); 297 void sendClansToClients (cServer& server, const std::vector<std::unique_ptr<cPlayer>>& playerList); 298 void sendGameTime (cServer& server, const cPlayer& receiver, int gameTime); 299 void sendSetAutomoving (cServer& server, const cVehicle& vehicle); 300 /** 301 * sends the result of a infiltrating action to the client 302 *@author alzi alias DoctorDeath 303 */ 304 void sendCommandoAnswer (cServer& server, bool success, bool steal, const cVehicle& srcUnit, const cPlayer& receiver); 305 void sendRequestSaveInfo (cServer& server, const int saveingID); 306 void sendSavedReport (cServer& server, const cSavedReport& savedReport, const cPlayer* receiver); 307 308 void sendCasualtiesReport (cServer& server, const cPlayer* receiver); 309 310 void sendScore (cServer& server, const cPlayer& subject, int turn, const cPlayer* receiver = nullptr); 311 void sendNumEcos (cServer& server, cPlayer& subject, const cPlayer* receiver = nullptr); 312 void sendUnitScore (cServer& server, const cBuilding&); 313 void sendGameSettings (cServer& server, const cPlayer& receiver); 314 315 void sendSelfDestroy (cServer& server, const cBuilding& building); 316 317 void sendEndMoveActionToClient (cServer& server, const cVehicle& vehicle, int destID, eEndMoveActionType type); 318 319 void sendRevealMap (cServer& server, const cPlayer& receiver); 320 321 #endif // game_logic_servereventsH 322