bldng.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. //---------------------------------------------------------------------------
  2. //
  3. // bldng.h -- File contains the Building Object Class
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef BLDNG_H
  11. #define BLDNG_H
  12. #ifndef DBLDNG_H
  13. #include "dbldng.h"
  14. #endif
  15. #ifndef TERROBJ_H
  16. #include "terrobj.h"
  17. #endif
  18. #ifndef GAMEOBJ_H
  19. #include "gameobj.h"
  20. #endif
  21. #ifndef OBJTYPE_H
  22. #include "objtype.h"
  23. #endif
  24. #ifndef DWARRIOR_H
  25. #include "dwarrior.h"
  26. #endif
  27. //---------------------------------------------------------------------------
  28. #define NO_RAM_FOR_BUILDING 0xDCDC0006
  29. #define NO_APPEARANCE_TYPE_FOR_BLD 0xDCDC0007
  30. #define NO_APPEARANCE_FOR_BLD 0xDCDC0008
  31. #define APPEARANCE_NOT_VFX_APPEAR 0xDCDC0009
  32. #define MAX_PRISONERS 4
  33. typedef enum {
  34. BUILDING_SUBTYPE_NONE,
  35. BUILDING_SUBTYPE_WALL,
  36. BUILDING_SUBTYPE_LANDBRIDGE,
  37. NUM_BUILDING_SUBTYPES
  38. } BuildingSubType;
  39. //---------------------------------------------------------------------------
  40. class BuildingType : public ObjectType {
  41. public:
  42. float damageLevel;
  43. float sensorRange;
  44. long teamId;
  45. float baseTonnage;
  46. float explDmg;
  47. float explRad;
  48. long buildingTypeName;
  49. long buildingDescriptionID;
  50. long startBR;
  51. long numMarines;
  52. long resourcePoints;
  53. bool marksImpassableWhenDestroyed;
  54. bool canRefit;
  55. bool mechBay; // otherwise it's a vehicle bay.
  56. bool capturable;
  57. bool powerSource;
  58. float perimeterAlarmRange;
  59. float perimeterAlarmTimer;
  60. float lookoutTowerRange;
  61. unsigned long activityEffectId;
  62. public:
  63. void init (void);
  64. BuildingType (void) {
  65. ObjectType::init();
  66. init();
  67. }
  68. virtual long init (FilePtr objFile, unsigned long fileSize);
  69. long init (FitIniFilePtr objFile);
  70. ~BuildingType (void) {
  71. destroy();
  72. }
  73. float getDamageLevel (void) {
  74. return(damageLevel);
  75. }
  76. virtual void destroy (void);
  77. virtual GameObjectPtr createInstance (void);
  78. virtual bool handleCollision (GameObjectPtr collidee, GameObjectPtr collider);
  79. virtual bool handleDestruction (GameObjectPtr collidee, GameObjectPtr collider);
  80. };
  81. //---------------------------------------------------------------------------
  82. typedef struct _BuildingData : public TerrainObjectData
  83. {
  84. char teamId;
  85. unsigned char baseTileId;
  86. char commanderId;
  87. GameObjectWatchID refitBuddyWID;
  88. DWORD parentId;
  89. GameObjectWatchID parent;
  90. unsigned char listID;
  91. float captureTime;
  92. //PerimeterAlarms
  93. bool moverInProximity;
  94. float proximityTimer;
  95. long updatedTurn;
  96. } BuildingData;
  97. class Building : public TerrainObject
  98. {
  99. public:
  100. char teamId;
  101. unsigned char baseTileId;
  102. SensorSystemPtr sensorSystem;
  103. char commanderId; //If capturable, who last captured it...
  104. GameObjectWatchID refitBuddyWID;
  105. DWORD parentId;
  106. GameObjectWatchID parent;
  107. unsigned char listID;
  108. float captureTime;
  109. float scoreTime;
  110. //PerimeterAlarms
  111. bool moverInProximity;
  112. float proximityTimer;
  113. long updatedTurn;
  114. public:
  115. virtual void init (bool create) {
  116. sensorSystem = NULL;
  117. setFlag(OBJECT_FLAG_JUSTCREATED, true);
  118. appearance = NULL;
  119. vertexNumber = 0;
  120. blockNumber = 0;
  121. baseTileId = 0;
  122. commanderId = -1;
  123. teamId = -1;
  124. refitBuddyWID = 0;
  125. parentId = 0xffffffff;
  126. parent = NULL;
  127. powerSupply = NULL;
  128. numSubAreas0 = 0;
  129. numSubAreas1 = 0;
  130. subAreas0 = NULL;
  131. subAreas1 = NULL;
  132. listID = 255;
  133. captureTime = 0.0;
  134. scoreTime = 0.0;
  135. moverInProximity = false;
  136. proximityTimer = 0.0f;
  137. updatedTurn = -1;
  138. }
  139. Building (void) : TerrainObject() {
  140. init(true);
  141. }
  142. ~Building (void) {
  143. destroy();
  144. }
  145. virtual void destroy (void);
  146. virtual long update (void);
  147. virtual void render (void);
  148. virtual void init (bool create, ObjectTypePtr objType);
  149. virtual void setSensorRange (float range);
  150. void setSensorData (TeamPtr team, float range = -1.0, bool setTeam = true);
  151. virtual long setTeamId (long _teamId, bool setup);
  152. virtual long getTeamId (void) {
  153. return(teamId);
  154. }
  155. virtual long getDescription(){ return ((BuildingType*)getObjectType())->buildingDescriptionID; }
  156. virtual TeamPtr getTeam (void);
  157. virtual bool isFriendly (TeamPtr team);
  158. virtual bool isEnemy (TeamPtr team);
  159. virtual bool isNeutral (TeamPtr team);
  160. void lightOnFire (float timeToBurn);
  161. long updateAnimations (void);
  162. virtual long handleWeaponHit (WeaponShotInfoPtr shotInfo, bool addMultiplayChunk = false);
  163. virtual void setDamage (float newDamage); //Damage encodes which groundtile to use, too.
  164. virtual long kill (void) {
  165. return(NO_ERR);
  166. }
  167. virtual char* getName (void);
  168. virtual Stuff::Vector3D getPositionFromHS (long weaponType)
  169. {
  170. //-----------------------------------------
  171. // Hotspot for buildings is position plus
  172. // some Z based on OBB to make Effect visible.
  173. // If this doesn't work, replace with art defined site.
  174. Stuff::Vector3D hsPos = position;
  175. if (appearance)
  176. {
  177. hsPos = appearance->getHitNode();
  178. if (hsPos == position)
  179. {
  180. hsPos.z += appearance->getTopZ() * 0.5f;
  181. }
  182. }
  183. return(hsPos);
  184. }
  185. virtual Stuff::Vector3D getLOSPosition (void)
  186. {
  187. //-----------------------------------------
  188. // Hotspot for buildings is position plus
  189. // some Z based on OBB to make Effect visible.
  190. //
  191. // Use THIS position for LOS Calc!!!
  192. Stuff::Vector3D hsPos = position;
  193. if (appearance)
  194. hsPos.z += appearance->getTopZ() * 0.5f;
  195. BuildingTypePtr bldgType = ((BuildingTypePtr)getObjectType());
  196. if ((bldgType->lookoutTowerRange > 0.0f) ||
  197. (bldgType->sensorRange > 0.0f))
  198. {
  199. hsPos.z = position.z + 75.0f;
  200. }
  201. return(hsPos);
  202. }
  203. virtual float getDestructLevel (void)
  204. {
  205. return (getDamageLevel() - damage);
  206. }
  207. virtual void setRefitBuddy (GameObjectWatchID objWID) {
  208. refitBuddyWID = objWID;
  209. }
  210. virtual void openFootPrint (void);
  211. virtual void closeFootPrint (void);
  212. bool isVisible (void);
  213. virtual bool isCaptureable (long capturingTeamID);
  214. virtual void setCommanderId (long _commanderId);
  215. virtual long getCommanderId (void) {
  216. return(commanderId);
  217. }
  218. virtual float getDamageLevel (void);
  219. virtual void getBlockAndVertexNumber (long& blockNum, long& vertexNum) {
  220. blockNum = blockNumber;
  221. vertexNum = vertexNumber;
  222. }
  223. virtual bool isBuilding(void) {
  224. return(true);
  225. }
  226. virtual bool isTerrainObject (void) {
  227. return(true);
  228. }
  229. void createBuildingMarines (void);
  230. virtual bool isLinked (void);
  231. virtual GameObjectPtr getParent (void);
  232. virtual void setParentId (DWORD pId);
  233. virtual SensorSystem* getSensorSystem(){ return sensorSystem; }
  234. virtual float getAppearRadius (void)
  235. {
  236. return appearance->getRadius();
  237. }
  238. virtual bool canBeCaptured (void)
  239. {
  240. return ((BuildingTypePtr)getObjectType())->capturable;
  241. }
  242. virtual bool isSelectable()
  243. {
  244. return appearance->isSelectable();
  245. }
  246. virtual bool isPowerSource(void)
  247. {
  248. return ((BuildingTypePtr)getObjectType())->powerSource;
  249. }
  250. virtual bool isLit (void)
  251. {
  252. if (appearance)
  253. return appearance->getIsLit();
  254. return false;
  255. }
  256. virtual bool isSpecialBuilding(void)
  257. {
  258. BuildingTypePtr bldgType = ((BuildingTypePtr)getObjectType());
  259. // if ((bldgType->getObjTypeNum() == GENERIC_HQ_BUILDING_OBJNUM) ||
  260. // (bldgType->getObjTypeNum() == GENERIC_DESTRUCTIBLE_RESOURCE_BUILDING_OBJNUM) ||
  261. // (bldgType->getObjTypeNum() == GENERIC_INDESTRUCTIBLE_RESOURCE_BUILDING_OBJNUM))
  262. // return(true);
  263. if ((bldgType->perimeterAlarmRange > 0.0f) &&
  264. (bldgType->perimeterAlarmTimer > 0.0f) ||
  265. (bldgType->lookoutTowerRange > 0.0f) ||
  266. (bldgType->sensorRange > 0.0f))
  267. {
  268. return true;
  269. }
  270. return false;
  271. }
  272. virtual bool isLookoutTower (void)
  273. {
  274. BuildingTypePtr bldgType = ((BuildingTypePtr)getObjectType());
  275. if (bldgType->lookoutTowerRange > 0.0f)
  276. {
  277. return true;
  278. }
  279. return false;
  280. }
  281. virtual float getRefitPoints(void)
  282. {
  283. return getDamageLevel() - getDamage();
  284. }
  285. virtual bool burnRefitPoints(float pointsToBurn);
  286. virtual void Save (PacketFilePtr file, long packetNum);
  287. void Load (BuildingData *data);
  288. void CopyTo (BuildingData *data);
  289. };
  290. #endif
  291. //***************************************************************************