weaponIGC.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: weaponIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CweaponIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // weaponIGC.h : Declaration of the CweaponIGC
  15. #ifndef __WEAPONIGC_H_
  16. #define __WEAPONIGC_H_
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CweaponIGC
  19. class CweaponIGC : public IweaponIGC
  20. {
  21. public:
  22. CweaponIGC(void);
  23. // IbaseIGC
  24. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize);
  25. virtual void Terminate(void);
  26. virtual void Update(Time now)
  27. {
  28. if (m_mountedFraction < 1.0f)
  29. {
  30. float dt = now - m_ship->GetLastUpdate();
  31. m_mountedFraction += dt * m_pMission->GetFloatConstant(c_fcidMountRate);
  32. if (m_mountedFraction < 1.0f)
  33. {
  34. m_fFiringShot = false;
  35. m_fFiringBurst = false;
  36. return;
  37. }
  38. IIgcSite* pigc = GetMission()->GetIgcSite();
  39. pigc->PlayNotificationSound(mountedSound, m_ship);
  40. pigc->PostNotificationText(m_ship, false, "%s ready.", GetPartType()->GetName());
  41. m_mountedFraction = 1.0f;
  42. }
  43. if ((!m_fActive) && fIsWeaponSelected())
  44. Activate();
  45. if (m_fActive)
  46. {
  47. FireWeapon(now);
  48. }
  49. else
  50. {
  51. m_fFiringShot = false;
  52. m_fFiringBurst = false;
  53. }
  54. }
  55. virtual ObjectType GetObjectType(void) const
  56. {
  57. return OT_weapon;
  58. }
  59. virtual ImissionIGC* GetMission(void) const
  60. {
  61. return m_pMission;
  62. }
  63. // IpartIGC
  64. virtual EquipmentType GetEquipmentType(void) const
  65. {
  66. return ET_Weapon;
  67. }
  68. virtual IpartTypeIGC* GetPartType(void) const
  69. {
  70. return m_partType;
  71. }
  72. virtual IshipIGC* GetShip(void) const
  73. {
  74. return m_ship;
  75. }
  76. virtual void SetShip(IshipIGC* newVal, Mount mount);
  77. virtual Mount GetMountID(void) const
  78. {
  79. return m_mountID;
  80. }
  81. virtual void SetMountID(Mount newVal);
  82. virtual bool fActive(void) const
  83. {
  84. return m_fActive;
  85. }
  86. virtual void Activate(void)
  87. {
  88. assert (m_ship);
  89. if (!m_fActive)
  90. {
  91. m_ship->ChangeSignature(m_typeData->signature);
  92. m_nextFire = m_ship->GetLastUpdate() + m_typeData->dtimeBurst;
  93. m_fActive = true;
  94. }
  95. }
  96. virtual void Deactivate(void)
  97. {
  98. assert (m_ship);
  99. if (m_fActive)
  100. {
  101. m_ship->ChangeSignature(-m_typeData->signature);
  102. m_fActive = false;
  103. }
  104. m_fFiringBurst = false;
  105. m_fFiringShot = false; // REVIEW: this may lead to a silent shot
  106. }
  107. virtual float GetMass(void) const
  108. {
  109. return m_typeData->mass;
  110. }
  111. virtual Money GetPrice(void) const
  112. {
  113. return m_typeData->price;
  114. }
  115. virtual float GetMountedFraction(void) const
  116. {
  117. return m_mountedFraction;
  118. }
  119. virtual void SetMountedFraction(float f)
  120. {
  121. m_mountedFraction = f;
  122. }
  123. virtual void Arm(void)
  124. {
  125. m_mountedFraction = 1.0f;
  126. m_nextFire = m_ship->GetLastUpdate();
  127. }
  128. // IweaponIGC
  129. virtual IprojectileTypeIGC* GetProjectileType(void) const
  130. {
  131. return m_projectileType;
  132. }
  133. virtual short GetAmmoPerShot(void) const
  134. {
  135. return m_typeData->cAmmoPerShot;
  136. }
  137. virtual float GetLifespan(void) const
  138. {
  139. float ls = m_projectileType->GetLifespan();
  140. if (m_ship && (m_typeData->energyPerShot != 0.0f))
  141. ls *= m_ship->GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaLifespanEnergy);
  142. return ls;
  143. }
  144. virtual const Vector& GetPosition(void) const
  145. {
  146. return *m_pposition;
  147. }
  148. virtual float GetDtBurst(void) const
  149. {
  150. return m_typeData->dtimeBurst;
  151. }
  152. virtual void SetGunner(IshipIGC* pship)
  153. {
  154. Deactivate();
  155. if (m_pshipGunner)
  156. m_pshipGunner->Release();
  157. m_pshipGunner = pship;
  158. if (pship)
  159. {
  160. assert (m_ship);
  161. assert (pship->GetParentShip() == m_ship);
  162. pship->AddRef();
  163. assert (m_mountID >= 0);
  164. assert (pship->GetParentShip());
  165. assert (pship->GetParentShip()->GetHullType()->GetHardpointData(m_mountID).bFixed == false);
  166. }
  167. }
  168. virtual IshipIGC* GetGunner(void) const
  169. {
  170. return m_pshipGunner;
  171. }
  172. virtual bool fFiringShot(void) const
  173. {
  174. return m_fFiringShot;
  175. }
  176. virtual bool fFiringBurst(void) const
  177. {
  178. return m_fFiringBurst;
  179. }
  180. virtual SoundID GetActivateSound(void) const
  181. {
  182. return m_typeData->activateSound;
  183. }
  184. virtual SoundID GetSingleShotSound(void) const
  185. {
  186. return m_typeData->singleShotSound;
  187. }
  188. virtual SoundID GetBurstSound(void) const
  189. {
  190. return m_typeData->burstSound;
  191. }
  192. private:
  193. bool fIsWeaponSelected(void) const
  194. {
  195. bool fSelected;
  196. if (m_ship->GetHullType()->GetHardpointData(m_mountID).bFixed)
  197. {
  198. int stateM = m_ship->GetStateM();
  199. fSelected = ((stateM & allWeaponsIGC) ||
  200. ((stateM & oneWeaponIGC) &&
  201. (m_mountID == ((stateM & selectedWeaponMaskIGC) >> selectedWeaponShiftIGC)))) &&
  202. (m_ship->GetRipcordModel() == NULL);
  203. }
  204. else
  205. {
  206. fSelected = m_pshipGunner && (m_pshipGunner->GetStateM() & weaponsMaskIGC);
  207. }
  208. return fSelected;
  209. }
  210. void FireWeapon(Time now);
  211. ImissionIGC* m_pMission;
  212. IshipIGC* m_pshipGunner;
  213. const DataWeaponTypeIGC* m_typeData;
  214. IpartTypeIGC* m_partType;
  215. IshipIGC* m_ship;
  216. IprojectileTypeIGC* m_projectileType;
  217. Time m_nextFire;
  218. const Vector* m_pposition;
  219. const Orientation* m_porientation;
  220. float m_mountedFraction;
  221. Mount m_mountID;
  222. bool m_fActive;
  223. bool m_fFiringShot;
  224. bool m_fFiringBurst;
  225. };
  226. #endif //__WEAPONIGC_H_