message.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // message.h
  19. // Project: Postal
  20. //
  21. // History
  22. //
  23. // 02/15/97 BRH Started this file to include a few messages that we will
  24. // start out with. All of the messages have the type first
  25. // so that if they are cast as a Generic Message, you can
  26. // look at the type first and do a switch statement to
  27. // cast it to the correct type of message struct.
  28. //
  29. // 02/16/97 BRH We talked about doing a union of the structs but I'm
  30. // not sure how that makes it easier to use rather than
  31. // doing the casting like DirectPlay. Also I was wondering
  32. // if these should have constructors that default their type
  33. // variable to their specific type rather than making the
  34. // person who creates a struct fill in the type.
  35. //
  36. // 02/17/97 BRH Created another message structure with a union of the
  37. // other message types and included the type enum in
  38. // that structure. Changed the Thing to use a MessageQueue
  39. // of this new structure rather than passing the generic
  40. // message structure pointer and casting it to the specific
  41. // type of message.
  42. //
  43. // 02/18/97 JMI Moved MessageType enum to global scope.
  44. //
  45. // 02/19/97 BRH Added ObjectDelete message which tells an object to
  46. // kill itself immediately (ie. delete this)
  47. //
  48. // 02/19/97 BRH Changed the bogus extra data in the messages like
  49. // burn heat, explosion force, bullet caliber to sDamage
  50. // so that all of these can give some kind of game relative
  51. // damage amount.
  52. //
  53. // 02/24/97 JMI Added generic notification message with generic parameters.
  54. // Useful for simple messages within an object and stuff like
  55. // that where it seems like defining a whole new message
  56. // would be silly.
  57. //
  58. // 03/04/97 JMI Well, I guess it wasn't that silly after all. Added a
  59. // DrawBlood_Message which I should've done to begin with
  60. // instead of adding that silly notification message.
  61. //
  62. // 03/05/97 BRH Added center and velocity of explosion to the explosion
  63. // message. Also added panic message which is sent by
  64. // victims to other victims to warn them.
  65. //
  66. // 03/05/97 JMI Added Suicide_Message.
  67. //
  68. // 03/06/97 JMI Added msg_Suicide to GameMessage union.
  69. //
  70. // 03/19/97 BRH Added Trigger message so that the CDude can trigger
  71. // the remote controlled mine or other weapons that we
  72. // may decide require an external trigger.
  73. //
  74. // 04/20/97 BRH Added bouy strategy suggestion messages. Bouys can
  75. // be assigned a suggestion message that an enemy can
  76. // ask the bouy to send in order to get information from
  77. // the bouy to perform certain local specific logic.
  78. //
  79. // 04/20/97 BRH Added load and save functions to messages so that the
  80. // bouys could use them to save and load the messages.
  81. //
  82. // 05/02/97 BRH Added a message for the dude trigger which informs
  83. // a pylon that a CDude stepped on the trigger area.
  84. // Also changed the Popout and ShootCycle messages to
  85. // contain more information.
  86. //
  87. // 06/09/97 BRH Added Messages for CDude to send to the CDemon to inform
  88. // of his actions like selecting a new weapon and firing
  89. // a weapon.
  90. //
  91. // 06/10/97 BRH Added Death and Writhing messages so CPerson can send
  92. // CDemon messsages for comments.
  93. //
  94. // 06/11/97 BRH Added u16ShooterID to the weapon messages so that we can
  95. // identify the shooter of the weapon so that credit can
  96. // be given to whoever gets a kill using a weapon.
  97. //
  98. // 08/01/97 BRH Added a cheater message to send to the Demon when someone
  99. // enters a cheat code.
  100. //
  101. // 08/02/97 BRH Added a call for help message that enemies send to each other
  102. // when they are getting shot.
  103. //
  104. // 08/28/97 BRH Added PutMeDown message that the flag sends to the dude
  105. // when it finds the flagbase.
  106. //
  107. ////////////////////////////////////////////////////////////////////////////////
  108. #ifndef MESSAGE_H
  109. #define MESSAGE_H
  110. #include "RSPiX.h"
  111. //#include "dude.h"
  112. ////////////////////////////////////////////////////////////////////////////////
  113. // Message Types
  114. ////////////////////////////////////////////////////////////////////////////////
  115. typedef unsigned char MessageType;
  116. enum
  117. {
  118. typeGeneric,
  119. typeShot,
  120. typeExplosion,
  121. typeBurn,
  122. typeKill,
  123. typeObjectDelete,
  124. typeNotification, // Generic notification with generic parameters for
  125. // reuse. Delete this silly message!
  126. typeDrawBlood, // Message indicating blood should be drawn on the
  127. // background at the specified location.
  128. typePanic,
  129. typeSuicide, // Receiver should commit suicide.
  130. typeTrigger, // Used to trigger remote control mines
  131. typePopout, // Used by bouy to give direction and distance for popout logic
  132. typeShootCycle, // Used by bouy to give next bouy ID for cycling between
  133. typeSafeSpot, // Used by bouy to identify itself as a "behind cover" bouy
  134. typeDudeTrigger, // Used by attribute trigger to tell pylons that a Dude is near
  135. typeWeaponSelect, // Used by CDude to tell CDemon when a new weapon has been selected
  136. typeWeaponFire, // Used by CDude to tell CDemon when a weapon has been fired.
  137. typeWrithing, // Used by CPerson to tell CDemon when a person is writhing
  138. typeDeath, // Used by CPerson to tell CDemon when a person has died
  139. typeCheater, // Used by CDude to tell CDemon when a person entered a cheat code
  140. // so that it can mock them.
  141. typeHelp, // Used by CPerson to tell others that it it getting shot
  142. typePutMeDown, // Used by flag to tell CDude to put it down in the base.
  143. typeEndOfMessages
  144. };
  145. ////////////////////////////////////////////////////////////////////////////////
  146. // Message structures
  147. ////////////////////////////////////////////////////////////////////////////////
  148. typedef struct tag_MESSAGE_GENERIC
  149. {
  150. MessageType eType; // = typeGeneric
  151. short sPriority;
  152. } Generic_Message, *pGeneric_Message;
  153. typedef struct tag_MESSAGE_SHOT
  154. {
  155. MessageType eType;// = typeShot;
  156. short sPriority;
  157. short sDamage;
  158. short sAngle;
  159. U16 u16ShooterID; // Instance ID of the shooter (for scoring)
  160. } Shot_Message, *pShot_Message;
  161. typedef struct tag_MESSAGE_EXPLOSION
  162. {
  163. MessageType eType; // = typeExplosion;
  164. short sPriority;
  165. short sDamage;
  166. short sX; // Center of explosion
  167. short sY; // Center of explosion
  168. short sZ; // Center of explosion
  169. short sVelocity; // Relative size of explosion
  170. U16 u16ShooterID;// Instance ID of the shooter
  171. } Explosion_Message, *pExplosion_Message;
  172. typedef struct tag_MESSAGE_BURN
  173. {
  174. MessageType eType; // = typeBurn;
  175. short sPriority;
  176. short sDamage;
  177. U16 u16ShooterID; // Instance ID of the shooter
  178. } Burn_Message, *pBurn_Message;
  179. typedef struct tag_MESSAGE_OBJECTDELETE
  180. {
  181. MessageType eType; // = typeObjectDelete
  182. short sPriority;
  183. } ObjectDelete_Message, *pObjectDelte_Message;
  184. typedef struct tag_MESSAGE_POPOUT
  185. {
  186. MessageType eType; // = typePopout
  187. short sPriority;
  188. UCHAR ucIDNext; // Next Pylon to run to
  189. U16 u16UniqueDudeID; // Dude to target
  190. U16 u16UniquePylonID; // Easier way to get to pylon data
  191. short sNextPylonX; // Next pylon X position
  192. short sNextPylonZ; // Next pylon Z position
  193. } Popout_Message, *pPopout_Message;
  194. typedef struct tag_MESSAGE_SHOOTCYCLE
  195. {
  196. MessageType eType; // = typeShootCycle
  197. short sPriority;
  198. UCHAR ucIDNext; // ID of next bouy in cycle
  199. U16 u16UniqueDudeID; // Dude to target
  200. U16 u16UniquePylonID; // Easier way to get to pylon data
  201. short sNextPylonX; // Next pylon X position
  202. short sNextPylonZ; // Next pylon Z position
  203. } ShootCycle_Message, *pShootCycle_Message;
  204. typedef struct tag_MESSAGE_SAFESPOT
  205. {
  206. MessageType eType; // = typeSafeSpot
  207. short sPriority;
  208. } SafeSpot_Message, *pSafeSpot_Message;
  209. typedef struct tag_MESSAGE_PANIC
  210. {
  211. MessageType eType; //typePanic
  212. short sPriority;
  213. short sX; // Center of panic
  214. short sY; // Center of panic
  215. short sZ; // Center of panic
  216. } Panic_Message, *pPanic_Message;
  217. typedef struct
  218. {
  219. MessageType eType; // = typeDrawBlood
  220. short sPriority;
  221. short s2dX; // 2D X position on background to draw blood.
  222. short s2dY; // 2D Y position on background to draw blood.
  223. } DrawBlood_Message;
  224. typedef struct
  225. {
  226. MessageType eType; // = typeSuicide
  227. short sPriority;
  228. } Suicide_Message;
  229. typedef struct tag_MESSAGE_TRIGGER
  230. {
  231. MessageType eType; // = typeTrigger
  232. short sPriority;
  233. } Trigger_Message;
  234. typedef struct tag_MESSAGE_DUDETRIGGER
  235. {
  236. MessageType eType; // = typeDudeTrigger
  237. short sPriority;
  238. U16 u16DudeUniqueID;
  239. double dX;
  240. double dZ;
  241. } DudeTrigger_Message;
  242. typedef struct tag_MESSAGE_WEAPONSELECT
  243. {
  244. MessageType eType; // = typeWeaponSelect
  245. short sPriority;
  246. short sWeapon; //CDude::WeaponType eWeapon;
  247. } WeaponSelect_Message;
  248. typedef struct tag_MESSAGE_WEAPONFIRE
  249. {
  250. MessageType eType; // = typeWeaponFire
  251. short sPriority;
  252. short sWeapon; //CDude::WeaponType eWeapon;
  253. } WeaponFire_Message;
  254. typedef struct tag_MESSAGE_WRITHING
  255. {
  256. MessageType eType; // = typeWrithing
  257. short sPriority;
  258. } Writhing_Message;
  259. typedef struct tag_MESSAGE_DEATH
  260. {
  261. MessageType eType; // = typeDeath
  262. short sPriority;
  263. } Death_Message;
  264. typedef struct tag_MESSAGE_CHEATER
  265. {
  266. MessageType eType;// = typeCheater
  267. short sPriority;
  268. } Cheater_Message;
  269. typedef struct tag_MESSAGE_HELP
  270. {
  271. MessageType eType; // = typeHelp
  272. short sPriority;
  273. } Help_Message;
  274. typedef struct tag_MESSAGE_PUTMEDOWN
  275. {
  276. MessageType eType;// = typePutMeDown
  277. short sPriority;
  278. U16 u16FlagInstanceID;
  279. } PutMeDown_Message;
  280. typedef struct tag_GameMessage
  281. {
  282. union
  283. {
  284. Generic_Message msg_Generic;
  285. Shot_Message msg_Shot;
  286. Explosion_Message msg_Explosion;
  287. Burn_Message msg_Burn;
  288. ObjectDelete_Message msg_ObjectDelete;
  289. DrawBlood_Message msg_DrawBlood;
  290. Panic_Message msg_Panic;
  291. Suicide_Message msg_Suicide;
  292. Trigger_Message msg_Trigger;
  293. Popout_Message msg_Popout;
  294. ShootCycle_Message msg_ShootCycle;
  295. SafeSpot_Message msg_SafeSpot;
  296. DudeTrigger_Message msg_DudeTrigger;
  297. WeaponSelect_Message msg_WeaponSelect;
  298. WeaponFire_Message msg_WeaponFire;
  299. Writhing_Message msg_Writhing;
  300. Death_Message msg_Death;
  301. Cheater_Message msg_Cheater;
  302. Help_Message msg_Help;
  303. PutMeDown_Message msg_PutMeDown;
  304. };
  305. // Function to save whatever type of message this is.
  306. short Save(RFile* pFile)
  307. {
  308. short sResult = 0;
  309. if (pFile && pFile->IsOpen())
  310. {
  311. pFile->Write(&msg_Generic.eType);
  312. pFile->Write(&msg_Generic.sPriority);
  313. switch (msg_Generic.eType)
  314. {
  315. case typeGeneric:
  316. case typeObjectDelete:
  317. case typeSafeSpot:
  318. case typeSuicide:
  319. case typeTrigger:
  320. case typeWeaponSelect:
  321. case typeWeaponFire:
  322. case typeWrithing:
  323. case typeDeath:
  324. case typeCheater:
  325. case typeHelp:
  326. break;
  327. case typeShot:
  328. pFile->Write(&msg_Shot.sDamage);
  329. pFile->Write(&msg_Shot.sAngle);
  330. break;
  331. case typeExplosion:
  332. pFile->Write(&msg_Explosion.sDamage);
  333. pFile->Write(&msg_Explosion.sX);
  334. pFile->Write(&msg_Explosion.sY);
  335. pFile->Write(&msg_Explosion.sZ);
  336. pFile->Write(&msg_Explosion.sVelocity);
  337. break;
  338. case typeBurn:
  339. pFile->Write(&msg_Burn.sDamage);
  340. break;
  341. case typePopout:
  342. case typeShootCycle:
  343. pFile->Write(&msg_Popout.ucIDNext);
  344. pFile->Write(&msg_Popout.u16UniqueDudeID);
  345. pFile->Write(&msg_Popout.u16UniquePylonID);
  346. pFile->Write(&msg_Popout.sNextPylonX);
  347. pFile->Write(&msg_Popout.sNextPylonZ);
  348. break;
  349. case typePanic:
  350. pFile->Write(&msg_Panic.sX);
  351. pFile->Write(&msg_Panic.sY);
  352. pFile->Write(&msg_Panic.sZ);
  353. break;
  354. case typeDrawBlood:
  355. pFile->Write(&msg_DrawBlood.s2dX);
  356. pFile->Write(&msg_DrawBlood.s2dY);
  357. break;
  358. case typeDudeTrigger:
  359. pFile->Write(&msg_DudeTrigger.u16DudeUniqueID);
  360. pFile->Write(&msg_DudeTrigger.dX);
  361. pFile->Write(&msg_DudeTrigger.dZ);
  362. break;
  363. case typePutMeDown:
  364. pFile->Write(&msg_PutMeDown.u16FlagInstanceID);
  365. break;
  366. }
  367. }
  368. else
  369. {
  370. sResult = -1;
  371. }
  372. return sResult;
  373. }
  374. // Function to load whatever type of message was saved
  375. short Load(RFile* pFile)
  376. {
  377. short sResult = 0;
  378. if (pFile && pFile->IsOpen())
  379. {
  380. pFile->Read(&msg_Generic.eType);
  381. pFile->Read(&msg_Generic.sPriority);
  382. switch (msg_Generic.eType)
  383. {
  384. case typeGeneric:
  385. case typeObjectDelete:
  386. case typeSafeSpot:
  387. case typeSuicide:
  388. case typeTrigger:
  389. break;
  390. case typeShot:
  391. pFile->Read(&msg_Shot.sDamage);
  392. pFile->Read(&msg_Shot.sAngle);
  393. break;
  394. case typeExplosion:
  395. pFile->Read(&msg_Explosion.sDamage);
  396. pFile->Read(&msg_Explosion.sX);
  397. pFile->Read(&msg_Explosion.sY);
  398. pFile->Read(&msg_Explosion.sZ);
  399. pFile->Read(&msg_Explosion.sVelocity);
  400. break;
  401. case typeBurn:
  402. pFile->Read(&msg_Burn.sDamage);
  403. break;
  404. case typePopout:
  405. case typeShootCycle:
  406. pFile->Read(&msg_Popout.ucIDNext);
  407. pFile->Read(&msg_Popout.u16UniqueDudeID);
  408. pFile->Read(&msg_Popout.u16UniquePylonID);
  409. pFile->Read(&msg_Popout.sNextPylonX);
  410. pFile->Read(&msg_Popout.sNextPylonZ);
  411. break;
  412. case typePanic:
  413. pFile->Read(&msg_Panic.sX);
  414. pFile->Read(&msg_Panic.sY);
  415. pFile->Read(&msg_Panic.sZ);
  416. break;
  417. case typeDrawBlood:
  418. pFile->Read(&msg_DrawBlood.s2dX);
  419. pFile->Read(&msg_DrawBlood.s2dY);
  420. break;
  421. case typeDudeTrigger:
  422. pFile->Read(&msg_DudeTrigger.u16DudeUniqueID);
  423. pFile->Read(&msg_DudeTrigger.dX);
  424. pFile->Read(&msg_DudeTrigger.dZ);
  425. break;
  426. case typePutMeDown:
  427. pFile->Read(&msg_PutMeDown.u16FlagInstanceID);
  428. break;
  429. }
  430. }
  431. else
  432. {
  433. sResult = FAILURE;
  434. }
  435. return sResult;
  436. }
  437. } GameMessage, *pGameMessage;
  438. ////////////////////////////////////////////////////////////////////////////////
  439. // Message union
  440. ////////////////////////////////////////////////////////////////////////////////
  441. #endif //MESSAGE_H
  442. ////////////////////////////////////////////////////////////////////////////////
  443. // EOF
  444. ////////////////////////////////////////////////////////////////////////////////