Skip to content

Commit

Permalink
Automatic merge of T1.5.1-190-g1cc4a74eb and 14 pull requests
Browse files Browse the repository at this point in the history
- Pull request #706 at 91bcfa2: Extended door functionality
- Pull request #722 at fb9079e: Fix Windows Forms deprecations in ActivityEditor
- Pull request #732 at dc256cd: Improvements for air brakes
- Pull request #735 at b9a0ea3: Added new parameter for battery switch
- Pull request #746 at f5566d7: Website release 1.5.1
- Pull request #753 at ab8fe32: Extends CabControls for user input
- Pull request #754 at 3549c39: Container weights: https://blueprints.launchpad.net/or/+spec/container-weights
- Pull request #760 at 113dd63: Updated EditorConfig with .NET and StyleCop analyzer configuration
- Pull request #761 at f6a3aca: fix: Allow 100% cloud-free skys by making 0% overcast = 0% clouds
- Pull request #763 at 12e250d: build: Remove use of SolutionDir which is not supported everywhere
- Pull request #764 at 5f9a01b: fix: Improve sky dome distortion causing bug #1471416
- Pull request #765 at 083467b: Bug fix for https://bugs.launchpad.net/or/+bug/2002183 OK to proceed sound played wrongly
- Pull request #766 at f143fcc: Control Car additional functionality
- Pull request #767 at 719c737: Refine sunrise and sunset
  • Loading branch information
openrails-bot committed Jan 15, 2023
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
34 changes: 20 additions & 14 deletions Source/Orts.Simulation/Simulation/Container.cs
Expand Up @@ -279,6 +279,24 @@ public void ComputeWorldPosition (FreightAnimationDiscrete freightAnimDiscrete)
var invWagonMatrix = Matrix.Invert(freightAnimDiscrete.Wagon.WorldPosition.XNAMatrix);
RelativeContainerMatrix = Matrix.Multiply(WorldPosition.XNAMatrix, invWagonMatrix);
}

public void ComputeLoadWeight(LoadState loadState)
{
switch (loadState)
{
case LoadState.Empty:
MassKG = EmptyMassKG;
break;
case LoadState.Loaded:
MassKG = MaxMassWhenLoadedKG;
break;
case LoadState.Random:
var loadPercent = Simulator.Random.Next(101);
if (loadPercent < 30) MassKG = EmptyMassKG;
else MassKG = MaxMassWhenLoadedKG * loadPercent / 100f;
break;
}
}
}

public class ContainerManager
Expand Down Expand Up @@ -542,20 +560,8 @@ public void Preload(string loadFilePath, int stackLocationIndex, LoadState loadS
container.LoadFromContainerFile(loadFilePath, Simulator.BasePath + @"\trains\trainset\");
ContainerManager.LoadedContainers.Add(loadFilePath, container);
}
switch (loadState)
{
case LoadState.Empty:
container.MassKG = container.EmptyMassKG;
break;
case LoadState.Loaded:
container.MassKG = container.MaxMassWhenLoadedKG;
break;
case LoadState.Random:
var loadPercent = Simulator.Random.Next(101);
if (loadPercent < 30) container.MassKG = container.EmptyMassKG;
else container.MassKG = container.MaxMassWhenLoadedKG * loadPercent / 100f;
break;
}
container.ComputeLoadWeight(loadState);

var stackLocation = StackLocations[stackLocationIndex];
if (stackLocation.Containers != null && stackLocation.Containers.Count >= stackLocation.MaxStackedContainers)
Trace.TraceWarning("Stack Location {0} is full, can't lay down container", stackLocationIndex);
Expand Down
10 changes: 8 additions & 2 deletions Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs
Expand Up @@ -874,7 +874,7 @@ public virtual void LoadFromWagFile(string wagFilePath)
totalContainerMassKG += discreteAnim.Container.MassKG;
}
}
MassKG = FreightAnimations.WagonEmptyWeight + FreightAnimations.FreightWeight + FreightAnimations.StaticFreightWeight + totalContainerMassKG;
CalculateTotalMass(totalContainerMassKG);

if (FreightAnimations.StaticFreightAnimationsPresent) // If it is static freight animation, set wagon physics to full wagon value
{
Expand Down Expand Up @@ -963,6 +963,12 @@ public virtual void LoadFromWagFile(string wagFilePath)
BrakeSystem = MSTSBrakeSystem.Create(CarBrakeSystemType, this);
}

// Compute total mass of wagon including freight animations and variable loads like containers
public void CalculateTotalMass(float totalContainerMassKG)
{
MassKG = FreightAnimations.WagonEmptyWeight + FreightAnimations.FreightWeight + FreightAnimations.StaticFreightWeight + totalContainerMassKG;
}

public void GetMeasurementUnits()
{
IsMetric = Simulator.Settings.Units == "Metric" || (Simulator.Settings.Units == "Automatic" && System.Globalization.RegionInfo.CurrentRegion.IsMetric) ||
Expand Down Expand Up @@ -2003,7 +2009,7 @@ public override void Update(float elapsedClockSeconds)
// Updates the mass of the wagon considering all types of loads
if (FreightAnimations != null && FreightAnimations.WagonEmptyWeight != -1)
{
MassKG = FreightAnimations.WagonEmptyWeight + FreightAnimations.FreightWeight + FreightAnimations.StaticFreightWeight + totalContainerMassKG;
CalculateTotalMass(totalContainerMassKG);
}
}
}
Expand Down
Expand Up @@ -309,20 +309,7 @@ public void Load(string loadFilePath, LoadPosition loadPosition, LoadState loadS
container.LoadFromContainerFile(loadFilePath, Wagon.Simulator.BasePath +@"\trains\trainset\");
ContainerManager.LoadedContainers.Add(loadFilePath, container);
}
switch (loadState)
{
case LoadState.Empty:
container.MassKG = container.EmptyMassKG;
break;
case LoadState.Loaded:
container.MassKG = container.MaxMassWhenLoadedKG;
break;
case LoadState.Random:
var loadPercent = Simulator.Random.Next(101);
if (loadPercent < 30) container.MassKG = container.EmptyMassKG;
else container.MassKG = container.MaxMassWhenLoadedKG * loadPercent / 100f;
break;
}
container.ComputeLoadWeight(loadState);

Vector3 offset = new Vector3(0, 0, 0);
var validity = Validity(Wagon, container, loadPosition, Offset, LoadingAreaLength, out offset);
Expand Down

0 comments on commit 66944de

Please sign in to comment.