realm.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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. // realm.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 01/22/97 JMI Added more LayerSpriteN, LayerOpaqueN, LayerAlphaN enums.
  23. //
  24. // 01/23/97 JMI Added macro enums LayerAttribMask and LayerAttribShift that
  25. // can be used on an attribute to get the sprite layer flags
  26. // indicated by the attribute. This value can be mapped through
  27. // the new static member ms_asAttribToLayer. Or, you can just
  28. // use the new inline static member CRealm::GetLayerFromAttrib().
  29. //
  30. // 01/27/97 JMI Now 4 bits are used from the attribute to determine the proper
  31. // layer for dudes.
  32. //
  33. // 01/28/97 JMI Added ms_apszLayerNames[] to access the names of the layers.
  34. //
  35. // 01/29/97 JMI Reordered Layers enum (fixed to the way Steve is doing it
  36. // (the opaque layers are now before equivalent alpha layers)).
  37. //
  38. // 02/02/97 JMI Added m_resmgr to load resources for each realm instance.
  39. //
  40. // 02/04/97 BRH Added ms_pCurrentNavNet and GetCurrentNavNet() functiion
  41. // to the realm. Previously the current NavNet was stored
  42. // in the editor which was OK for bouys but difficult to get
  43. // for other game objects.
  44. //
  45. // 02/13/97 JMI Added hood pointer to CRealm.
  46. //
  47. // 02/17/97 JMI Added set lists to CRealm. Now there is a list for each
  48. // set of Things. The sets are enumerated in CThing.
  49. //
  50. // 02/18/97 JMI Added GetNext*Collision() functions for a sphere and a
  51. // line segment.
  52. //
  53. // 02/19/97 JMI Removed stuff having to do with old collision sets and
  54. // added new Smashatorium for collision detection.
  55. //
  56. // 02/23/97 JMI Added m_iNext and m_bUpdating so RemoveThing() and
  57. // AddThing() can make the necessary adjustments to the next
  58. // iterator processed in the Update() loop.
  59. //
  60. // 03/13/97 JMI Upped FileVersion to 2 for new CDude stuff.
  61. //
  62. // 03/14/97 JMI Upped FileVersion to 3 for new CThing3d base class for
  63. // CCharacter.
  64. //
  65. // 03/18/97 JMI Upped FileVersion to 4 for CBand, which now loads info
  66. // for creating child items.
  67. //
  68. // 04/15/97 BRH Upped FileVersion to 5 for CMine, which now saves the
  69. // fuse time for the timed mines.
  70. //
  71. // 04/17/97 BRH Took timeout check out of Shutdown and Startup (it was
  72. // already commented out of Startup). The 1 second timeout
  73. // when calling shutdown caused large levels like parade
  74. // to abort before saving everything.
  75. //
  76. // 04/20/97 BRH Changed FileVersion to 6 for CBouy which now saves
  77. // a message.
  78. //
  79. // 04/21/97 JMI Added m_sNumSuspends and IsSuspended().
  80. //
  81. // 04/23/97 JMI Upped file version to 7 for new CDispenser parameter,
  82. // m_sMaxDispensees.
  83. //
  84. // 04/24/97 JMI Upped file version to 8 for newly saved CBarrel parameter,
  85. // m_dRot.
  86. //
  87. // 04/24/97 JMI Upped file version to 9 for new CDude parameter,
  88. // m_sNumShells.
  89. //
  90. // 04/25/97 JMI Upped file version to 10 for new CDude parameter,
  91. // m_sNumFuel.
  92. //
  93. // 04/29/97 JMI Changed GetHeight() to return 0 for the clipped case.
  94. //
  95. // 04/30/97 JMI Upped file version to 11 since CMine no longer saves its
  96. // type. The type (which is now determined by the class ID)
  97. // is saved by the base class CThing.
  98. //
  99. // 05/01/97 BRH Updated FileVersion to 12 since its May Day. (and because
  100. // on May Day I removed the message saving from the Bouy)
  101. //
  102. // 05/04/97 BRH Removed the STL version since all of the lists seem to
  103. // be working fine with the CListNode lists.
  104. //
  105. // 05/09/97 JRD Added an attribute map for trigger regions and a pylon ID table
  106. //
  107. // 05/13/97 JMI Upped file version to 13 for new CDude parameters,
  108. // m_sNumMines and m_sNumHeatseekers.
  109. //
  110. // 05/13/97 JMI Added IsPathClear() map functions to determine if a path
  111. // is clear of terrain that cannot be surmounted.
  112. //
  113. // 05/16/97 JMI Changed layer bits to be 8 bits (instead of 4). This
  114. // caused the REALM_ATTR_EFFECT_MASK to lose 4 bits and the
  115. // REALM_ATTR_LIGHT_BIT to move up 4 bits (0x0010 to 0x0100).
  116. // Also, the table ms_asAttribToLayer to be increased from
  117. // 16 entries to 256 entries.
  118. // Also, removed GetLayerFromAttrib() which was left over from
  119. // the pre RMultiGrid days.
  120. //
  121. // 05/19/97 BRH Changed file version to 14 to support thought balloon flag
  122. // for the CPerson.
  123. //
  124. // 05/26/97 BRH Added population variables to keep track of Numer of
  125. // people killed, number of people alive etc.
  126. //
  127. // 05/26/97 JMI Added IsEndOfLevelGoalMet() based on population vars added
  128. // above.
  129. // Also, added DrawStatus().
  130. // Also, increased file version to 15 so hood can save end of
  131. // level goal.
  132. //
  133. // 05/29/97 JMI Changed REALM_ATTR_LAYER_MASK to 0x7fff (was 0x00ff).
  134. // Moved REALM_ATTR_EFFECT_MASK and REALM_ATTR_LIGHT_BIT to
  135. // m_pTerrainMap (was in m_pAttrMap). This required the light
  136. // bit to go from 0x0100 to 0x0200 ('no walk' was already
  137. // using 0x0100 in m_pTerrainMap).
  138. // Changed all occurences of m_pAttrMap to m_pLayerMap.
  139. // Changed all occurences of m_pHeightMap to m_pTerrainMap.
  140. // Also, added CreateLayerMap() that creates the attribute
  141. // to layer map now that it is so huge.
  142. //
  143. // 06/05/97 JMI Upped FileVersion to 16 to accommodate new CStockPile,
  144. // m_stockpile, in CThing3d.
  145. //
  146. // 06/06/97 JMI Upped FileVersion to 17 to accommodate new CStockPile,
  147. // m_stockpile, in CPowerUp.
  148. //
  149. // 06/09/97 JMI Upped FileVersion to 18 to allow CItem3d to save its
  150. // rotation velocities.
  151. //
  152. // 06/09/97 JMI Upped FileVersion to 19 to allow CStockPile to save its
  153. // new weapon flags.
  154. //
  155. // 06/14/97 JMI Upped FileVersion to 20 to allow CPowerUp to be descended
  156. // from CThing3d (instead of CThing).
  157. //
  158. // 06/15/97 JMI Upped FileVersion to 21 to allow CStockPile to load and
  159. // save its new m_sKevlarLayers.
  160. //
  161. // 06/15/97 JMI Upped FileVersion to 22 to allow CStockPile to load and
  162. // save its new m_sBackpack.
  163. //
  164. // 06/17/97 MJR Moved some vars that were CPylon statics into the realm
  165. // so they could be instantiated on a realm-by-realm basis.
  166. //
  167. // 06/26/97 BRH Changed the population scoring to go down as people get
  168. // killed.
  169. //
  170. // 06/26/97 JMI Moved Map2DTo3D from reality.h to here.
  171. //
  172. // 06/28/97 JMI Moved attribute access functions from realm.h to realm.cpp
  173. // while we're getting all the conversion from 3D to the X/Z
  174. // plane stuff right. Compiling the entire project for any
  175. // tweak just doesn't sound very fun. Hopefully, though,
  176. // there'll won't be many tweaks.
  177. // Also, upped FileVersion to 23 so CHood can save its new
  178. // m_sRealmRotX param.
  179. //
  180. // 06/28/97 BRH Added score variables for separate hostiles and civilians
  181. // and changed the RegisterBirth, RegisterDeath functions
  182. // to change the values for each different type.
  183. //
  184. // 06/29/97 JMI Added version of ScaleZ() that takes shorts.
  185. // Changed both versions of ScaleZ() to MapZ3DtoY2D()
  186. // and added two versions of MapY2DtoZ3D().
  187. //
  188. // 06/30/97 JMI Upped file version to 24 so things can know whether to
  189. // convert their cheezy 3D realm coords to real 3D realm
  190. // coords.
  191. //
  192. // 06/30/97 JMI Added GetRealmWidth() and GetRealmHeight() to get the
  193. // realm's width and height on the X/Z plane.
  194. //
  195. // 06/30/97 JMI Added bCheckExtents parm to IsPathClear(). See proto for
  196. // details.
  197. //
  198. // 07/01/97 JMI Added MapY2DtoY3D() and MapY3DtoY2D().
  199. // Also, added GetHeightAndNoWalk().
  200. //
  201. // 07/01/97 BRH Changed the file version for the Sentry gun since it now
  202. // loads and saves the rotational velocity parameter.
  203. //
  204. // 07/01/97 JMI Changed the file version for the Hood so it can load and
  205. // save whether to use the attribute map heights with or
  206. // without scaling based on the view angle.
  207. // Also, added function to scale heights that checks the
  208. // hood value.
  209. //
  210. // 07/04/97 BRH Added timer for Score to display and CGoalTimer to
  211. // manipulate.
  212. //
  213. // 07/07/97 BRH Added scoring modes to the realm so that they can more
  214. // easily be set by options at the beginning of the game,
  215. // changed by CThings, and read by the scoring module.
  216. // Changed the file version for the realm so that it can
  217. // save the new properties.
  218. //
  219. // 07/09/97 JMI Added function to get the full path for a 2D resource
  220. // based on the current hood setting for 'Use top-view 2Ds'.
  221. // Also, upped file version the hood can save this setting.
  222. //
  223. // 07/09/97 BRH Increased the file version to add additional data to
  224. // the realm file.
  225. //
  226. // 07/09/97 JMI Moved m_s2dResPathIndex from CHood to CRealm b/c of order
  227. // issues when loading. Also, increased the file version so
  228. // CHood can not load/save this data and CRealm can.
  229. //
  230. // 07/10/97 BRH Added m_sFlagsCaptured to keep track of the flag count
  231. // for capture the flag and checkpoint games. Also moved
  232. // IsEndOfLevelGoalMet to the cpp file and added cases
  233. // for the different scoring types.
  234. //
  235. // 07/12/97 JMI Added m_bMultiplayer, which signifies whether this is
  236. // a multi or single player game.
  237. // Also, added Init(). See proto for details.
  238. //
  239. // 07/14/97 BRH Added m_sFlagbaseCaptured for the levels were the flags
  240. // must be returned to their proper base in order to count.
  241. //
  242. // 07/15/97 BRH Added a parameter to IsEndOfLevelGoalMet which now takes
  243. // a bool telling whether the end of level key has been
  244. // hit, indicating that the user wants to go on if the
  245. // standard play mode goal has been fulfilled.
  246. //
  247. // 07/18/97 JMI Upped the file version so CSoundThing can load its volume
  248. // half life.
  249. //
  250. // 07/19/97 JMI Upped the file version so CWarp can save the initial
  251. // rotation for the warped in CDude.
  252. //
  253. // 07/23/97 JMI Changed file version so CStockPile can save new
  254. // m_sNapalmLauncher member.
  255. //
  256. // 07/24/97 MJR Changed file version so CSoundThing can save more members.
  257. //
  258. // 07/27/97 BRH Added a variable to save what the score timer was
  259. // initially set to in order to determine the time
  260. // elapsed for high score purposes.
  261. //
  262. // 07/28/97 JMI Upped file version to 35 so CDispenser could save an
  263. // additional logic parm.
  264. //
  265. // 07/30/97 BRH Added a string to hold the name of the realm which
  266. // will be used for storing high scores for a particular
  267. // realm.
  268. //
  269. // 07/30/97 JMI Upped file version so CStockPile can save/load new member.
  270. //
  271. // 07/31/97 BRH Changed file version so band member can save dest bouy.
  272. //
  273. // 08/01/97 JMI Upped file version to 38 so CSoundThing can save new
  274. // members.
  275. //
  276. // 08/03/07 JRD Upped the verion to 39 to save 3d scale. Note that this is
  277. // the FINAL 3x version possible. Soon we will move to 40 and
  278. // 32 bit code.
  279. //
  280. // 08/04/97 JMI Upped file version to 40 so CSoundThing can save
  281. // m_sAmbient.
  282. //
  283. // 08/05/97 JMI Added CRealm::Flags struct and an instance in CRealm,
  284. // m_flags.
  285. //
  286. // 08/06/97 JMI Upped file version to 41 so CStockPile can save/load new
  287. // member.
  288. //
  289. // 08/07/97 JMI Upped file version to 42 so CItem3d can save/load new
  290. // members.
  291. //
  292. // 08/08/97 BRH Upped file version to 43 to save extra special bouy data
  293. // in the Doofus.
  294. //
  295. // 08/09/97 JMI Added progress callback and components. There is now a
  296. // callback member that is called (when non-zero) that passes
  297. // the number of items processed so far and the total number of
  298. // items to process. The return value of the callback dictates
  299. // whether to proceed with the operation. Although, this is
  300. // meant to be generic so we can use it for any type of
  301. // process, it is currently only used by Load() and Save().
  302. //
  303. // 08/10/97 JRD Upped File Version to 44 to save shadow info.
  304. //
  305. // 08/11/97 BRH Upped File Version to 45 to save flag color info.
  306. //
  307. // 08/15/97 BRH Upped File version to save barrel special flag.
  308. //
  309. // 08/20/97 JMI Made ms_apsz2dResPaths[] a static class member (was just
  310. // defined at realm.cpp file scope) and added enum macro for
  311. // number of elements.
  312. //
  313. // 11/21/97 JMI Added bCoopMode flag indicating whether we're in cooperative
  314. // or deathmatch mode when in multiplayer.
  315. //
  316. // 12/02/97 JMI Increased FileVersion to 47 so CDemon could save its new
  317. // m_sSoundBank.
  318. //
  319. ////////////////////////////////////////////////////////////////////////////////
  320. #ifndef REALM_H
  321. #define REALM_H
  322. #include "RSPiX.h"
  323. #include "scene.h"
  324. #include "thing.h"
  325. #include "hood.h"
  326. #include "yatime.h"
  327. #include "IdBank.h"
  328. #include "smash.h"
  329. #include "trigger.h"
  330. ///////////////////////////////////////////////////////////////////////////////
  331. // If PATHS_IN_INCLUDES macro is defined, we can utilize relative
  332. // paths to a header file. In this case we generally go off of our
  333. // RSPiX root directory. System.h MUST be included before this macro
  334. // is evaluated. System.h is the header that, based on the current
  335. // platform (or more so in this case on the compiler), defines
  336. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  337. // instead.
  338. ///////////////////////////////////////////////////////////////////////////////
  339. #ifdef PATHS_IN_INCLUDES
  340. #include "WishPiX/ResourceManager/resmgr.h"
  341. #include "ORANGE/MultiGrid/MultiGrid.h"
  342. #include "ORANGE/MultiGrid/MultiGridIndirect.h"
  343. #else
  344. #include "resmgr.h"
  345. #include "multigrid.h"
  346. #include "multigridindirect.h"
  347. #endif
  348. // The overall "universe" in which a game takes place is represented by one or
  349. // more CRealm's. A realm is basically a collection of objects plus a handfull
  350. // of functions for managing those objects. These functions include loading,
  351. // saving, suspending, resuming, updating, and rendering the realm.
  352. //
  353. // All of the objects within a realm must be derived from CThing.
  354. // I'm thinking that the way objects know what realm they belong to is that
  355. // we pass a pointer to the realm to the object's constructor. All objects
  356. // would need to define such a constructor or some other function that
  357. // indirectly constructs the object. Actually, I don't think objects need
  358. // to jump through hoops anymore to stay alive because there would now be
  359. // a simplified mechanism by which an object can move from realm to realm!
  360. // If that's the case, then we might be able to heavily simplify the current
  361. // object model.
  362. //
  363. // Is there any way around the requirement that everything derive from a single
  364. // object? Since we're going to pass the constructor (or whatever) a pointer
  365. // to the realm, couldn't that object register various functions with the
  366. // realm, which would essentially be our own version of virtual functions?
  367. // We're already doing this when it comes to static functions since those can't
  368. // be virtual in C++, so why not extend it to all functions? The main benefit
  369. // of getting away from a single base class is that it allows more flexibility
  370. // on the part of the implimentation of individual objects, and decouples the
  371. // objects, which always seems like a good idea. The negative side is that it
  372. // takes a bit more effort on the part of the ll the objects to comply with the
  373. // rules.
  374. //
  375. // A simple game might consist of a number of realm files that are loaded one
  376. // after another as the player "completes" each realm. In this case, the game
  377. // could utilize a single realm object since only one realm exists at any time.
  378. //
  379. // A more complex game might allow the player to move back and forth between
  380. // certain realms. This could still be handled , and might want those realms to
  381. //
  382. // When we talk about loading and saving a realm or an individual thing, there's
  383. // really two issues. One is saving and loading the actual data related to
  384. // that thing, and the other involves the resources. The first part is basically
  385. // unvavaoidable and fast -- it usually doesn't involve much data. It's the
  386. // second part, the resources, that may take a significant amount of time.
  387. // Under the new realm-based scheme, I'm thinking that objects wouldn't free
  388. // their resources until their were destroyed. If the realm is cleared or
  389. // destroyed, then the objects in it are destroyed. Very simple, without any
  390. // of the other complexities that the old model had.
  391. //
  392. // To move objects from one realm to another, we could create a temporary
  393. // realm, move the objects into that, then destroy the old realm, then create
  394. // the new one, then transfer the new objects into it. Or maybe we just create
  395. // the new realm but don't load it, transfer the objects into it, then destroy
  396. // the old one, then load the new one. Either way, it works pretty well.
  397. //
  398. // Not sure yet how to transfer objects between realms. I'm thinking it's best
  399. // to call the object and let it handle it, since it may want/need to transfer
  400. // other related objects, or do things prior or after transferring, and so on.
  401. //
  402. // I'm also not sure whether we should offer all objects the chance to transfer
  403. // or just call those we know need to transfer (meaning at the game level).
  404. // I'm leaning towards just calling specific objects, because the other way
  405. // we would need to convey to the objects the reason for the transfer, which
  406. // seems like it will be kind of vague. But it would be nicer in the sense that
  407. // we wouldn't have to be carefull to call the correct objects. This doesn't
  408. // need to be decided just yet.
  409. // Masks and bits for m_pTerrainMap:
  410. // The height map contains the height, the 'no walk', and the light attributes.
  411. #define REALM_ATTR_HEIGHT_MASK 0x00ff
  412. #define REALM_ATTR_FLOOR_MASK 0xff00
  413. #define REALM_ATTR_EFFECT_MASK 0xff00
  414. #define REALM_ATTR_LIGHT_BIT 0x0200
  415. #define REALM_ATTR_NOT_WALKABLE 0x0100
  416. // Masks and bits for m_pLayerMap:
  417. // The attribute map contains only the layer bits.
  418. #define REALM_ATTR_LAYER_MASK 0x7fff
  419. #define REALM_NONSTL 1
  420. class CNavigationNet;
  421. class CRealm
  422. {
  423. friend class CNavigationNet;
  424. //---------------------------------------------------------------------------
  425. // Types, enums, etc.
  426. //---------------------------------------------------------------------------
  427. public:
  428. // Miscellaneous enums
  429. enum
  430. {
  431. FileID = 0x44434241, // File ID
  432. FileVersion = 49, // File version
  433. Num2dPaths = 3 // Number of 2D res paths
  434. };
  435. enum // Macros.
  436. {
  437. LayerAttribMask = REALM_ATTR_LAYER_MASK // Mask against attribute to
  438. // get appropriate sprite
  439. // layer.
  440. };
  441. // Layer enums
  442. typedef enum
  443. {
  444. // First entry must start at 0!
  445. LayerBg = 0,
  446. LayerSprite1,
  447. LayerOpaque1,
  448. LayerSprite2,
  449. LayerAlpha1,
  450. LayerSprite3,
  451. LayerOpaque2,
  452. LayerSprite4,
  453. LayerAlpha2,
  454. LayerSprite5,
  455. LayerOpaque3,
  456. LayerSprite6,
  457. LayerAlpha3,
  458. LayerSprite7,
  459. LayerOpaque4,
  460. LayerSprite8,
  461. LayerAlpha4,
  462. LayerSprite9,
  463. LayerOpaque5,
  464. LayerSprite10,
  465. LayerAlpha5,
  466. LayerSprite11,
  467. LayerOpaque6,
  468. LayerSprite12,
  469. LayerAlpha6,
  470. LayerSprite13,
  471. LayerOpaque7,
  472. LayerSprite14,
  473. LayerAlpha7,
  474. LayerSprite15,
  475. LayerOpaque8,
  476. LayerSprite16,
  477. // This must be the last entry so it gets set to the total number of layers
  478. TotalLayers
  479. } Layer;
  480. // Scoring modes
  481. typedef unsigned short ScoringMode;
  482. typedef enum
  483. {
  484. Standard = 0, // Standard single player showing population, hostiles, kills and kill %
  485. Timed, // Score as many kills as possible in set amount of time
  486. TimedGoal, // Kill the set number of enemies before time expires
  487. TimedFlag, // Capture the flag before time expires
  488. Goal, // Kill the set number of enemies as quickly as possible
  489. CaptureFlag, // Capture the flag - no time limit
  490. Checkpoint, // Grab all of the flags before time runs out, each flag gives bonus time
  491. MPTimed, // Multiplayer Timed - Score the most frags in the given amount of time
  492. MPFrag, // First person to Frag Limit wins
  493. MPLastMan, // Last man standing wins - scoring shows who's dead & alive
  494. MPCaptureFlag, // Capture your flag and return to base.
  495. MPTimedFlag, // Capture your flag before time runs out
  496. MPTimedFrag, // Time limit and frag limit for MP games
  497. MPLastManFrag, // No rejuvination with frag limit
  498. MPLastManTimed, // No rejuvination with time limit
  499. MPLastManTimedFrag,//No rejuvination with time and frag limit
  500. TotalScoringModes
  501. };
  502. // Realm flags.
  503. typedef struct
  504. {
  505. bool bMultiplayer; // true, if multiplayer game; false, if
  506. // single player game.
  507. // Note that this has nothing to do with
  508. // whether the level was designed or in-
  509. // tended as a single or multiplayer
  510. // level.
  511. bool bCoopMode; // true, if in cooperative mode; false, if
  512. // in deathmatch mode. N/A if bMultiplayer
  513. // is false.
  514. bool bEditing; // In editor mode. That is, in the mode
  515. // where one can create new objects, modify,
  516. // move them, etc.
  517. bool bEditPlay; // Playing a realm from within the editor.
  518. short sDifficulty; // Difficulty level.
  519. } Flags;
  520. // Callback called by various processes in Realm (such as Load and Save)
  521. // to indicate current progress and allow a hook that can abort the process.
  522. typedef bool (*ProgressCall)( // Returns true to continue; false to
  523. // abort operation.
  524. short sLastItemProcessed, // In: Number of items processed so far.
  525. short sTotalItemsToProcess); // In: Total items to process.
  526. //---------------------------------------------------------------------------
  527. // Static variables
  528. //---------------------------------------------------------------------------
  529. private:
  530. static short ms_sFileCount;
  531. //---------------------------------------------------------------------------
  532. // Public static variables
  533. //---------------------------------------------------------------------------
  534. public:
  535. // Maps the layer portion of an attribute to the appropriate
  536. // layer.
  537. static short ms_asAttribToLayer[LayerAttribMask + 1];
  538. // Names of layers. Use Layer enum values to index.
  539. static char* ms_apszLayerNames[TotalLayers];
  540. // 2D resource paths.
  541. static char* ms_apsz2dResPaths[Num2dPaths];
  542. //---------------------------------------------------------------------------
  543. // Non-static variables
  544. //---------------------------------------------------------------------------
  545. public:
  546. CListNode<CThing>* m_pNext;
  547. // This flag indicates (by true) that we are in the Update() loop.
  548. // It is false at all other times.
  549. bool m_bUpdating;
  550. // The scene, which is basically the visual representation of the realm
  551. CScene m_scene;
  552. // Head and tail pointers for all CThings.
  553. CListNode<CThing> m_everythingHead;
  554. CListNode<CThing> m_everythingTail;
  555. short m_sNumThings;
  556. // Array of Head and Tail pointers to the various lists of derived CThings
  557. // in the game. The array is indexed by the class ID, and each list contains
  558. // only objects of that type.
  559. CListNode<CThing> m_aclassHeads[CThing::TotalIDs];
  560. CListNode<CThing> m_aclassTails[CThing::TotalIDs];
  561. short m_asClassNumThings[CThing::TotalIDs];
  562. // Pointer to the attribute map. The CHood is expected to set these
  563. // as soon as it can so that other obects can use it. This is really
  564. // just a shortcut to the attribute map since so many objects need to use
  565. // it so often.
  566. // The CHood should also clear these when the map is destroyed.
  567. RMultiGrid* m_pTerrainMap;
  568. RMultiGrid* m_pLayerMap;
  569. RMultiGridIndirect* m_pTriggerMap; // This is a shadow reference
  570. CTrigger* m_pTriggerMapHolder; // This points to the CThing holding the actual map
  571. // Pointer to the CHood. The CHood is expected to set this as soon as it
  572. // is allocated so that other objects can use this to access it. Since
  573. // there is only one and it is often access every iteration, this'll make
  574. // it a bit quicker.
  575. // The CHood should also clear this when it is destroyed.
  576. CHood* m_phood;
  577. // Time object, which manages game time
  578. CTime m_time;
  579. // Bank of IDs so each item in Realm can be uniquely identified.
  580. CIdBank m_idbank;
  581. // Resource manager. All resources loaded by CThings in this realm should
  582. // be loaded through this.
  583. // The base path and/or SAK, will be set via the CHood.
  584. RResMgr m_resmgr;
  585. // Smashitorium. Used for collision detection. Add your CSmash to this
  586. // CSmashitorium to be included in collision detection for this CRealm.
  587. CSmashatorium m_smashatorium;
  588. // Number of Suspend() calls that have occurred without corresponding
  589. // Resume() calls.
  590. // If 0, we are not suspended.
  591. short m_sNumSuspends;
  592. // Pylon stuff
  593. USHORT m_asPylonUIDs[256]; // Complete Cheese!
  594. short m_sNumPylons;
  595. UCHAR m_ucNextPylonID;
  596. // Path index for 2D assets.
  597. short m_s2dResPathIndex;
  598. // Process progress callback. See ProgressCall typedef for details.
  599. ProgressCall m_fnProgress;
  600. protected:
  601. CNavigationNet* m_pCurrentNavNet;
  602. public:
  603. // Population variables to keep track of those alive and dead.
  604. short m_sPopulationBirths; // Number of enemies & victims born in this level
  605. short m_sPopulation; // Current population
  606. short m_sPopulationDeaths; // Number of enemies & victims killed in this level
  607. short m_sHostileBirths; // Number of hostiles that have been born in this level
  608. short m_sHostileKills; // Number of hostiles that have been killed
  609. short m_sHostiles; // Number of hostiles remaining alive
  610. // Timer values for different scoring methods.
  611. bool m_bScoreTimerCountsUp; // Which direction the timer runs, up or down
  612. long m_lScoreInitialTime; // What timer was initially set to.
  613. long m_lScoreTimeDisplay; // Time in ms that is used for the Score display
  614. // (score converts it to minutes:seconds)
  615. long m_lPrevTime; // Previous read of the clock
  616. long m_lElapsedTime;
  617. long m_lThisTime;
  618. long m_lLastStatusDrawTime; // Last time the status was drawn.
  619. // Goals for different modes of play.
  620. ScoringMode m_ScoringMode; // Scoring mode that score module uses
  621. // to determine what to display.
  622. double m_dKillsPercentGoal; // Kill Percent needed to end the level.
  623. short m_sKillsGoal; // Kill number needed to end the level
  624. short m_sFlagsGoal; // Number of flags needed to end the level
  625. short m_sFlagsCaptured; // Number of flags captured.
  626. short m_sFlagbaseCaptured; // Number of flags returned to proper base
  627. RString m_rsRealmString; // Name of realm (currently full path of file)
  628. Flags m_flags; // Realm flags.
  629. bool m_bPressedEndLevelKey; // True if the player pressed the key or controller button bound to "End Map"
  630. // Different from the hardcoded F1 key
  631. //---------------------------------------------------------------------------
  632. // Non-static functions
  633. //---------------------------------------------------------------------------
  634. public:
  635. // Default (and only) constructor
  636. CRealm();
  637. // Destructor
  638. ~CRealm();
  639. // Register a birth for this realm - Each enemy and victim should call
  640. // this when they are created.
  641. void RegisterBirth(bool bCivilian = false)
  642. {
  643. m_sPopulationBirths++;
  644. m_sPopulation++;
  645. if (!bCivilian)
  646. {
  647. m_sHostiles++;
  648. m_sHostileBirths++;
  649. }
  650. };
  651. // Register a death for this realm
  652. void RegisterDeath(bool bCivilian = false, bool bPlayerKill = true)
  653. {
  654. // Added bPlayerKill to make it easier to get the Boondock Saints achievement.
  655. if (StatsAreAllowed && bPlayerKill)
  656. {
  657. // need to unlock achievement in here, too, since this fires when starting a level without you killing anything.
  658. UnlockAchievement(ACHIEVEMENT_KILL_FIRST_VICTIM);
  659. Stat_TotalKilled++;
  660. if (Stat_TotalKilled >= 100)
  661. UnlockAchievement(ACHIEVEMENT_KILL_100);
  662. if (Stat_TotalKilled >= 1000)
  663. UnlockAchievement(ACHIEVEMENT_KILL_1000);
  664. if (Stat_TotalKilled >= 10000)
  665. UnlockAchievement(ACHIEVEMENT_KILL_10000);
  666. if (!bCivilian)
  667. Stat_KilledHostiles++;
  668. else
  669. {
  670. Flag_Achievements &= ~FLAG_KILLED_ONLY_HOSTILES;
  671. Stat_KilledCivilians++;
  672. }
  673. }
  674. m_sPopulationDeaths++;
  675. // Added this to make the population display go down.
  676. m_sPopulation--;
  677. if (!bCivilian)
  678. {
  679. m_sHostileKills++;
  680. m_sHostiles--;
  681. }
  682. }
  683. // Check if kills percent goal has been met.
  684. bool IsEndOfLevelGoalMet(bool bEndLevelKey); // Returns true, if end of level goal
  685. // has been met.
  686. /*
  687. // Add thing to realm
  688. void AddThing(
  689. CThing* pThing, // In: Pointer to thing to be added
  690. CThing::ClassIDType id, // In: Thing's class ID
  691. #if _MSC_VER >= 1020
  692. CThing::Things::const_iterator* piterEvery, // Out: Iterator into everything container
  693. CThing::Things::const_iterator* piterClass) // Out: Iterator into class container
  694. #else
  695. CThing::Things::iterator* piterEvery, // Out: Iterator into everything container
  696. CThing::Things::iterator* piterClass) // Out: Iterator into class container
  697. #endif
  698. {
  699. *piterEvery = m_everything.insert(m_everything.end(), pThing);
  700. *piterClass = m_apthings[id]->insert(m_apthings[id]->end(), pThing);
  701. // If in the update loop . . .
  702. if (m_bUpdating == true)
  703. {
  704. // If the next is the end . . .
  705. if (m_iNext == m_everything.end())
  706. {
  707. // Get the added thing.
  708. m_iNext = *piterEvery;
  709. }
  710. }
  711. }
  712. */
  713. // Add thing to realm
  714. void AddThing(
  715. CThing* pThing,
  716. CThing::ClassIDType id)
  717. {
  718. pThing->m_everything.InsertBefore(&m_everythingTail);
  719. pThing->m_nodeClass.InsertBefore(&(m_aclassTails[id]));
  720. m_sNumThings++;
  721. m_asClassNumThings[id]++;
  722. // If in the update loop...
  723. if (m_bUpdating == true)
  724. {
  725. // If the next is the end...
  726. if (m_pNext == &m_everythingTail)
  727. {
  728. // Set next to the newly added thing
  729. m_pNext = &(pThing->m_everything);
  730. }
  731. }
  732. }
  733. // Remove thing from realm
  734. /*
  735. void RemoveThing(
  736. CThing::ClassIDType id, // In: Thing's class ID
  737. #if _MSC_VER >= 1020
  738. CThing::Things::const_iterator iterEvery, // In: Thing's iterator into everything container
  739. CThing::Things::const_iterator iterClass) // In: Thing's iterator into class container
  740. #else
  741. CThing::Things::iterator iterEvery, // In: Thing's iterator into everything container
  742. CThing::Things::iterator iterClass) // In: Thing's iterator into class container
  743. #endif
  744. {
  745. // If in the update loop . . .
  746. if (m_bUpdating == true)
  747. {
  748. // If the next is thing being removed . . .
  749. if (m_iNext == iterEvery)
  750. {
  751. // This is safe b/c the end is always available and will
  752. // never be removed.
  753. m_iNext++;
  754. }
  755. }
  756. m_everything.erase(iterEvery);
  757. m_apthings[id]->erase(iterClass);
  758. }
  759. */
  760. // Remove thing from realm
  761. void RemoveThing(
  762. CThing* pThing)
  763. {
  764. // If in the update loop...
  765. if (m_bUpdating == true)
  766. {
  767. // If the next is the thing being removed...
  768. if (m_pNext == &(pThing->m_everything))
  769. {
  770. // This is save b/c the end is always available and will never be removed
  771. m_pNext = pThing->m_everything.m_pnNext;
  772. }
  773. }
  774. pThing->m_everything.Remove();
  775. pThing->m_nodeClass.Remove();
  776. m_sNumThings--;
  777. m_asClassNumThings[pThing->GetClassID()]--;
  778. }
  779. // Clear
  780. void Clear(void);
  781. // Determine if specified file exists according to same rules used by Load()
  782. static
  783. bool DoesFileExist( // Returns true if file exists, false otherwise
  784. const char* pszFileName); // In: Name of file
  785. // Open the specified realm file (primarily for internal use, but who knows, it might be usefull)
  786. static
  787. short Open( // Returns 0 if successfull, non-zero otherwise
  788. const char* pszFileName, // In: Name of file to load from
  789. RFile* pfile); // I/O: RFile to be used
  790. // Load
  791. short Load( // Returns 0 if successfull, non-zero otherwise
  792. const char* pszFileName, // In: Name of file to load from
  793. bool bEditMode); // In: Use true for edit mode, false otherwise
  794. // Load
  795. short Load( // Returns 0 if successfull, non-zero otherwise
  796. RFile* pFile, // In: File to load from
  797. bool bEditMode); // In: Use true for edit mode, false otherwise
  798. // Save
  799. short Save( // Returns 0 if successfull, non-zero otherwise
  800. const char* pszFileName); // In: Name of file to save to
  801. // Save
  802. short Save( // Returns 0 if successfull, non-zero otherwise
  803. RFile* pFile); // In: File to save to
  804. // Startup
  805. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  806. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  807. // Suspend
  808. void Suspend(void);
  809. // Resume
  810. void Resume(void);
  811. bool IsSuspended(void) // Returns true, if suspended; false, otherwise.
  812. { return (m_sNumSuspends == 0) ? false : true; }
  813. // Update
  814. void Update(void);
  815. // Render
  816. void Render(void);
  817. // Edit-mode update
  818. void EditUpdate(void);
  819. // Edit-mode render
  820. void EditRender(void);
  821. // Edit-Modify dialog - set properties for the realm like scoring & play mode.
  822. void EditModify(void);
  823. // Give the current network for this realm
  824. CNavigationNet* GetCurrentNavNet(void)
  825. { return m_pCurrentNavNet; }
  826. short GetHeight(short sX, short sZ);
  827. short GetHeightAndNoWalk( // Returns height at new location.
  828. short sX, // In: X position to check on map.
  829. short sZ, // In: Z position to check on map.
  830. bool* pbNoWalk); // Out: true, if 'no walk'.
  831. short GetTerrainAttributes(short sX, short sZ);
  832. short GetFloorAttribute(short sX, short sZ);
  833. short GetFloorMapValue(short sX, short sZ, short sMask = 0x007f);
  834. short GetLayer(short sX, short sZ);
  835. short GetEffectAttribute(short sX, short sZ);
  836. short GetEffectMapValue(short sX, short sZ);
  837. // Determine if a path is clear of terrain.
  838. bool IsPathClear( // Returns true, if the entire path is clear.
  839. // Returns false, if only a portion of the path is clear.
  840. // (see *psX, *psY, *psZ).
  841. short sX, // In: Starting X.
  842. short sY, // In: Starting Y.
  843. short sZ, // In: Starting Z.
  844. short sRotY, // In: Rotation around y axis (direction on X/Z plane).
  845. double dCrawlRate, // In: Rate at which to scan ('crawl') path in pixels per
  846. // iteration.
  847. // NOTE: Values less than 1.0 are inefficient.
  848. // NOTE: We scan terrain using GetHeight()
  849. // at only one pixel.
  850. // NOTE: We could change this to a speed in pixels per second
  851. // where we'd assume a certain frame rate.
  852. short sDistanceXZ, // In: Distance on X/Z plane.
  853. short sVerticalTolerance = 0, // In: Max traverser can step up.
  854. short* psX = NULL, // Out: If not NULL, last clear point on path.
  855. short* psY = NULL, // Out: If not NULL, last clear point on path.
  856. short* psZ = NULL, // Out: If not NULL, last clear point on path.
  857. bool bCheckExtents = true); // In: If true, will consider the edge of the realm a path
  858. // inhibitor. If false, reaching the edge of the realm
  859. // indicates a clear path.
  860. // Determine if a path is clear of terrain.
  861. bool IsPathClear( // Returns true, if the entire path is clear.
  862. // Returns false, if only a portion of the path is clear.
  863. // (see *psX, *psY, *psZ).
  864. short sX, // In: Starting X.
  865. short sY, // In: Starting Y.
  866. short sZ, // In: Starting Z.
  867. double dCrawlRate, // In: Rate at which to scan ('crawl') path in pixels per
  868. // iteration.
  869. // NOTE: Values less than 1.0 are inefficient.
  870. // NOTE: We scan terrain using GetHeight()
  871. // at only one pixel.
  872. // NOTE: We could change this to a speed in pixels per second
  873. // where we'd assume a certain frame rate.
  874. short sDstX, // In: Destination X.
  875. short sDstZ, // In: Destination Z.
  876. short sVerticalTolerance = 0, // In: Max traverser can step up.
  877. short* psX = NULL, // Out: If not NULL, last clear point on path.
  878. short* psY = NULL, // Out: If not NULL, last clear point on path.
  879. short* psZ = NULL, // Out: If not NULL, last clear point on path.
  880. bool bCheckExtents = true); // In: If true, will consider the edge of the realm a path
  881. // inhibitor. If false, reaching the edge of the realm
  882. // indicates a clear path.
  883. // Gives this realm an opportunity and drawing surface to display its
  884. // current status.
  885. void DrawStatus( // Returns nothing.
  886. RImage* pim, // In: Image in which to draw status.
  887. RRect* prc); // In: Rectangle in which to draw status. Clips to.
  888. // Maps a 3D coordinate onto the viewing plane.
  889. void Map3Dto2D( // Returns nothing.
  890. short sX, // In.
  891. short sY, // In.
  892. short sZ, // In.
  893. short* psX, // Out.
  894. short* psY); // Out.
  895. // Maps a 3D coordinate onto the viewing plane.
  896. void Map3Dto2D( // Returns nothing.
  897. double dX, // In.
  898. double dY, // In.
  899. double dZ, // In.
  900. double* pdX, // Out.
  901. double* pdY); // Out.
  902. // Scales a Z coordinate onto the viewing plane using the
  903. // view angle (~angle of projection).
  904. void MapZ3DtoY2D( // Returns nothing.
  905. double dZIn, // In.
  906. double* pdYOut); // Out.
  907. // Scales a Z coordinate onto the viewing plane using the
  908. // view angle (~angle of projection).
  909. void MapZ3DtoY2D( // Returns nothing.
  910. short sZIn, // In.
  911. short* psYOut); // Out.
  912. // Scales a Y coordinate from the viewing plane using the
  913. // view angle (~angle of projection).
  914. void MapY2DtoZ3D( // Returns nothing.
  915. double dYIn, // In.
  916. double* pdZOut); // Out.
  917. // Scales a Y coordinate from the viewing plane using the
  918. // view angle (~angle of projection).
  919. void MapY2DtoZ3D( // Returns nothing.
  920. short sYIn, // In.
  921. short* psZOut); // Out.
  922. // Scales a Y coordinate onto the viewing plane using the
  923. // view angle (~angle of projection).
  924. void MapY3DtoY2D( // Returns nothing.
  925. double dYIn, // In.
  926. double* pdYOut); // Out.
  927. // Scales a Y coordinate onto the viewing plane using the
  928. // view angle (~angle of projection).
  929. void MapY3DtoY2D( // Returns nothing.
  930. short sYIn, // In.
  931. short* psYOut); // Out.
  932. // Scales a Y coordinate from the viewing plane using the
  933. // view angle (~angle of projection).
  934. void MapY2DtoY3D( // Returns nothing.
  935. double dYIn, // In.
  936. double* pdYOut); // Out.
  937. // Scales a Y coordinate from the viewing plane using the
  938. // view angle (~angle of projection).
  939. void MapY2DtoY3D( // Returns nothing.
  940. short sYIn, // In.
  941. short* psYOut); // Out.
  942. // If enabled, scales the specified height based on the view angle.
  943. void MapAttribHeight( // Returns nothing.
  944. short sHIn, // In.
  945. short* psHOut); // Out.
  946. // Get dimension of realm on X/Z plane.
  947. short GetRealmWidth(void) // Returns width of realm's X/Z plane.
  948. {
  949. short sRealmW;
  950. MapY2DtoZ3D(m_phood->GetWidth(), &sRealmW);
  951. return sRealmW;
  952. }
  953. // Get dimension of realm on X/Z plane.
  954. short GetRealmHeight(void) // Returns height of realm's X/Z plane.
  955. {
  956. short sRealmH;
  957. MapY2DtoZ3D(m_phood->GetHeight(), &sRealmH);
  958. return sRealmH;
  959. }
  960. // Makes a 2D path based on the current hood setting for 'Use top-view 2Ds'.
  961. // Note that this function returns to you a ptr to its one and only static
  962. // string of length RSP_MAX_PATH. Do not write to this string and do not
  963. // store this string. It is best to just use this call to pass a string to
  964. // a function that will just use it right away (i.e., will not store it or
  965. // modify it).
  966. const char* Make2dResPath( // Returns a ptr to an internal static buffer
  967. // containing the passed string, pszResName,
  968. // preceded by the appropriate directory based
  969. // on the current hood settings.
  970. const char* pszResName); // In: Resource name to prepend path to.
  971. //---------------------------------------------------------------------------
  972. // Protected (Internal) functions
  973. //---------------------------------------------------------------------------
  974. protected:
  975. // This will set all values that are to be set on construction and during
  976. // a Clear(). This is called by CRealm() and Clear(). This gives us one
  977. // spot to implement these, rather than having to do it twice.
  978. void Init(void); // Returns nothing. Cannot fail.
  979. //---------------------------------------------------------------------------
  980. // Public static functions
  981. //---------------------------------------------------------------------------
  982. public:
  983. static short GetLayerViaAttrib( // Returns the sprite layer indicated by
  984. // the specified attribute.
  985. U16 u16Attrib)
  986. {
  987. return ms_asAttribToLayer[u16Attrib & REALM_ATTR_LAYER_MASK];
  988. }
  989. // Creates the layer map, if it has not already been done.
  990. // Now that the layer map needs to be 32K of uncompressable data, we create it
  991. // at run time.
  992. static void CreateLayerMap(void);
  993. //---------------------------------------------------------------------------
  994. // Protected static functions
  995. //---------------------------------------------------------------------------
  996. protected:
  997. };
  998. #endif // REALM_H
  999. ////////////////////////////////////////////////////////////////////////////////
  1000. // EOF
  1001. ////////////////////////////////////////////////////////////////////////////////