navnet.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. // navigationnet.h
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 01/28/97 BRH Added navigation net objects as the thing that holds
  23. // a group of bouys together in a navigational network.
  24. //
  25. // 03/13/97 JMI Load now takes a version number.
  26. //
  27. // 06/30/97 JMI Moved definitions of EditRect() and EditHotSpot() into
  28. // navnet.cpp.
  29. //
  30. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  31. //
  32. // 08/08/97 BRH Added EditPostLoad function which adds the Nav Net name
  33. // to the editor's list box, just as it does when EditNew is
  34. // called. This way the NavNets loaded from the realm file
  35. // are now correctly displayed.
  36. //
  37. ////////////////////////////////////////////////////////////////////////////////
  38. #ifndef NAVIGATIONNET_H
  39. #define NAVIGATIONNET_H
  40. #include "RSPiX.h"
  41. #include "realm.h"
  42. #include "bouy.h"
  43. #include <map>
  44. // CNavigationNet is the class for navigation
  45. class CNavigationNet : public CThing
  46. {
  47. //---------------------------------------------------------------------------
  48. // Types, enums, etc.
  49. //---------------------------------------------------------------------------
  50. public:
  51. #if _MSC_VER >= 1020 || __MWERKS__ >= 0x1100
  52. #if __MWERKS__ >= 0x1100
  53. ITERATOR_TRAITS(const CBouy*);
  54. #endif
  55. typedef map <UCHAR, CBouy*, less<UCHAR>, allocator<CBouy*> > nodeMap;
  56. #else
  57. typedef map <UCHAR, CBouy*, less<UCHAR> > nodeMap;
  58. #endif
  59. //---------------------------------------------------------------------------
  60. // Variables
  61. //---------------------------------------------------------------------------
  62. public:
  63. nodeMap m_NodeMap; // Map of ID's to CBouy nodes
  64. protected:
  65. double m_dX; // x coord
  66. double m_dY; // y coord
  67. double m_dZ; // z coord
  68. UCHAR m_ucNextID;
  69. UCHAR m_ucNumSavedBouys;
  70. RImage* m_pImage; // Pointer to only image (replace with 3d anim, soon)
  71. CSprite2 m_sprite; // Sprite (replace with CSprite3, soon)
  72. RString m_rstrNetName; // Name of Nav Net
  73. TreeListNode m_BouyTreeListHead; // Head of sorted list
  74. TreeListNode m_BouyTreeListTail; // Tail of sorted list
  75. short m_sSuspend; // Suspend flag
  76. // Tracks file counter so we know when to load/save "common" data
  77. static short ms_sFileCount;
  78. // "Constant" values that we want to be able to tune using the editor
  79. //---------------------------------------------------------------------------
  80. // Constructor(s) / destructor
  81. //---------------------------------------------------------------------------
  82. protected:
  83. // Constructor
  84. CNavigationNet(CRealm* pRealm)
  85. : CThing(pRealm, CNavigationNetID)
  86. {
  87. m_pImage = 0;
  88. m_sSuspend = 0;
  89. m_ucNextID = 1;
  90. // Set yourself to be the new current Nav Net in the realm
  91. pRealm->m_pCurrentNavNet = this;
  92. // Set default name as NavNetxx where xx is CThing ID
  93. m_rstrNetName = "Untitled NavNet";
  94. // Initialize the dummy nodes for the sorted tree/list
  95. m_BouyTreeListHead.m_powner = NULL;
  96. m_BouyTreeListHead.m_pnPrev = NULL;
  97. m_BouyTreeListHead.m_pnRight = NULL;
  98. m_BouyTreeListHead.m_pnLeft = NULL;
  99. m_BouyTreeListHead.m_pnNext = &m_BouyTreeListTail;
  100. m_BouyTreeListTail.m_powner = NULL;
  101. m_BouyTreeListTail.m_pnPrev = &m_BouyTreeListHead;
  102. m_BouyTreeListTail.m_pnNext = NULL;
  103. m_BouyTreeListTail.m_pnRight = NULL;
  104. m_BouyTreeListTail.m_pnLeft = NULL;
  105. }
  106. public:
  107. // Destructor
  108. ~CNavigationNet()
  109. {
  110. // Remove sprite from scene (this is safe even if it was already removed!)
  111. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  112. // Free resources
  113. FreeResources();
  114. }
  115. //---------------------------------------------------------------------------
  116. // Required static functions
  117. //---------------------------------------------------------------------------
  118. public:
  119. // Construct object
  120. static short Construct( // Returns 0 if successfull, non-zero otherwise
  121. CRealm* pRealm, // In: Pointer to realm this object belongs to
  122. CThing** ppNew) // Out: Pointer to new object
  123. {
  124. short sResult = 0;
  125. *ppNew = new CNavigationNet(pRealm);
  126. if (*ppNew == 0)
  127. {
  128. sResult = -1;
  129. TRACE("CNavigationNet::Construct(): Couldn't construct CNavigationNet (that's a bad thing)\n");
  130. }
  131. return sResult;
  132. }
  133. //---------------------------------------------------------------------------
  134. // Required virtual functions (implimenting them as inlines doesn't pay!)
  135. //---------------------------------------------------------------------------
  136. public:
  137. // Load object (should call base class version!)
  138. short Load( // Returns 0 if successfull, non-zero otherwise
  139. RFile* pFile, // In: File to load from
  140. bool bEditMode, // In: True for edit mode, false otherwise
  141. short sFileCount, // In: File count (unique per file, never 0)
  142. ULONG ulFileVersion); // In: Version of file format to load.
  143. // Save object (should call base class version!)
  144. short Save( // Returns 0 if successfull, non-zero otherwise
  145. RFile* pFile, // In: File to save to
  146. short sFileCount); // In: File count (unique per file, never 0)
  147. // Startup object
  148. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  149. // Shutdown object
  150. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  151. // Suspend object
  152. void Suspend(void);
  153. // Resume object
  154. void Resume(void);
  155. // Update object
  156. void Update(void);
  157. // Render object
  158. void Render(void);
  159. // Called by editor to init new object at specified position
  160. short EditNew( // Returns 0 if successfull, non-zero otherwise
  161. short sX, // In: New x coord
  162. short sY, // In: New y coord
  163. short sZ); // In: New z coord
  164. // Called by editor to init nav net after it is loaded
  165. short EditPostLoad(void);
  166. // Called by editor to modify object
  167. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  168. // Called by editor to move object to specified position
  169. short EditMove( // Returns 0 if successfull, non-zero otherwise
  170. short sX, // In: New x coord
  171. short sY, // In: New y coord
  172. short sZ); // In: New z coord
  173. // Called by editor to update object
  174. void EditUpdate(void);
  175. // Called by editor to render object
  176. void EditRender(void);
  177. // Give Edit a rectangle around this object
  178. void EditRect(RRect* pRect);
  179. // Called by editor to get the hotspot of an object in 2D.
  180. void EditHotSpot( // Returns nothiing.
  181. short* psX, // Out: X coord of 2D hotspot relative to
  182. // EditRect() pos.
  183. short* psY); // Out: Y coord of 2D hotspot relative to
  184. // EditRect() pos.
  185. // Get the coordinates of this thing.
  186. virtual // Overriden here.
  187. double GetX(void) { return m_dX; }
  188. virtual // Overriden here.
  189. double GetY(void) { return m_dY; }
  190. virtual // Overriden here.
  191. double GetZ(void) { return m_dZ; }
  192. // Add a bouy to this network and assign it an ID
  193. UCHAR AddBouy(CBouy* pBouy);
  194. // Remove a bouy from the network
  195. void RemoveBouy(UCHAR ucBouyID);
  196. // Get the address of the Bouy with this ID
  197. CBouy* GetBouy(UCHAR ucBouy);
  198. // Find the bouy closest to this location in the world
  199. UCHAR FindNearestBouy(short sX, short sZ);
  200. // Preprocess the routing tables by pinging all nodes
  201. void UpdateRoutingTables(void);
  202. // Print the routing tables for debugging purposes
  203. void PrintRoutingTables(void);
  204. // Ping - return minimum number of hops from source to destination nodes
  205. // UCHAR Ping(UCHAR dst, UCHAR src, UCHAR depth, UCHAR maxdepth);
  206. UCHAR Ping(UCHAR dst, UCHAR src, UCHAR depth);
  207. UCHAR GetNumNodes(void)
  208. { return m_ucNextID;}
  209. // Set this NavNet as the default one for the Realm.
  210. short SetAsDefault(void)
  211. { short sReturn = SUCCESS;
  212. if (m_pRealm)
  213. {
  214. m_pRealm->m_pCurrentNavNet = this;
  215. }
  216. else
  217. sReturn = FAILURE;
  218. return sReturn;
  219. }
  220. // Delete all bouys from this network.
  221. short DeleteNetwork(void);
  222. //---------------------------------------------------------------------------
  223. // Internal functions
  224. //---------------------------------------------------------------------------
  225. protected:
  226. // Get all required resources
  227. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  228. // Free all resources
  229. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  230. };
  231. #endif //DOOFUS_H
  232. ////////////////////////////////////////////////////////////////////////////////
  233. // EOF
  234. ////////////////////////////////////////////////////////////////////////////////