mineigc.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: mineIGC.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the CmineIGC class. This file was initially created by
  10. ** the ATL wizard for the core object.
  11. **
  12. ** History:
  13. */
  14. // mineIGC.cpp : Implementation of CmineIGC
  15. #include "pch.h"
  16. #include "mineIGC.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CmineIGC
  19. CmineIGC::CmineIGC(void)
  20. :
  21. m_launcher(NULL),
  22. m_mineType(NULL),
  23. m_bCreateNow (false)
  24. {
  25. }
  26. CmineIGC::~CmineIGC(void)
  27. {
  28. }
  29. HRESULT CmineIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
  30. {
  31. ZRetailAssert (data && (dataSize > sizeof(DataMineBase)));
  32. {
  33. DataMineBase* dataMineBase = (DataMineBase*)data;
  34. if ((dataMineBase->exportF) &&
  35. ((DataMineExport*)dataMineBase)->createNow)
  36. {
  37. m_time0 = now;
  38. }
  39. else
  40. {
  41. m_time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataMineBase->time0);
  42. }
  43. TmodelIGC<ImineIGC>::Initialize(pMission, now, data, dataSize);
  44. IshipIGC* pshipLauncher;
  45. IclusterIGC* pcluster;
  46. DataMineTypeIGC* dataMineType;
  47. if (dataMineBase->exportF)
  48. {
  49. assert (dataSize >= sizeof(DataMineExport));
  50. DataMineExport* dataMineExport = (DataMineExport*)dataMineBase;
  51. m_mineType = (ImineTypeIGC*)(pMission->GetExpendableType(dataMineExport->minetypeID));
  52. assert (m_mineType);
  53. assert (m_mineType->GetObjectType() == OT_mineType);
  54. pcluster = pMission->GetCluster(dataMineExport->clusterID);
  55. assert (m_mineType);
  56. dataMineType = (DataMineTypeIGC*)(m_mineType->GetData());
  57. pshipLauncher = pMission->GetShip(dataMineExport->launcherID);
  58. SetSide(pMission->GetSide(dataMineExport->sideID));
  59. m_fraction = dataMineExport->fraction;
  60. }
  61. else
  62. {
  63. assert (dataSize == sizeof(DataMineIGC));
  64. DataMineIGC* dataMine = (DataMineIGC*)dataMineBase;
  65. m_mineType = dataMine->pminetype;
  66. pcluster = dataMine->pcluster;
  67. assert (m_mineType);
  68. assert (m_mineType->GetObjectType() == OT_mineType);
  69. dataMineType = (DataMineTypeIGC*)(m_mineType->GetData());
  70. pshipLauncher = dataMine->pshipLauncher;
  71. SetSide(dataMine->psideLauncher);
  72. m_fraction = 1.0f;
  73. }
  74. if (pshipLauncher && (dataMineType->launcherDef.price == 0))
  75. {
  76. m_launcher = pshipLauncher;
  77. m_launcher->AddRef();
  78. }
  79. assert (GetSide());
  80. assert (pcluster);
  81. m_mineType->AddRef();
  82. //Load the model for the mine
  83. LoadMine(dataMineType->textureName, 1.0f, dataMineType->radius, dataMineType->iconName,
  84. c_mtSeenBySide | c_mtPredictable | c_mtHitable | c_mtStatic);
  85. SetRadius(dataMineType->radius);
  86. SetSignature(dataMineType->signature);
  87. SetSecondaryName(dataMineType->launcherDef.name);
  88. {
  89. //lifespan == 0 => immortal mine that can hit until it gets terminated on the next update; this is bad
  90. assert (dataMineType->lifespan > 0.0f);
  91. m_timeExpire = m_time0 + dataMineType->lifespan;
  92. assert (m_timeExpire != m_time0);
  93. }
  94. SetMass(0.0f);
  95. m_mineID = dataMineBase->mineID;
  96. SetPosition(dataMineBase->p0);
  97. SetCluster(pcluster);
  98. pMission->AddMine(this);
  99. }
  100. return S_OK;
  101. }
  102. void CmineIGC::Terminate(void)
  103. {
  104. AddRef();
  105. GetMyMission()->DeleteMine(this);
  106. TmodelIGC<ImineIGC>::Terminate();
  107. if (m_launcher)
  108. {
  109. m_launcher->Release();
  110. m_launcher = NULL;
  111. }
  112. if (m_mineType)
  113. {
  114. m_mineType->Release();
  115. m_mineType = NULL;
  116. }
  117. Release();
  118. }
  119. void CmineIGC::Update(Time now)
  120. {
  121. if (now > m_timeExpire)
  122. Terminate();
  123. else
  124. TmodelIGC<ImineIGC>::Update(now);
  125. }
  126. int CmineIGC::Export(void* data) const
  127. {
  128. int size = sizeof(DataMineExport);
  129. if (data)
  130. {
  131. DataMineExport* pdme = (DataMineExport*)data;
  132. pdme->p0 = GetPosition();
  133. pdme->time0 = m_time0;
  134. pdme->mineID = GetObjectID();
  135. pdme->exportF = true;
  136. pdme->clusterID = GetCluster()->GetObjectID();
  137. pdme->minetypeID = m_mineType->GetObjectID();
  138. pdme->launcherID = m_launcher ? m_launcher->GetObjectID() : NA;
  139. pdme->sideID = GetSide()->GetObjectID();
  140. pdme->fraction = m_fraction;
  141. pdme->createNow = m_bCreateNow;
  142. }
  143. return size;
  144. }