EVENT.H 8.5 KB

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