Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void ApplyVolumetricExplosionOnEntities(ref MyExplosionInfo m_explosionInfo, List<MyEntity> entities, MyGridExplosion explosionDamageInfo)
- {
- float num = (float)explosionDamageInfo.Sphere.Radius * 2f;
- float num2 = 1f / num;
- float num3 = 1f / (float)explosionDamageInfo.Sphere.Radius;
- HkSphereShape? hkSphereShape = null;
- foreach (MyEntity myEntity in entities)
- {
- float num4 = (float)myEntity.PositionComp.WorldAABB.Distance(this.m_explosionSphere.Center);
- float num5 = num4 * num2;
- if (num5 <= 1f)
- {
- float num6 = 1f - num5 * num5;
- MyAmmoBase myAmmoBase = myEntity as MyAmmoBase;
- if (myAmmoBase != null)
- {
- myAmmoBase.MarkForDestroy();
- }
- else if (myEntity.Physics != null && myEntity.Physics.Enabled && !myEntity.Physics.IsStatic && m_explosionInfo.ApplyForceAndDamage)
- {
- m_explosionInfo.StrengthImpulse = 100f * (float)this.m_explosionSphere.Radius;
- m_explosionInfo.StrengthAngularImpulse = 50000f;
- m_explosionInfo.HitEntity = ((m_explosionInfo.HitEntity != null) ? m_explosionInfo.HitEntity.GetBaseEntity() : null);
- Vector3 value;
- if (m_explosionInfo.Direction != null && m_explosionInfo.HitEntity != null && m_explosionInfo.HitEntity.GetTopMostParent(null) == myEntity)
- {
- ////////////////////////////////////////
- value = m_explosionInfo.Direction.Value;
- ////////////////////////////////////////
- }
- else
- {
- Vector3 vector = Vector3.Zero;
- MyCubeGrid myCubeGrid = myEntity as MyCubeGrid;
- if (myCubeGrid != null)
- {
- if (hkSphereShape == null)
- {
- hkSphereShape = new HkSphereShape?(new HkSphereShape(num));
- }
- HkRigidBody rigidBody = myCubeGrid.Physics.RigidBody;
- Matrix rigidBodyMatrix = rigidBody.GetRigidBodyMatrix();
- Vector3 translation = rigidBodyMatrix.Translation;
- Quaternion quaternion = Quaternion.CreateFromRotationMatrix(rigidBodyMatrix);
- Vector3 vector2 = myCubeGrid.Physics.WorldToCluster(this.m_explosionSphere.Center);
- using (ClearToken<HkShapeCollision> penetrationsShapeShape = MyPhysics.GetPenetrationsShapeShape(hkSphereShape.Value, ref vector2, ref Quaternion.Identity, rigidBody.GetShape(), ref translation, ref quaternion))
- {
- float gridSize = myCubeGrid.GridSize;
- MyGridShape shape = myCubeGrid.Physics.Shape;
- int num7 = Math.Min(penetrationsShapeShape.List.Count, 100);
- BoundingSphere sphere = new BoundingSphere(Vector3D.Transform(this.m_explosionSphere.Center, myCubeGrid.PositionComp.WorldMatrixNormalizedInv) / (double)gridSize, (float)this.m_explosionSphere.Radius / gridSize);
- BoundingBoxI boundingBoxI = BoundingBoxI.CreateFromSphere(sphere);
- boundingBoxI.Inflate(1);
- int num8 = 0;
- Vector3 vector3 = Vector3.Zero;
- for (int i = 0; i < num7; i++)
- {
- HkShapeCollision hkShapeCollision = penetrationsShapeShape.List[i];
- if (hkShapeCollision.ShapeKeyCount != 0u && hkShapeCollision.ShapeKeyCount <= 1u)
- {
- Vector3I vector3I;
- Vector3I vector3I2;
- shape.GetShapeBounds(hkShapeCollision.GetShapeKey(0), out vector3I, out vector3I2);
- if (vector3I != vector3I2)
- {
- MySlimBlock cubeBlock = myCubeGrid.GetCubeBlock(vector3I);
- if (cubeBlock != null)
- {
- if (cubeBlock.FatBlock == null)
- {
- Vector3I.Clamp(ref vector3I, ref boundingBoxI.Min, ref boundingBoxI.Max, out vector3I);
- Vector3I.Clamp(ref vector3I2, ref boundingBoxI.Min, ref boundingBoxI.Max, out vector3I2);
- Vector3I_RangeIterator vector3I_RangeIterator = new Vector3I_RangeIterator(ref vector3I, ref vector3I2);
- while (vector3I_RangeIterator.IsValid())
- {
- Vector3I current = vector3I_RangeIterator.Current;
- if (sphere.Contains(current) == ContainmentType.Contains)
- {
- num8++;
- vector3 += current;
- }
- vector3I_RangeIterator.MoveNext();
- }
- }
- else
- {
- num8++;
- vector3 += new Vector3(vector3I2 + vector3I) / 2f;
- }
- }
- }
- else
- {
- num8++;
- vector3 += vector3I;
- }
- }
- }
- if (vector3 != Vector3.Zero)
- {
- vector3 /= (float)num8;
- vector = myCubeGrid.GridIntegerToWorld(vector3) - this.m_explosionSphere.Center;
- }
- }
- }
- if (vector == Vector3.Zero)
- {
- vector = myEntity.PositionComp.WorldAABB.Center - this.m_explosionSphere.Center;
- }
- vector.Normalize();
- value = vector;
- }
- bool flag = !(myEntity is MyCubeGrid) || MyExplosions.ShouldUseMassScaleForEntity(myEntity);
- float num9 = num6 / (flag ? 50f : 1f) * m_explosionInfo.StrengthImpulse;
- float mass = myEntity.Physics.Mass;
- if (flag)
- {
- float num10 = MathHelper.Lerp(0.1f, 1f, 1f - MyMath.FastTanH(mass / 1000000f));
- num9 *= mass * num10;
- }
- else
- {
- num9 = Math.Min(num9, mass);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- 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);
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- }
- if (myEntity is IMyDestroyableObject || myAmmoBase != null || m_explosionInfo.ApplyForceAndDamage)
- {
- MyCharacter myCharacter = myEntity as MyCharacter;
- if (myCharacter != null)
- {
- MyCockpit myCockpit = myCharacter.IsUsing as MyCockpit;
- if (myCockpit != null)
- {
- if (explosionDamageInfo.DamagedBlocks.ContainsKey(myCockpit.SlimBlock))
- {
- float damageRemaining = explosionDamageInfo.DamageRemaining[myCockpit.SlimBlock].DamageRemaining;
- myCharacter.DoDamage(damageRemaining, MyDamageType.Explosion, true, (m_explosionInfo.OwnerEntity != null) ? m_explosionInfo.OwnerEntity.EntityId : 0L);
- continue;
- }
- continue;
- }
- }
- if (!(myEntity is MyCubeGrid))
- {
- IMyDestroyableObject myDestroyableObject = myEntity as IMyDestroyableObject;
- if (myDestroyableObject != null)
- {
- float num11 = num4 * num3;
- if (num11 <= 1f)
- {
- float num12 = 1f - num11 * num11;
- float damage = explosionDamageInfo.Damage * num12;
- myDestroyableObject.DoDamage(damage, MyDamageType.Explosion, true, null, (m_explosionInfo.OwnerEntity != null) ? m_explosionInfo.OwnerEntity.EntityId : 0L);
- }
- }
- }
- }
- }
- }
- if (hkSphereShape != null)
- {
- hkSphereShape.Value.Base.RemoveReference();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement