CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

EVENT.H (10384B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header: /CounterStrike/EVENT.H 1     3/03/97 10:24a Joe_bostic $ */
     17 /***********************************************************************************************
     18  ***              C O N F I D E N T I A L  ---  W E S T W O O D  S T U D I O S               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Command & Conquer                                            *
     22  *                                                                                             *
     23  *                    File Name : EVENT.H                                                      *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 12/09/94                                                     *
     28  *                                                                                             *
     29  *                  Last Update : December 9, 1994 [JLB]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #ifndef EVENT_H
     36 #define EVENT_H
     37 
     38 /*
     39 **	This event class is used to contain all external game events (things that the player can
     40 **	do at any time) so that these events can be transported between linked computers. This
     41 **	encapsulation is required in order to ensure that each event affects all computers at the
     42 **	same time (same game frame).
     43 ** NOTE: If you add or remove an event type, you must also update the globals
     44 ** EventLength[] and EventNames[].
     45 */
     46 class EventClass
     47 {
     48 	public:
     49 
     50 		/*
     51 		**	All external events are identified by these labels.
     52 		*/
     53 		typedef enum EventType : unsigned char	{
     54 			EMPTY,
     55 
     56 			ALLY,					// Make allie of specified house.
     57 			MEGAMISSION,		// Full change of mission with target and destination.
     58 			MEGAMISSION_F,		// Full change of mission with target and destination, and formation overrides.
     59 			IDLE,					// Request to enter idle mode.
     60 			SCATTER,				// Request to scatter from current location.
     61 			DESTRUCT,			// Self destruct request (surrender action).
     62 			DEPLOY,				// MCV is to deploy at current location.
     63 			PLACE,				// Place building at location specified.
     64 			OPTIONS,				// Bring up options screen.
     65 			GAMESPEED,			// Set game speed
     66 			PRODUCE,				// Start or Resume production.
     67 			SUSPEND,				// Suspend production.
     68 			ABANDON,				// Abandon production.
     69 			PRIMARY,				// Primary factory selected.
     70 			SPECIAL_PLACE,		// Special target location selected
     71 			EXIT,					// Exit game.
     72 			ANIMATION,			// Flash ground as movement feedback.
     73 			REPAIR,				// Repair specified object.
     74 			SELL,					//	Sell specified object.
     75 			SELLCELL,			// Sell wall at specified cell.
     76 			SPECIAL,				// Special options control.
     77 
     78 			// Private events.
     79 			FRAMESYNC,			// Game-connection packet; includes Scenario CRC & sender's frame #
     80 									// Used to initiate game connection phase & to reconnect;
     81 									// When one of these is received, the receiver knows there are
     82 									// no associated commands in this packet.
     83 			MESSAGE,				// Message to another player (The message is the 40 bytes
     84 									// after the event class).
     85 			RESPONSE_TIME,		// use a new propagation delay value
     86 			FRAMEINFO,			// Game-heartbeat packet; includes Game CRC & command count
     87 									// All packets sent for a frame are prefixed with one of these
     88 			SAVEGAME,			// allows multiplayer games to save
     89 			ARCHIVE,				// Updates archive target on specified object.
     90 			ADDPLAYER,			// Add a new player
     91 
     92 			TIMING,				// new timing values for all systems to use
     93 			PROCESS_TIME,		// a system's average processing time, in ticks per frame
     94 
     95 #ifdef FIXIT_VERSION_3		//	Stalemate games.
     96 			PROPOSE_DRAW,		//	Players proposes that 2-player game be called a stalemate.
     97 			RETRACT_DRAW,		//	Player retracts proposed draw offer.
     98 #endif
     99 
    100 			LAST_EVENT,			// one past the last event
    101 		} EventType;
    102 
    103 		EventType Type;		// Type of queue command object.
    104 
    105 		/*
    106 		** 'Frame' is the frame that the command should execute on.
    107 		** 27 bits gives over 25 days of playing time without wrapping,
    108 		** at 30 frames per second, so it should be plenty!
    109 		*/
    110 		unsigned Frame : 26;
    111 
    112 		/*
    113 		** House index of the player originating this event
    114 		*/
    115 		unsigned ID : 5;
    116 
    117 		/*
    118 		** This bit tells us if we've already executed this event.
    119 		*/
    120 		unsigned IsExecuted: 1;
    121 
    122 		/*
    123 		**	This union contains the specific data that the event requires.
    124 		*/
    125 		union {
    126 			struct {
    127 				SpecialClass	Data;		// The special option flags.
    128 			} Options;
    129 			struct {
    130 				CELL			Cell;			// The cell to sell wall at.
    131 			} SellCell;
    132 			struct {
    133 				xTargetClass	Whom;			// The object to apply the event to.
    134 			} Target;
    135 			struct {
    136 				AnimType		What;			// The animation to create.
    137 				HousesType	Owner;		// The owner of the animation (when it matters).
    138 				COORDINATE			Where;		// The location to place the animation.
    139 				int			Visible;	// Who this animation is visible to.
    140 			} Anim;
    141 			struct {
    142 				int 			Value;		// general-purpose data
    143 			} General;
    144 			struct {
    145 				xTargetClass	Whom;			// Whom to apply mission to.
    146 				MissionType	Mission;		// What mission to apply.
    147 				xTargetClass	Target;		// Target to assign.
    148 				xTargetClass	Destination;// Destination to assign.
    149 			} MegaMission;
    150 			struct {
    151 				xTargetClass	Whom;			// Whom to apply mission to.
    152 				MissionType	Mission;		// What mission to apply.
    153 				xTargetClass	Target;		// Target to assign.
    154 				xTargetClass	Destination;// Destination to assign.
    155 				SpeedType	Speed;		// Formation override speed.
    156 				MPHType		MaxSpeed;	// Formation override maximum speed.
    157 			} MegaMission_F;
    158 			struct {
    159 				xTargetClass	Whom;			// Whom to apply mission to.
    160 				MissionType Mission;		// What mission to apply.
    161 			} Mission;
    162 			struct {
    163 				xTargetClass	Whom;			// Whom to apply movement change to.
    164 				xTargetClass	Where;		// Where to set NavCom to.
    165 			} NavCom;
    166 			struct {
    167 				xTargetClass	Whom;			// Whom to apply attack change to.
    168 				xTargetClass	Target;		// What to set TarCom to.
    169 			} TarCom;
    170 			struct {
    171 				RTTIType		Type;
    172 				int			ID;
    173 			} Specific;
    174 			struct {
    175 				RTTIType		Type;
    176 				CELL			Cell;
    177 			} Place;
    178 			struct {
    179 				int			ID;
    180 				CELL			Cell;
    181 			} Special;
    182 
    183 			/*
    184 			** This structure is used for FRAMEINFO, FRAMESYNC, and RESPONSE_TIME
    185 			** events; exactly one of these will be sent each frame, whether there's
    186 			** data that frame or not.
    187 			** CRC: the game CRC when this packet was generated; used to detect sync errors
    188 			** CommandCount: # of commands the sender has sent; used to detect missed packets
    189 			** Delay: sender's propagation delay value for this frame
    190 			*/
    191 			struct {
    192 				unsigned long CRC;
    193 				unsigned short CommandCount;	// # commands sent so far
    194 				unsigned char Delay;				// propagation delay used this frame
    195 														// (Frame - Delay = sender's current frame #)
    196 			} FrameInfo;
    197 			/*
    198 			** This structure is used for the special variable-length event.  This event
    199 			** can be anything the application wants it to be.  Its purpose is to allow
    200 			** relatively large amounts of data to be associated with the event, without
    201 			** bloating the size of this union (and thus all other event types).
    202 			*/
    203 			struct {
    204 				void * Pointer;
    205 				unsigned long Size;
    206 			} Variable;
    207 
    208 			//
    209 			// This structure sets new timing values for all systems in a multiplayer
    210 			// game.  This structure replaces the RESPONSE_TIME event for
    211 			// the COMM_MULTI_E_COMP protocol.
    212 			//
    213 			struct {
    214 				unsigned short DesiredFrameRate;
    215 				unsigned short MaxAhead;
    216 			} Timing;
    217 
    218 			//
    219 			// This structure is transmitted by all systems, and is used to compute
    220 			// the "desired" frame rate for the game.
    221 			//
    222 			struct {
    223 				unsigned short AverageTicks;
    224 			} ProcessTime;
    225 
    226 		} Data;
    227 
    228 		//-------------- Constructors ---------------------
    229 		EventClass(void) {Type = EMPTY;};
    230 		EventClass(SpecialClass data);
    231 		EventClass(EventType type, TargetClass target);
    232 		EventClass(EventType type);
    233 		EventClass(EventType type, int val);
    234 		EventClass(EventType type, CELL cell);
    235 		EventClass(EventType type, TargetClass src, TargetClass dest);
    236 		EventClass(TargetClass src, MissionType mission, TargetClass target=TARGET_NONE, TargetClass destination=TARGET_NONE);
    237 
    238 		EventClass(TargetClass src, MissionType mission, TargetClass target, TargetClass destination, SpeedType speed, MPHType maxspeed);
    239 
    240 		EventClass(EventType type, RTTIType object, int id);
    241 		EventClass(EventType type, RTTIType object, CELL cell);
    242 		EventClass(EventType type, int id, CELL cell);
    243 		EventClass(AnimType anim, HousesType owner, COORDINATE coord, int visible = -1);
    244 		EventClass(void *ptr, unsigned long size);
    245 		EventClass(EventType type, void *ptr, unsigned long size);
    246 
    247 		// Process the event.
    248 		void Execute(void);
    249 
    250 		int operator == (EventClass & q) {
    251 			return memcmp(this, &q, sizeof(q)) == 0;
    252 		};
    253 
    254 		static unsigned char EventLength[LAST_EVENT];
    255 		static char * EventNames[LAST_EVENT];
    256 };
    257 
    258 #endif