probeigc.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: probeIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CprobeIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // probeIGC.h : Declaration of the CprobeIGC
  15. #ifndef __PROBEIGC_H_
  16. #define __PROBEIGC_H_
  17. #include "modelIGC.h"
  18. class CprobeIGC : public TmodelIGC<IprobeIGC>
  19. {
  20. public:
  21. CprobeIGC(void);
  22. ~CprobeIGC(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 int Export(void* data) const;
  29. virtual ObjectType GetObjectType(void) const
  30. {
  31. return OT_probe;
  32. }
  33. virtual ObjectID GetObjectID(void) const
  34. {
  35. return m_probeID;
  36. }
  37. // ImodelIGC
  38. virtual void SetCluster(IclusterIGC* cluster)
  39. {
  40. AddRef();
  41. {
  42. IclusterIGC* c = GetCluster();
  43. if (c)
  44. c->DeleteProbe(this);
  45. }
  46. TmodelIGC<IprobeIGC>::SetCluster(cluster);
  47. if (cluster)
  48. cluster->AddProbe(this);
  49. Release();
  50. }
  51. // IdamageIGC
  52. virtual DamageResult ReceiveDamage(DamageTypeID type,
  53. float amount,
  54. Time timeCollision,
  55. const Vector& position1,
  56. const Vector& position2,
  57. ImodelIGC* launcher)
  58. {
  59. IsideIGC* pside = GetSide();
  60. if (launcher &&
  61. (!GetMyMission()->GetMissionParams()->bAllowFriendlyFire) &&
  62. (pside == launcher->GetSide()) &&
  63. (amount >= 0.0f) &&
  64. !m_probeType->HasCapability(c_eabmRescueAny))
  65. {
  66. return c_drNoDamage;
  67. }
  68. DamageResult dr = c_drHullDamage;
  69. float oldFraction = m_fraction;
  70. float maxHP = m_probeType->GetHitPoints();
  71. amount *= GetMyMission()->GetDamageConstant(type, m_probeType->GetDefenseType());
  72. if (amount < 0.0f)
  73. {
  74. if (maxHP > 0.0f)
  75. {
  76. m_fraction -= amount / maxHP;
  77. if (m_fraction > 1.0f)
  78. m_fraction = 1.0f;
  79. GetThingSite ()->RemoveDamage (m_fraction);
  80. }
  81. }
  82. else if (amount > 0.0f)
  83. {
  84. if (launcher && (launcher->GetObjectType() == OT_ship))
  85. amount *= ((IshipIGC*)launcher)->GetExperienceMultiplier();
  86. m_fraction = maxHP > 0.0f ? (m_fraction - amount / maxHP) : 0.0f;
  87. if (m_fraction <= 0.0f)
  88. {
  89. m_fraction = 0.0f;
  90. if (oldFraction > 0.0f)
  91. {
  92. GetMyMission()->GetIgcSite()->KillProbeEvent(this);
  93. dr = c_drKilled;
  94. }
  95. }
  96. else if ((type & c_dmgidNoDebris) == 0)
  97. GetThingSite ()->AddDamage (position2 - position1, m_fraction);
  98. }
  99. return dr;
  100. }
  101. virtual float GetFraction(void) const
  102. {
  103. return m_fraction;
  104. }
  105. virtual void SetFraction(float newVal)
  106. {
  107. m_fraction = newVal;
  108. }
  109. virtual float GetHitPoints(void) const
  110. {
  111. return m_fraction * m_probeType->GetHitPoints();
  112. }
  113. // IscannerIGC
  114. bool InScannerRange(ImodelIGC* pModel) const
  115. {
  116. assert (pModel);
  117. bool rc;
  118. IclusterIGC* pcluster = GetCluster();
  119. if (pModel->GetCluster() == pcluster)
  120. {
  121. if (pModel->GetFlag() == NA)
  122. {
  123. float m = m_probeType->GetScannerRange() * pModel->GetSignature() * GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaScanRange);
  124. {
  125. IsideIGC* pside = pModel->GetSide();
  126. if (pside)
  127. m /= pside->GetGlobalAttributeSet().GetAttribute(c_gaSignature);
  128. }
  129. float r = GetRadius() + pModel->GetRadius() + m;
  130. rc = ((GetPosition() - pModel->GetPosition()).LengthSquared() <= r * r) &&
  131. LineOfSightExist(pcluster, this, pModel);
  132. }
  133. else
  134. rc = true;
  135. }
  136. else
  137. rc = false;
  138. return rc;
  139. }
  140. bool CanSee(ImodelIGC* pModel) const
  141. {
  142. assert (pModel);
  143. IsideIGC* side = GetSide();
  144. return (pModel->GetSide() == side) || //Always see things on our side
  145. pModel->SeenBySide(side) ||
  146. InScannerRange(pModel); //or we can see it ourselves
  147. }
  148. //IprobeIGC
  149. virtual IprobeTypeIGC* GetProbeType(void) const
  150. {
  151. return m_probeType;
  152. }
  153. virtual IprojectileTypeIGC* GetProjectileType(void) const
  154. {
  155. return m_projectileType;
  156. }
  157. virtual const Vector& GetEmissionPt(void) const
  158. {
  159. return m_probeType->GetEmissionPt();
  160. }
  161. virtual float GetProjectileLifespan(void) const
  162. {
  163. float ls;
  164. if (m_projectileType)
  165. {
  166. ls = m_projectileType->GetLifespan();
  167. if (m_ammo == 0)
  168. ls *= GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaLifespanEnergy);
  169. }
  170. else
  171. ls = 0.0f;
  172. return ls;
  173. }
  174. virtual float GetLifespan(void) const
  175. {
  176. return m_probeType->GetLifespan();
  177. }
  178. virtual float GetDtBurst(void) const
  179. {
  180. return m_probeType->GetDtBurst();
  181. }
  182. virtual float GetAccuracy(void) const
  183. {
  184. return m_probeType->GetAccuracy();
  185. }
  186. virtual bool GetCanRipcord(float ripcordSpeed) const
  187. {
  188. float dt = m_probeType->GetRipcordDelay();
  189. return (dt >= 0.0f) &&
  190. ((GetMyLastUpdate() - m_time0) >= dt) &&
  191. ((GetMyLastUpdate() + (ripcordSpeed + 1.0f)) <= m_timeExpire);
  192. }
  193. virtual float GetRipcordDelay(void) const
  194. {
  195. return m_probeType->GetRipcordDelay();
  196. }
  197. virtual SoundID GetAmbientSound(void) const
  198. {
  199. return m_probeType->GetAmbientSound();
  200. }
  201. virtual void SetCreateNow (void)
  202. {
  203. m_bCreateNow = true;
  204. }
  205. virtual float GetTimeFraction(void) const
  206. {
  207. Time timeNow = GetMyLastUpdate();
  208. float f = (m_timeExpire - timeNow) / (m_timeExpire - m_time0);
  209. if (f < 0.0f)
  210. f = 0.0f;
  211. else if (f > 1.0f)
  212. f = 1.0f;
  213. return f;
  214. }
  215. private:
  216. void ValidTarget(ImodelIGC* pmodel,
  217. IsideIGC* pside,
  218. const Vector& myPosition,
  219. float dtUpdate,
  220. float accuracy,
  221. float speed,
  222. float lifespan,
  223. ObjectType type,
  224. ImodelIGC** ppmodelMin,
  225. float* pdistance2Min,
  226. Vector* pdirectionMin);
  227. void GetTarget(const ModelListIGC* models,
  228. IsideIGC* pside,
  229. const Vector& myPosition,
  230. float dtUpdate,
  231. float accuracy,
  232. float speed,
  233. float lifespan,
  234. ObjectType type,
  235. ImodelIGC** ppmodelMin,
  236. float* pdistance2Min,
  237. Vector* pdirectionMin);
  238. ImissionIGC* m_pMission;
  239. IprobeTypeIGC* m_probeType;
  240. IprojectileTypeIGC* m_projectileType;
  241. TRef<IshipIGC> m_launcher;
  242. TRef<ImodelIGC> m_target;
  243. float m_fraction;
  244. Time m_time0;
  245. Time m_timeExpire;
  246. Time m_nextFire;
  247. short m_ammo;
  248. ProbeID m_probeID;
  249. bool m_bSeenByAll;
  250. bool m_bCreateNow;
  251. };
  252. #endif //__PROBEIGC_H_