Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Core/World/Physics/PhysicsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public SectorMoveStatus MoveSectorZ(double speed, double destZ, SectorMoveSpecia
var moveType = moveSpecial.MoveData.SectorMoveType;
var startZ = sectorPlane.Z;
if (!m_world.Config.Compatibility.VanillaSectorPhysics && IsSectorMovementBlocked(sector, startZ, destZ, moveSpecial))
return SectorMoveStatus.BlockedAndStop;
return SectorMoveStatus.Blocked | SectorMoveStatus.Stop;

// Move lower entities first to handle stacked entities
// Ordering by Id is only required for EntityRenderer nudging to prevent z-fighting
Expand All @@ -204,7 +204,7 @@ public SectorMoveStatus MoveSectorZ(double speed, double destZ, SectorMoveSpecia
if (!moveSpecial.IsDoor && !m_world.Config.Compatibility.VanillaSectorPhysics && IsSectorMovementBlocked(sector, startZ, destZ, moveSpecial))
{
FixPlaneClip(sector, sectorPlane, moveType);
status = SectorMoveStatus.BlockedAndStop;
status = SectorMoveStatus.Blocked | SectorMoveStatus.Stop;
}

if (solid)
Expand Down Expand Up @@ -310,14 +310,16 @@ public SectorMoveStatus MoveSectorZ(double speed, double destZ, SectorMoveSpecia

if (moveData.Crush != null)
{
status |= SectorMoveStatus.Crushed;

if (moveData.Crush.Value.CrushMode == ZDoomCrushMode.Hexen || moveData.Crush.Value.Damage == 0)
{
highestBlockEntity = entity;
highestBlockHeight = entity.Height;
highestBlockEntityWasCrushing = entityMoveData.WasCrushing;
status |= SectorMoveStatus.Blocked;
}

status = SectorMoveStatus.Crush;

m_crushEntities.Add(entity);
}
else if (CheckSectorMoveBlock(entity, moveType, entityMoveData.SaveZ))
Expand Down Expand Up @@ -383,16 +385,16 @@ public SectorMoveStatus MoveSectorZ(double speed, double destZ, SectorMoveSpecia

// If an entity is blocking this and the destination is blocked then we need to stop to match vanilla behavior.
if (isCompleted && status == SectorMoveStatus.Blocked)
return SectorMoveStatus.BlockedAndStop;
return SectorMoveStatus.Blocked | SectorMoveStatus.Stop;

if (status == SectorMoveStatus.BlockedAndStop)
if (status == (SectorMoveStatus.Blocked | SectorMoveStatus.Stop))
return status;

if (WorldStatic.Sector3D && checkSector3D && sector.TaggedSectors3D.Length > 0)
{
status = TestMoveSector3D(speed, destZ, startZ, moveSpecial, sector, sectorPlane, moveType);

if (status == SectorMoveStatus.Blocked || status == SectorMoveStatus.BlockedAndStop)
if ((status & (SectorMoveStatus.Blocked | SectorMoveStatus.Stop)) != 0)
sectorPlane.SetZ(startZ);
}

Expand Down Expand Up @@ -455,9 +457,9 @@ private SectorMoveStatus TestMoveSector3D(double speed, double destZ, double sta
moveSpecial.MoveData.SectorMoveType = face;
moveSpecial.MoveData.Sector3D = null;

if (status != SectorMoveStatus.Success)
if ((status & SectorMoveStatus.Blocked) != 0)
return status;
}
}

return SectorMoveStatus.Success;
}
Expand Down
14 changes: 9 additions & 5 deletions Core/World/Physics/SectorMoveStatus.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;

namespace Helion.World.Physics;

[Flags]
public enum SectorMoveStatus
{
Blocked,
Success,
Crush,
BlockedAndStop
}
None = 0,
Success = 1,
Blocked = 2,
Crushed = 4,
Stop = 8
}
7 changes: 4 additions & 3 deletions Core/World/Special/Specials/ElevatorSpecial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public override void GetSectors(List<(Sector, SectorPlane)> data)
public ElevatorSpecial(IWorld world, Sector sector, double floorDestZ, double speed,
MoveDirection moveDirection, SectorSoundData soundData)
{
var crush = new CrushData(Maps.Specials.ZDoom.ZDoomCrushMode.Hexen, 5);
Sector = sector;

var floor = world.DataCache.GetSectorMoveSpecial(world, sector, Sector.Floor.Z, floorDestZ,
new SectorMoveData(SectorPlaneFace.Floor, moveDirection, MoveRepetition.None, speed, 0), soundData);
new SectorMoveData(SectorPlaneFace.Floor, moveDirection, MoveRepetition.None, speed, 0, crush: crush), soundData);
var ceiling = world.DataCache.GetSectorMoveSpecial(world, sector, Sector.Ceiling.Z, floorDestZ + sector.Ceiling.Z - sector.Floor.Z,
new SectorMoveData(SectorPlaneFace.Ceiling, moveDirection, MoveRepetition.None, speed, 0), soundData);
new SectorMoveData(SectorPlaneFace.Ceiling, moveDirection, MoveRepetition.None, speed, 0, crush: crush), soundData);

// Sector plane that can potentially be blocked needs to moved first
// Reverse when sector controls 3D sectors
Expand Down Expand Up @@ -60,7 +61,7 @@ public ElevatorSpecial(Sector sector, SectorMoveSpecial firstMove, SectorMoveSpe
public override SpecialTickStatus Tick()
{
m_firstMove.Tick();
if (m_firstMove.MoveStatus == SectorMoveStatus.Blocked)
if ((m_firstMove.MoveStatus & SectorMoveStatus.Blocked) != 0)
m_secondMove.ResetInterpolation();
else
return m_secondMove.Tick();
Expand Down
36 changes: 21 additions & 15 deletions Core/World/Special/Specials/SectorMoveSpecial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ public virtual SpecialTickStatus Tick()

IsInitialMove = false;

if (MoveStatus == SectorMoveStatus.BlockedAndStop)
if ((MoveStatus & SectorMoveStatus.Stop) != 0)
DestZ = SectorPlane.Z;

if (MoveData.LightTag > 0)
DoorLight.UpdateLight(m_world, MoveData.LightTag, m_maxZ, m_minZ, Sector.Ceiling.Z);

CheckPlaySound();

if ((IsNonRepeat && SectorPlane.Z == DestZ) || MoveStatus == SectorMoveStatus.BlockedAndStop)
if ((IsNonRepeat && SectorPlane.Z == DestZ) || (MoveStatus & SectorMoveStatus.Stop) != 0)
{
if (CheckInstantMove(destZ))
ResetInterpolation();
Expand Down Expand Up @@ -474,27 +474,33 @@ private void PerformAndHandleMoveZ(double destZ)
{
MoveStatus = m_world.MoveSectorZ(MoveSpeed, destZ, this);

switch (MoveStatus)
// Never flip crushers on blocked
if ((MoveStatus & SectorMoveStatus.Blocked) != 0 && (MoveStatus & SectorMoveStatus.Crushed) == 0)
{
case SectorMoveStatus.Blocked:
if (MoveData.MoveRepetition != MoveRepetition.None)
FlipMovementDirection(true);
break;
if (MoveData.MoveRepetition != MoveRepetition.None)
FlipMovementDirection(true);
}

case SectorMoveStatus.Crush when IsInitCrush:
SetSectorDataChange();
if ((MoveStatus & SectorMoveStatus.Crushed) != 0)
{
if (IsInitCrush)
{
IsCrushing = true;
if (MoveData.Crush != null && MoveData.Crush.Value.CrushMode == ZDoomCrushMode.DoomWithSlowDown)
MoveSpeed = MoveSpeed < 0 ? -Constants.DoomSlowCrushSpeed : Constants.DoomSlowCrushSpeed;
break;
}

case SectorMoveStatus.Success:
if ((MoveStatus & SectorMoveStatus.Blocked) == 0)
SetSectorDataChange();
break;
}
}

if (IsCrushing && MoveStatus == SectorMoveStatus.Success)
IsCrushing = false;
if ((MoveStatus & SectorMoveStatus.Success) != 0)
{
SetSectorDataChange();

if (IsCrushing)
IsCrushing = false;
}
}

private void SetSectorDataChange()
Expand Down
Loading