Ejemplo n.º 1
0
 private void HandleDecompressionFloorRip(float sum)
 {
     if (sum > 20 && _robustRandom.Prob(MathF.Clamp(sum / 100, 0.005f, 0.5f)))
     {
         _gridAtmosphereComponent.PryTile(GridIndices);
     }
 }
Ejemplo n.º 2
0
        public static float Clamp01(float value)
        {
            /*
             * if (value < 0F)
             *  return 0F;
             *
             * if (value > 1F)
             *  return 1F;
             *
             * return value;
             */

            return(MathF.Clamp(value, 0, 1));
        }
Ejemplo n.º 3
0
        public void ExperiencePressureDifference(int cycle, float pressureDifference, Direction direction,
                                                 float pressureResistanceProbDelta, GridCoordinates throwTarget)
        {
            if (ControlledComponent == null)
            {
                return;
            }

            // TODO ATMOS stuns?

            var transform         = ControlledComponent.Owner.Transform;
            var pressureComponent = ControlledComponent.Owner.GetComponent <MovedByPressureComponent>();
            var maxForce          = MathF.Sqrt(pressureDifference) * 2.25f;
            var moveProb          = 100f;

            if (pressureComponent.PressureResistance > 0)
            {
                moveProb = MathF.Abs((pressureDifference / pressureComponent.PressureResistance * ProbabilityBasePercent) -
                                     ProbabilityOffset);
            }

            if (moveProb > ProbabilityOffset && _robustRandom.Prob(MathF.Min(moveProb / 100f, 1f)) &&
                !float.IsPositiveInfinity(pressureComponent.MoveResist) &&
                (!ControlledComponent.Anchored &&
                 (maxForce >= (pressureComponent.MoveResist * MoveForcePushRatio))) ||
                (ControlledComponent.Anchored && (maxForce >= (pressureComponent.MoveResist * MoveForceForcePushRatio))))
            {
                if (maxForce > ThrowForce && throwTarget != GridCoordinates.InvalidGrid)
                {
                    var moveForce = MathF.Min(maxForce * MathF.Clamp(moveProb, 0, 100) / 100f, 50f);
                    var pos       = throwTarget.Position - transform.GridPosition.Position;
                    LinearVelocity = pos * moveForce;
                }
                else
                {
                    var moveForce = MathF.Min(maxForce * MathF.Clamp(moveProb, 0, 100) / 100f, 25f);
                    LinearVelocity = direction.ToVec() * moveForce;
                }

                pressureComponent.LastHighPressureMovementAirCycle = cycle;
            }
        }
Ejemplo n.º 4
0
 public static float Clamp(this float val, float min, float max)
 {
     return(MathF.Clamp(val, min, max));
 }
Ejemplo n.º 5
0
        //[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void HighPressureMovements()
        {
            // TODO ATMOS finish this

            if (PressureDifference > 15)
            {
                if (_soundCooldown == 0)
                {
                    EntitySystem.Get <AudioSystem>().PlayAtCoords("/Audio/Effects/space_wind.ogg",
                                                                  GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(MathF.Clamp(PressureDifference / 10, 10, 100)));
                }
            }


            foreach (var entity in _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(GridIndex).ParentMapId, Box2.UnitCentered.Translated(GridIndices)))
            {
                if (!entity.TryGetComponent(out ICollidableComponent physics) ||
                    !entity.TryGetComponent(out MovedByPressureComponent pressure))
                {
                    continue;
                }

                var pressureMovements = physics.EnsureController <HighPressureMovementController>();
                if (pressure.LastHighPressureMovementAirCycle < _gridAtmosphereComponent.UpdateCounter)
                {
                    pressureMovements.ExperiencePressureDifference(_gridAtmosphereComponent.UpdateCounter, PressureDifference, _pressureDirection, 0, PressureSpecificTarget?.GridIndices.ToGridCoordinates(_mapManager, GridIndex) ?? GridCoordinates.InvalidGrid);
                }
            }

            if (PressureDifference > 100)
            {
                // Do space wind graphics here!
            }

            _soundCooldown++;
            if (_soundCooldown > 75)
            {
                _soundCooldown = 0;
            }
        }