dispenser.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. // dispenser.h
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 03/19/97 JMI Started this dispenser item class using CItem3d as a
  23. // template.
  24. //
  25. // 03/20/97 JMI Added m_ulFileVersion, InstantiateDispensee(), and
  26. // SaveDispensee() members. Removed m_idDispensee.
  27. //
  28. // 03/21/97 JMI Added ms_sDispenseeFileCount.
  29. //
  30. // 04/23/97 JMI Added new logic type Exists and added a max for the number
  31. // of dispensees and a current number of dispensees dispensed.
  32. //
  33. // 06/14/97 JMI Made default logic type Timed.
  34. //
  35. // 06/27/97 JMI Added m_imRender and m_bEditMode.
  36. //
  37. // 06/28/97 JMI Added a function to render the dispensee,
  38. // RenderDisipensee().
  39. //
  40. // 06/30/97 JMI m_sDispenseeHotSpotX, m_sDispenseeHotSpotY, and
  41. // m_rcDispensee.
  42. //
  43. // 07/10/97 JMI Added GetClosestDude().
  44. // Also, added new logic type DistanceToDude.
  45. //
  46. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  47. //
  48. // 07/28/97 JMI Changed m_lLogicParm1,2,3 to m_alLogicParms[4] (adding one
  49. // logic parm while changing the storage technique).
  50. //
  51. ////////////////////////////////////////////////////////////////////////////////
  52. #ifndef DISPENSER_H
  53. #define DISPENSER_H
  54. #include "RSPiX.h"
  55. #include "thing.h"
  56. #include "scene.h"
  57. #include "realm.h"
  58. #include "dude.h"
  59. class CDispenser : public CThing
  60. {
  61. //---------------------------------------------------------------------------
  62. // Types, enums, etc.
  63. //---------------------------------------------------------------------------
  64. public:
  65. typedef enum
  66. {
  67. Timed, // Must be 0.
  68. Exists,
  69. DistanceToDude,
  70. // Add new logic types above.
  71. NumLogicTypes
  72. } LogicType;
  73. typedef enum
  74. {
  75. NumParms = 4
  76. } Macros;
  77. typedef struct
  78. {
  79. char* pszName; // Name of logic (for list box).
  80. char* apszParms[NumParms]; // Parm descriptions or NULL for none.
  81. char* pszDescription; // Description of logic (for text box).
  82. } LogicInfo;
  83. //---------------------------------------------------------------------------
  84. // Variables
  85. //---------------------------------------------------------------------------
  86. public:
  87. CSprite2 m_sprite; // 2D sprite.
  88. RImage* m_pim; // 2D image resource ptr.
  89. RImage m_imRender; // Used to render dispenser
  90. // and dispensee in edit mode.
  91. ClassIDType m_idDispenseeType; // Type of object to dispense.
  92. RFile m_fileDispensee; // Mem file representing
  93. // dispensee.
  94. ULONG m_ulFileVersion; // File version of data stored
  95. // in m_fileDispensee.
  96. short m_sX; // Location of this object,
  97. short m_sY; // the dispenser, which is
  98. short m_sZ; // also the location at which
  99. // we will dispense the
  100. // dispensee.
  101. LogicType m_logictype; // Logic used for dispensing.
  102. long m_alLogicParms[NumParms]; // Generic parameters for logic.
  103. short m_sMaxDispensees; // Maximum number of dispensees.
  104. short m_sNumDispensees; // Number of dispensees already
  105. // dispensed.
  106. U16 m_u16IdDispensee; // ID of the last dispensee
  107. // we created.
  108. long m_lNextUpdate; // Time of next update.
  109. bool m_bEditMode; // true, if in edit mode, false
  110. // otherwise.
  111. short m_sDispenseeHotSpotX; // Hotspot of dispensee.
  112. short m_sDispenseeHotSpotY; // Hotspot of dispensee.
  113. RRect m_rcDispensee; // Rect of dispensee.
  114. short m_sSuspend;
  115. // Tracks file counter so we know when to load/save "common" data
  116. static short ms_sFileCount;
  117. static short ms_sDispenseeFileCount;
  118. //---------------------------------------------------------------------------
  119. // Static Variables
  120. //---------------------------------------------------------------------------
  121. public:
  122. // "Constant" values that we want to be able to tune using the editor
  123. // Descriptions of logic types and their parameters.
  124. static LogicInfo ms_aliLogics[NumLogicTypes];
  125. //---------------------------------------------------------------------------
  126. // Constructor(s) / destructor
  127. //---------------------------------------------------------------------------
  128. protected:
  129. // Constructor
  130. CDispenser(CRealm* pRealm)
  131. : CThing(pRealm, CDispenserID)
  132. {
  133. m_pim = NULL;
  134. m_idDispenseeType = TotalIDs; // This means none.
  135. m_sSuspend = FALSE;
  136. memset(m_alLogicParms, 0, sizeof(m_alLogicParms) );
  137. m_sMaxDispensees = 10;
  138. m_sNumDispensees = 0;
  139. m_u16IdDispensee = CIdBank::IdNil;
  140. m_logictype = Timed;
  141. m_bEditMode = false;
  142. m_sDispenseeHotSpotX = 0;
  143. m_sDispenseeHotSpotY = 0;
  144. }
  145. public:
  146. // Destructor
  147. ~CDispenser()
  148. {
  149. // Kill dispenser
  150. Kill();
  151. }
  152. //---------------------------------------------------------------------------
  153. // Required static functions
  154. //---------------------------------------------------------------------------
  155. public:
  156. // Construct object
  157. static short Construct( // Returns 0 if successfull, non-zero otherwise
  158. CRealm* pRealm, // In: Pointer to realm this object belongs to
  159. CThing** ppNew) // Out: Pointer to new object
  160. {
  161. short sResult = 0;
  162. *ppNew = new CDispenser(pRealm);
  163. if (*ppNew == 0)
  164. {
  165. sResult = -1;
  166. TRACE("CDispenser::Construct(): Couldn't construct CDispenser!\n");
  167. }
  168. return sResult;
  169. }
  170. //---------------------------------------------------------------------------
  171. // Required virtual functions (implimenting them as inlines doesn't pay!)
  172. //---------------------------------------------------------------------------
  173. public:
  174. // Load object (should call base class version!)
  175. short Load( // Returns 0 if successfull, non-zero otherwise
  176. RFile* pFile, // In: File to load from
  177. bool bEditMode, // In: True for edit mode, false otherwise
  178. short sFileCount, // In: File count (unique per file, never 0)
  179. ULONG ulFileVersion); // In: Version of file format to load.
  180. // Save object (should call base class version!)
  181. short Save( // Returns 0 if successfull, non-zero otherwise
  182. RFile* pFile, // In: File to save to
  183. short sFileCount); // In: File count (unique per file, never 0)
  184. // Startup object
  185. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  186. // Shutdown object
  187. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  188. // Suspend object
  189. void Suspend(void);
  190. // Resume object
  191. void Resume(void);
  192. // Update object
  193. // (virtual (Overridden here)).
  194. void Update(void);
  195. // Called by editor to init new object at specified position
  196. // (virtual (Overridden here)).
  197. short EditNew( // Returns 0 if successfull, non-zero otherwise
  198. short sX, // In: New x coord
  199. short sY, // In: New y coord
  200. short sZ); // In: New z coord
  201. // Called by editor to modify object.
  202. // (virtual (Overridden here)).
  203. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  204. // Called by editor to move object to specified position
  205. // (virtual (Overridden here)).
  206. short EditMove( // Returns 0 if successfull, non-zero otherwise
  207. short sX, // In: New x coord
  208. short sY, // In: New y coord
  209. short sZ); // In: New z coord
  210. // Called by editor to render object
  211. // (virtual (Overridden here)).
  212. void EditRender(void);
  213. // Give Edit a rectangle around this object
  214. // (virtual (Overridden here)).
  215. void EditRect(RRect* pRect);
  216. // Called by editor to get the hotspot of an object in 2D.
  217. // (virtual (Overridden here)).
  218. void EditHotSpot( // Returns nothiing.
  219. short* psX, // Out: X coord of 2D hotspot relative to
  220. // EditRect() pos.
  221. short* psY); // Out: Y coord of 2D hotspot relative to
  222. // EditRect() pos.
  223. // Get the coordinates of this thing.
  224. virtual // Overriden here.
  225. double GetX(void) { return (double)m_sX; }
  226. virtual // Overriden here.
  227. double GetY(void) { return (double)m_sY; }
  228. virtual // Overriden here.
  229. double GetZ(void) { return (double)m_sZ; }
  230. //---------------------------------------------------------------------------
  231. // Other functions
  232. //---------------------------------------------------------------------------
  233. public:
  234. // Message handling functions ////////////////////////////////////////////
  235. //---------------------------------------------------------------------------
  236. // Internal functions
  237. //---------------------------------------------------------------------------
  238. protected:
  239. // Init dispenser
  240. short Init( // Returns 0 if successfull, non-zero otherwise
  241. bool bEditMode); // true, if in edit mode; false, otherwise.
  242. // Kill dispenser
  243. void Kill(void);
  244. // Get all required resources
  245. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  246. // Free all resources
  247. void FreeResources(void);
  248. // Create a dispensee from the memfile, if open.
  249. short InstantiateDispensee( // Returns 0 on success.
  250. CThing** ppthing, // Out: New thing loaded from m_fileDispensee.
  251. bool bEditMode); // In: true if in edit mode.
  252. // Write dispensee to the memfile.
  253. short SaveDispensee( // Returns 0 on success.
  254. CThing* pthing); // In: Instance of Dispensee to save.
  255. // Render dispensee to m_imRender.
  256. short RenderDispensee( // Returns 0 on success.
  257. CThing* pthing); // In: Instance of Dispensee to render.
  258. // Get the closest dude.
  259. short GetClosestDudeDistance( // Returns 0 on success. Fails, if no dudes.
  260. long* plClosestDistance); // Out: Distance to closest dude.
  261. // Destroy an instantiated dispensee.
  262. void DestroyDispensee( // Returns nothing.
  263. CThing** ppthing); // In: Ptr to the instance.
  264. };
  265. #endif //DISPENSER_H
  266. ////////////////////////////////////////////////////////////////////////////////
  267. // EOF
  268. ////////////////////////////////////////////////////////////////////////////////