CnC_Remastered_Collection

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

EVENT.H (8958B)


      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:   F:\projects\c&c\vcs\code\event.h_v   2.19   16 Oct 1995 16:46:14   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 */
     44 class EventClass
     45 {
     46 	public:
     47 
     48 		/*
     49 		**	All external events are identified by these labels.
     50 		*/
     51 		typedef enum EventType : unsigned char {
     52 			EMPTY,
     53 
     54 			ALLY,					// Make allie of specified house.
     55 			MEGAMISSION,		// Full change of mission with target and destination.
     56 			IDLE,					// Request to enter idle mode.
     57 			SCATTER,				// Request to scatter from current location.
     58 			DESTRUCT,			// Self destruct request (surrender action).
     59 			DEPLOY,				// MCV is to deploy at current location.
     60 			PLACE,				// Place building at location specified.
     61 			OPTIONS,				// Bring up options screen.
     62 			GAMESPEED,			// Set game speed
     63 			PRODUCE,				// Start or Resume production.
     64 			SUSPEND,				// Suspend production.
     65 			ABANDON,				// Abandon production.
     66 			PRIMARY,				// Primary factory selected.
     67 			SPECIAL_PLACE,		// Special target location selected
     68 			EXIT,					// Exit game.
     69 			ANIMATION,			// Flash ground as movement feedback.
     70 			REPAIR,				// Repair specified object.
     71 			SELL,					//	Sell specified object.
     72 			SPECIAL,				// Special options control.
     73 
     74 			// Private events.
     75 			FRAMESYNC,			// Game-connection packet; includes Scenario CRC & sender's frame #
     76 									// Used to initiate game connection phase & to reconnect;
     77 									// When one of these is received, the receiver knows there are
     78 									// no associated commands in this packet.
     79 			MESSAGE,				// Message to another player (The message is the 40 bytes
     80 									// after the event class).
     81 			RESPONSE_TIME,		// use a new propogation delay value
     82 			FRAMEINFO,			// Game-heartbeat packet; includes Game CRC & command count
     83 									// All packets sent for a frame are prefixed with one of these
     84 			ARCHIVE,				// Updates archive target on specified object.
     85 			TIMING,				// new timing values for all systems to use
     86 			PROCESS_TIME,		// a system's average processing time, in ticks per frame
     87 			LAST_EVENT,			// one past the last event
     88 		} EventType;
     89 
     90 		EventType Type;		// Type of queue command object.
     91 
     92 		/*
     93 		** 'Frame' is the frame that the command should execute on.
     94 		** 27 bits gives over 25 days of playing time without wrapping,
     95 		** at 30 frames per second, so it should be plenty!
     96 		*/
     97 		unsigned Frame : 27;
     98 
     99 		/*
    100 		** House index of the player originating this event
    101 		*/
    102 		unsigned ID : 4;
    103 
    104 		/*
    105 		** This bit tells us if we've already executed this event.
    106 		*/
    107 		unsigned IsExecuted: 1;
    108 
    109 		/*
    110 		** Multiplayer ID of the player originating this event.
    111 		** High nybble: the color index of this player.
    112 		** Low nybble: the HousesType this player is "acting like" (GDI/NOD)
    113 		*/
    114 		unsigned char MPlayerID;
    115 
    116 		/*
    117 		**	This union contains the specific data that the event requires.
    118 		*/
    119 		union {
    120 			struct {
    121 				SpecialClass	Data;		// The special option flags.
    122 			} Options;
    123 			struct {
    124 				TARGET		Whom;			// The object to apply the event to.
    125 			} Target;
    126 			struct {
    127 				AnimType		What;			// The animation to create.
    128 				HousesType	Owner;		// The owner of the animation (when it matters).
    129 				COORDINATE			Where;		// The location to place the animation.
    130 				int			Visible;	// Who this animation is visible to.
    131 			} Anim;
    132 			struct {
    133 				int 			Value;		// general-purpose data
    134 			} General;
    135 			struct {
    136 				TARGET		Whom;			// Whom to apply mission to.
    137 				MissionType	Mission;		// What mission to apply.
    138 				TARGET		Target;		// Target to assign.
    139 				TARGET		Destination;// Destination to assign.
    140 			} MegaMission;
    141 			struct {
    142 				TARGET		Whom;			// Whom to apply mission to.
    143 				MissionType Mission;		// What mission to apply.
    144 			} Mission;
    145 			struct {
    146 				TARGET		Whom;			// Whom to apply movement change to.
    147 				TARGET		Where;		// Where to set NavCom to.
    148 			} NavCom;
    149 			struct {
    150 				TARGET		Whom;			// Whom to apply attack change to.
    151 				TARGET		Target;		// What to set TarCom to.
    152 			} TarCom;
    153 			struct {
    154 				RTTIType		Type;
    155 				int			ID;
    156 			} Specific;
    157 			struct {
    158 				RTTIType		Type;
    159 				CELL			Cell;
    160 			} Place;
    161 			struct {
    162 				int			ID;
    163 				CELL			Cell;
    164 			} Special;
    165 			/*
    166 			** This structure is used for FRAMEINFO, FRAMESYNC, and RESPONSE_TIME
    167 			** events; exactly one of these will be sent each frame, whether there's
    168 			** data that frame or not.
    169 			** CRC: the game CRC when this packet was generated; used to detect sync errors
    170 			** CommandCount: # of commands the sender has sent; used to detect missed packets
    171 			** Delay: sender's propogation delay value for this frame
    172 			*/
    173 			struct {
    174 				unsigned long CRC;
    175 				unsigned short CommandCount;	// # commands sent so far
    176 				unsigned char Delay;				// propogation delay used this frame
    177 														// (Frame - Delay = sender's current frame #)
    178 			} FrameInfo;
    179 
    180 			//
    181 			// This structure sets new timing values for all systems in a multiplayer
    182 			// game.  This structure replaces the RESPONSE_TIME event for
    183 			// the COMM_MULTI_E_COMP protocol.
    184 			//
    185 			struct {
    186 				unsigned short DesiredFrameRate;
    187 				unsigned short MaxAhead;
    188 			} Timing;
    189 
    190 			//
    191 			// This structure is transmitted by all systems, and is used to compute
    192 			// the "desired" frame rate for the game.
    193 			//
    194 			struct {
    195 				unsigned short AverageTicks;
    196 			} ProcessTime;
    197 
    198 		} Data;
    199 
    200 		//-------------- Functions ---------------------
    201 		EventClass(void) {Type = EMPTY;};
    202 		EventClass(SpecialClass data);
    203 		EventClass(EventType type, TARGET target);
    204 		EventClass(EventType type);
    205 		EventClass(EventType type, int val);
    206 		EventClass(EventType type, TARGET src, TARGET dest);
    207 //		EventClass(TARGET src, MissionType mission);
    208 		EventClass(TARGET src, MissionType mission, TARGET target=TARGET_NONE, TARGET destination=TARGET_NONE);
    209 		EventClass(EventType type, RTTIType object, int id);
    210 		EventClass(EventType type, RTTIType object, CELL cell);
    211 		EventClass(EventType type, int id, CELL cell);
    212 		EventClass(AnimType anim, HousesType owner, COORDINATE coord, int visible = -1);
    213 
    214 		// Process the event.
    215 		void Execute(void);
    216 
    217 		int operator == (EventClass & q) {
    218 			return memcmp(this, &q, sizeof(q)) == 0;
    219 		};
    220 
    221 		static unsigned char EventLength[LAST_EVENT];
    222 		static char * EventNames[LAST_EVENT];
    223 };
    224 
    225 #endif