carnage.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. //***************************************************************************
  2. //
  3. // Carnage.h -- Base class for any and all damage-related effects that
  4. // dynamically appear and disappear with short lifetimes.
  5. // Things such as fires, explosions and debris.
  6. //
  7. // MechCommander 2
  8. //
  9. //---------------------------------------------------------------------------//
  10. // Copyright (C) Microsoft Corporation. All rights reserved. //
  11. //===========================================================================//
  12. #ifndef CARNAGE_H
  13. #define CARNAGE_H
  14. //---------------------------------------------------------------------------
  15. #ifndef DCARNAGE_H
  16. #include "dcarnage.h"
  17. #endif
  18. #ifndef GAMEOBJ_H
  19. #include "gameobj.h"
  20. #endif
  21. #ifndef OBJTYPE_H
  22. #include "objtype.h"
  23. #endif
  24. #include <gosFX\gosfxheaders.hpp>
  25. //***************************************************************************
  26. typedef union _CarnageInfo
  27. {
  28. struct {
  29. float timeToBurn;
  30. float radius;
  31. long reallyVisible;
  32. } fire;
  33. struct {
  34. float timer;
  35. float radius;
  36. float chunkSize;
  37. } explosion;
  38. } CarnageInfo;
  39. //---------------------------------------------------------------------------
  40. typedef struct _CarnageData : public GameObjectData
  41. {
  42. CarnageEnumType carnageType;
  43. GameObjectWatchID ownerWID;
  44. CarnageInfo info;
  45. long effectId;
  46. } CarnageData;
  47. class Carnage : public GameObject
  48. {
  49. //-------------
  50. // Data Members
  51. public:
  52. CarnageEnumType carnageType;
  53. GameObjectWatchID ownerWID;
  54. CarnageInfo info;
  55. static float maxFireBurnTime;
  56. //NEW GOS FX
  57. long effectId;
  58. gosFX::Effect *gosEffect;
  59. //Lighting Data
  60. TG_LightPtr pointLight;
  61. DWORD lightId;
  62. float intensity;
  63. float inRadius;
  64. float outRadius;
  65. float duration;
  66. //-----------------
  67. // member Functions
  68. public:
  69. virtual void init (bool create);
  70. Carnage (void) : GameObject()
  71. {
  72. init(true);
  73. }
  74. ~Carnage (void)
  75. {
  76. destroy();
  77. }
  78. virtual void init (bool create, ObjectTypePtr _type);
  79. virtual void init (CarnageEnumType _carnageType);
  80. virtual void init (long fxId)
  81. {
  82. effectId = fxId;
  83. }
  84. virtual void destroy (void);
  85. virtual long kill (void)
  86. {
  87. return(NO_ERR);
  88. }
  89. virtual bool onScreen (void);
  90. virtual long update (void);
  91. virtual void render (void);
  92. virtual void setOwner (GameObjectPtr myOwner)
  93. {
  94. if (myOwner) {
  95. ownerWID = myOwner->getWatchID();
  96. if (carnageType == CARNAGE_FIRE)
  97. myOwner->setFireHandle(getHandle());
  98. }
  99. else
  100. ownerWID = 0;
  101. }
  102. GameObjectPtr getOwner (void);
  103. bool isVisible (long whichFire = 0);
  104. virtual float getExtentRadius (void)
  105. {
  106. if (carnageType == CARNAGE_FIRE)
  107. return(info.fire.radius);
  108. else if (carnageType == CARNAGE_EXPLOSION)
  109. return(info.explosion.radius);
  110. return(0.0);
  111. }
  112. virtual void setExtentRadius (float radius)
  113. {
  114. if (carnageType == CARNAGE_FIRE)
  115. info.fire.radius = radius;
  116. else if (carnageType == CARNAGE_EXPLOSION)
  117. info.explosion.radius = radius;
  118. }
  119. virtual void handleStaticCollision (void);
  120. void addTimeLeft (float seconds);
  121. void finishNow (void);
  122. virtual void Save (PacketFilePtr file, long packetNum);
  123. void CopyTo (CarnageData *data);
  124. void Load (CarnageData *data);
  125. };
  126. //---------------------------------------------------------------------------
  127. class FireType : public ObjectType
  128. {
  129. //-------------
  130. // Data Members
  131. public:
  132. float damageLevel;
  133. unsigned long soundEffectId;
  134. unsigned long lightObjectId;
  135. unsigned long startLoopFrame;
  136. unsigned long endLoopFrame;
  137. unsigned long numLoops;
  138. float maxExtent; //How Good am I at setting off other fires
  139. float timeToMax; //How long before I grow to MaxExtent size
  140. long totalFires;
  141. float* fireOffsetX;
  142. float* fireOffsetY;
  143. float* fireDelay;
  144. long* fireRandomOffsetX;
  145. long* fireRandomOffsetY;
  146. long* fireRandomDelay;
  147. //-----------------
  148. // Member Functions
  149. public:
  150. void init (void)
  151. {
  152. ObjectType::init();
  153. objectTypeClass = FIRE_TYPE;
  154. objectClass = FIRE;
  155. damageLevel = 0.0;
  156. soundEffectId = -1;
  157. timeToMax = 0.0;
  158. maxExtent = 0.0;
  159. totalFires = 1;
  160. fireOffsetX = NULL;
  161. fireOffsetY = NULL;
  162. fireDelay = NULL;
  163. fireRandomOffsetX = NULL;
  164. fireRandomOffsetY = NULL;
  165. fireRandomDelay = NULL;
  166. }
  167. FireType (void)
  168. {
  169. init();
  170. }
  171. virtual long init (FilePtr objFile, unsigned long fileSize);
  172. long init (FitIniFilePtr objFile);
  173. ~FireType (void)
  174. {
  175. destroy();
  176. }
  177. virtual void destroy (void);
  178. virtual GameObjectPtr createInstance (void);
  179. virtual bool handleCollision (GameObjectPtr collidee, GameObjectPtr collider);
  180. virtual bool handleDestruction (GameObjectPtr collidee, GameObjectPtr collider);
  181. };
  182. //---------------------------------------------------------------------------
  183. class ExplosionType : public ObjectType
  184. {
  185. public:
  186. float damageLevel;
  187. unsigned long soundEffectId;
  188. unsigned long lightObjectId;
  189. long explRadius;
  190. float chunkSize;
  191. float lightMinMaxRadius;
  192. float lightMaxMaxRadius;
  193. float lightOutMinRadius;
  194. float lightOutMaxRadius;
  195. DWORD lightRGB;
  196. float maxIntensity;
  197. float minIntensity;
  198. float duration;
  199. float delayUntilCollidable;
  200. public:
  201. void init (void)
  202. {
  203. ObjectType::init();
  204. objectTypeClass = EXPLOSION_TYPE;
  205. objectClass = EXPLOSION;
  206. damageLevel = 0.0;
  207. soundEffectId = -1;
  208. explRadius = 0;
  209. chunkSize = 0.0;
  210. delayUntilCollidable = 0.5f;
  211. lightMinMaxRadius = 0.0f;
  212. lightMaxMaxRadius = 0.0f;
  213. lightOutMinRadius = 0.0f;
  214. lightOutMaxRadius = 0.0f;
  215. lightRGB = 0x00000000;
  216. maxIntensity = 0.0f;
  217. minIntensity = 0.0f;
  218. duration = 0.0f;
  219. }
  220. ExplosionType (void)
  221. {
  222. init();
  223. }
  224. virtual long init (FilePtr objFile, unsigned long fileSize);
  225. long init (FitIniFilePtr objFile);
  226. ~ExplosionType (void)
  227. {
  228. destroy();
  229. }
  230. virtual void destroy (void);
  231. virtual GameObjectPtr createInstance (void);
  232. virtual bool handleCollision (GameObjectPtr collidee, GameObjectPtr collider);
  233. virtual bool handleDestruction (GameObjectPtr collidee, GameObjectPtr collider);
  234. };
  235. #endif
  236. //***************************************************************************