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_clienteventsH
21 #define game_logic_clienteventsH
22 
23 #include <array>
24 
25 #include "defines.h"
26 #include "network.h"
27 #include "game/logic/serverevents.h"
28 #include "game/logic/upgradecalculator.h"
29 
30 class cBuildListItem;
31 class cUnit;
32 class cClient;
33 class cPosition;
34 class cSavedReport;
35 class cGameGuiState;
36 struct sLandingUnit;
37 
38 enum CLIENT_EVENT_TYPES
39 {
40 	// Types between FIRST_CLIENT_MESSAGE and FIRST_MENU_MESSAGE are for the client
41 	GAME_EV_ADD_BUILDING = FIRST_CLIENT_MESSAGE,	// adds a building
42 	GAME_EV_ADD_VEHICLE,			// adds a vehicle
43 	GAME_EV_DEL_BUILDING,			// deletes a building
44 	GAME_EV_DEL_VEHICLE,			// deletes a vehicle
45 	GAME_EV_ADD_ENEM_BUILDING,		// adds a enemy building with current data
46 	GAME_EV_ADD_ENEM_VEHICLE,		// adds a vehicle with current data
47 	GAME_EV_PLAYER_CLANS,			// data about the clans of the players
48 	GAME_EV_MAKE_TURNEND,			// a player has to do actions for a turn ending
49 	GAME_EV_FINISHED_TURN,			// a player has finished his turn
50 	GAME_EV_TURN_START_TIME,		// time at that the turn started
51 	GAME_EV_TURN_END_DEADLINE_START_TIME,	// time at that the turn deadline started
52 	GAME_EV_UNIT_DATA,				// set new data values for a vehicle
53 	GAME_EV_SPECIFIC_UNIT_DATA,		// more specific unit values which are only for the owner
54 	GAME_EV_UNIT_UPGRADE_VALUES,	// message contains upgraded values for a unit
55 	GAME_EV_DO_START_WORK,			// starts a building
56 	GAME_EV_DO_STOP_WORK,			// stops a building
57 	GAME_EV_NEXT_MOVE,				// infos about the next move
58 	GAME_EV_MOVE_JOB_SERVER,		// a message with all waypoints
59 	GAME_EV_ATTACKJOB,				// sends an cAttackJob object to a client
60 	GAME_EV_RESOURCES,				// a message with new scaned resources for a client
61 	GAME_EV_BUILD_ANSWER,			// the answer of the server to a build request of a client
62 	GAME_EV_STOP_BUILD,				// a vehicle has to stop building
63 	GAME_EV_SUBBASE_VALUES,			// the values of a subbase
64 	GAME_EV_BUILDLIST,				// the buildlist of a building
65 	GAME_EV_MINE_PRODUCE_VALUES,	// the produce values of a mine
66 	GAME_EV_MARK_LOG,				// marks a position in the logfile
67 	GAME_EV_SUPPLY,					// rearms or repairs a unit
68 	GAME_EV_ADD_RUBBLE,				// adds a rubble field to the client
69 	GAME_EV_DETECTION_STATE,		// informs a client whether a vehicle has been detected
70 	GAME_EV_CLEAR_ANSWER,			// the answer to a clearing request
71 	GAME_EV_STOP_CLEARING,			// a bulldowzer has to stop clearing
72 	GAME_EV_NOFOG,					// the player can disable his fog
73 	GAME_EV_DEFEATED,				// a player has been defeated
74 	GAME_EV_FREEZE,					// a client has to be freezed
75 	GAME_EV_UNFREEZE,				// a client has to be defreezed
76 	GAME_EV_WAIT_FOR,				// a client has to wait for an other player to finish his turn
77 	GAME_EV_DEL_PLAYER,				// a client has to delete a player
78 	GAME_EV_TURN,					// a message with the current turn
79 	GAME_EV_HUD_SETTINGS,			// hud settings for a client
80 	GAME_EV_STORE_UNIT,				// a unit has to be stored
81 	GAME_EV_EXIT_UNIT,				// a unit has to be exit
82 	GAME_EV_DELETE_EVERYTHING,		// a client has to delete all units to be ready for a resync
83 	GAME_EV_CREDITS_CHANGED,		// the credits of a player changed (e.g. because he bought upgrades)
84 	GAME_EV_UPGRADED_BUILDINGS,		// the buildings in the msg have been upgraded to the current version
85 	GAME_EV_UPGRADED_VEHICLES,		// the vehicles in the msg have been upgraded to the current version
86 	GAME_EV_RESEARCH_SETTINGS,		// the research centers were newly assigned to research areas
87 	GAME_EV_RESEARCH_LEVEL,			// the research level reached by a player
88 	GAME_EV_FINISHED_RESEARCH_AREAS,
89 	GAME_EV_REFRESH_RESEARCH_COUNT,	// the client has to refresh the researchCount and the research sums for the areas after a resync
90 	GAME_EV_SET_AUTOMOVE,			// a unit has to enable automoving
91 	GAME_EV_COMMANDO_ANSWER,		// information about the result of a commando action
92 	GAME_EV_REQ_SAVE_INFO,			// request the hud state and the saved reports from a client
93 	GAME_EV_SAVED_REPORT,			// sends saved reports to a client
94 	GAME_EV_SCORE,                  // sends a player's score to a client
95 	GAME_EV_NUM_ECOS,               // sends a player's ecosphere count to a client
96 	GAME_EV_UNIT_SCORE,             // sends a unit's score to its owner
97 	GAME_EV_GAME_SETTINGS,          // the game settings
98 	GAME_EV_SELFDESTROY,
99 	GAME_EV_END_MOVE_ACTION_SERVER,	// the server has added an end move action to a movejob
100 	GAME_EV_CASUALTIES_REPORT,		// sends the casualties stats to a client
101 	GAME_EV_REVEAL_MAP,             // a client should reveal the whole map
102 	NET_GAME_TIME_SERVER,			// notification about current server time
103 	GAME_EV_SET_GAME_TIME,			// used to resync the gametime of a client
104 };
105 
106 enum CHAT_MESSAGE_TYPES
107 {
108 	USER_MESSAGE,
109 	SERVER_ERROR_MESSAGE,
110 	SERVER_INFO_MESSAGE,
111 };
112 
113 void sendClan (const cClient& client);
114 void sendLandingUnits (const cClient& client, const std::vector<sLandingUnit>& landingList);
115 void sendUnitUpgrades (const cClient& client);
116 void sendLandingCoords (const cClient& client, const cPosition& coords);
117 void sendReadyToStart (const cClient& client);
118 
119 void sendReconnectionSuccess (const cClient& client);
120 void sendTakenUpgrades (const cClient& client, const std::vector<std::pair<sID, cUnitUpgrade>>& unitUpgrades);
121 
122 /**
123 * Generates a event with a chat message and pushes it to the event queue or sends it over TCP/IP if necessary
124 *@param sMsg the chat message.
125 */
126 void sendChatMessageToServer (const cClient& client, const cPlayer& player, const std::string& message);
127 /**
128 * Sends an event that the player wants to end this turn
129 *@author alzi alias DoctorDeath
130 */
131 void sendWantToEndTurn (const cClient& client);
132 
133 /**
134 * sends a request to start a building to the Server
135 *@author Eiko
136 */
137 void sendWantStartWork (const cClient& client, const cUnit& building);
138 
139 /**
140 * sends a request to stop a building to the Server
141 *@author Eiko
142 */
143 void sendWantStopWork (const cClient& client, const cUnit& building);
144 
145 /**
146 * sends all waypoints of a movejob to the server.
147 *@author alzi alias DoctorDeath
148 */
149 void sendMoveJob (const cClient& client, sWaypoint* path, int vehicleID);
150 
151 /**
152 *
153 *@author alzi alias DoctorDeath
154 */
155 void sendWantStopMove (const cClient& client, int iVehicleID);
156 
157 /**
158 *requests the server to resume the movejob of the vehicle. If 0 is passed, all movejobs of the player will be resumed.
159 *@author eiko
160 */
161 void sendMoveJobResume (const cClient& client, int unitId);
162 
163 /**
164 * sends all necessary information to identify aggressor
165 * and target of an attack to the server
166 */
167 void sendWantAttack (const cClient& client, int aggressorID, const cPosition& targetPosition, int targetId);
168 
169 /**
170 * sends whether a minelayer is laying or clearing mines
171 *@author alzi alias DoctorDeath
172 *@param Vehicle the vehicle which status has to be send
173 */
174 void sendMineLayerStatus (const cClient& client, const cVehicle& vehicle);
175 /**
176 * sends that a vehicle wants to start building
177 *@author alzi alias DoctorDeath
178 *@param iVehicleID the ID of the vehicle which wants to start building
179 *@param iBuildingType type of the building to be build
180 *@param iBuildSpeed speed of building ( 0->1x, 1->2x or 2->4x )
181 *@param iBuildOff the offest were to build. Upper left coner on big buildings
182 *@param bBuildPath true if the vehicle is building in path
183 *@param iPathOff offset were the path will end
184 */
185 void sendWantBuild (const cClient& client, int iVehicleID, sID buildingTypeID, int iBuildSpeed, const cPosition& buildPosition, bool bBuildPath, const cPosition& pathEndPosition);
186 /**
187 * sends that a vehicle wants to leave the building lot
188 *@author alzi alias DoctorDeath
189 *@param Vehicle the vehicle which has finished building
190 *@param EscapeX X coordinate to which he wants do move now
191 *@param EscapeY Y coordinate to which he wants do move now
192 */
193 void sendWantEndBuilding (const cClient& client, const cVehicle& vehicle, const cPosition& escapePosition);
194 /**
195 * sends that the player wants a vehicle to stop building
196 *@author alzi alias DoctorDeath
197 */
198 void sendWantStopBuilding (const cClient& client, int iVehicleID);
199 /**
200 * sends that the client wants to transfer resources
201 *@author alzi alias DoctorDeath
202 *@param bSrcVehicle true if the source unit is a vehicle
203 *@param iSrcID ID of the source unit
204 *@param bDestVehicle true if the destination unit is a vehicle
205 *@param iDestID ID of the destination unit
206 *@param iTransferValue value of the transfer
207 *@param iType Type of resources which will be transferred.
208 *       (See: NEED_METAL, NEED_OIL or NEED_GOLD)
209 */
210 void sendWantTransfer (const cClient& client, bool bSrcVehicle, int iSrcID, bool bDestVehicle, int iDestID, int iTransferValue, int iType);
211 /**
212 * sends a request for building all vehicles in the buildlist of the building
213 *@author alzi alias DoctorDeath
214 */
215 void sendWantBuildList (const cClient& client, const cBuilding& building, const std::vector<cBuildListItem>& buildList, bool bRepeat, int buildSpeed);
216 /**
217 * sends that the client wants to exit the finished vehicle
218 *@author alzi alias DoctorDeath
219 */
220 void sendWantExitFinishedVehicle (const cClient& client, const cBuilding& building, const cPosition& position);
221 /**
222 * sends that the client wants to change the produce values in the minemanager of a building
223 *@author alzi alias DoctorDeath
224 */
225 void sendChangeResources (const cClient& client, const cBuilding& building, int iMetalProd, int iOilProd, int iGoldProd);
226 /**
227  * sends that the client wants to change the manual fire status of a unit
228  *@author pagra
229  */
230 void sendChangeManualFireStatus (const cClient& client, int iUnitID, bool bVehicle);
231 /**
232 * sends that the client wants to change the sentry status of a unit
233 *@author alzi alias DoctorDeath
234 */
235 void sendChangeSentry (const cClient& client, int iUnitID, bool bVehicle);
236 /**
237 * sends that the client wants to rearm or repair a unit by an rearm-/repairable vehicle
238 *@author alzi alias DoctorDeath
239 */
240 void sendWantSupply (const cClient& client, int iDestID, bool bDestVehicle, int iSrcID, bool bSrcVehicle, int iType);
241 /**
242 * sends that the client wants to start clearing the field under the unit
243 *@author alzi alias DoctorDeath
244 */
245 void sendWantStartClear (const cClient& client, const cVehicle& vehicle);
246 /**
247 * sends that the client wants to stop clearing the field under the unit
248 *@author alzi alias DoctorDeath
249 */
250 void sendWantStopClear (const cClient& client, const cVehicle& vehicle);
251 /**
252 * sends that the client wants to abort waiting for the reconnect of a disconnected player
253 *@author alzi alias DoctorDeath
254 */
255 void sendAbortWaiting (const cClient& client);
256 void sendWantLoad (const cClient& client, int unitid, bool vehicle, int loadedunitid);
257 void sendWantActivate (const cClient& client, int unitid, bool vehicle, int activatunitid, const cPosition& position);
258 /**
259 * sends a request to resync the player
260 */
261 void sendRequestResync (const cClient& client, char playerNumber, bool newGame);
262 
263 void sendRequestCasualtiesReport (const cClient& client);
264 
265 /**
266 * sends that a unit has been set to automove status
267 */
268 void sendSetAutoStatus (const cClient& client, int vehicleID, bool set);
269 /**
270 * sends that the infiltrator wants to infiltrate a unit
271 *@author alzi alias DoctorDeath
272 */
273 void sendWantComAction (const cClient& client, int srcUnitID, int destUnitID, bool destIsVehicle, bool steal);
274 void sendUpgradeBuilding (const cClient& client, const cBuilding& building, bool upgradeAll);
275 void sendWantUpgrade (const cClient& client, int buildingID, int storageSlot, bool upgradeAll);
276 void sendWantResearchChange (const cClient& client, const std::array<int, cResearch::kNrResearchAreas>& newResearchSettings);
277 void sendGameGuiState (const cClient& client, const cGameGuiState& gameGuiState, const cPlayer& owner, int savingID);
278 void sendSaveReportInfo (const cClient& client, const cSavedReport& savedReport, int ownerNr, int savingID);
279 void sendFinishedSendSaveInfo (const cClient& client, int ownerNr, int savingID);
280 
281 void sendWantSelfDestroy (const cClient& client, const cBuilding& building);
282 void sendWantChangeUnitName (const cClient& client, const std::string& newName, int unitID);
283 
284 void sendEndMoveAction (const cClient& client, int vehicleID, int destID, eEndMoveActionType type);
285 
286 void sentWantKickPlayer (const cClient& client, const cPlayer& player);
287 
288 #endif // game_logic_clienteventsH
289