Skip to content

Commit 17423b9

Browse files
committed
Blueprint for container management https://blueprints.launchpad.net/or/+spec/containers
1 parent 84cbb79 commit 17423b9

File tree

7 files changed

+154
-175
lines changed

7 files changed

+154
-175
lines changed

Source/Orts.Formats.Msts/WorldFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public class PickupObj : BaseObj
317317
public StackLocationItems StackLocations;
318318
public float PickingSurfaceYOffset;
319319
public Vector3 PickingSurfaceRelativeTopStartPosition;
320-
public float MaxGrabberSpan;
320+
public int GrabberArmsParts = 2;
321321
public string CraneSound;
322322

323323
public WorldLocation Location;
@@ -347,7 +347,7 @@ public override void AddOrModifyObj(SBR subBlock)
347347
case TokenID.ORTSStackLocations: StackLocations = new StackLocationItems(subBlock, this); break;
348348
case TokenID.ORTSPickingSurfaceYOffset: PickingSurfaceYOffset = subBlock.ReadFloat(); break;
349349
case TokenID.ORTSPickingSurfaceRelativeTopStartPosition: PickingSurfaceRelativeTopStartPosition = subBlock.ReadVector3(); break;
350-
case TokenID.ORTSMaxGrabberSpan: MaxGrabberSpan = subBlock.ReadFloat(); break;
350+
case TokenID.ORTSGrabberArmsParts: GrabberArmsParts = subBlock.ReadInt(); break;
351351
case TokenID.ORTSCraneSound: CraneSound = subBlock.ReadString(); break;
352352
case TokenID.PickupAnimData: PickupAnimData = new PickupAnimDataItem(subBlock); break;
353353
case TokenID.PickupCapacity: PickupCapacity = new PickupCapacityItem(subBlock); break;

Source/Orts.Formats.OR/ContainerFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Orts.Formats.OR
2828
{
2929
/// <summary>
3030
///
31-
/// class ORWeatherFile
31+
/// class ContainerFile
3232
/// </summary>
3333

3434
public class ContainerFile

Source/Orts.Parsers.Msts/TokenID.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ public enum TokenID : uint
17131713
ORTSStackLocationsLength,
17141714
ORTSPickingSurfaceYOffset,
17151715
ORTSPickingSurfaceRelativeTopStartPosition,
1716-
ORTSMaxGrabberSpan,
1716+
ORTSGrabberArmsParts,
17171717
StackLocation,
17181718
MaxStackedContainers,
17191719
Length,

Source/Orts.Simulation/Simulation/Container.cs

Lines changed: 82 additions & 104 deletions
Large diffs are not rendered by default.

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/FreightAnimations.cs

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public class FreightAnimations
5757
public bool DoubleStacker;
5858
public MSTSWagon Wagon;
5959
public List<LoadData> LoadDataList;
60+
public const float EmptySuperpositionTolerance = 0.10f;
61+
public const float FullSuperpositionTolerance = 0.2f;
6062

6163
// additions to manage consequences of variable weight on friction and brake forces
6264
public float EmptyORTSDavis_A = -9999;
@@ -317,7 +319,7 @@ public void Load(MSTSWagon wagon, string loadFilePath, LoadPosition loadPosition
317319
}
318320
else
319321
{
320-
container.LoadFromContainerFile(loadFilePath);
322+
container.LoadFromContainerFile(loadFilePath, wagon.Simulator.BasePath +@"\trains\trainset\");
321323
ContainerManager.LoadedContainers.Add(loadFilePath, container);
322324
}
323325
Vector3 offset = new Vector3(0, 0, 0);
@@ -487,66 +489,68 @@ public void UpdateEmptyFreightAnims(float containerLengthM)
487489
if (EmptyAnimations.Count == 0)
488490
{
489491
if (anim.LoadPosition == LoadPosition.Above) return;
490-
if (containerLengthM >= LoadingAreaLength - 0.02) return;
491-
Vector3 offset = anim.Offset;
492-
switch (anim.LoadPosition)
492+
if (containerLengthM < LoadingAreaLength - EmptySuperpositionTolerance)
493493
{
494-
case LoadPosition.Center:
495-
if ((LoadingAreaLength + 0.02f - anim.Container.LengthM) / 2 > 6.10f)
496-
{
497-
// one empty area behind, one in front
498-
var emptyLength = (LoadingAreaLength - anim.Container.LengthM) / 2;
499-
offset.Z = Offset.Z + LoadingAreaLength /2 - (LoadingAreaLength - anim.Container.LengthM) / 4;
500-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Rear, offset, emptyLength));
501-
offset.Z = Offset.Z - LoadingAreaLength / 2 + (LoadingAreaLength - anim.Container.LengthM) / 4;
502-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Front, offset, emptyLength));
503-
}
504-
break;
505-
case LoadPosition.CenterRear:
506-
// one empty area in front, check if enough place for the rear one
507-
offset = Offset;
508-
offset.Z -= LoadingAreaLength / 4;
509-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, DoubleStacker ? LoadPosition.CenterFront : LoadPosition.Front,
510-
offset, LoadingAreaLength / 2));
511-
if (LoadingAreaLength / 2 + 0.01f - containerLengthM > 6.10)
512-
{
513-
offset.Z = Offset.Z + anim.Container.LengthM / 2 + LoadingAreaLength / 4;
514-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Rear, offset,
515-
LoadingAreaLength / 2 - containerLengthM));
516-
}
517-
break;
518-
case LoadPosition.CenterFront:
519-
offset = Offset;
520-
offset.Z += LoadingAreaLength / 4;
521-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, DoubleStacker ? LoadPosition.CenterRear : LoadPosition.Rear,
522-
offset, LoadingAreaLength / 2));
523-
if (LoadingAreaLength / 2 + 0.01f - containerLengthM > 6.10)
524-
{
525-
offset.Z = Offset.Z - containerLengthM / 2 - LoadingAreaLength / 4;
526-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Front, offset,
527-
LoadingAreaLength / 2 - containerLengthM));
528-
}
529-
break;
530-
case LoadPosition.Rear:
531-
if (LoadingAreaLength + 0.02f - containerLengthM > 6.10f)
532-
{
494+
Vector3 offset = anim.Offset;
495+
switch (anim.LoadPosition)
496+
{
497+
case LoadPosition.Center:
498+
if ((LoadingAreaLength + EmptySuperpositionTolerance - anim.Container.LengthM) / 2 > Container.Length20ftM)
499+
{
500+
// one empty area behind, one in front
501+
var emptyLength = (LoadingAreaLength - anim.Container.LengthM) / 2;
502+
offset.Z = Offset.Z + LoadingAreaLength / 2 - (LoadingAreaLength - anim.Container.LengthM) / 4;
503+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Rear, offset, emptyLength));
504+
offset.Z = Offset.Z - LoadingAreaLength / 2 + (LoadingAreaLength - anim.Container.LengthM) / 4;
505+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Front, offset, emptyLength));
506+
}
507+
break;
508+
case LoadPosition.CenterRear:
509+
// one empty area in front, check if enough place for the rear one
533510
offset = Offset;
534-
offset.Z -= anim.Container.LengthM / 2;
535-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Front, offset,
536-
LoadingAreaLength - containerLengthM));
537-
}
538-
break;
539-
case LoadPosition.Front:
540-
if (LoadingAreaLength + 0.02f - containerLengthM > 6.10f)
541-
{
511+
offset.Z -= LoadingAreaLength / 4;
512+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, DoubleStacker ? LoadPosition.CenterFront : LoadPosition.Front,
513+
offset, LoadingAreaLength / 2));
514+
if (LoadingAreaLength / 2 + 0.01f - containerLengthM > 6.10)
515+
{
516+
offset.Z = Offset.Z + anim.Container.LengthM / 2 + LoadingAreaLength / 4;
517+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Rear, offset,
518+
LoadingAreaLength / 2 - containerLengthM));
519+
}
520+
break;
521+
case LoadPosition.CenterFront:
542522
offset = Offset;
543-
offset.Z += containerLengthM / 2;
544-
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Rear, offset,
545-
LoadingAreaLength - containerLengthM));
546-
}
547-
break;
548-
default:
549-
break;
523+
offset.Z += LoadingAreaLength / 4;
524+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, DoubleStacker ? LoadPosition.CenterRear : LoadPosition.Rear,
525+
offset, LoadingAreaLength / 2));
526+
if (LoadingAreaLength / 2 + EmptySuperpositionTolerance - containerLengthM > Container.Length20ftM)
527+
{
528+
offset.Z = Offset.Z - containerLengthM / 2 - LoadingAreaLength / 4;
529+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Front, offset,
530+
LoadingAreaLength / 2 - containerLengthM));
531+
}
532+
break;
533+
case LoadPosition.Rear:
534+
if (LoadingAreaLength + EmptySuperpositionTolerance - containerLengthM > Container.Length20ftM)
535+
{
536+
offset = Offset;
537+
offset.Z -= anim.Container.LengthM / 2;
538+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Front, offset,
539+
LoadingAreaLength - containerLengthM));
540+
}
541+
break;
542+
case LoadPosition.Front:
543+
if (LoadingAreaLength + EmptySuperpositionTolerance - containerLengthM > Container.Length20ftM)
544+
{
545+
offset = Offset;
546+
offset.Z += containerLengthM / 2;
547+
EmptyAnimations.Add(new FreightAnimationDiscrete(this, null, LoadPosition.Rear, offset,
548+
LoadingAreaLength - containerLengthM));
549+
}
550+
break;
551+
default:
552+
break;
553+
}
550554
}
551555
}
552556
else
@@ -688,8 +692,8 @@ public void UpdateEmptyFreightAnims(float containerLengthM)
688692
emptyAnim.Offset.Z += multiplier * anim.LoadingAreaLength / 2;
689693
emptyAnim.LinkedIntakePoint.OffsetM = -emptyAnim.Offset.Z;
690694
emptyAnim.LoadingAreaLength -= anim.LoadingAreaLength;
691-
if (Math.Abs(emptyAnim.Offset.Z - Offset.Z) < 0.02f) emptyAnim.LoadPosition = LoadPosition.Center;
692-
else if (Math.Abs(emptyAnim.LoadingAreaLength + anim.LoadingAreaLength - LoadingAreaLength / 2)< 0.02f)
695+
if (Math.Abs(emptyAnim.Offset.Z - Offset.Z) < FullSuperpositionTolerance) emptyAnim.LoadPosition = LoadPosition.Center;
696+
else if (Math.Abs(emptyAnim.LoadingAreaLength + anim.LoadingAreaLength - LoadingAreaLength / 2) < FullSuperpositionTolerance)
693697
emptyAnim.LoadPosition = anim.LoadPosition == LoadPosition.Front ? LoadPosition.CenterFront : LoadPosition.CenterRear;
694698
continue;
695699
}

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ WagonAndMatchingPickup GetMatchingPickup(Train train, bool onlyUnload = false)
487487
var d2 = WorldLocation.GetDistanceSquared(intakeLocation, pickup.Location);
488488
if (intake.Type == MSTSWagon.PickupType.Container && containerStation != null &&
489489
(wagon.Train.FrontTDBTraveller.TN.Index == containerStation.TrackNode.Index ||
490-
wagon.Train.FrontTDBTraveller.TN.Index == containerStation.TrackNode.Index) &&
490+
wagon.Train.RearTDBTraveller.TN.Index == containerStation.TrackNode.Index) &&
491491
d2 < containerStation.MinZSpan * containerStation.MinZSpan)
492492
// for container it's enough if the intake is within the reachable range of the container crane
493493
{

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,6 @@ public class FuelPickupItemShape : PoseableShape
997997
protected FuelPickupItem FuelPickupItem;
998998
protected SoundSource Sound;
999999
protected float FrameRate;
1000-
protected Viewer Viewer;
10011000
protected WorldPosition Position;
10021001

10031002
protected int AnimationFrames;
@@ -1007,7 +1006,6 @@ public FuelPickupItemShape(Viewer viewer, string path, WorldPosition position, S
10071006
: base(viewer, path, position, shapeFlags)
10081007
{
10091008
FuelPickupItemObj = fuelpickupitemObj;
1010-
Viewer = viewer;
10111009
Position = position;
10121010
Initialize();
10131011
}
@@ -1162,7 +1160,6 @@ public class ContainerHandlingItemShape : FuelPickupItemShape
11621160
protected controller controllerGrabber01;
11631161
protected controller controllerGrabber02;
11641162
protected float slowDownThreshold = 0.03f;
1165-
protected SoundSource Sound;
11661163
// To detect transitions that trigger sounds
11671164
protected bool OldMoveX;
11681165
protected bool OldMoveY;
@@ -1256,7 +1253,7 @@ public override void Initialize()
12561253
Matrix.Multiply(ref absAnimationMatrix, ref XNAMatrices[IAnimationMatrixZ], out absAnimationMatrix);
12571254
Matrix.Multiply(ref absAnimationMatrix, ref Location.XNAMatrix, out absAnimationMatrix);
12581255
ContainerHandlingItem.PassSpanParameters(((linear_key)controllerZ[0]).Z, ((linear_key)controllerZ[1]).Z,
1259-
((linear_key)controllerGrabber01[0]).Z, ((linear_key)controllerGrabber02[0]).Z);
1256+
((linear_key)controllerGrabber01[0]).Z - ((linear_key)controllerGrabber01[1]).Z, ((linear_key)controllerGrabber02[0]).Z - ((linear_key)controllerGrabber02[1]).Z);
12601257
ContainerHandlingItem.ReInitPositionOffset(absAnimationMatrix);
12611258

12621259
AnimationKeyX = Math.Abs((ContainerHandlingItem.PickingSurfaceRelativeTopStartPosition.X - ((linear_key)controllerX[0]).X) / (((linear_key)controllerX[1]).X - ((linear_key)controllerX[0]).X)) * controllerX[1].Frame;
@@ -1400,7 +1397,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
14001397

14011398
if (ContainerHandlingItem.MoveGrabber)
14021399
{
1403-
var animationTarget = Math.Abs((ContainerHandlingItem.TargetGrabber01 - ((linear_key)controllerGrabber01[0]).Z) / (((linear_key)controllerGrabber01[1]).Z - ((linear_key)controllerGrabber01[0]).Z)) * controllerGrabber01[1].Frame;
1400+
var animationTarget = Math.Abs((ContainerHandlingItem.TargetGrabber01 - ((linear_key)controllerGrabber01[0]).Z + ((linear_key)controllerGrabber01[1]).Z) / (((linear_key)controllerGrabber01[1]).Z - ((linear_key)controllerGrabber01[0]).Z)) * controllerGrabber01[1].Frame;
14041401
tempFrameRate = Math.Abs(AnimationKeyGrabber01 - animationTarget) > slowDownThreshold ? FrameRate : FrameRate / 4;
14051402
if (AnimationKeyGrabber01 < animationTarget)
14061403
{
@@ -1420,7 +1417,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
14201417
}
14211418
if (AnimationKeyGrabber01 < 0)
14221419
AnimationKeyGrabber01 = 0;
1423-
var animationTarget2 = Math.Abs((ContainerHandlingItem.TargetGrabber02 - ((linear_key)controllerGrabber02[0]).Z) / (((linear_key)controllerGrabber02[1]).Z - ((linear_key)controllerGrabber02[0]).Z)) * controllerGrabber02[1].Frame;
1420+
var animationTarget2 = Math.Abs((ContainerHandlingItem.TargetGrabber02 - ((linear_key)controllerGrabber02[0]).Z + ((linear_key)controllerGrabber02[1]).Z) / (((linear_key)controllerGrabber02[1]).Z - ((linear_key)controllerGrabber02[0]).Z)) * controllerGrabber02[1].Frame;
14241421
tempFrameRate = Math.Abs(AnimationKeyGrabber01 - animationTarget2) > slowDownThreshold ? FrameRate : FrameRate / 4;
14251422
if (AnimationKeyGrabber02 < animationTarget2)
14261423
{

0 commit comments

Comments
 (0)