flag.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. // flag.h
  19. // Project: Postal
  20. //
  21. // History:
  22. //
  23. // 06/30/97 BRH Started this file to contain the Capture the flag object.
  24. // The flag is the thing that can be carried to the base.
  25. //
  26. // 07/06/97 BRH Added Time bonus for the time bonus challenge levels.
  27. //
  28. // 07/12/97 BRH Added m_u16FlagID to match flags and bases.
  29. //
  30. ////////////////////////////////////////////////////////////////////////////////
  31. #ifndef FLAG_H
  32. #define FLAG_H
  33. #include "RSPiX.h"
  34. #include "realm.h"
  35. #include "Thing3d.h"
  36. // CFlag is the flag object for capture the flag challenge levels
  37. class CFlag : public CThing3d
  38. {
  39. //---------------------------------------------------------------------------
  40. // Types, enums, etc.
  41. //---------------------------------------------------------------------------
  42. public:
  43. typedef enum
  44. {
  45. Red = 0,
  46. Blue,
  47. EndOfColors
  48. } FlagColor;
  49. //---------------------------------------------------------------------------
  50. // Variables
  51. //---------------------------------------------------------------------------
  52. public:
  53. CAnim3D* m_panimCurBase; // current animation for the base
  54. U16 m_u16FlagID; // Used to match flag & base
  55. protected:
  56. CAnim3D m_animFlagWave; // animation for the flag waving
  57. U32 m_u32IncludeBits; // Bits to include for Smash collision
  58. U32 m_u32DontcareBits; // Bits to ignore for Smash collision
  59. U32 m_u32ExcludeBits; // Bits to exclude for Smash collision
  60. long m_lTimeBonus; // Flag stores a time bonus for
  61. // special game play modes.
  62. U16 m_u16FlagColor; // Color of flag;
  63. short m_sSavedX; // Save the position of the flagbase
  64. short m_sSavedY; // Save the position of the flagbase
  65. short m_sSavedZ; // Save the position of the flagbase
  66. // Tracks file counter so we know when to load/save "common" data
  67. static short ms_sFileCount;
  68. // "Constant" values that we want to be able to tune using the editor
  69. static double ms_dInRange; // In range to the base
  70. //---------------------------------------------------------------------------
  71. // Constructor(s) / destructor
  72. //---------------------------------------------------------------------------
  73. protected:
  74. // Constructor
  75. CFlag(CRealm* pRealm)
  76. : CThing3d(pRealm, CFlagID)
  77. {
  78. m_sSuspend = 0;
  79. m_dRot = 0;
  80. m_dX = m_dY = m_dZ = m_dVel = m_dAcc = 0;
  81. m_panimCur = NULL;
  82. m_sprite.m_pthing = this;
  83. m_u16FlagID = 1;
  84. m_lTimeBonus = 0;
  85. m_u16FlagColor = Red;
  86. m_sSavedX = 0;
  87. m_sSavedY = 0;
  88. m_sSavedZ = 0;
  89. }
  90. public:
  91. // Destructor
  92. ~CFlag()
  93. {
  94. // Remove sprite from scene (this is safe even if it was already removed!)
  95. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  96. m_pRealm->m_smashatorium.Remove(&m_smash);
  97. // Free resources
  98. FreeResources();
  99. }
  100. //---------------------------------------------------------------------------
  101. // Required static functions
  102. //---------------------------------------------------------------------------
  103. public:
  104. // Construct object
  105. static short Construct( // Returns 0 if successfull, non-zero otherwise
  106. CRealm* pRealm, // In: Pointer to realm this object belongs to
  107. CThing** ppNew) // Out: Pointer to new object
  108. {
  109. short sResult = 0;
  110. *ppNew = new CFlag(pRealm);
  111. if (*ppNew == 0)
  112. {
  113. sResult = -1;
  114. TRACE("CFlag::Construct(): Couldn't construct CFlag (that's a bad thing)\n");
  115. }
  116. return sResult;
  117. }
  118. //---------------------------------------------------------------------------
  119. // Required virtual functions (implimenting them as inlines doesn't pay!)
  120. //---------------------------------------------------------------------------
  121. public:
  122. // Load object (should call base class version!)
  123. short Load( // Returns 0 if successfull, non-zero otherwise
  124. RFile* pFile, // In: File to load from
  125. bool bEditMode, // In: True for edit mode, false otherwise
  126. short sFileCount, // In: File count (unique per file, never 0)
  127. ULONG ulFileVersion); // In: Version of file format to load.
  128. // Save object (should call base class version!)
  129. short Save( // Returns 0 if successfull, non-zero otherwise
  130. RFile* pFile, // In: File to save to
  131. short sFileCount); // In: File count (unique per file, never 0)
  132. // Startup object
  133. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  134. // Shutdown object
  135. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  136. // Update object
  137. void Update(void);
  138. // Called by editor to init new object at specified position
  139. short EditNew( // Returns 0 if successfull, non-zero otherwise
  140. short sX, // In: New x coord
  141. short sY, // In: New y coord
  142. short sZ); // In: New z coord
  143. // Called by editor to modify object
  144. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  145. // Called by editor to move object to specified position
  146. short EditMove( // Returns 0 if successfull, non-zero otherwise
  147. short sX, // In: New x coord
  148. short sY, // In: New y coord
  149. short sZ); // In: New z coord
  150. // Give Edit a rectangle around this object
  151. void EditRect(RRect* pRect);
  152. // Called by editor to get the hotspot of an object in 2D.
  153. // (virtual (Overridden here)).
  154. void EditHotSpot( // Returns nothiing.
  155. short* psX, // Out: X coord of 2D hotspot relative to
  156. // EditRect() pos.
  157. short* psY); // Out: Y coord of 2D hotspot relative to
  158. // EditRect() pos.
  159. //---------------------------------------------------------------------------
  160. // Internal functions
  161. //---------------------------------------------------------------------------
  162. protected:
  163. // Get all required resources
  164. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  165. // Free all resources
  166. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  167. // Initialize states, positions etc.
  168. short Init(void);
  169. // Update the animation radius based on the current frame
  170. void UpdateRadius(void);
  171. // Message handling functions ////////////////////////////////////////////
  172. // Handles an Explosion_Message.
  173. virtual // Override to implement additional functionality.
  174. // Call base class to get default functionality.
  175. void OnExplosionMsg( // Returns nothing.
  176. Explosion_Message* pexplosionmsg); // In: Message to handle.
  177. // Handles a Burn_Message.
  178. virtual // Override to implement additional functionality.
  179. // Call base class to get default functionality.
  180. void OnBurnMsg( // Returns nothing.
  181. Burn_Message* pburnmsg); // In: Message to handle.
  182. };
  183. #endif //FLAG_H
  184. ////////////////////////////////////////////////////////////////////////////////
  185. // EOF
  186. ////////////////////////////////////////////////////////////////////////////////