EVENT.H 10 KB

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