thing.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. // thing.h
  19. // Project: Postal
  20. //
  21. //
  22. // 01/17/97 JMI Started DoGui(). Checked in so can work at home. Compiles.
  23. //
  24. // 01/21/97 JMI Made ms_aClassInfo[] public.
  25. //
  26. // 01/22/97 JMI Added bEditorCreatable as member of ClassInfo indicating
  27. // whether the item is creatable in the editor by the user.
  28. //
  29. // 01/29/97 JMI Added m_u16InstanceId, an identifier unique to each instance
  30. // of CThing within its Realm. Also, added the initialization
  31. // of this ID in the constructor, the release of the ID in the
  32. // destructor, and the saving and loading of the ID in Save()
  33. // and Load(). Note that this value is either created by the
  34. // editor, loaded from the .rlm file, or assigned by the
  35. // server (dynamically created CThings (one's not loaded from
  36. // the .rlm file) will get their IDs assigned somehow at run-
  37. // time).
  38. //
  39. // 01/30/97 JMI Had to move Load() into thing.cpp b/c of dependency on
  40. // CRealm. Also, added SetInstanceID() proto.
  41. //
  42. // 02/02/97 JMI Added virtual EditHotSpot() with stub.
  43. //
  44. // 02/07/97 JMI Added support for new CGameEditThing.
  45. // Also, Update() was still pure virtual (must've missed b4
  46. // when we converted to no pure virtuals)...Fixed.
  47. //
  48. // 02/10/97 BRH Added CNapalmID and CFireID.
  49. //
  50. // 02/11/97 JMI Moved CAnim3D to thing.h from dude.h.
  51. //
  52. // 02/11/97 JMI Added ChanTransform (channel of transforms) that will be
  53. // useful for rigid bodies.
  54. // Also, made CAnim3D functions virtual for safety purposes.
  55. //
  56. // 02/11/97 BRH Added CImbecile and changed CDoofus to non-editing (since
  57. // it is now base class). Also added CFirebomb and
  58. // CFirefrag objects.
  59. //
  60. // 02/13/97 JMI Changing RForm3d to RSop.
  61. //
  62. // 02/14/97 JMI Changed ChanBounds to RP3d (was REAL).
  63. //
  64. // 02/16/97 BRH Added message.h and the message queue along with the
  65. // SendThingMessage function to allow CThings to communicate.
  66. // Also set the thing base class version of Update to
  67. // empty the queue each time. If you aren't dealing with
  68. // messages, call the base class Update after yours to
  69. // get rid of unused messages. There should be a better way
  70. // to have the base class automatically clear the queue
  71. // so that CThings that aren't aware of message queues at all
  72. // won't have message queues fill up.
  73. //
  74. // 02/17/97 JMI Added collision functions to CThing.
  75. // Added GetSphere(), which fills in a sphere indicating the
  76. // position and size of a CThing.
  77. // Also, added sets. Every item falls into one of currently
  78. // four sets: Dudes, Enemies, Weapons, Misc.
  79. //
  80. // 02/17/97 BRH Changed the message queue to use the new message structure
  81. // which includes a union of the messages.
  82. //
  83. // 02/18/97 JMI Now uses spherical regions for collision and R3DLine instead
  84. // or R3DRay.
  85. //
  86. // 02/18/97 JMI Changed GetSphere() to GetCollisionSphere().
  87. // Also, removed ThingSet (now use Things instead (they were
  88. // defined identically)).
  89. //
  90. // 02/19/97 JMI Added CAnimThingID CThing class ID.
  91. // Also, removed stuff having to do with collision sets.
  92. //
  93. // 02/23/97 MJR Added concept of having optional PreLoad() functions for
  94. // classes derived from CThing. The idea is that certain
  95. // kinds of things are only created while the game is being
  96. // played, but we don't want them to have to load whatever
  97. // resources they need at that time because it causes the
  98. // gameplay to momentarily pause. Instead, such classes can
  99. // have a PreLoad() function that gets call when the realm is
  100. // first loaded, and they can load whatever they need then.
  101. //
  102. // 02/24/97 MJR Added CSoundThing stuff.
  103. //
  104. // 02/25/97 JMI Added CGunner stuff.
  105. //
  106. // 03/03/97 JMI Added m_ptransRigid to CAnim3D.
  107. //
  108. // 03/04/97 BRH Added CBandID.
  109. //
  110. // 03/05/97 JMI Added ConstructWidthID() to construct an object and assign
  111. // it an ID, if it does not already have one.
  112. //
  113. // 03/05/97 JMI The CAnim3D::Get() overload that sets looping was not
  114. // checking the success/failure status of the other
  115. // CAnim3D::Get() call before accessing the pointers.
  116. // So, if an animation did not load, a crash or bad stuff
  117. // were pretty much guaranteed. Fixed.
  118. //
  119. // 03/06/97 JMI Added CItem3dID.
  120. //
  121. // 03/13/97 JMI Load now takes a version number.
  122. //
  123. // 03/17/97 BRH Added CBarrelID.
  124. //
  125. // 03/19/97 BRH Added CMineID.
  126. //
  127. // 03/19/97 JMI Added CDispenserID.
  128. //
  129. // 04/16/97 BRH Added Jon's template CListNode that replaces the old STL
  130. // lists in CRealm. The CListNode contains next and previous
  131. // pointers rather than having the CThing being put into an
  132. // STL container in CRealm.
  133. //
  134. // 04/25/97 BRH Added CFireballID.
  135. // Added CCopID.
  136. //
  137. // 04/28/97 BRH Added fake ID's for the fake classes
  138. // CPistolID, CMachineGunID, CShotGunID.
  139. //
  140. // 04/28/97 BRH Added CPersonID
  141. //
  142. // 04/29/97 JMI Added Get() to CAnim3D that takes a few simple parameters
  143. // regarding the resource names which it uses to create all
  144. // 7 resource names. This is less annoying than the one
  145. // that requires you allocate an array of strings (which we
  146. // had done b/c we thought we'd combine various things's
  147. // meshes, sops, etc. but have not yet done).
  148. //
  149. // 04/29/97 BRH Added Get() to CAnim3D that takes the base name and the
  150. // verb to combine to create the filenames for all parts
  151. // of each animation. This is the easiest form to use
  152. // for CPerson which stores the base name, verb, and
  153. // rigid body transform name.
  154. //
  155. // 04/30/97 JMI Changed CMineID to CProximityMineID and added CTimedMineID,
  156. // CBouncingBettyMineID, and CRemoteControlMineID.
  157. //
  158. // 05/01/97 BRH Added CPylonID.
  159. //
  160. // 05/01/97 JMI Made m_everything and m_nodeClass public.
  161. //
  162. // 05/02/97 JMI Moved m_pRealm into the public section.
  163. //
  164. // 05/04/97 BRH Removed STL references since the new CListNode method
  165. // seems to be working. Took Tkachuk out of the project
  166. //
  167. // 05/05/97 BRH Had to put placeholder Tkachuk back in to avoid screwing
  168. // up all of the realm files.
  169. //
  170. // 05/08/97 JMI Added CPowerUpID.
  171. //
  172. // 05/09/97 BRH Added COstrichID.
  173. //
  174. // 05/12/97 JRD Added CTriggerID.
  175. //
  176. // 05/13/97 BRH Addec CHeatseekerID.
  177. //
  178. // 05/13/97 JMI Added CChunkID.
  179. //
  180. // 05/17/97 JMI Removed out of date functions IsColliding() and
  181. // GetCollisionSphere().
  182. //
  183. // 05/18/97 BRH Changed CAnim3D's Get function to ignore rigid body
  184. // transform files with blank names, so that it is easier
  185. // to specify animations that don't have rigid body
  186. // transforms in the personatorium.
  187. //
  188. // 05/23/97 JMI Moved CAnim3D from here to Anim3D.cpp/h.
  189. //
  190. // 05/26/97 JMI Finally broke down and added an RHot* so the editor can
  191. // quickly from CThing* to RHot*.
  192. //
  193. // 05/26/97 BRH Added CAssault which is the Shot Gun fired rapidly.
  194. // This is just another dummy ID like the rest of the guns.
  195. //
  196. // 06/02/97 JMI Added CLadderID.
  197. //
  198. // 06/02/97 BRH Added CSentryID and CSentryGunID.
  199. //
  200. // 06/02/97 JMI Removed CLadder stuff.
  201. //
  202. // 06/03/97 JMI Made DoGui() static.
  203. // Also, added CWarpID.
  204. //
  205. // 06/03/97 JMI Changed Construct() and ConstructWithID() to check to make
  206. // sure the creation function exists before calling it.
  207. //
  208. // 06/05/97 JMI Added m_lDoGuiPressedId and GuiPressed() statics.
  209. //
  210. // 06/09/97 BRH Added CDemonID.
  211. //
  212. // 06/11/97 JMI Added CCharacterID.
  213. //
  214. // 06/17/97 JMI Added a section for functions that should be blocked from
  215. // used w/i CThings.
  216. // Added some functions that should not be used from CThings:
  217. // IsSamplePlaying(*), rspGetMilliseconds(), and
  218. // rspGetMicroseconds().
  219. //
  220. // 06/26/97 JMI Added inline aliases to CRealm's Map3DTo2D()s.
  221. //
  222. // 06/27/97 JMI Added GetSprite() which returns this thing's sprite or
  223. // NULL.
  224. //
  225. // 06/30/97 BRH Added CGoalTimerID, CFlagID, and CFlagbaseID.
  226. //
  227. // 07/02/97 BRH Added CFirestream as a better fire for the flamethrower.
  228. //
  229. // 07/03/97 JMI Removed GuiPressed() and added an RProcessGui which is a
  230. // simple way to process a GUI. It is nearly the same as the
  231. // RMsgBox interface but is for Load()ed or otherwise
  232. // preprepared GUIs where RMsgBox is a more dynamic method
  233. // of using a dialog box. Also, the RProcessGui works for
  234. // any GUI (not just RDlg).
  235. //
  236. // 07/03/97 JMI Added callback for RProcessGui so we can use ::Update()
  237. // instead of its internal update stuff.
  238. //
  239. // 07/09/97 JMI Changed FuncPreload to take a pointer to the calling realm
  240. // as a parameter.
  241. //
  242. // 07/14/97 JMI Moved Construct() definition into thing.cpp.
  243. // Now checks to make sure id is bounds.
  244. //
  245. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  246. //
  247. // 07/30/97 JMI Added CDeathWadID.
  248. //
  249. // 08/06/97 JMI Added CDoubleBarrelID.
  250. //
  251. // 08/08/97 JMI Added more weapons for doofuses:
  252. // CUziID, CAutoRifleID, CSmallPistolID, CDynamiteID.
  253. //
  254. // 08/10/97 JMI Added CSndRelayID for CSndRelay.
  255. //
  256. ////////////////////////////////////////////////////////////////////////////////
  257. #ifndef THING_H
  258. #define THING_H
  259. #include "RSPiX.h"
  260. #ifdef PATHS_IN_INCLUDES
  261. #include "ORANGE/Channel/channel.h"
  262. #include "ORANGE/CDT/PQueue.h"
  263. #else
  264. #include "channel.h"
  265. #include "pqueue.h"
  266. #endif
  267. #include "game.h"
  268. #include "message.h"
  269. #include "Anim3D.h"
  270. #include "SampleMaster.h"
  271. #include "sprites.h"
  272. #include "smash.h"
  273. // Forward declaration of class to avoid recursive depency of include files
  274. class CRealm;
  275. class CSmash;
  276. // Template node class for linked lists
  277. template <class Owner>
  278. class CListNode
  279. {
  280. typedef CListNode Node;
  281. // protected:
  282. public:
  283. CListNode() { } // Do not use.
  284. public:
  285. CListNode(Owner* powner)
  286. { m_powner = powner; }
  287. // Note: This function can only be used with a list that has
  288. // dummy nodes for head and tail.
  289. Owner* GetNext(void)
  290. { return m_pnNext->m_powner; }
  291. // Note: This function can only be used with a list that has
  292. // dummy nodes for head and tail.
  293. Owner* GetPrev(void)
  294. { return m_pnPrev->m_powner; }
  295. // Note: This function can only be used with a list that has
  296. // dummy nodes for head and tail.
  297. void InsertBefore(
  298. Node* pn) // In: Node to insert before.
  299. {
  300. ASSERT(m_pnNext == NULL && m_pnPrev == NULL);
  301. m_pnNext = pn;
  302. m_pnPrev = pn->m_pnPrev;
  303. m_pnPrev->m_pnNext = this;
  304. pn->m_pnPrev = this;
  305. }
  306. // Note: This function can only be used with a list that has
  307. // dummy nodes for head and tail.
  308. void AddAfter(
  309. Node* pn) // In: Node to add after.
  310. {
  311. ASSERT(m_pnNext == NULL && m_pnPrev == NULL);
  312. m_pnNext = pn->m_pnNext;
  313. m_pnPrev = pn;
  314. m_pnNext->m_pnPrev = this;
  315. pn->m_pnNext = this;
  316. }
  317. // Note: This function can only be used with a list that has
  318. // dummy nodes for head and tail.
  319. // Note: Do not call, if already removed.
  320. void Remove(void)
  321. {
  322. m_pnNext->m_pnPrev = m_pnPrev;
  323. m_pnPrev->m_pnNext = m_pnNext;
  324. m_pnNext = NULL;
  325. m_pnPrev = NULL;
  326. }
  327. public:
  328. Node* m_pnNext;
  329. Node* m_pnPrev;
  330. Owner* m_powner;
  331. };
  332. // This abstract class is the root of all objects that are part of a CRealm.
  333. // Its primary purpose is to force all derived classes to supply a common set
  334. // of functions so all ojects can be accessed in a generic manner.
  335. class CThing
  336. {
  337. // Make CRealm a friend so it can access private stuff
  338. friend class CRealm;
  339. //---------------------------------------------------------------------------
  340. // Types, enums, etc.
  341. //---------------------------------------------------------------------------
  342. public:
  343. // Typedefs for static functions that all derived classes should have
  344. typedef short (*FuncConstruct)(CRealm* pRealm, CThing** ppNew);
  345. typedef short (*FuncPreload)(CRealm* pRealm);
  346. typedef short (*FuncDestroy)(void);
  347. // Struct containing info about derived classes
  348. typedef struct
  349. {
  350. FuncConstruct funcConstruct; // Construct() function pointer
  351. FuncPreload funcPreload; // Preload() function pointer
  352. const char* pszClassName; // Pointer to class name
  353. bool bEditorCreatable; // true indicates the editor can
  354. // create this object at user
  355. // request. false indicates it
  356. // cannot.
  357. } ClassInfo;
  358. // Typedef for class ID's, required because we want specify the type,
  359. // whereas the compiler always uses type int for enums.
  360. typedef unsigned char ClassIDType;
  361. // Class ID's for all derived classes that need to be loaded/saved. If
  362. // these numbers change, it will completely invalidate any world files
  363. // that were created prior to the change! Add new ID's after existing
  364. // ID's so the existing ones don't change.
  365. typedef enum
  366. {
  367. // First entry should start at 0!
  368. CHoodID = 0,
  369. CDudeID,
  370. CDoofusID,
  371. CTkachukID,
  372. CRocketManID,
  373. CGrenaderID,
  374. CRocketID,
  375. CGrenadeID,
  376. CBallID,
  377. CExplodeID,
  378. CBouyID,
  379. CNavigationNetID,
  380. CGameEditThingID,
  381. CNapalmID,
  382. CFireID,
  383. CImbecileID,
  384. CFirebombID,
  385. CFirefragID,
  386. CAnimThingID,
  387. CSoundThingID,
  388. CGunnerID,
  389. CBandID,
  390. CItem3dID,
  391. CBarrelID,
  392. CProximityMineID,
  393. CDispenserID,
  394. CFireballID,
  395. CCopID,
  396. CPistolID,
  397. CMachineGunID,
  398. CShotGunID,
  399. CPersonID,
  400. CTimedMineID,
  401. CBouncingBettyMineID,
  402. CRemoteControlMineID,
  403. CPylonID,
  404. CPowerUpID,
  405. COstrichID,
  406. CTriggerID,
  407. CHeatseekerID,
  408. CChunkID,
  409. CAssaultWeaponID,
  410. CSentryID,
  411. CSentryGunID,
  412. CWarpID,
  413. CDemonID,
  414. CCharacterID,
  415. CGoalTimerID,
  416. CFlagID,
  417. CFlagbaseID,
  418. CFirestreamID,
  419. CDeathWadID,
  420. CDoubleBarrelID,
  421. CUziID,
  422. CAutoRifleID,
  423. CSmallPistolID,
  424. CDynamiteID,
  425. CSndRelayID,
  426. // This must be the last entry so it gets set to the total number of ID's
  427. TotalIDs
  428. };
  429. typedef enum // Macros within CThing namespace.
  430. {
  431. InvalidPosition = -5770321
  432. } Macros;
  433. //---------------------------------------------------------------------------
  434. // Protected static member variables
  435. //---------------------------------------------------------------------------
  436. protected:
  437. // Flag to detect attempts to construct a CGameObj before CGameObj's static
  438. // member variables are initialized by the C++ startup process. Aside from
  439. // the typical problems involving C++ initialization order, it doesn't really
  440. // make sense to create CGameObj's as global/static objects since they are
  441. // supposed to be created/destroyed dynamically as worlds are loaded.
  442. static short ms_sDetectStaticInits;
  443. // This is used by DoGui() to perform GUI processing.
  444. static RProcessGui ms_pgDoGui;
  445. //---------------------------------------------------------------------------
  446. // Public static member variables
  447. //---------------------------------------------------------------------------
  448. public:
  449. // Array of class info for each derived class
  450. static ClassInfo ms_aClassInfo[TotalIDs];
  451. //---------------------------------------------------------------------------
  452. // Static functions dealing with common static functions in derived classes.
  453. // The purpose of these functions is to make it easy to call the appropriate
  454. // static function in a derived class based on its class ID. This basically
  455. // impliments something similar to virtual functions, except these are static
  456. // functions, which the C++ mechanism doesn't support.
  457. //---------------------------------------------------------------------------
  458. public:
  459. // Construct object
  460. static short Construct( // Returns 0 if successfull, non-zero otherwise
  461. ClassIDType id, // In: Class ID
  462. CRealm* pRealm, // In: Pointer to realm this object belongs to
  463. CThing** ppNew); // Out: Pointer to new object
  464. // Construct object and assign it an ID from the Realm's ID bank,
  465. // if it does not already have one.
  466. static short ConstructWithID( // Returns 0 if successfull, non-zero otherwise
  467. ClassIDType id, // In: Class ID
  468. CRealm* pRealm, // In: Pointer to realm this object belongs to
  469. CThing** ppNew); // Out: Pointer to new object
  470. //---------------------------------------------------------------------------
  471. // Non-static variables
  472. //---------------------------------------------------------------------------
  473. public:
  474. // Prioritized Message queue for Things to use to communicate with each other
  475. RPQueue <GameMessage, short> m_MessageQueue;
  476. // Pointer to the realm this object belongs to
  477. CRealm* m_pRealm;
  478. // This is intended for the editor. It would probably be a bad idea to use
  479. // this pointer outside of gameedit.cpp.
  480. RHot* m_phot;
  481. protected:
  482. // Flag indicating whether object wants it's Startup() to be called
  483. short m_sCallStartup;
  484. // Flag indicating whether object wants it's Shutdown() to be called
  485. short m_sCallShutdown;
  486. /*
  487. // Iterator that specifies this object's position in the realm's container
  488. // of every object and its class-based container of objects.
  489. #if _MSC_VER >= 1020
  490. Things::const_iterator m_iterEvery;
  491. Things::const_iterator m_iterClass;
  492. #else
  493. Things::iterator m_iterEvery;
  494. Things::iterator m_iterClass;
  495. #endif
  496. */
  497. // Class ID is stored here for instant access
  498. ClassIDType m_id;
  499. // Unique ID specific to this instance of CThing (set in constructor,
  500. // released in destructor).
  501. U16 m_u16InstanceId;
  502. //---------------------------------------------------------------------------
  503. // Public member variables
  504. //---------------------------------------------------------------------------
  505. public:
  506. CListNode<CThing> m_everything;
  507. CListNode<CThing> m_nodeClass;
  508. //---------------------------------------------------------------------------
  509. // Constructor(s) / destructor
  510. //---------------------------------------------------------------------------
  511. protected:
  512. // Constructor
  513. CThing(
  514. CRealm* pRealm, // In: Pointer to realm
  515. ClassIDType id); // In: Class ID
  516. public:
  517. // Destructor (must be virtual so derived class destructors are always called!)
  518. virtual ~CThing();
  519. //---------------------------------------------------------------------------
  520. // CThing-only functions
  521. //---------------------------------------------------------------------------
  522. public:
  523. // Get object's class ID (must NOT be virtual!)
  524. ClassIDType GetClassID(void) // Returns object's class ID
  525. {
  526. return m_id;
  527. }
  528. // Get object instance's unique ID.
  529. U16 GetInstanceID(void)
  530. {
  531. return m_u16InstanceId;
  532. }
  533. // Set object instance's unique ID.
  534. void SetInstanceID( // Returns nothing.
  535. U16 u16Id); // New id for this instance.
  536. // Helper for processing your GUIs.
  537. // Will be made visible by calling pguiRoot->SetVisible(TRUE).
  538. // GUI will be run with focus-awareness until a GUI with ID 1 or 2 is
  539. // clicked. Typically, 1 should be an 'OK' equivalent and 2 'Cancel'.
  540. // Return value indicates which item was clicked (1, 2, or by the ID
  541. // of a GUI that was previously passed to SetGuiToNotify() ).
  542. // Processing involves using queued RSPiX user input via
  543. // rspGetNextInputEvent().
  544. static // Static for your usage pleasure.
  545. long DoGui( // Returns ID of item that terminated looping.
  546. // Returns 0 if rspGetQuitStatus() is nonzero.
  547. // Returns negative on error.
  548. RGuiItem* pguiRoot); // Root of GUI items to process through user.
  549. // Call this for any GUIs besides the standard OK (ID 1) and Cancel (ID 2)
  550. // to set the callback (for on 'pressed') for any GUI you want to end
  551. // a DoGui().
  552. static // Static.
  553. void SetGuiToNotify( // Returns nothing.
  554. RGuiItem* pguiNotifier); // In: The pressed GUI.
  555. // Callback from ms_pgDoGui for system update.
  556. static // Static for use as a callback.
  557. long SysUpdate( // Returns a non-zero ID to abort or zero
  558. // to continue.
  559. RInputEvent* pie); // Out: Next input event to process.
  560. short SendThingMessage(pGameMessage pMessage, U16 u16ID)
  561. {
  562. return SendThingMessage(pMessage, pMessage->msg_Generic.sPriority, u16ID);
  563. }
  564. short SendThingMessage(pGameMessage pMessage, CThing* pThing)
  565. {
  566. return SendThingMessage(pMessage, pMessage->msg_Generic.sPriority, pThing);
  567. }
  568. short SendThingMessage(pGameMessage pMessage, short sPriority, U16 u16ID);
  569. short SendThingMessage(pGameMessage pMessage, short sPriority, CThing* pThing);
  570. // Maps a 3D coordinate onto the viewing plane.
  571. void Map3Dto2D( // Returns nothing.
  572. short sX, // In.
  573. short sY, // In.
  574. short sZ, // In.
  575. short* psX, // Out.
  576. short* psY); // Out.
  577. // Maps a 3D coordinate onto the viewing plane.
  578. void Map3Dto2D( // Returns nothing.
  579. double dX, // In.
  580. double dY, // In.
  581. double dZ, // In.
  582. double* pdX, // Out.
  583. double* pdY); // Out.
  584. //---------------------------------------------------------------------------
  585. // Virtual functions that should be overloaded for additional functionality.
  586. // The default implementations simply return success.
  587. //---------------------------------------------------------------------------
  588. public:
  589. // Load object (should call base class version!)
  590. virtual short Load( // Returns 0 if successfull, non-zero otherwise
  591. RFile* pFile, // In: File to load from
  592. bool bEditMode, // In: True for edit mode, false otherwise
  593. short sFileCount, // In: File count (unique per file, never 0)
  594. ULONG ulFileVersion); // In: File version being loaded.
  595. // Save object (should call base class version!)
  596. virtual short Save( // Returns 0 if successfull, non-zero otherwise
  597. RFile* pFile, // In: File to save to
  598. short /*sFileCount*/) // In: File count (unique per file, never 0)
  599. {
  600. // Save this thing's ID. The ID is unique to this 'thing' within its realm
  601. // (i.e., no other CThing or derived class has this same ID within this realm).
  602. // This is assigned by the editor via a call to the realm's m_idbank.Get().
  603. pFile->Write(m_u16InstanceId);
  604. return pFile->Error();
  605. }
  606. // Startup object
  607. virtual short Startup(void) // Returns 0 if successfull, non-zero otherwise
  608. {
  609. return 0;
  610. }
  611. // Shutdown object
  612. virtual short Shutdown(void) // Returns 0 if successfull, non-zero otherwise
  613. {
  614. return 0;
  615. }
  616. // Suspend object
  617. virtual void Suspend(void)
  618. {
  619. }
  620. // Resume object
  621. virtual void Resume(void)
  622. {
  623. }
  624. // Update object
  625. virtual void Update(void)
  626. {
  627. }
  628. // Render object
  629. virtual void Render(void)
  630. {
  631. }
  632. // Called by editor to init new object at specified position
  633. virtual short EditNew( // Returns 0 if successfull, non-zero otherwise
  634. short /*sX*/, // In: New x coord
  635. short /*sY*/, // In: New y coord
  636. short /*sZ*/) // In: New z coord
  637. {
  638. return 0;
  639. }
  640. // Called by editor to modify object
  641. virtual short EditModify(void) // Returns 0 if successfull, non-zero otherwise
  642. {
  643. return 0;
  644. }
  645. // Called by editor to move object to specified position
  646. virtual short EditMove( // Returns 0 if successfull, non-zero otherwise
  647. short /*sX*/, // In: New x coord
  648. short /*sY*/, // In: New y coord
  649. short /*sZ*/) // In: New z coord
  650. {
  651. return 0;
  652. }
  653. // Called by editor to get the clickable pos/area of an object in 2D.
  654. virtual // If you override this, do NOT call this base class.
  655. void EditRect( // Returns nothiing.
  656. RRect* prc) // Out: Clickable pos/area of object.
  657. {
  658. // Default implementation makes the object unclickable.
  659. prc->sX = 0;
  660. prc->sY = 0;
  661. prc->sW = 0;
  662. prc->sH = 0;
  663. }
  664. // Called by editor to get the hotspot of an object in 2D.
  665. virtual // If you override this, do NOT call this base class.
  666. void EditHotSpot( // Returns nothiing.
  667. short* psX, // Out: X coord of 2D hotspot relative to
  668. // EditRect() pos.
  669. short* psY) // Out: Y coord of 2D hotspot relative to
  670. // EditRect() pos.
  671. {
  672. // Default implementation puts hotspot in upper left corner of
  673. // EditRect().
  674. *psX = 0;
  675. *psY = 0;
  676. }
  677. // Called by editor to update object
  678. virtual void EditUpdate(void)
  679. {
  680. }
  681. // Called by editor to render object
  682. virtual void EditRender(void)
  683. {
  684. }
  685. // Get the sprite for this thing. If there's more than one, pick one
  686. // or none to return.
  687. virtual // If you override this, do NOT call this base class.
  688. CSprite* GetSprite(void) // Returns the sprite for this thing or NULL.
  689. { return NULL; }
  690. // Get the coordinates of this thing. This implementation returns
  691. // InvalidPosition to indicate that it is not implemented for this
  692. // class type. Override these functions for your class type to
  693. // enable this feature.
  694. virtual // Override to implement this functionality.
  695. double GetX(void) { return InvalidPosition; }
  696. virtual // Override to implement this functionality.
  697. double GetY(void) { return InvalidPosition; }
  698. virtual // Override to implement this functionality.
  699. double GetZ(void) { return InvalidPosition; }
  700. // Get the smash - for normal CThings that don't have a smash, it
  701. // will return NULL, CThing3d's though always have a smash.
  702. virtual
  703. CSmash* GetSmash(void) {return NULL;}
  704. //////////////////////////////////////////////////////////////////////////
  705. // These are defined merely to discourage their use within CThings.
  706. // They can cause problems when they are used in a chain of events that
  707. // leads up to a rand() b/c they do not act the same from run to run and/or
  708. // from machine to machine.
  709. //
  710. // DO NOT USE THE THESE FUNCTIONS!!! DO __NOT__ SIMPLY PUT A '::' IN FRONT
  711. // OF YOUR REF TO THESE FUNCTIONS!!!!
  712. //////////////////////////////////////////////////////////////////////////
  713. // Never rely on sounds finishing w/i a CThing. This varies greatly from
  714. // machine to machine (and, in many cases, from run to run).
  715. bool IsSamplePlaying(
  716. SampleMasterID /*id*/)
  717. {
  718. ASSERT(0);
  719. return false;
  720. }
  721. bool IsSamplePlaying(
  722. RSnd* /*psnd*/,
  723. SampleMasterID /*id*/)
  724. {
  725. ASSERT(0);
  726. return false;
  727. }
  728. long rspGetMilliseconds(void)
  729. {
  730. ASSERT(0);
  731. return 0;
  732. }
  733. long rspGetMicroseconds(
  734. short /*sReset = FALSE*/)
  735. {
  736. ASSERT(0);
  737. return 0;
  738. }
  739. };
  740. #endif // THING_H
  741. ////////////////////////////////////////////////////////////////////////////////
  742. // EOF
  743. ////////////////////////////////////////////////////////////////////////////////