asteroidigc.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: asteroidIGC.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the CasteroidIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // asteroidIGC.cpp : Implementation of CasteroidIGC
  15. #include "pch.h"
  16. #include "asteroidIGC.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CasteroidIGC
  19. HRESULT CasteroidIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
  20. {
  21. TmodelIGC<IasteroidIGC>::Initialize(pMission, now, data, dataSize);
  22. ZRetailAssert (data && (dataSize == sizeof(DataAsteroidIGC)));
  23. {
  24. DataAsteroidIGC* dataAsteroid = (DataAsteroidIGC*)data;
  25. m_asteroidDef = dataAsteroid->asteroidDef;
  26. IclusterIGC* cluster = pMission->GetCluster(dataAsteroid->clusterID);
  27. ZRetailAssert (cluster);
  28. {
  29. HRESULT rc = Load(0,
  30. m_asteroidDef.modelName,
  31. m_asteroidDef.textureName,
  32. m_asteroidDef.iconName,
  33. c_mtStatic | c_mtHitable | c_mtDamagable | c_mtSeenBySide | c_mtPredictable);
  34. assert (SUCCEEDED(rc));
  35. SetRadius((float)m_asteroidDef.radius);
  36. SetPosition(dataAsteroid->position);
  37. {
  38. Orientation o(dataAsteroid->forward, dataAsteroid->up);
  39. SetOrientation(o);
  40. }
  41. SetRotation(dataAsteroid->rotation);
  42. SetSignature(dataAsteroid->signature);
  43. m_fraction = dataAsteroid->fraction;
  44. if (dataAsteroid->name[0] != '\0')
  45. SetName(dataAsteroid->name);
  46. else
  47. SetSecondaryName(dataAsteroid->name + 1);
  48. SetCluster(cluster);
  49. #ifdef DEBUG
  50. {
  51. //Verify that there is no pre-existing asteroid with the same ID
  52. for (AsteroidLinkIGC* pal = pMission->GetAsteroids()->first(); (pal != NULL); pal = pal->next())
  53. {
  54. assert (pal->data()->GetObjectID() != m_asteroidDef.asteroidID);
  55. }
  56. }
  57. #endif
  58. pMission->AddAsteroid(this);
  59. }
  60. }
  61. return S_OK;
  62. }
  63. int CasteroidIGC::Export(void* data) const
  64. {
  65. if (data)
  66. {
  67. DataAsteroidIGC* dataAsteroid = (DataAsteroidIGC*)data;
  68. dataAsteroid->asteroidDef = m_asteroidDef;
  69. dataAsteroid->position = GetPosition();
  70. {
  71. const Orientation& o = GetOrientation();
  72. dataAsteroid->forward = o.GetForward();
  73. dataAsteroid->up = o.GetUp();
  74. }
  75. dataAsteroid->rotation = GetRotation();
  76. assert (GetCluster());
  77. dataAsteroid->clusterID = GetCluster()->GetObjectID();
  78. dataAsteroid->signature = GetSignature();
  79. dataAsteroid->fraction = m_fraction;
  80. const char* pszName = GetName();
  81. if (*pszName == '\0')
  82. memcpy(dataAsteroid->name, GetName(), sizeof(dataAsteroid->name));
  83. else
  84. UTL::putName(dataAsteroid->name, GetName());
  85. }
  86. return sizeof(DataAsteroidIGC);
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // IasteroidIGC
  90. struct AsteroidTypeRow
  91. {
  92. const char* name;
  93. const char* prefix;
  94. AsteroidDef def;
  95. };
  96. static const AsteroidTypeRow asteroidTypes[] =
  97. {
  98. { "asteroid", "\0a", { 0.0f, 0, 0, 0, 25000, 400, "bgrnd03", "", "meteoricon" } },
  99. { "asteroid", "\0a", { 0.0f, 0, 0, 0, 25000, 400, "bgrnd05", "", "meteoricon" } },
  100. { "asteroid", "\0a", { 0.0f, 0, c_aabmBuildable, 0, 10000, 200, "bgrnd03", "", "meteoricon" } },
  101. { "asteroid", "\0a", { 0.0f, 0, c_aabmBuildable, 0, 10000, 200, "bgrnd05", "", "meteoricon" } },
  102. { "Helium 3", "He", { 1.0f, 1.0f, c_aabmMineHe3, 0, 25000, 100, "bgrnd56", "", "heliumrock" } },
  103. { "Uranium", "U", { 0.0f, 0, (c_aabmSpecial << 0), 0, 25000, 200, "bgrnd51", "", "hotrock" } },
  104. { "Silicon", "Si", { 0.0f, 0, (c_aabmSpecial << 1), 0, 25000, 200, "bgrnd52", "", "copperrock" } },
  105. { "Carbonaceous", "C", { 0.0f, 0, (c_aabmSpecial << 2), 0, 25000, 200, "bgrnd53", "", "carbonrock" } }
  106. };
  107. const int nFirstHugeType = 0;
  108. const int nNumHugeTypes = 2;
  109. const int nFirstGenericType = nFirstHugeType + nNumHugeTypes;
  110. const int nNumGenericTypes = 2;
  111. const int nFirstMinableType = nFirstGenericType + nNumGenericTypes;
  112. const int nNumMinableTypes = 1;
  113. const int nFirstSpecialType = nFirstMinableType + nNumMinableTypes;
  114. const int nNumSpecialTypes = 3;
  115. const int numAsteroidTypes = sizeof(asteroidTypes) / sizeof(AsteroidTypeRow);
  116. static const AsteroidTypeRow& FindAsteroidRow(AsteroidAbilityBitMask aabm)
  117. {
  118. for (int i = 0; i < numAsteroidTypes; i++)
  119. {
  120. if (aabm == asteroidTypes[i].def.aabmCapabilities)
  121. {
  122. return asteroidTypes[i];
  123. }
  124. }
  125. ZAssert(false); // asteroid type not found
  126. return asteroidTypes[0];
  127. }
  128. const char* IasteroidIGC::GetTypeName(AsteroidAbilityBitMask aabm)
  129. {
  130. return FindAsteroidRow(aabm).name;
  131. }
  132. const char* IasteroidIGC::GetTypePrefix(int index)
  133. {
  134. return asteroidTypes[index].prefix;
  135. }
  136. const AsteroidDef& IasteroidIGC::GetTypeDefaults(int index)
  137. {
  138. return asteroidTypes[index].def;
  139. }
  140. int IasteroidIGC::NumberSpecialAsteroids(const MissionParams* pmp)
  141. {
  142. static const int c_nSpecialAsteroidTypes[8] = {3, 1, 1, 2, 1, 2, 2, 3};
  143. int c = (pmp->bAllowSupremacyPath ? 4 : 0) +
  144. (pmp->bAllowTacticalPath ? 2 : 0) +
  145. (pmp->bAllowExpansionPath ? 1 : 0);
  146. return c_nSpecialAsteroidTypes[c];
  147. }
  148. int IasteroidIGC::GetSpecialAsterioid(const MissionParams* pmp, int index)
  149. {
  150. int n;
  151. switch ((pmp->bAllowSupremacyPath ? 4 : 0) +
  152. (pmp->bAllowTacticalPath ? 2 : 0) +
  153. (pmp->bAllowExpansionPath ? 1 : 0))
  154. {
  155. case 0:
  156. case 7:
  157. n = index % 3;
  158. break;
  159. case 1:
  160. n = 0;
  161. break;
  162. case 2:
  163. n = 1;
  164. break;
  165. case 3:
  166. n = index % 2;
  167. break;
  168. case 4:
  169. n = 2;
  170. break;
  171. case 5:
  172. n = ((index % 2) == 0) ? 0 : 2;
  173. break;
  174. case 6:
  175. n = 1 + (index % 2);
  176. break;
  177. }
  178. return n + nFirstSpecialType;
  179. }
  180. int IasteroidIGC::GetRandomType(AsteroidAbilityBitMask aabm)
  181. {
  182. int index;
  183. switch (aabm)
  184. {
  185. case 0:
  186. index = nFirstHugeType + randomInt(0, 1);
  187. break;
  188. case c_aabmBuildable:
  189. index = nFirstGenericType + randomInt(0, 1);
  190. break;
  191. case c_aabmMineHe3:
  192. index = nFirstMinableType;
  193. break;
  194. default:
  195. assert (false);
  196. }
  197. return index;
  198. }