EVENT.H 9.9 KB

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