trigger.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. // trigger.cpp
  19. // Project: Nostril (aka Postal)
  20. //
  21. // This module impliments the CTrigger class -> holds trigger attributes
  22. //
  23. // History:
  24. // 12/25/96 MJR Started.
  25. //
  26. // 05/12/97 JRD Turned this into a CTrigger to load the trigger attributes
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. #include "RSPiX.h"
  30. #include "trigger.h"
  31. #include "game.h"
  32. #include "realm.h"
  33. ////////////////////////////////////////////////////////////////////////////////
  34. // Macros/types/etc.
  35. ////////////////////////////////////////////////////////////////////////////////
  36. ////////////////////////////////////////////////////////////////////////////////
  37. // Variables/data
  38. ////////////////////////////////////////////////////////////////////////////////
  39. ////////////////////////////////////////////////////////////////////////////////
  40. // Function prototypes
  41. ////////////////////////////////////////////////////////////////////////////////
  42. ////////////////////////////////////////////////////////////////////////////////
  43. // Constructor
  44. // (protected).
  45. ////////////////////////////////////////////////////////////////////////////////
  46. CTrigger::CTrigger(CRealm* pRealm)
  47. : CThing(pRealm, CTriggerID)
  48. {
  49. // Insert a default instance into the realm:
  50. m_pmgi = NULL;
  51. m_pRealm->m_pTriggerMapHolder = this;
  52. m_pRealm->m_pTriggerMap = m_pmgi;
  53. // Assume we don't know the UID's fdor the pylons yet, so clear them all out:
  54. for (short i=0;i < 256;i++)
  55. {
  56. m_ausPylonUIDs[i] = pRealm->m_asPylonUIDs[i] = 0;
  57. }
  58. }
  59. ////////////////////////////////////////////////////////////////////////////////
  60. // Destructor
  61. // (public).
  62. ////////////////////////////////////////////////////////////////////////////////
  63. CTrigger::~CTrigger()
  64. {
  65. if (m_pmgi) delete m_pmgi;
  66. m_pmgi = NULL;
  67. // Clear it from the realm:
  68. m_pRealm->m_pTriggerMap = NULL;
  69. m_pRealm->m_pTriggerMapHolder = NULL;
  70. }
  71. ////////////////////////////////////////////////////////////////////////////////
  72. // Load object (should call base class version!)
  73. ////////////////////////////////////////////////////////////////////////////////
  74. short CTrigger::Load( // Returns 0 if successfull, non-zero otherwise
  75. RFile* pFile, // In: File to load from
  76. bool bEditMode, // In: True for edit mode, false otherwise
  77. short sFileCount, // In: File count (unique per file, never 0)
  78. ULONG ulFileVersion) // In: Version of file format to load.
  79. {
  80. short sResult = 0;
  81. // In most cases, the base class Load() should be called.
  82. sResult = CThing::Load(pFile, bEditMode, sFileCount, ulFileVersion);
  83. if (sResult == 0)
  84. {
  85. // Load object data
  86. m_pRealm->m_pTriggerMap = NULL; // clear the shadow
  87. // ASSUME THERE WILL ALREADY BE AN EMPTY TRIGGER MAP HOLDER!
  88. if (m_pRealm->m_pTriggerMapHolder == NULL) m_pRealm->m_pTriggerMapHolder = new CTrigger(m_pRealm);
  89. if (m_pmgi) delete m_pmgi;
  90. m_pmgi = NULL;
  91. short sData = 0;
  92. pFile->Read(&sData);
  93. // Was there something here?
  94. if (sData)
  95. {
  96. m_pmgi = new RMultiGridIndirect;
  97. if (m_pmgi)
  98. {
  99. if (m_pmgi->Load(pFile) != SUCCESS)
  100. {
  101. TRACE("CTrigger::Load(): Warning - couldn't load trigger attributes!\n");
  102. sResult = -1;
  103. }
  104. else
  105. {
  106. // Load the ID list:
  107. if (pFile->Read(m_ausPylonUIDs,256) != 256) // Grab the ID's
  108. {
  109. TRACE("CTrigger::Load(): Warning - I lost my pylon IDs!\n");
  110. sResult = -1;
  111. }
  112. else
  113. {
  114. // Install into the Realm
  115. m_pRealm->m_pTriggerMapHolder = this;
  116. m_pRealm->m_pTriggerMap = m_pmgi;
  117. // Copy the Pylons to the realm!
  118. for (short i=0;i < 256;i++) m_pRealm->m_asPylonUIDs[i] = m_ausPylonUIDs[i];
  119. }
  120. }
  121. }
  122. }
  123. // Make sure there were no file errors or format errors . . .
  124. if (!pFile->Error() && sResult == 0)
  125. {
  126. }
  127. else
  128. {
  129. sResult = -1;
  130. TRACE("CTrigger::Load(): Error reading from file!\n");
  131. }
  132. }
  133. else
  134. {
  135. TRACE("CTrigger::Load(): CThing::Load() failed.\n");
  136. }
  137. return sResult;
  138. }
  139. ////////////////////////////////////////////////////////////////////////////////
  140. // Save object (should call base class version!)
  141. ////////////////////////////////////////////////////////////////////////////////
  142. short CTrigger::Save( // Returns 0 if successfull, non-zero otherwise
  143. RFile* pFile, // In: File to save to
  144. short sFileCount) // In: File count (unique per file, never 0)
  145. {
  146. short sResult = 0;
  147. // In most cases, the base class Save() should be called.
  148. sResult = CThing::Save(pFile, sFileCount);
  149. if (sResult == 0)
  150. {
  151. // Save object data
  152. short sData = 0; // NO DATA
  153. if (m_pmgi == NULL)
  154. {
  155. sData = 0;
  156. pFile->Write(sData);
  157. }
  158. else
  159. {
  160. // There IS an attribute:
  161. sData = 1;
  162. pFile->Write(sData);
  163. if (m_pmgi->Save(pFile) != SUCCESS)
  164. {
  165. sResult = -1;
  166. TRACE("CTrigger::Save(): Error - coudln't save trigger attributes.\n");
  167. }
  168. else
  169. {
  170. // Save the Pylon Data:
  171. if (pFile->Write(m_ausPylonUIDs,256) != 256)
  172. {
  173. sResult = -1;
  174. TRACE("CTrigger::Save(): Error - coudln't save Pylon IDs.\n");
  175. }
  176. }
  177. }
  178. sResult = pFile->Error();
  179. if (sResult == 0)
  180. {
  181. }
  182. else
  183. {
  184. TRACE("CTrigger::Save(): Error writing to file.\n");
  185. }
  186. }
  187. else
  188. {
  189. TRACE("CTrigger::Save(): CThing::Save() failed.\n");
  190. }
  191. return sResult;
  192. }
  193. ////////////////////////////////////////////////////////////////////////////////
  194. // Startup object
  195. ////////////////////////////////////////////////////////////////////////////////
  196. short CTrigger::Startup(void) // Returns 0 if successfull, non-zero otherwise
  197. {
  198. return 0;
  199. }
  200. ////////////////////////////////////////////////////////////////////////////////
  201. // Shutdown object
  202. ////////////////////////////////////////////////////////////////////////////////
  203. short CTrigger::Shutdown(void) // Returns 0 if successfull, non-zero otherwise
  204. {
  205. return 0;
  206. }
  207. ////////////////////////////////////////////////////////////////////////////////
  208. // Suspend object
  209. ////////////////////////////////////////////////////////////////////////////////
  210. void CTrigger::Suspend(void)
  211. {
  212. }
  213. ////////////////////////////////////////////////////////////////////////////////
  214. // Resume object
  215. ////////////////////////////////////////////////////////////////////////////////
  216. void CTrigger::Resume(void)
  217. {
  218. }
  219. ////////////////////////////////////////////////////////////////////////////////
  220. // Update object
  221. ////////////////////////////////////////////////////////////////////////////////
  222. void CTrigger::Update(void)
  223. {
  224. }
  225. ////////////////////////////////////////////////////////////////////////////////
  226. // Render object
  227. ////////////////////////////////////////////////////////////////////////////////
  228. void CTrigger::Render(void)
  229. {
  230. }
  231. ////////////////////////////////////////////////////////////////////////////////
  232. // Called by editor to init new object at specified position
  233. ////////////////////////////////////////////////////////////////////////////////
  234. short CTrigger::EditNew( // Returns 0 if successfull, non-zero otherwise
  235. short sX, // In: New x coord
  236. short sY, // In: New y coord
  237. short sZ) // In: New z coord
  238. {
  239. return 0;
  240. }
  241. ////////////////////////////////////////////////////////////////////////////////
  242. // Called by editor to modify object
  243. ////////////////////////////////////////////////////////////////////////////////
  244. short CTrigger::EditModify(void)
  245. {
  246. return 0;
  247. }
  248. ////////////////////////////////////////////////////////////////////////////////
  249. // Called by editor to move object to specified position
  250. ////////////////////////////////////////////////////////////////////////////////
  251. short CTrigger::EditMove( // Returns 0 if successfull, non-zero otherwise
  252. short /*sX*/, // In: New x coord
  253. short /*sY*/, // In: New y coord
  254. short /*sZ*/) // In: New z coord
  255. {
  256. return 0;
  257. }
  258. ////////////////////////////////////////////////////////////////////////////////
  259. // Called by editor to update object
  260. ////////////////////////////////////////////////////////////////////////////////
  261. void CTrigger::EditUpdate(void)
  262. {
  263. }
  264. ////////////////////////////////////////////////////////////////////////////////
  265. // Called by editor to render object
  266. ////////////////////////////////////////////////////////////////////////////////
  267. void CTrigger::EditRender(void)
  268. {
  269. }
  270. ////////////////////////////////////////////////////////////////////////////////
  271. // Add myself into the realm that created me.
  272. ////////////////////////////////////////////////////////////////////////////////
  273. void CTrigger::AddData(RMultiGridIndirect* pmgi)
  274. {
  275. m_pRealm->m_pTriggerMap = m_pmgi = pmgi;
  276. // Copy my Pylon Data into the Realm's:
  277. for (short i=0;i < 256;i++) m_pRealm->m_asPylonUIDs[i] = m_ausPylonUIDs[i];
  278. }
  279. ////////////////////////////////////////////////////////////////////////////////
  280. // EOF
  281. ////////////////////////////////////////////////////////////////////////////////