public void DetachFromNeighbors(ComponentManager Manager, ElevatorShaft Segment) { if (Manager.FindComponent(Segment.TrackAbove) is ElevatorShaft neighbor) { neighbor.TrackBelow = ComponentManager.InvalidID; } if (Manager.FindComponent(Segment.TrackBelow) is ElevatorShaft neighbor2) { neighbor2.TrackAbove = ComponentManager.InvalidID; } Segment.TrackAbove = ComponentManager.InvalidID; Segment.TrackBelow = ComponentManager.InvalidID; }
public void AttachToNeighbors(ComponentManager Manager, ElevatorShaft Segment) { System.Diagnostics.Debug.Assert(Segment.TrackAbove == ComponentManager.InvalidID && Segment.TrackBelow == ComponentManager.InvalidID); if (FindNeighbor(Manager, Segment.BoundingBox.Offset(0.0f, 1.0f, 0.0f).Expand(-0.2f), out ElevatorShaft aboveNeighbor)) { Segment.TrackAbove = aboveNeighbor.GlobalID; aboveNeighbor.TrackBelow = Segment.GlobalID; } if (FindNeighbor(Manager, Segment.BoundingBox.Offset(0.0f, -1.0f, 0.0f).Expand(-0.2f), out ElevatorShaft belowNeighbor)) { Segment.TrackBelow = belowNeighbor.GlobalID; belowNeighbor.TrackAbove = Segment.GlobalID; } }
private void RemoveSegmentFromShaft(ElevatorShaft Track) { var above = Track.Manager.FindComponent(Track.TrackAbove) as ElevatorShaft; if (above != null) { BuildShaftUpward(above); } var below = Track.Manager.FindComponent(Track.TrackBelow) as ElevatorShaft; if (below != null) { BuildShaftDownward(below); } CreateNewShaft(new ElevatorShaft[] { Track }); }
private bool FindNeighbor(ComponentManager Manager, BoundingBox Bounds, out ElevatorShaft Neighbor) { Neighbor = null; foreach (var entity in Manager.World.EnumerateIntersectingObjects(Bounds, CollisionType.Static)) { if (Object.ReferenceEquals(entity, this)) { continue; } if (entity is ElevatorShaft found) { Neighbor = found; return(true); } } return(false); }
private void MergeShafts(ElevatorShaft Track) { // Find bottom of shaft. var bottom = Track; while (true) { var lower = Track.Manager.FindComponent(bottom.TrackBelow) as ElevatorShaft; if (lower != null) { bottom = lower; } else { break; } } BuildShaftUpward(bottom); }
private bool MovePlatform(ElevatorShaft Destination, CreatureAI Rider, DwarfTime Time) { var dest = Destination.Position - new Vector3(0, 0.5f, 0); var delta = dest - Platform.LocalPosition; if (delta.LengthSquared() < 0.05f) { return(true); } delta.Normalize(); delta *= (float)Time.ElapsedGameTime.TotalSeconds * ElevatorSpeed; Platform.LocalPosition = Platform.LocalPosition + delta; if (Rider != null) { Rider.Physics.LocalPosition = Platform.LocalPosition + new Vector3(0, Rider.Physics.BoundingBoxSize.Y, 0); Rider.Physics.Velocity = Vector3.Zero; Rider.Physics.PropogateTransforms(); } return(false); }
private void BuildShaftDownward(ElevatorShaft Track) { // Build list of all segments in shaft. var segments = new List <ElevatorShaft>(); segments.Add(Track); while (true) { var lower = Track.Manager.FindComponent(Track.TrackBelow) as ElevatorShaft; if (lower != null) { segments.Add(lower); Track = lower; } else { break; } } CreateNewShaft(segments); }