warp.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. // Warp.cpp
  19. // Project: Postal
  20. //
  21. // History:
  22. // 06/02/97 JMI Started.
  23. //
  24. // 06/06/97 JMI Priority was being set incorrectly (was adding the height
  25. // of this object to our Z, but since our hotspot is at our
  26. // bottom, our priority is simply our Z).
  27. //
  28. // 06/07/97 JMI Added WarpIn() and WarpInAnywhere() function bodies.
  29. // Also, added CreateWarpFromDude().
  30. //
  31. // 06/15/97 JMI Moved initialization of ms_stockpile into warp.cpp since
  32. // the stockpile is non aggregatable.
  33. //
  34. // 06/16/97 JMI Moved initialization of dude's original hitpoints such
  35. // that both warp types (ones where he is preallocated and
  36. // ones where he is allocated by the WarpIn called) set it.
  37. //
  38. // 06/17/97 JMI Converted all occurrences of rand() to GetRand() and
  39. // srand() to SeedRand().
  40. //
  41. // 06/29/97 JMI Converted EditRect(), EditRender(), and/or Render() to
  42. // use Map3Dto2D().
  43. //
  44. // 06/30/97 JMI Now maps the Z to 3D when loading fileversions previous to
  45. // 24.
  46. //
  47. // 07/09/97 JMI Now uses m_pRealm->Make2dResPath() to get the fullpath
  48. // for 2D image components.
  49. //
  50. // 07/19/97 JMI Added m_sRotY, the dude's initial rotation around the Y
  51. // axis. Also, now passes a GUI to CStockPile::UserEdit()
  52. // with some settings for us.
  53. //
  54. // 08/03/97 BRH Increased the starting hit points for the Dude if the
  55. // game difficulty is set to 11.
  56. //
  57. // 08/05/97 JMI Changed priority to use Z position rather than 2D
  58. // projected Y position.
  59. //
  60. // 08/08/97 JMI Upped GUI_ID_ROT_Y from 101 to 1001 so it wouldn't
  61. // conflict with the stockpile dialog.
  62. //
  63. // 08/10/97 JMI Now the warp places the dude via a call to
  64. // CDude::SetPosition().
  65. //
  66. // 08/14/97 JMI Switched references to g_GameSettings.m_sDifficulty to
  67. // m_pRealm->m_flags.sDifficulty.
  68. //
  69. // 09/30/97 JMI Filled in empty fields in ms_stockpile. Although it is
  70. // not necessary b/c of the implicit filescope zero init,
  71. // it just seems like a good idea. But they are still zero
  72. // (just using enums instead of 0s) so there should be no
  73. // synch problems with old versions.
  74. //
  75. // 12/01/97 BRH For multiplayer deathmatch, the warp sets the hit
  76. // points to WARP_DEATHMATCH_DEFAULT_HP which will be
  77. // set to an amount we determine to be more fun. Right
  78. // now, most levels are set to 500 hit points, but for
  79. // deathmatch, its too hard to kill each other.
  80. //
  81. //////////////////////////////////////////////////////////////////////////////
  82. //
  83. // This CThing-derived class will represent places and settings for dudes to
  84. // 'warp' in at/with.
  85. //
  86. //////////////////////////////////////////////////////////////////////////////
  87. #define WARP_CPP
  88. #include "RSPiX.h"
  89. #include "warp.h"
  90. #include "game.h"
  91. #include "reality.h"
  92. ////////////////////////////////////////////////////////////////////////////////
  93. // Macros/types/etc.
  94. ////////////////////////////////////////////////////////////////////////////////
  95. // This is for edit mode only.
  96. #define WARP_IMAGE_FILENAME "warp.bmp"
  97. #define GUI_FILENAME "res/editor/warp.gui"
  98. #define GUI_ID_ROT_Y 1001
  99. #define WARP_DEATHMATCH_DEFAULT_HP 100
  100. ////////////////////////////////////////////////////////////////////////////////
  101. // Variables/data
  102. ////////////////////////////////////////////////////////////////////////////////
  103. // The stockpile of ammo and health used by all CWarps.
  104. CStockPile CWarp::ms_stockpile =
  105. {
  106. // Use CDude defaults for stockpile.
  107. CDude::DefHitPoints,
  108. CDude::DefNumGrenades,
  109. CDude::DefNumFireBombs,
  110. CDude::DefNumMissiles,
  111. CDude::DefNumNapalms,
  112. CDude::DefNumBullets,
  113. CDude::DefNumShells,
  114. CDude::DefNumFuel,
  115. CDude::DefNumMines,
  116. CDude::DefNumHeatseekers,
  117. CDude::DefHasMachineGun,
  118. CDude::DefHasLauncher,
  119. CDude::DefHasShotgun,
  120. CDude::DefHasSprayCannon,
  121. CDude::DefHasFlamer,
  122. CDude::DefHasNapalmLauncher,
  123. CDude::DefHasDeathWadLauncher,
  124. CDude::DefHasDoubleBarrel,
  125. CDude::DefKevlarLayers,
  126. CDude::DefHasBackpack,
  127. };
  128. // Tracks file counter so we know when to load/save "common" data
  129. short CWarp::ms_sFileCount = 0;
  130. ////////////////////////////////////////////////////////////////////////////////
  131. // Load object (should call base class version!)
  132. ////////////////////////////////////////////////////////////////////////////////
  133. short CWarp::Load( // Returns 0 if successfull, non-zero otherwise
  134. RFile* pFile, // In: File to load from
  135. bool bEditMode, // In: True for edit mode, false otherwise
  136. short sFileCount, // In: File count (unique per file, never 0)
  137. ULONG ulFileVersion) // In: Version of file format to load.
  138. {
  139. short sResult = CThing::Load(pFile, bEditMode, sFileCount, ulFileVersion);
  140. if (sResult == 0)
  141. {
  142. // If statics have not yet been loaded . . .
  143. if (ms_sFileCount != sFileCount)
  144. {
  145. ms_sFileCount = sFileCount;
  146. ms_stockpile.Load(pFile, ulFileVersion);
  147. }
  148. switch (ulFileVersion)
  149. {
  150. default:
  151. case 32:
  152. pFile->Read(&m_sRotY);
  153. case 31:
  154. case 30:
  155. case 29:
  156. case 28:
  157. case 27:
  158. case 26:
  159. case 25:
  160. case 24:
  161. case 23:
  162. case 22:
  163. case 21:
  164. case 20:
  165. case 19:
  166. case 18:
  167. case 17:
  168. case 16:
  169. case 15:
  170. case 14:
  171. case 13:
  172. case 12:
  173. case 11:
  174. case 10:
  175. case 9:
  176. case 8:
  177. case 7:
  178. case 6:
  179. case 5:
  180. case 4:
  181. case 3:
  182. case 2:
  183. case 1:
  184. pFile->Read(&m_dX);
  185. pFile->Read(&m_dY);
  186. pFile->Read(&m_dZ);
  187. break;
  188. }
  189. // If the file version is earlier than the change to real 3D coords . . .
  190. if (ulFileVersion < 24)
  191. {
  192. // Convert to 3D.
  193. m_pRealm->MapY2DtoZ3D(
  194. m_dZ,
  195. &m_dZ);
  196. }
  197. // Make sure there were no file errors or format errors . . .
  198. if (!pFile->Error() && sResult == 0)
  199. {
  200. // If in edit mode . . .
  201. if (bEditMode == true)
  202. {
  203. // Get resources and initialize.
  204. sResult = Init();
  205. }
  206. }
  207. else
  208. {
  209. sResult = -1;
  210. TRACE("CWarp::Load(): Error reading from file!\n");
  211. }
  212. }
  213. return sResult;
  214. }
  215. ////////////////////////////////////////////////////////////////////////////////
  216. // Save object (should call base class version!)
  217. ////////////////////////////////////////////////////////////////////////////////
  218. short CWarp::Save( // Returns 0 if successfull, non-zero otherwise
  219. RFile* pFile, // In: File to save to
  220. short sFileCount) // In: File count (unique per file, never 0)
  221. {
  222. short sResult = CThing::Save(pFile, sFileCount);
  223. if (sResult == 0)
  224. {
  225. // Save common data just once per file (not with each object)
  226. if (ms_sFileCount != sFileCount)
  227. {
  228. ms_sFileCount = sFileCount;
  229. ms_stockpile.Save(pFile);
  230. }
  231. pFile->Write(&m_sRotY);
  232. pFile->Write(&m_dX);
  233. pFile->Write(&m_dY);
  234. pFile->Write(&m_dZ);
  235. // Make sure there were no file errors
  236. sResult = pFile->Error();
  237. }
  238. return sResult;
  239. }
  240. ////////////////////////////////////////////////////////////////////////////////
  241. // Startup object
  242. ////////////////////////////////////////////////////////////////////////////////
  243. short CWarp::Startup(void) // Returns 0 if successfull, non-zero otherwise
  244. {
  245. return 0;
  246. }
  247. ////////////////////////////////////////////////////////////////////////////////
  248. // Shutdown object
  249. ////////////////////////////////////////////////////////////////////////////////
  250. short CWarp::Shutdown(void) // Returns 0 if successfull, non-zero otherwise
  251. {
  252. return 0;
  253. }
  254. ////////////////////////////////////////////////////////////////////////////////
  255. // Suspend object
  256. ////////////////////////////////////////////////////////////////////////////////
  257. void CWarp::Suspend(void)
  258. {
  259. m_sSuspend++;
  260. }
  261. ////////////////////////////////////////////////////////////////////////////////
  262. // Resume object
  263. ////////////////////////////////////////////////////////////////////////////////
  264. void CWarp::Resume(void)
  265. {
  266. m_sSuspend--;
  267. }
  268. ////////////////////////////////////////////////////////////////////////////////
  269. // Update object
  270. ////////////////////////////////////////////////////////////////////////////////
  271. void CWarp::Update(void)
  272. {
  273. // Do schtuff.
  274. }
  275. ////////////////////////////////////////////////////////////////////////////////
  276. // Render object
  277. ////////////////////////////////////////////////////////////////////////////////
  278. void CWarp::Render(void)
  279. {
  280. // Doesn't normally draw anything (see EditRender() for render during
  281. // edit mode).
  282. }
  283. ////////////////////////////////////////////////////////////////////////////////
  284. // Called by editor to init new object at specified position
  285. ////////////////////////////////////////////////////////////////////////////////
  286. short CWarp::EditNew( // Returns 0 if successfull, non-zero otherwise
  287. short sX, // In: New x coord
  288. short sY, // In: New y coord
  289. short sZ) // In: New z coord
  290. {
  291. short sResult = 0;
  292. // Use specified position
  293. m_dX = (double)sX;
  294. m_dY = (double)sY;
  295. m_dZ = (double)sZ;
  296. sResult = Init();
  297. return sResult;
  298. }
  299. ////////////////////////////////////////////////////////////////////////////////
  300. // Called by editor to modify object
  301. ////////////////////////////////////////////////////////////////////////////////
  302. short CWarp::EditModify(void)
  303. {
  304. short sResult = 0;
  305. // Load our GUI.
  306. RGuiItem* pgui = RGuiItem::LoadInstantiate(FullPathVD(GUI_FILENAME));
  307. if (pgui)
  308. {
  309. // Set current Y axis rotation.
  310. RGuiItem* pguiRotY = pgui->GetItemFromId(GUI_ID_ROT_Y);
  311. if (pguiRotY)
  312. {
  313. pguiRotY->SetText("%d", m_sRotY);
  314. pguiRotY->Compose();
  315. }
  316. // Display stockpile's GUI with ours at the bottom.
  317. sResult = ms_stockpile.UserEdit(pgui);
  318. // If not cancelled . . .
  319. if (sResult == 0)
  320. {
  321. if (pguiRotY)
  322. {
  323. m_sRotY = pguiRotY->GetVal();
  324. }
  325. }
  326. // Destroy our GUI.
  327. delete pgui;
  328. }
  329. return sResult;
  330. }
  331. ////////////////////////////////////////////////////////////////////////////////
  332. // Called by editor to move object to specified position
  333. ////////////////////////////////////////////////////////////////////////////////
  334. short CWarp::EditMove( // Returns 0 if successfull, non-zero otherwise
  335. short sX, // In: New x coord
  336. short sY, // In: New y coord
  337. short sZ) // In: New z coord
  338. {
  339. m_dX = (double)sX;
  340. m_dY = (double)sY;
  341. m_dZ = (double)sZ;
  342. return 0;
  343. }
  344. ////////////////////////////////////////////////////////////////////////////////
  345. // Called by editor to get the clickable pos/area of an object in 2D.
  346. // (virtual (Overridden here)).
  347. ////////////////////////////////////////////////////////////////////////////////
  348. void CWarp::EditRect( // Returns nothiing.
  349. RRect* prc) // Out: Clickable pos/area of object.
  350. {
  351. Map3Dto2D(
  352. m_dX,
  353. m_dY,
  354. m_dZ,
  355. &(prc->sX),
  356. &(prc->sY) );
  357. prc->sW = 10; // Safety.
  358. prc->sH = 10; // Safety.
  359. if (m_sprite.m_pImage != NULL)
  360. {
  361. prc->sW = m_sprite.m_pImage->m_sWidth;
  362. prc->sH = m_sprite.m_pImage->m_sHeight;
  363. }
  364. prc->sX -= prc->sW / 2;
  365. prc->sY -= prc->sH;
  366. }
  367. ////////////////////////////////////////////////////////////////////////////////
  368. // Called by editor to get the hotspot of an object in 2D.
  369. // (virtual (Overridden here)).
  370. ////////////////////////////////////////////////////////////////////////////////
  371. void CWarp::EditHotSpot( // Returns nothiing.
  372. short* psX, // Out: X coord of 2D hotspot relative to
  373. // EditRect() pos.
  374. short* psY) // Out: Y coord of 2D hotspot relative to
  375. // EditRect() pos.
  376. {
  377. *psX = 0; // Safety.
  378. *psY = 0; // Safety.
  379. if (m_sprite.m_pImage != NULL)
  380. {
  381. *psX = m_sprite.m_pImage->m_sWidth / 2;
  382. *psY = m_sprite.m_pImage->m_sHeight;
  383. }
  384. }
  385. ////////////////////////////////////////////////////////////////////////////////
  386. // Called by editor to update object
  387. ////////////////////////////////////////////////////////////////////////////////
  388. void CWarp::EditUpdate(void)
  389. {
  390. // The editor schtuff.
  391. }
  392. ////////////////////////////////////////////////////////////////////////////////
  393. // Called by editor to render object
  394. ////////////////////////////////////////////////////////////////////////////////
  395. void CWarp::EditRender(void)
  396. {
  397. // Map from 3d to 2d coords
  398. Map3Dto2D(
  399. (short) m_dX,
  400. (short) m_dY,
  401. (short) m_dZ,
  402. &m_sprite.m_sX2,
  403. &m_sprite.m_sY2);
  404. // Priority is based on bottom edge of sprite on viewing plane.
  405. m_sprite.m_sPriority = m_dZ;
  406. // Center on image.
  407. m_sprite.m_sX2 -= m_sprite.m_pImage->m_sWidth / 2;
  408. m_sprite.m_sY2 -= m_sprite.m_pImage->m_sHeight;
  409. // Layer should be based on info we get from attribute map.
  410. m_sprite.m_sLayer = CRealm::GetLayerViaAttrib(m_pRealm->GetLayer((short) m_dX, (short) m_dZ));
  411. // Update sprite in scene
  412. m_pRealm->m_scene.UpdateSprite(&m_sprite);
  413. }
  414. ////////////////////////////////////////////////////////////////////////////////
  415. // Initialize object.
  416. ////////////////////////////////////////////////////////////////////////////////
  417. short CWarp::Init(void) // Returns 0 on success.
  418. {
  419. short sRes = GetResources();
  420. return sRes;
  421. }
  422. ////////////////////////////////////////////////////////////////////////////////
  423. // Get all required resources
  424. ////////////////////////////////////////////////////////////////////////////////
  425. short CWarp::GetResources(void) // Returns 0 if successfull, non-zero otherwise
  426. {
  427. short sResult = 0;
  428. // Safe to call even if no resource.
  429. FreeResources();
  430. sResult = rspGetResource(
  431. &g_resmgrGame,
  432. m_pRealm->Make2dResPath(WARP_IMAGE_FILENAME),
  433. &m_sprite.m_pImage);
  434. return sResult;
  435. }
  436. ////////////////////////////////////////////////////////////////////////////////
  437. // Free all resources
  438. ////////////////////////////////////////////////////////////////////////////////
  439. short CWarp::FreeResources(void) // Returns 0 if successfull, non-zero otherwise
  440. {
  441. short sResult = 0;
  442. if (m_sprite.m_pImage != NULL)
  443. {
  444. rspReleaseResource(&g_resmgrGame, &m_sprite.m_pImage);
  445. }
  446. return sResult;
  447. }
  448. ////////////////////////////////////////////////////////////////////////////////
  449. // Stocks, rejuvenates, and places a CDude. The dude can be passed to this
  450. // function or allocated by this function.
  451. ////////////////////////////////////////////////////////////////////////////////
  452. short CWarp::WarpIn( // Returns 0 on success.
  453. CDude** ppdude, // In: CDude to 'warp in', *ppdude = NULL to create one.
  454. // Out: Newly created CDude, if no CDude passed in.
  455. short sOptions) // In: Options for 'warp in'.
  456. {
  457. short sRes = 0; // Assume success.
  458. // If we are on difficulty 11, multiply the dude's hit points by 10 so that
  459. // the player can have some chance of playing.
  460. if (m_pRealm->m_flags.sDifficulty == 11)
  461. {
  462. ms_stockpile.m_sHitPoints *= 10;
  463. if (ms_stockpile.m_sHitPoints < 0)
  464. ms_stockpile.m_sHitPoints = 30000;
  465. }
  466. // If we are playing multiplayer deathmatch, then set the hitpoints to the
  467. // default deathmatch amount so that it is easier to kill each other
  468. // and thus more fun.
  469. if (m_pRealm->m_flags.bMultiplayer == true && m_pRealm->m_flags.bCoopMode == false)
  470. {
  471. ms_stockpile.m_sHitPoints = WARP_DEATHMATCH_DEFAULT_HP;
  472. }
  473. // If no dude passed . . .
  474. if (*ppdude == NULL)
  475. {
  476. sRes = ConstructWithID(CDudeID, m_pRealm, (CThing**)ppdude);
  477. if (sRes == 0)
  478. {
  479. // Copy stockpile to new CDude.
  480. (*ppdude)->m_stockpile.Copy(&ms_stockpile);
  481. // Initialize.
  482. sRes = (*ppdude)->Init();
  483. if (sRes == 0)
  484. {
  485. // Start up.
  486. sRes = (*ppdude)->Startup();
  487. if (sRes == 0)
  488. {
  489. // Successfully created and setup CDude.
  490. }
  491. else
  492. {
  493. TRACE("WarpIn(): (*ppdude)->Startup() failed.\n");
  494. }
  495. }
  496. else
  497. {
  498. TRACE("WarpIn(): (*ppdude)->Init() failed.\n");
  499. }
  500. }
  501. else
  502. {
  503. TRACE("WarpIn(): Construct() failed for CDude.\n");
  504. }
  505. }
  506. else
  507. {
  508. switch (sOptions & StockPileMask)
  509. {
  510. case CopyStockPile:
  511. // Copy stockpile to CDude.
  512. (*ppdude)->m_stockpile.Copy(&ms_stockpile);
  513. break;
  514. case UnionStockPile:
  515. // Union stockpile with CDude.
  516. (*ppdude)->m_stockpile.Union(&ms_stockpile);
  517. break;
  518. case AddStockPile:
  519. // Add stockpile to CDude.
  520. (*ppdude)->m_stockpile.Add(&ms_stockpile);
  521. break;
  522. }
  523. }
  524. // If successful so far . . .
  525. if (sRes == 0)
  526. {
  527. // Truncate to amount he can carry.
  528. (*ppdude)->m_stockpile.Truncate();
  529. if ((*ppdude)->m_stockpile.m_sHitPoints > 0)
  530. {
  531. // Base original hitpoints upon new settings.
  532. (*ppdude)->m_sOrigHitPoints = (*ppdude)->m_stockpile.m_sHitPoints;
  533. }
  534. // Place.
  535. (*ppdude)->SetPosition(m_dX, m_dY, m_dZ);
  536. // Orient.
  537. (*ppdude)->m_dRot = m_sRotY;
  538. }
  539. return sRes;
  540. }
  541. ////////////////////////////////////////////////////////////////////////////////
  542. // Stocks, rejuvenates, and places a CDude at a random warp. The dude can
  543. // be passed to this function or allocated by this function.
  544. // (static)
  545. ////////////////////////////////////////////////////////////////////////////////
  546. short CWarp::WarpInAnywhere( // Returns 0 on success.
  547. CRealm* prealm, // In: Realm in which to choose CWarp.
  548. CDude** ppdude, // In: CDude to 'warp in', *ppdude = NULL to create one.
  549. // Out: Newly created CDude, if no CDude passed in.
  550. short sOptions) // In: Options for 'warp in'.
  551. {
  552. short sRes = 0; // Assume success.
  553. // Find a warp:
  554. short sNumWarps = prealm->m_asClassNumThings[CWarpID];
  555. if (sNumWarps > 0)
  556. {
  557. // Pick a random warp number.
  558. short sWarpNum = GetRand() % sNumWarps;
  559. // Find that warp.
  560. short i;
  561. CListNode<CThing>* pln = prealm->m_aclassHeads[CWarpID].m_pnNext;
  562. CListNode<CThing>* plnTail = &(prealm->m_aclassTails[CWarpID]);
  563. for (i = 0; i < sWarpNum && pln != plnTail; i++, pln = pln->m_pnNext)
  564. ;
  565. // If we found one . . .
  566. if (pln != plnTail)
  567. {
  568. ASSERT(pln->m_powner != NULL);
  569. // Do it.
  570. sRes = ((CWarp*)(pln->m_powner) )->WarpIn(ppdude, sOptions);
  571. }
  572. else
  573. {
  574. TRACE("WarpInAnywhere(): Failed to find chosen CWarp.\n");
  575. sRes = -2;
  576. }
  577. }
  578. else
  579. {
  580. TRACE("WarpInAnywhere(): Specified realm contains no CWarps.\n");
  581. sRes = -1;
  582. }
  583. return sRes;
  584. }
  585. ////////////////////////////////////////////////////////////////////////////////
  586. // Creates a warp based on a dude's settings.
  587. // (static)
  588. ////////////////////////////////////////////////////////////////////////////////
  589. short CWarp::CreateWarpFromDude( // Returns 0 on success.
  590. CRealm* prealm, // In: Realm in which to choose CWarp.
  591. CDude* pdude, // In: Dude to create warp from.
  592. CWarp** ppwarp, // Out: New warp on success.
  593. bool bCopyStockPile) // In: true to copy stockpile, false otherwise.
  594. {
  595. short sRes = 0; // Assume success.
  596. // Create warp . . .
  597. if (ConstructWithID(CWarpID, prealm, (CThing**)ppwarp) == 0)
  598. {
  599. // Copy dude's position and orientation.
  600. (*ppwarp)->m_dX = pdude->m_dX;
  601. (*ppwarp)->m_dY = pdude->m_dY;
  602. (*ppwarp)->m_dZ = pdude->m_dZ;
  603. (*ppwarp)->m_sRotY = pdude->m_dRot;
  604. if (bCopyStockPile == true)
  605. {
  606. // Copy dude's stockpile.
  607. // Note that this is static member of warp so this only needs to be for
  608. // one, but the question is which one.
  609. (*ppwarp)->ms_stockpile.Copy( &(pdude->m_stockpile) );
  610. }
  611. }
  612. else
  613. {
  614. TRACE("CreateWarpFromDude(): ConstructWithID() failed.\n");
  615. sRes = -1;
  616. }
  617. return sRes;
  618. }
  619. ////////////////////////////////////////////////////////////////////////////////
  620. // EOF
  621. ////////////////////////////////////////////////////////////////////////////////