cmponent.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. //***************************************************************************
  2. //
  3. // cmponent.h -- File contains the Component definition
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef CMPONENT_H
  11. #define CMPONENT_H
  12. //---------------------------------------------------------------------------
  13. #ifndef INIFILE_H
  14. #include "inifile.h"
  15. #endif
  16. #ifndef ERR_H
  17. #include "err.h"
  18. #endif
  19. #include <string.h>
  20. #ifndef _MBCS
  21. #include <gameos.hpp>
  22. #else
  23. #include <assert.h>
  24. #define gosASSERT assert
  25. #define gos_Malloc malloc
  26. #define gos_Free free
  27. #endif
  28. //***************************************************************************
  29. #define MAXLEN_COMPONENT_NAME 256
  30. #define MAXLEN_COMPONENT_ABBREV 256
  31. #define NUM_BODY_LOCATIONS 8
  32. #define TECH_BASE_CLAN 1
  33. #define TECH_BASE_INNERSPHERE 2
  34. #define COMPONENT_USE_MECH 1
  35. #define COMPONENT_USE_VEHICLE 2
  36. #define COMPONENT_USE_CLAN 16
  37. #define COMPONENT_USE_INNERSPHERE 32
  38. #define WEAPON_AMMO_OFFSET 65 // Master Component Index Offset from weapon
  39. typedef enum {
  40. COMPONENT_FORM_SIMPLE = 0,
  41. COMPONENT_FORM_COCKPIT,
  42. COMPONENT_FORM_SENSOR,
  43. COMPONENT_FORM_ACTUATOR,
  44. COMPONENT_FORM_ENGINE,
  45. COMPONENT_FORM_HEATSINK,
  46. COMPONENT_FORM_WEAPON,
  47. COMPONENT_FORM_WEAPON_ENERGY,
  48. COMPONENT_FORM_WEAPON_BALLISTIC,
  49. COMPONENT_FORM_WEAPON_MISSILE,
  50. COMPONENT_FORM_AMMO,
  51. COMPONENT_FORM_JUMPJET,
  52. COMPONENT_FORM_CASE,
  53. COMPONENT_FORM_LIFESUPPORT,
  54. COMPONENT_FORM_GYROSCOPE,
  55. COMPONENT_FORM_POWER_AMPLIFIER,
  56. COMPONENT_FORM_ECM,
  57. COMPONENT_FORM_PROBE,
  58. COMPONENT_FORM_JAMMER,
  59. COMPONENT_FORM_BULK,
  60. NUM_COMPONENT_FORMS
  61. } ComponentFormType;
  62. typedef enum {
  63. WEAPON_AMMO_NONE, // unlimited ammo (energy weapons)
  64. WEAPON_AMMO_SRM,
  65. WEAPON_AMMO_LRM,
  66. WEAPON_AMMO_ST,
  67. WEAPON_AMMO_LIMITED, // not SRM, LRM or ST, but still finite ammo amount
  68. NUM_WEAPON_AMMO_TYPES
  69. } WeaponAmmoType;
  70. typedef enum {
  71. WEAPON_STATE_READY,
  72. WEAPON_STATE_RECYCLING,
  73. WEAPON_STATE_DAMAGED,
  74. WEAPON_STATE_DESTROYED
  75. } WeaponStateType;
  76. typedef enum {
  77. WEAPON_RANGE_SHORT,
  78. WEAPON_RANGE_MEDIUM,
  79. WEAPON_RANGE_LONG,
  80. WEAPON_RANGE_SHORT_MEDIUM,
  81. WEAPON_RANGE_MEDIUM_LONG,
  82. NUM_WEAPON_RANGE_TYPES
  83. } WeaponRangeType;
  84. //******************************************************************************************
  85. #define WEAPON_FLAG_STREAK 1
  86. #define WEAPON_FLAG_INFERNO 2
  87. #define WEAPON_FLAG_LBX 4
  88. #define WEAPON_FLAG_ARTILLERY 8
  89. typedef union {
  90. struct {
  91. float range; // in meters
  92. } sensor;
  93. struct {
  94. float range;
  95. float effect;
  96. } ecm;
  97. struct {
  98. float effect;
  99. } jammer;
  100. struct {
  101. float effect;
  102. } probe;
  103. struct {
  104. short rating;
  105. } engine;
  106. struct {
  107. short dissipation;
  108. } heatsink;
  109. struct {
  110. float heat; // how much heat does it generate?
  111. float damage; // amount of damage
  112. float recycleTime; // in seconds
  113. long ammoAmount; // amount of ammo per shot
  114. unsigned char ammoType; // 0 = unlimited, 1 = finite amount (e.g. bullets)
  115. unsigned char ammoMasterId; // ammo used by this weapon
  116. unsigned char range; // short, med or long
  117. unsigned char flags;
  118. short type; // which weapon type is this
  119. char specialEffect; // used to cue whatever visual/sound effects this needs
  120. } weapon;
  121. struct {
  122. long ammoPerTon; // ammo per ton
  123. float explosiveDamage;// damage done (per missile) if it explodes
  124. } ammo;
  125. struct {
  126. long rangeMod; // range modifier
  127. } jumpjet;
  128. } ComponentStats;
  129. //******************************************************************************************
  130. class MasterComponent;
  131. typedef MasterComponent* MasterComponentPtr;
  132. class MasterComponent {
  133. private:
  134. long masterID; // unique ID for component
  135. long resourcePoints; // resource cost of object
  136. ComponentFormType form; // form of component
  137. char name[MAXLEN_COMPONENT_NAME]; // name string/description
  138. char abbreviation[MAXLEN_COMPONENT_ABBREV]; // abbreviated name
  139. float tonnage; // in tons
  140. char size; // # of total spaces used
  141. char health; // # of hits before destroyed
  142. char criticalSpacesReq[NUM_BODY_LOCATIONS]; // # of critical spaces required in specific location
  143. char disableLevel; // # of critical spaces to disable
  144. unsigned char uses;
  145. unsigned char techBase;
  146. float CV; // CV for this component
  147. ComponentStats stats;
  148. unsigned long art;
  149. public:
  150. static MasterComponentPtr masterList;
  151. static long numComponents;
  152. static long armActuatorID;
  153. static long legActuatorID;
  154. static long clanAntiMissileSystemID;
  155. static long innerSphereAntiMissileSystemID;
  156. public:
  157. void* operator new (size_t mySize);
  158. void operator delete (void* us);
  159. void destroy (void);
  160. ~MasterComponent (void) {
  161. destroy();
  162. }
  163. void init (void) {
  164. masterID = -1;
  165. name[0] = NULL;
  166. abbreviation[0] = NULL;
  167. }
  168. MasterComponent (void) {
  169. init();
  170. }
  171. long init (FitIniFile* componentFile);
  172. long initEXCEL (char* dataLine, float baseSensorRange);
  173. long saveEXCEL (FilePtr file, unsigned char masterId,float baseSensorRange);
  174. char* getName (void) {
  175. return(&name[0]);
  176. }
  177. long getMasterID (void) {
  178. return(masterID);
  179. }
  180. long getResourcePoints (void) {
  181. return(resourcePoints);
  182. }
  183. ComponentFormType getForm (void) {
  184. return(form);
  185. }
  186. long getSize (void) {
  187. return(size);
  188. }
  189. void setSize (long sz)
  190. {
  191. size = sz;
  192. }
  193. long getHealth (void) {
  194. return(health);
  195. }
  196. char getCriticalSpacesReq (long location)
  197. {
  198. if ((location < 0) && (location > NUM_BODY_LOCATIONS))
  199. return -1;
  200. return(criticalSpacesReq[location]);
  201. }
  202. void setCriticalSpacesReq (long location, char value)
  203. {
  204. if ((location < 0) && (location > NUM_BODY_LOCATIONS))
  205. return;
  206. criticalSpacesReq[location] = value;
  207. }
  208. char getDisableLevel (void) {
  209. return(disableLevel);
  210. }
  211. float getCV (void) {
  212. return(CV);
  213. }
  214. void setCV (float cv)
  215. {
  216. CV = cv;
  217. }
  218. float getTonnage (void) {
  219. return(tonnage);
  220. }
  221. void setTonnage (float tons)
  222. {
  223. tonnage = tons;
  224. }
  225. float getHeatDissipation (void)
  226. {
  227. return (stats.heatsink.dissipation);
  228. }
  229. void setHeatDissipation (float heatD)
  230. {
  231. stats.heatsink.dissipation = heatD;
  232. }
  233. float getWeaponHeat (void) {
  234. return(stats.weapon.heat);
  235. }
  236. void setWeaponHeat (float weaponHeat)
  237. {
  238. stats.weapon.heat = weaponHeat;
  239. }
  240. float getWeaponDamage (void) {
  241. return(stats.weapon.damage);
  242. }
  243. void setWeaponDamage (float weapDmg)
  244. {
  245. stats.weapon.damage = weapDmg;
  246. }
  247. float getWeaponRecycleTime (void) {
  248. return(stats.weapon.recycleTime);
  249. }
  250. void setWeaponRecycleTime (float recycleTime)
  251. {
  252. stats.weapon.recycleTime = recycleTime;
  253. }
  254. long getWeaponAmmoAmount (void) {
  255. return(stats.weapon.ammoAmount);
  256. }
  257. void setWeaponAmmoAmount (long weaponAmmo)
  258. {
  259. stats.weapon.ammoAmount = weaponAmmo;
  260. }
  261. unsigned long getWeaponAmmoType (void) {
  262. return(stats.weapon.ammoType);
  263. }
  264. void setWeaponAmmoType (long ammoType)
  265. {
  266. stats.weapon.ammoType = ammoType;
  267. }
  268. unsigned long getWeaponAmmoMasterId (void) {
  269. return(stats.weapon.ammoMasterId);
  270. }
  271. void setWeaponAmmoMasterId (long ammoId)
  272. {
  273. stats.weapon.ammoMasterId = ammoId;
  274. }
  275. long getWeaponRange (void) {
  276. return(stats.weapon.range);
  277. }
  278. void setWeaponRange (long weaponRange) {
  279. stats.weapon.range = weaponRange;
  280. }
  281. void clearWeaponFlags (void)
  282. {
  283. stats.weapon.flags = 0;
  284. }
  285. bool getWeaponInferno (void) {
  286. return((stats.weapon.flags & WEAPON_FLAG_INFERNO) != 0);
  287. }
  288. void setWeaponInferno (void)
  289. {
  290. stats.weapon.flags |= WEAPON_FLAG_INFERNO;
  291. }
  292. bool getWeaponStreak (void) {
  293. return((stats.weapon.flags & WEAPON_FLAG_STREAK) != 0);
  294. }
  295. void setWeaponStreak (void)
  296. {
  297. stats.weapon.flags |= WEAPON_FLAG_STREAK;
  298. }
  299. bool getWeaponLBX (void) {
  300. return((stats.weapon.flags & WEAPON_FLAG_LBX) != 0);
  301. }
  302. void setWeaponLBX (void)
  303. {
  304. stats.weapon.flags |= WEAPON_FLAG_LBX;
  305. }
  306. bool getWeaponArtillery (void) {
  307. return((stats.weapon.flags & WEAPON_FLAG_ARTILLERY) != 0);
  308. }
  309. void setWeaponArtillery (void)
  310. {
  311. stats.weapon.flags |= WEAPON_FLAG_ARTILLERY;
  312. }
  313. bool getCanClanUse (void)
  314. {
  315. return ((uses & COMPONENT_USE_CLAN) != 0);
  316. }
  317. bool getCanISUse (void)
  318. {
  319. return ((uses & COMPONENT_USE_INNERSPHERE) != 0);
  320. }
  321. bool getCanMechUse (void)
  322. {
  323. return ((uses & COMPONENT_USE_MECH) != 0);
  324. }
  325. bool getCanVehicleUse (void)
  326. {
  327. return ((uses & COMPONENT_USE_VEHICLE) != 0);
  328. }
  329. void clearUseFlags (void)
  330. {
  331. uses = 0;
  332. }
  333. void setCanClanUse (void)
  334. {
  335. uses |= COMPONENT_USE_CLAN;
  336. }
  337. void setCanISUse (void)
  338. {
  339. uses |= COMPONENT_USE_INNERSPHERE;
  340. }
  341. void setCanVehicleUse (void)
  342. {
  343. uses |= COMPONENT_USE_VEHICLE;
  344. }
  345. void setCanMechUse (void)
  346. {
  347. uses |= COMPONENT_USE_MECH;
  348. }
  349. bool getClanTechBase (void)
  350. {
  351. return ((techBase & TECH_BASE_CLAN) != 0);
  352. }
  353. bool getISTechBase (void)
  354. {
  355. return ((techBase & TECH_BASE_INNERSPHERE) != 0);
  356. }
  357. void setClanTechBase (void)
  358. {
  359. techBase = TECH_BASE_CLAN;
  360. }
  361. void setISTechBase (void)
  362. {
  363. techBase = TECH_BASE_INNERSPHERE;
  364. }
  365. void setBothTechBase (void)
  366. {
  367. techBase = TECH_BASE_INNERSPHERE + TECH_BASE_CLAN;
  368. }
  369. // long getWeaponType (void) {
  370. // return(stats.weapon.type);
  371. // }
  372. long getWeaponSpecialEffect (void) {
  373. return(stats.weapon.specialEffect);
  374. }
  375. long getAmmoPerTon (void) {
  376. return(stats.ammo.ammoPerTon);
  377. }
  378. void setAmmoPerTon (long ammoPerTon)
  379. {
  380. stats.ammo.ammoPerTon = ammoPerTon;
  381. }
  382. float getJumpJetRangeMod (void)
  383. {
  384. return (stats.jumpjet.rangeMod);
  385. }
  386. void setJumpJetRangeMod (float rangeMod)
  387. {
  388. stats.jumpjet.rangeMod = rangeMod;
  389. }
  390. float getAmmoExplosiveDamage (void) {
  391. return(stats.ammo.explosiveDamage);
  392. }
  393. void setAmmoExplosiveDamage (float ammoDamage)
  394. {
  395. stats.ammo.explosiveDamage = ammoDamage;
  396. }
  397. float getSensorRange (void) {
  398. return(stats.sensor.range);
  399. }
  400. unsigned char getTechBase (void) {
  401. return(techBase);
  402. }
  403. void setResourcePoints (long points) {
  404. resourcePoints = points;
  405. }
  406. void setSensorRange (float range)
  407. {
  408. stats.sensor.range = (short)range;
  409. }
  410. float getEcmRange (void) {
  411. return(stats.ecm.range);
  412. }
  413. void setEcmRange (float range) {
  414. stats.ecm.range = range;
  415. }
  416. float getEcmEffect (void) {
  417. return(stats.ecm.effect);
  418. }
  419. void setEcmEffect (float effect) {
  420. stats.ecm.effect = effect;
  421. }
  422. float getJammerEffect (void) {
  423. return(stats.jammer.effect);
  424. }
  425. void setJammerEffect (float effect) {
  426. stats.jammer.effect = effect;
  427. }
  428. float getProbeEffect (void) {
  429. return(stats.probe.effect);
  430. }
  431. void setProbeEffect (float effect) {
  432. stats.probe.effect = effect;
  433. }
  434. char *getAbbreviation (void) {
  435. return (&abbreviation[0]);
  436. }
  437. bool isOffensiveWeapon (void);
  438. bool isDefensiveWeapon (void);
  439. void multiplyWeaponRanges (float factor);
  440. static long loadMasterList (char* fileName, long numComponents, float baseSensorRange);
  441. static long saveMasterList (char* fileName, long numComponents,float baseSensorRange);
  442. static long freeMasterList (void);
  443. static long multiplyMasterListWeaponRanges (float factor);
  444. };
  445. #endif
  446. //******************************************************************************************