claymoremine.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. class ClaymoreMine : ExplosivesBase
  2. {
  3. protected const string ANIM_PHASE_PACKED = "Bag";
  4. protected const string ANIM_PHASE_DEPLOYED = "Mine";
  5. protected const string SELECTION_NAME_LED = "LED";
  6. protected ref RemotelyActivatedItemBehaviour m_RAIB;
  7. protected ERemoteDetonatorLEDState m_LastLEDState;
  8. void ClaymoreMine()
  9. {
  10. m_RAIB = new RemotelyActivatedItemBehaviour(this);
  11. SetAmmoTypes({"ClaymoreMine_Ammo","ClaymoreMine_Secondary_Ammo"});
  12. SetParticleExplosion(ParticleList.CLAYMORE_EXPLOSION);
  13. SetParticleOrientation("90 0 0");
  14. RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdLow");
  15. RegisterNetSyncVariableInt("m_RAIB.m_PairDeviceNetIdHigh");
  16. UpdateLED(ERemoteDetonatorLEDState.OFF, true);
  17. }
  18. override void EOnInit(IEntity other, int extra)
  19. {
  20. UpdateVisuals();
  21. }
  22. override void EEKilled(Object killer)
  23. {
  24. super.EEKilled(killer);
  25. #ifdef DIAG_DEVELOPER
  26. #ifndef SERVER
  27. RemoveDebugVisuals();
  28. #endif
  29. #endif
  30. }
  31. override void EEDelete(EntityAI parent)
  32. {
  33. super.EEDelete(parent);
  34. #ifdef DIAG_DEVELOPER
  35. #ifndef SERVER
  36. RemoveDebugVisuals();
  37. #endif
  38. #endif
  39. }
  40. override protected void InitiateExplosion()
  41. {
  42. if (GetDefused())
  43. {
  44. return;
  45. }
  46. super.InitiateExplosion();
  47. }
  48. override void AfterStoreLoad()
  49. {
  50. super.AfterStoreLoad();
  51. UpdateVisuals();
  52. if (GetArmed())
  53. {
  54. UpdateLED(ERemoteDetonatorLEDState.LIT, true);
  55. }
  56. }
  57. override void OnVariablesSynchronized()
  58. {
  59. super.OnVariablesSynchronized();
  60. if (m_RAIB)
  61. {
  62. m_RAIB.OnVariableSynchronized();
  63. }
  64. UpdateVisuals();
  65. }
  66. override void EEItemLocationChanged(notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
  67. {
  68. super.EEItemLocationChanged(oldLoc, newLoc);
  69. if (m_RAIB)
  70. {
  71. m_RAIB.Pair();
  72. }
  73. }
  74. override RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour()
  75. {
  76. return m_RAIB;
  77. }
  78. override void PairRemote(notnull EntityAI trigger)
  79. {
  80. m_RAIB.Pair(trigger);
  81. }
  82. override EntityAI GetPairDevice()
  83. {
  84. return m_RAIB.GetPairDevice();
  85. }
  86. override bool CanBeDisarmed()
  87. {
  88. return GetArmed();
  89. }
  90. override void OnActivatedByItem(notnull ItemBase item)
  91. {
  92. if (GetGame().IsServer())
  93. {
  94. if (m_RAIB.IsPaired() && GetArmed())
  95. {
  96. if (GetPairDevice() == item)
  97. {
  98. SetHealth("", "", 0.0);
  99. }
  100. }
  101. }
  102. }
  103. override void OnArmed()
  104. {
  105. super.OnArmed();
  106. UpdateVisuals();
  107. UpdateLED(ERemoteDetonatorLEDState.LIT, true);
  108. #ifdef DIAG_DEVELOPER
  109. #ifndef SERVER
  110. // have to call this function a little later, after claymore transform has been finalized
  111. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(DrawDamageZone, 500);
  112. #endif
  113. #endif
  114. }
  115. override void OnDisarmed(bool pWithTool)
  116. {
  117. super.OnDisarmed(pWithTool);
  118. #ifdef DIAG_DEVELOPER
  119. RemoveDebugVisuals();
  120. #endif
  121. SetDefused(pWithTool);
  122. UnpairRemote();
  123. if (pWithTool)
  124. {
  125. SetHealth("", "", 0.0);
  126. }
  127. UpdateVisuals();
  128. UpdateLED(ERemoteDetonatorLEDState.OFF, true);
  129. }
  130. override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
  131. {
  132. super.OnPlacementComplete(player, position, orientation);
  133. if (GetGame().IsServer())
  134. {
  135. RemoteDetonatorTrigger rdt = RemoteDetonatorTrigger.SpawnInPlayerHands(player);
  136. if (rdt)
  137. {
  138. PairWithDevice(rdt);
  139. Arm();
  140. }
  141. }
  142. }
  143. protected void UpdateVisuals()
  144. {
  145. if (GetArmed() || GetDefused())
  146. {
  147. ShowSelection(ANIM_PHASE_DEPLOYED);
  148. HideSelection(ANIM_PHASE_PACKED);
  149. if (GetOnViewIndexChanged())
  150. {
  151. GetOnViewIndexChanged().Invoke();
  152. }
  153. }
  154. else
  155. {
  156. HideSelection(ANIM_PHASE_DEPLOYED);
  157. ShowSelection(ANIM_PHASE_PACKED);
  158. if (GetOnViewIndexChanged())
  159. {
  160. GetOnViewIndexChanged().Invoke();
  161. }
  162. }
  163. }
  164. protected void UpdateLED(ERemoteDetonatorLEDState pState, bool pForced = false)
  165. {
  166. if (pState != m_LastLEDState || pForced)
  167. {
  168. int selectionIdx = GetHiddenSelectionIndex(SELECTION_NAME_LED);
  169. switch (pState)
  170. {
  171. case ERemoteDetonatorLEDState.LIT:
  172. SetObjectTexture(selectionIdx, RemoteDetonator.COLOR_LED_LIT);
  173. break;
  174. default:
  175. SetObjectTexture(selectionIdx, RemoteDetonator.COLOR_LED_OFF);
  176. break;
  177. }
  178. m_LastLEDState = pState;
  179. }
  180. }
  181. override bool IsTakeable()
  182. {
  183. return !GetArmed() && super.IsTakeable();
  184. }
  185. override bool IsDeployable()
  186. {
  187. return true;
  188. }
  189. override void SetActions()
  190. {
  191. super.SetActions();
  192. AddAction(ActionTogglePlaceObject);
  193. AddAction(ActionDeployObject);
  194. AddAction(ActionArmExplosive);
  195. }
  196. override int GetViewIndex()
  197. {
  198. if (MemoryPointExists("invView2"))
  199. {
  200. if (GetArmed())
  201. {
  202. return 1;
  203. }
  204. }
  205. return 0;
  206. }
  207. override string GetDeploySoundset()
  208. {
  209. return "placeClaymore_SoundSet";
  210. }
  211. override string GetLoopDeploySoundset()
  212. {
  213. return "claymore_deploy_Soundset";
  214. }
  215. override string GetArmSoundset()
  216. {
  217. return "claymore_deploy_Soundset";
  218. }
  219. override string GetDisarmSoundset()
  220. {
  221. return "claymore_disarm_SoundSet";
  222. }
  223. override void OnDebugSpawn()
  224. {
  225. RemoteDetonatorTrigger rdt = RemoteDetonatorTrigger.Cast(SpawnEntityOnGroundPos("RemoteDetonatorTrigger", GetPosition() + GetDirection() * 0.5));
  226. PairWithDevice(rdt);
  227. Arm();
  228. }
  229. #ifdef DIAG_DEVELOPER
  230. //================================================================
  231. // DEBUG
  232. //================================================================
  233. protected Shape m_DamageZone;
  234. override protected string GetDebugText()
  235. {
  236. string debug_output;
  237. debug_output += string.Format("low net id: %1\n", m_RAIB.GetPairDeviceNetIdLow());
  238. debug_output += string.Format("high net id: %1\n", m_RAIB.GetPairDeviceNetIdHigh());
  239. debug_output += string.Format("pair device: %1\n", m_RAIB.GetPairDevice());
  240. return debug_output;
  241. }
  242. protected void DrawDamageZone()
  243. {
  244. if (!DiagMenu.GetBool(DiagMenuIDs.WEAPON_CLAYMORE_DEBUG))
  245. {
  246. return;
  247. }
  248. auto game = GetGame();
  249. string cfgPath = "CfgAmmo " + m_AmmoTypes[0];
  250. float hitRange = game.ConfigGetFloat(cfgPath + " indirectHitRange");
  251. float hitRangeMultiplier = game.ConfigGetFloat(cfgPath + " indirectHitRangeMultiplier");
  252. float verticalAngle = game.ConfigGetFloat(cfgPath + " indirectHitAngle1");
  253. float horizontalAngle = game.ConfigGetFloat(cfgPath + " indirectHitAngle2");
  254. float range = hitRange * hitRangeMultiplier;
  255. vector selfMatrix[4];
  256. RemoveDebugVisuals();
  257. GetTransform(selfMatrix);
  258. m_DamageZone = Debug.DrawFrustum(horizontalAngle, verticalAngle, range);
  259. m_DamageZone.SetMatrix(selfMatrix);
  260. }
  261. void RemoveDebugVisuals()
  262. {
  263. if ( m_DamageZone )
  264. {
  265. m_DamageZone.Destroy();
  266. m_DamageZone = null;
  267. }
  268. }
  269. #endif
  270. }
  271. class ClaymoreMinePlacing : ClaymoreMine {}