Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.31 KB | None | 0 0
  1.         private void ApplyVolumetricExplosionOnEntities(ref MyExplosionInfo m_explosionInfo, List<MyEntity> entities, MyGridExplosion explosionDamageInfo)
  2.         {
  3.             float num = (float)explosionDamageInfo.Sphere.Radius * 2f;
  4.             float num2 = 1f / num;
  5.             float num3 = 1f / (float)explosionDamageInfo.Sphere.Radius;
  6.             HkSphereShape? hkSphereShape = null;
  7.             foreach (MyEntity myEntity in entities)
  8.             {
  9.                 float num4 = (float)myEntity.PositionComp.WorldAABB.Distance(this.m_explosionSphere.Center);
  10.                 float num5 = num4 * num2;
  11.                 if (num5 <= 1f)
  12.                 {
  13.                     float num6 = 1f - num5 * num5;
  14.                     MyAmmoBase myAmmoBase = myEntity as MyAmmoBase;
  15.                     if (myAmmoBase != null)
  16.                     {
  17.                         myAmmoBase.MarkForDestroy();
  18.                     }
  19.                     else if (myEntity.Physics != null && myEntity.Physics.Enabled && !myEntity.Physics.IsStatic && m_explosionInfo.ApplyForceAndDamage)
  20.                     {
  21.                         m_explosionInfo.StrengthImpulse = 100f * (float)this.m_explosionSphere.Radius;
  22.                         m_explosionInfo.StrengthAngularImpulse = 50000f;
  23.                         m_explosionInfo.HitEntity = ((m_explosionInfo.HitEntity != null) ? m_explosionInfo.HitEntity.GetBaseEntity() : null);
  24.                         Vector3 value;
  25.                         if (m_explosionInfo.Direction != null && m_explosionInfo.HitEntity != null && m_explosionInfo.HitEntity.GetTopMostParent(null) == myEntity)
  26.                         {
  27.                             ////////////////////////////////////////
  28.                             value = m_explosionInfo.Direction.Value;
  29.                             ////////////////////////////////////////
  30.                         }
  31.                         else
  32.                         {
  33.                             Vector3 vector = Vector3.Zero;
  34.                             MyCubeGrid myCubeGrid = myEntity as MyCubeGrid;
  35.                             if (myCubeGrid != null)
  36.                             {
  37.                                 if (hkSphereShape == null)
  38.                                 {
  39.                                     hkSphereShape = new HkSphereShape?(new HkSphereShape(num));
  40.                                 }
  41.                                 HkRigidBody rigidBody = myCubeGrid.Physics.RigidBody;
  42.                                 Matrix rigidBodyMatrix = rigidBody.GetRigidBodyMatrix();
  43.                                 Vector3 translation = rigidBodyMatrix.Translation;
  44.                                 Quaternion quaternion = Quaternion.CreateFromRotationMatrix(rigidBodyMatrix);
  45.                                 Vector3 vector2 = myCubeGrid.Physics.WorldToCluster(this.m_explosionSphere.Center);
  46.                                 using (ClearToken<HkShapeCollision> penetrationsShapeShape = MyPhysics.GetPenetrationsShapeShape(hkSphereShape.Value, ref vector2, ref Quaternion.Identity, rigidBody.GetShape(), ref translation, ref quaternion))
  47.                                 {
  48.                                     float gridSize = myCubeGrid.GridSize;
  49.                                     MyGridShape shape = myCubeGrid.Physics.Shape;
  50.                                     int num7 = Math.Min(penetrationsShapeShape.List.Count, 100);
  51.                                     BoundingSphere sphere = new BoundingSphere(Vector3D.Transform(this.m_explosionSphere.Center, myCubeGrid.PositionComp.WorldMatrixNormalizedInv) / (double)gridSize, (float)this.m_explosionSphere.Radius / gridSize);
  52.                                     BoundingBoxI boundingBoxI = BoundingBoxI.CreateFromSphere(sphere);
  53.                                     boundingBoxI.Inflate(1);
  54.                                     int num8 = 0;
  55.                                     Vector3 vector3 = Vector3.Zero;
  56.                                     for (int i = 0; i < num7; i++)
  57.                                     {
  58.                                         HkShapeCollision hkShapeCollision = penetrationsShapeShape.List[i];
  59.                                         if (hkShapeCollision.ShapeKeyCount != 0u && hkShapeCollision.ShapeKeyCount <= 1u)
  60.                                         {
  61.                                             Vector3I vector3I;
  62.                                             Vector3I vector3I2;
  63.                                             shape.GetShapeBounds(hkShapeCollision.GetShapeKey(0), out vector3I, out vector3I2);
  64.                                             if (vector3I != vector3I2)
  65.                                             {
  66.                                                 MySlimBlock cubeBlock = myCubeGrid.GetCubeBlock(vector3I);
  67.                                                 if (cubeBlock != null)
  68.                                                 {
  69.                                                     if (cubeBlock.FatBlock == null)
  70.                                                     {
  71.                                                         Vector3I.Clamp(ref vector3I, ref boundingBoxI.Min, ref boundingBoxI.Max, out vector3I);
  72.                                                         Vector3I.Clamp(ref vector3I2, ref boundingBoxI.Min, ref boundingBoxI.Max, out vector3I2);
  73.                                                         Vector3I_RangeIterator vector3I_RangeIterator = new Vector3I_RangeIterator(ref vector3I, ref vector3I2);
  74.                                                         while (vector3I_RangeIterator.IsValid())
  75.                                                         {
  76.                                                             Vector3I current = vector3I_RangeIterator.Current;
  77.                                                             if (sphere.Contains(current) == ContainmentType.Contains)
  78.                                                             {
  79.                                                                 num8++;
  80.                                                                 vector3 += current;
  81.                                                             }
  82.                                                             vector3I_RangeIterator.MoveNext();
  83.                                                         }
  84.                                                     }
  85.                                                     else
  86.                                                     {
  87.                                                         num8++;
  88.                                                         vector3 += new Vector3(vector3I2 + vector3I) / 2f;
  89.                                                     }
  90.                                                 }
  91.                                             }
  92.                                             else
  93.                                             {
  94.                                                 num8++;
  95.                                                 vector3 += vector3I;
  96.                                             }
  97.                                         }
  98.                                     }
  99.                                     if (vector3 != Vector3.Zero)
  100.                                     {
  101.                                         vector3 /= (float)num8;
  102.                                         vector = myCubeGrid.GridIntegerToWorld(vector3) - this.m_explosionSphere.Center;
  103.                                     }
  104.                                 }
  105.                             }
  106.                             if (vector == Vector3.Zero)
  107.                             {
  108.                                 vector = myEntity.PositionComp.WorldAABB.Center - this.m_explosionSphere.Center;
  109.                             }
  110.                             vector.Normalize();
  111.                             value = vector;
  112.                         }
  113.                         bool flag = !(myEntity is MyCubeGrid) || MyExplosions.ShouldUseMassScaleForEntity(myEntity);
  114.                         float num9 = num6 / (flag ? 50f : 1f) * m_explosionInfo.StrengthImpulse;
  115.                         float mass = myEntity.Physics.Mass;
  116.                         if (flag)
  117.                         {
  118.                             float num10 = MathHelper.Lerp(0.1f, 1f, 1f - MyMath.FastTanH(mass / 1000000f));
  119.                             num9 *= mass * num10;
  120.                         }
  121.                         else
  122.                         {
  123.                             num9 = Math.Min(num9, mass);
  124.                         }
  125.                         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  126.                         myEntity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, new Vector3?(value * num9), new Vector3D?(this.m_explosionSphere.Center), null, null, true, false);
  127.                         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  128.                     }
  129.                     if (myEntity is IMyDestroyableObject || myAmmoBase != null || m_explosionInfo.ApplyForceAndDamage)
  130.                     {
  131.                         MyCharacter myCharacter = myEntity as MyCharacter;
  132.                         if (myCharacter != null)
  133.                         {
  134.                             MyCockpit myCockpit = myCharacter.IsUsing as MyCockpit;
  135.                             if (myCockpit != null)
  136.                             {
  137.                                 if (explosionDamageInfo.DamagedBlocks.ContainsKey(myCockpit.SlimBlock))
  138.                                 {
  139.                                     float damageRemaining = explosionDamageInfo.DamageRemaining[myCockpit.SlimBlock].DamageRemaining;
  140.                                     myCharacter.DoDamage(damageRemaining, MyDamageType.Explosion, true, (m_explosionInfo.OwnerEntity != null) ? m_explosionInfo.OwnerEntity.EntityId : 0L);
  141.                                     continue;
  142.                                 }
  143.                                 continue;
  144.                             }
  145.                         }
  146.                         if (!(myEntity is MyCubeGrid))
  147.                         {
  148.                             IMyDestroyableObject myDestroyableObject = myEntity as IMyDestroyableObject;
  149.                             if (myDestroyableObject != null)
  150.                             {
  151.                                 float num11 = num4 * num3;
  152.                                 if (num11 <= 1f)
  153.                                 {
  154.                                     float num12 = 1f - num11 * num11;
  155.                                     float damage = explosionDamageInfo.Damage * num12;
  156.                                     myDestroyableObject.DoDamage(damage, MyDamageType.Explosion, true, null, (m_explosionInfo.OwnerEntity != null) ? m_explosionInfo.OwnerEntity.EntityId : 0L);
  157.                                 }
  158.                             }
  159.                         }
  160.                     }
  161.                 }
  162.             }
  163.             if (hkSphereShape != null)
  164.             {
  165.                 hkSphereShape.Value.Base.RemoveReference();
  166.             }
  167.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement