dispenserigc.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: dispenserIGC.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the CdispenserIGC class. This file was initially created by
  10. ** the ATL wizard for the core object.
  11. **
  12. ** History:
  13. */
  14. // dispenserIGC.cpp : Implementation of CdispenserIGC
  15. #include "pch.h"
  16. #include "dispenserIGC.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CdispenserIGC
  19. CdispenserIGC::CdispenserIGC(void)
  20. :
  21. m_ship(NULL),
  22. m_partType(NULL),
  23. m_expendableType(NULL),
  24. m_mountID(c_mountNA)
  25. {
  26. }
  27. CdispenserIGC::~CdispenserIGC(void)
  28. {
  29. }
  30. HRESULT CdispenserIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
  31. {
  32. assert (pMission);
  33. m_pMission = pMission;
  34. ZRetailAssert (data && (dataSize == sizeof(DataPartIGC)));
  35. {
  36. m_partType = (IlauncherTypeIGC*)(((DataPartIGC*)data)->partType);
  37. assert (m_partType);
  38. m_partType->AddRef();
  39. m_expendableType = (IexpendableTypeIGC*)(m_partType->GetExpendableType());
  40. assert (m_expendableType);
  41. assert ((m_expendableType->GetObjectType() == OT_mineType) ||
  42. (m_expendableType->GetObjectType() == OT_probeType) ||
  43. (m_expendableType->GetObjectType() == OT_chaffType));
  44. m_expendableType->AddRef();
  45. m_amount = 0;
  46. }
  47. return S_OK;
  48. }
  49. void CdispenserIGC::Terminate(void)
  50. {
  51. AddRef();
  52. SetShip(NULL, NA);
  53. if (m_partType)
  54. {
  55. m_partType->Release();
  56. m_partType = NULL;
  57. }
  58. if (m_expendableType)
  59. {
  60. m_expendableType->Release();
  61. m_expendableType = NULL;
  62. }
  63. Release();
  64. }
  65. void CdispenserIGC::Update(Time now)
  66. {
  67. assert (m_ship);
  68. if (m_mountedFraction < 1.0f)
  69. {
  70. float dt = now - m_ship->GetLastUpdate();
  71. assert (dt >= 0.0f);
  72. m_mountedFraction += dt * m_pMission->GetFloatConstant(c_fcidMountRate);
  73. if (m_mountedFraction < 1.0f)
  74. return;
  75. IIgcSite* pigc = GetMission()->GetIgcSite();
  76. pigc->PlayNotificationSound(mountedSound, m_ship);
  77. pigc->PostNotificationText(m_ship, false, "%s ready.", GetPartType()->GetName());
  78. m_mountedFraction = 1.0f;
  79. }
  80. if ((m_timeLoaded < now) && (m_amount > 0))
  81. {
  82. static const int c_maskFire[ET_MAX] =
  83. { chaffFireIGC,
  84. 0, 0,
  85. mineFireIGC,
  86. 0, 0, 0, 0 };
  87. assert (c_maskFire[ET_ChaffLauncher] == chaffFireIGC);
  88. assert (c_maskFire[ET_Dispenser] == mineFireIGC);
  89. EquipmentType et = m_expendableType->GetEquipmentType();
  90. if ((m_ship->GetStateM() & c_maskFire[et]) &&
  91. ((et == ET_ChaffLauncher) || (m_ship->GetRipcordModel() == NULL)))
  92. {
  93. m_timeLoaded = now + m_expendableType->GetLoadTime();
  94. m_pMission->GetIgcSite()->FireExpendable(m_ship,
  95. this,
  96. now);
  97. }
  98. }
  99. }
  100. void CdispenserIGC::SetShip(IshipIGC* newVal, Mount mount)
  101. {
  102. //There may be only a single reference to this part ... so make sure the part
  103. //does not get deleted midway through things
  104. AddRef();
  105. if (m_ship)
  106. {
  107. m_ship->DeletePart(this);
  108. m_ship->Release();
  109. }
  110. assert (m_mountID == c_mountNA);
  111. m_ship = newVal;
  112. if (m_ship)
  113. {
  114. m_ship->AddRef();
  115. m_ship->AddPart(this);
  116. m_emissionPt = m_ship->GetHitTest()->GetFrameOffset("missemt");
  117. SetMountID(mount);
  118. }
  119. Release();
  120. }
  121. void CdispenserIGC::SetMountID(Mount newVal)
  122. {
  123. assert (m_ship);
  124. if (newVal != m_mountID)
  125. {
  126. if ((newVal < 0) && (m_mountID == 0))
  127. Deactivate(); //was active iff mounted
  128. m_ship->MountPart(this, newVal, &m_mountID);
  129. if (newVal == 0)
  130. Activate(); //active iff mounted
  131. }
  132. }