ammunitionpiles.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //!ammo pile base
  2. class Ammunition_Base: Magazine_Base
  3. {
  4. static ref map<string, float> m_AmmoWeightByBulletType = new map<string, float>();
  5. static float GetAmmoWeightByBulletType(string bulletType)
  6. {
  7. if (m_AmmoWeightByBulletType.Contains(bulletType))
  8. {
  9. return m_AmmoWeightByBulletType.Get(bulletType);
  10. }
  11. else
  12. {
  13. float ammoWeight;
  14. string ammoTypeName;
  15. GetGame().ConfigGetText( string.Format("CfgAmmo %1 spawnPileType", bulletType) , ammoTypeName);
  16. if (ammoTypeName)
  17. ammoWeight = GetGame().ConfigGetFloat(string.Format("CfgMagazines %1 weight", ammoTypeName));
  18. else
  19. ErrorEx("empty 'spawnPileType' for bullet type:" + bulletType);
  20. if (ammoWeight)
  21. m_AmmoWeightByBulletType.Insert(bulletType, ammoWeight);
  22. return ammoWeight;
  23. }
  24. }
  25. override bool IsAmmoPile()
  26. {
  27. return true;
  28. }
  29. override protected float GetWeightSpecialized(bool forceRecalc = false)
  30. {
  31. #ifdef DEVELOPER
  32. if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
  33. {
  34. WeightDebugData data = WeightDebug.GetWeightDebug(this);
  35. data.SetCalcDetails("TAmmo: ("+GetAmmoCount()+"(Ammo count) * "+ GetConfigWeightModifiedDebugText());
  36. }
  37. #endif
  38. return GetAmmoCount() * GetConfigWeightModified();
  39. }
  40. override void SetQuantityToMinimum()
  41. {
  42. ServerSetAmmoCount(1);
  43. }
  44. override void SetFromProjectile(ProjectileStoppedInfo info)
  45. {
  46. float dmgPerUse = GetGame().ConfigGetFloat("cfgAmmo " + info.GetAmmoType() + " dmgPerUse");
  47. float totalDmg = info.GetProjectileDamage() + dmgPerUse;
  48. float health = Math.Max(1 - totalDmg, 0);
  49. SetQuantityToMinimum();
  50. SetHealth01("","", health);
  51. // SetCartridgeDamageAtIndex() MUST be called AFTER SetHealth01()!!
  52. // otherwise, decreasing health by less than an entire health level get ignored
  53. SetCartridgeDamageAtIndex(0, totalDmg);
  54. }
  55. };
  56. class Ammo_45ACP: Ammunition_Base {};
  57. class Ammo_308Win: Ammunition_Base {};
  58. class Ammo_308WinTracer: Ammunition_Base {};
  59. class Ammo_9x19: Ammunition_Base {};
  60. class Ammo_380: Ammunition_Base {};
  61. class Ammo_556x45: Ammunition_Base {};
  62. class Ammo_556x45Tracer: Ammunition_Base {};
  63. class Ammo_762x54: Ammunition_Base {};
  64. class Ammo_762x54Tracer: Ammunition_Base {};
  65. class Ammo_762x39: Ammunition_Base {};
  66. class Ammo_762x39Tracer: Ammunition_Base {};
  67. class Ammo_9x39: Ammunition_Base {};
  68. class Ammo_22: Ammunition_Base {};
  69. class Ammo_12gaPellets: Ammunition_Base {};
  70. class Ammo_12gaSlug: Ammunition_Base {};
  71. class Ammo_357: Ammunition_Base {};
  72. class Ammo_545x39: Ammunition_Base {};
  73. class Ammo_545x39Tracer: Ammunition_Base {};
  74. class Bolt_Base: Ammunition_Base
  75. {
  76. override bool IsInventoryVisible()
  77. {
  78. //! omitted super call is intended
  79. return CanBeActionTarget();
  80. }
  81. override bool CanBeActionTarget()
  82. {
  83. if (super.CanBeActionTarget())
  84. {
  85. EntityAI parent = EntityAI.Cast(GetParent());
  86. if (parent)
  87. {
  88. return !parent.IsManagingArrows();
  89. }
  90. }
  91. return true;
  92. }
  93. override void EEParentedTo(EntityAI parent)
  94. {
  95. if (!parent)
  96. return;
  97. ArrowManagerBase arrowManager = parent.GetArrowManager();
  98. if (arrowManager)
  99. {
  100. arrowManager.AddArrow(this);
  101. }
  102. }
  103. override void EEParentedFrom(EntityAI parent)
  104. {
  105. if (!parent)
  106. return;
  107. ArrowManagerBase arrowManager = parent.GetArrowManager();
  108. if (arrowManager)
  109. {
  110. arrowManager.RemoveArrow(this);
  111. }
  112. }
  113. }
  114. class Ammo_DartSyringe: Ammunition_Base {};
  115. class Ammo_Flare: Ammunition_Base {};
  116. class Ammo_RPG7_HE: Ammunition_Base {};
  117. class Ammo_RPG7_AP: Ammunition_Base {};
  118. class Ammo_LAW_HE: Ammunition_Base {};
  119. class Ammo_GrenadeM4 : Ammunition_Base {};
  120. //bolts
  121. class Ammo_HuntingBolt : Bolt_Base {}
  122. class Ammo_ImprovisedBolt_1 : Bolt_Base
  123. {
  124. override void SetActions()
  125. {
  126. super.SetActions();
  127. AddAction(ActionCraftBoltsFeather);
  128. }
  129. }
  130. class Ammo_ImprovisedBolt_2 : Bolt_Base {}
  131. class Ammo_CupidsBolt : Bolt_Base
  132. {
  133. override void EEParentedTo(EntityAI parent)
  134. {
  135. Delete();
  136. }
  137. override void EEParentedFrom(EntityAI parent);
  138. static void PlayOnHitParticle(vector position)
  139. {
  140. ParticleManager.GetInstance().PlayInWorld(ParticleList.BOLT_CUPID_HIT, position);
  141. }
  142. }
  143. // 40mm
  144. class Ammo_40mm_Base: Ammunition_Base
  145. {
  146. override bool IsTakeable()
  147. {
  148. return GetAnimationPhase("Visibility") == 0;
  149. }
  150. override bool IsInventoryVisible()
  151. {
  152. if (!super.IsInventoryVisible())
  153. {
  154. return false;
  155. }
  156. return IsTakeable();
  157. }
  158. };
  159. class Ammo_40mm_Explosive: Ammo_40mm_Base
  160. {
  161. override bool ShootsExplosiveAmmo()
  162. {
  163. return true;
  164. }
  165. override void OnActivatedByItem(notnull ItemBase item)
  166. {
  167. if (GetGame().IsServer())
  168. {
  169. DamageSystem.ExplosionDamage(this, null, "Explosion_40mm_Ammo", item.GetPosition(), DamageType.EXPLOSION);
  170. }
  171. }
  172. override void EEKilled(Object killer)
  173. {
  174. super.EEKilled(killer);
  175. DamageSystem.ExplosionDamage(this, null, "Explosion_40mm_Ammo", GetPosition(), DamageType.EXPLOSION);
  176. GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( DeleteSafe, 1000, false);
  177. }
  178. override void OnDamageDestroyed(int oldLevel)
  179. {
  180. super.OnDamageDestroyed(oldLevel);
  181. #ifndef SERVER
  182. ClearFlags(EntityFlags.VISIBLE, false);
  183. #endif
  184. }
  185. }
  186. //class Ammo_40mm_Grenade_Gas: Ammo_40mm_Base {};
  187. class Ammo_40mm_ChemGas: Ammo_40mm_Base
  188. {
  189. override void OnActivatedByItem(notnull ItemBase item)
  190. {
  191. if (GetGame().IsServer())
  192. {
  193. GetGame().CreateObject("ContaminatedArea_Local", item.GetPosition());
  194. }
  195. }
  196. override void EEKilled(Object killer)
  197. {
  198. super.EEKilled(killer);
  199. GetGame().CreateObject("ContaminatedArea_Local", GetPosition());
  200. GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( DeleteSafe, 1000, false);
  201. }
  202. override void OnDamageDestroyed(int oldLevel)
  203. {
  204. super.OnDamageDestroyed(oldLevel);
  205. #ifndef SERVER
  206. ClearFlags(EntityFlags.VISIBLE, false);
  207. ParticleManager.GetInstance().PlayInWorld(ParticleList.GRENADE_CHEM_BREAK, GetPosition());
  208. #endif
  209. }
  210. }
  211. class Ammo_40mm_Smoke_ColorBase: Ammo_40mm_Base
  212. {
  213. protected Particle m_ParticleSmoke;
  214. protected float m_ParticleLifetime;
  215. protected int m_ParticleId;
  216. protected bool m_Activated;
  217. void Ammo_40mm_Smoke_ColorBase()
  218. {
  219. RegisterNetSyncVariableBool("m_Activated");
  220. }
  221. override void OnVariablesSynchronized()
  222. {
  223. super.OnVariablesSynchronized();
  224. if (m_Activated)
  225. {
  226. #ifndef SERVER
  227. string particleStrIdentifier = GetGame().ConfigGetTextOut(string.Format("CfgMagazines %1 particleStrIdentifier", GetType()));
  228. m_ParticleId = ParticleList.GetParticleIDByName(particleStrIdentifier);
  229. if (m_ParticleId > 0)
  230. {
  231. m_ParticleSmoke = ParticleManager.GetInstance().PlayOnObject(m_ParticleId, this);
  232. m_ParticleSmoke.SetWiggle(7, 0.3);
  233. }
  234. #endif
  235. }
  236. }
  237. protected void Activate()
  238. {
  239. m_ParticleLifetime = GetGame().ConfigGetFloat(string.Format("CfgMagazines %1 particleLifeTime", GetType()));
  240. m_Activated = true;
  241. SetSynchDirty();
  242. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(DeleteSafe, m_ParticleLifetime * 1000);
  243. }
  244. //! special behaviour - do not call super
  245. override void EEKilled(Object killer)
  246. {
  247. //analytics (behaviour from EntityAI)
  248. GetGame().GetAnalyticsServer().OnEntityKilled(killer, this);
  249. }
  250. override void EEDelete(EntityAI parent)
  251. {
  252. #ifndef SERVER
  253. if (m_ParticleSmoke)
  254. {
  255. m_ParticleSmoke.Stop();
  256. }
  257. #endif
  258. super.EEDelete(parent);
  259. }
  260. override bool CanPutInCargo( EntityAI parent )
  261. {
  262. return !m_Activated;
  263. }
  264. override void OnActivatedByItem(notnull ItemBase item)
  265. {
  266. SetHealth("", "", 0.0);
  267. Activate();
  268. }
  269. }
  270. class Ammo_40mm_Smoke_Red: Ammo_40mm_Smoke_ColorBase {};
  271. class Ammo_40mm_Smoke_Green: Ammo_40mm_Smoke_ColorBase {};
  272. class Ammo_40mm_Smoke_White: Ammo_40mm_Smoke_ColorBase {};
  273. class Ammo_40mm_Smoke_Black: Ammo_40mm_Smoke_ColorBase {};