pylon.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. // pylon.h
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. //
  23. // 05/01/97 BRH Started this object from the bouys. It will take over
  24. // the duty of logic suggestions and markers and the bouys
  25. // will go back to strictly navigation.
  26. //
  27. // 06/17/97 MJR Moved some vars that were CPylon statics into the realm
  28. // so they could be instantiated on a realm-by-realm basis.
  29. //
  30. // 06/30/97 JMI Moved EditRect() and EditHotSpot() from pylon.h to
  31. // pylon.cpp.
  32. //
  33. // 07/08/97 JMI Now removes its smash from the smashatorium in the
  34. // destructor.
  35. //
  36. // 07/14/97 JMI Now memsets m_msg to 0s before initializing the few members
  37. // that can be accessed via msg_Generic type.
  38. //
  39. // 07/17/97 BRH Chagned Triggeed function to trigger only if the dude
  40. // on the traget area is alive.
  41. //
  42. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  43. //
  44. ////////////////////////////////////////////////////////////////////////////////
  45. #ifndef PYLON_H
  46. #define PYLON_H
  47. #include "RSPiX.h"
  48. #include "realm.h"
  49. #include "smash.h"
  50. #include "Thing3d.h"
  51. #include "dude.h"
  52. //#include <vector>
  53. #define PYLON_MAX_PYLONS 254
  54. // CPylon is the class for navigation
  55. class CPylon : public CThing
  56. {
  57. friend class CNavigationNet;
  58. //---------------------------------------------------------------------------
  59. // Types, enums, etc.
  60. //---------------------------------------------------------------------------
  61. public:
  62. //---------------------------------------------------------------------------
  63. // Variables
  64. //---------------------------------------------------------------------------
  65. public:
  66. UCHAR m_ucID; // Pylon ID
  67. GameMessage m_msg; // Place for storing hint messages
  68. U16 m_u16TargetDudeID; // ID of dude you are supposed to attack;
  69. protected:
  70. double m_dX; // x coord
  71. double m_dY; // y coord
  72. double m_dZ; // z coord
  73. RImage* m_pImage; // Pointer to only image (replace with 3d anim, soon)
  74. CSprite2 m_sprite; // Sprite (replace with CSprite3, soon)
  75. CSmash m_smash; // Collision region
  76. short m_sSuspend; // Suspend flag
  77. // Tracks file counter so we know when to load/save "common" data
  78. static short ms_sFileCount;
  79. // "Constant" values that we want to be able to tune using the editor
  80. //---------------------------------------------------------------------------
  81. // Constructor(s) / destructor
  82. //---------------------------------------------------------------------------
  83. protected:
  84. // Constructor
  85. CPylon(CRealm* pRealm)
  86. : CThing(pRealm, CPylonID)
  87. {
  88. m_pImage = 0;
  89. m_sSuspend = 0;
  90. // Let's default the whole thing to zero.
  91. memset(&m_msg, 0, sizeof(m_msg) );
  92. // Then set some portions we can via the generic type.
  93. m_msg.msg_Generic.eType = typeGeneric;
  94. m_msg.msg_Generic.sPriority = 0;
  95. pRealm->m_sNumPylons++;
  96. m_u16TargetDudeID = 0;
  97. }
  98. public:
  99. // Destructor
  100. ~CPylon()
  101. {
  102. // Remove sprite from scene (this is safe even if it was already removed!)
  103. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  104. // Remove smash from smashatorium (this is safe even if it was already removed!).
  105. m_pRealm->m_smashatorium.Remove(&m_smash);
  106. // Free resources
  107. FreeResources();
  108. m_pRealm->m_sNumPylons--;
  109. }
  110. //---------------------------------------------------------------------------
  111. // Required static functions
  112. //---------------------------------------------------------------------------
  113. public:
  114. // Construct object
  115. static short Construct( // Returns 0 if successfull, non-zero otherwise
  116. CRealm* pRealm, // In: Pointer to realm this object belongs to
  117. CThing** ppNew) // Out: Pointer to new object
  118. {
  119. short sResult = 0;
  120. if (pRealm->m_sNumPylons < PYLON_MAX_PYLONS)
  121. {
  122. *ppNew = new CPylon(pRealm);
  123. if (*ppNew == 0)
  124. {
  125. sResult = -1;
  126. TRACE("CPylon::Construct(): Couldn't construct CPylon (that's a bad thing)\n");
  127. }
  128. }
  129. else
  130. {
  131. TRACE("CPylon::CPylon() - No more pylon ID's available\n");
  132. *ppNew = NULL;
  133. sResult = -1;
  134. }
  135. return sResult;
  136. }
  137. //---------------------------------------------------------------------------
  138. // Enemy logic hint functions
  139. //---------------------------------------------------------------------------
  140. // An enemy can call this function to request that a message be sent to it
  141. // with any hint information that this bouy may have.
  142. void MessageRequest(CThing* pThing);
  143. //---------------------------------------------------------------------------
  144. // Required virtual functions (implimenting them as inlines doesn't pay!)
  145. //---------------------------------------------------------------------------
  146. public:
  147. // Load object (should call base class version!)
  148. short Load( // Returns 0 if successfull, non-zero otherwise
  149. RFile* pFile, // In: File to load from
  150. bool bEditMode, // In: True for edit mode, false otherwise
  151. short sFileCount, // In: File count (unique per file, never 0)
  152. ULONG ulFileVersion); // In: Version of file format to load.
  153. // Save object (should call base class version!)
  154. short Save( // Returns 0 if successfull, non-zero otherwise
  155. RFile* pFile, // In: File to save to
  156. short sFileCount); // In: File count (unique per file, never 0)
  157. // Startup object
  158. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  159. // Shutdown object
  160. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  161. // Suspend object
  162. void Suspend(void);
  163. // Resume object
  164. void Resume(void);
  165. // Update object
  166. void Update(void);
  167. // Render object
  168. void Render(void);
  169. // Called by editor to init new object at specified position
  170. short EditNew( // Returns 0 if successfull, non-zero otherwise
  171. short sX, // In: New x coord
  172. short sY, // In: New y coord
  173. short sZ); // In: New z coord
  174. // Called by editor to modify object
  175. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  176. // Called by editor to move object to specified position
  177. short EditMove( // Returns 0 if successfull, non-zero otherwise
  178. short sX, // In: New x coord
  179. short sY, // In: New y coord
  180. short sZ); // In: New z coord
  181. // Called by editor to update object
  182. void EditUpdate(void);
  183. // Called by editor to render object
  184. void EditRender(void);
  185. // Give Edit a rectangle around this object
  186. void EditRect(RRect* pRect);
  187. // Called by editor to get the hotspot of an object in 2D.
  188. void EditHotSpot( // Returns nothiing.
  189. short* psX, // Out: X coord of 2D hotspot relative to
  190. // EditRect() pos.
  191. short* psY); // Out: Y coord of 2D hotspot relative to
  192. // EditRect() pos.
  193. // Get the coordinates of this thing.
  194. virtual // Overriden here.
  195. double GetX(void) { return m_dX; }
  196. virtual // Overriden here.
  197. double GetY(void) { return m_dY; }
  198. virtual // Overriden here.
  199. double GetZ(void) { return m_dZ; }
  200. // Search the list of pylons and return a pointer to the one with the given ID
  201. CPylon* GetPylon(UCHAR ucPylonID);
  202. // Search the list of pylons and return the instance ID of the one with
  203. // the given pylon id.
  204. U16 GetPylonUniqueID(UCHAR ucPylonID);
  205. // Return true if the pylon was triggered in the last interation
  206. inline bool Triggered(void)
  207. {
  208. bool bTriggered = false;
  209. if (m_u16TargetDudeID != CIdBank::IdNil)
  210. {
  211. CThing* pthing;
  212. m_pRealm->m_idbank.GetThingByID((CThing**) &pthing, m_u16TargetDudeID);
  213. if (pthing && pthing->GetClassID() == CDudeID)
  214. {
  215. if (((CDude*) pthing)->m_state != CThing3d::State_Dead)
  216. bTriggered = true;
  217. }
  218. }
  219. return bTriggered;
  220. }
  221. //---------------------------------------------------------------------------
  222. // Internal functions
  223. //---------------------------------------------------------------------------
  224. protected:
  225. // Get all required resources
  226. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  227. // Free all resources
  228. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  229. // GetFreePylonID - get the next ID that is not in use
  230. UCHAR GetFreePylonID(void);
  231. // Process Messages - look for DudeTrigger message
  232. void ProcessMessages(void);
  233. };
  234. #endif //PYLON_H
  235. ////////////////////////////////////////////////////////////////////////////////
  236. // EOF
  237. ////////////////////////////////////////////////////////////////////////////////