missileigc.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: missileIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CmissileIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // missileIGC.h : Declaration of the CmissileIGC
  15. #ifndef __MISSILEIGC_H_
  16. #define __MISSILEIGC_H_
  17. #include "modelIGC.h"
  18. class CmissileIGC : public TmodelIGC<ImissileIGC>
  19. {
  20. public:
  21. CmissileIGC(void);
  22. ~CmissileIGC(void);
  23. public:
  24. // IbaseIGC
  25. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize);
  26. virtual void Terminate(void);
  27. virtual void Update(Time now);
  28. virtual ObjectType GetObjectType(void) const
  29. {
  30. return OT_missile;
  31. }
  32. virtual ObjectID GetObjectID(void) const
  33. {
  34. return m_missileID;
  35. }
  36. // ImodelIGC
  37. virtual void SetCluster(IclusterIGC* cluster)
  38. {
  39. AddRef();
  40. {
  41. IclusterIGC* c = GetCluster();
  42. if (c)
  43. c->DeleteMissile(this);
  44. }
  45. TmodelIGC<ImissileIGC>::SetCluster(cluster);
  46. if (cluster)
  47. cluster->AddMissile(this);
  48. Release();
  49. }
  50. virtual void HandleCollision(Time timeCollision,
  51. float tCollision,
  52. const CollisionEntry& entry,
  53. ImodelIGC* pModel);
  54. /*
  55. virtual void SetSide(IsideIGC* pside) //override the default SetSide method
  56. {
  57. TmodelIGC<ImissileIGC>::SetSide(pside);
  58. if (pside)
  59. GetThingSite()->SetTrailColor(pside->GetColor());
  60. }
  61. */
  62. // IdamageIGC
  63. virtual DamageResult ReceiveDamage(DamageTypeID type,
  64. float amount,
  65. Time timeCollision,
  66. const Vector& position1,
  67. const Vector& position2,
  68. ImodelIGC* launcher)
  69. {
  70. DamageResult dr = c_drHullDamage;
  71. amount *= GetMyMission()->GetDamageConstant(type, m_missileType->GetDefenseType());
  72. float maxHP = m_missileType->GetHitPoints();
  73. if (amount < 0.0f)
  74. {
  75. if (maxHP > 0.0f)
  76. {
  77. m_fraction -= amount / maxHP;
  78. if (m_fraction > 1.0f)
  79. m_fraction = 1.0f;
  80. }
  81. }
  82. else if (amount != 0.0)
  83. {
  84. float oldFraction = m_fraction;
  85. m_fraction = (maxHP > 0.0f) ? (m_fraction - amount / maxHP) : 0.0f;
  86. if (m_fraction <= 0.0f)
  87. {
  88. m_fraction = 0.0f;
  89. if (oldFraction > 0.0f)
  90. {
  91. GetMyMission()->GetIgcSite()->KillMissileEvent(this, position1);
  92. dr = c_drKilled;
  93. }
  94. }
  95. }
  96. return dr;
  97. }
  98. virtual float GetFraction(void) const
  99. {
  100. return m_fraction;
  101. }
  102. virtual void SetFraction(float newVal)
  103. {
  104. m_fraction = newVal;
  105. }
  106. virtual float GetHitPoints(void) const
  107. {
  108. return m_fraction * m_missileType->GetHitPoints();
  109. }
  110. // ImissileIGC
  111. virtual ImissileTypeIGC* GetMissileType(void) const
  112. {
  113. return m_missileType;
  114. }
  115. virtual IshipIGC* GetLauncher(void) const
  116. {
  117. return m_launcher;
  118. }
  119. virtual ImodelIGC* GetTarget(void) const
  120. {
  121. return m_target;
  122. }
  123. virtual void SetTarget(ImodelIGC* newVal)
  124. {
  125. if (m_target)
  126. m_target->Release();
  127. m_target = newVal;
  128. if (newVal)
  129. newVal->AddRef();
  130. m_lock = 1.0f;
  131. //Assume m_tImpact does not change (not unreasonable given that the only reason to call SetTarget
  132. //is when the missile is spoofed and then the chaff is on top of the target.
  133. }
  134. virtual float GetLock(void) const
  135. {
  136. return m_lock;
  137. }
  138. virtual void Explode(const Vector& position);
  139. virtual void Disarm(void)
  140. {
  141. m_bDisarmed = true;
  142. if (m_launcher->GetLastMissileFired() == this)
  143. m_launcher->SetLastMissileFired(NULL);
  144. }
  145. private:
  146. ImissileTypeIGC* m_missileType;
  147. IshipIGC* m_launcher;
  148. ImodelIGC* m_target;
  149. Time m_timeActivate;
  150. Time m_timeExpire;
  151. float m_tImpact; //current estimated time of impact
  152. float m_fraction;
  153. float m_lock;
  154. MissileID m_missileID;
  155. Vector m_explodePosition;
  156. bool m_bDisarmed;
  157. };
  158. #endif //__MISSILEIGC_H_