Connector/Ejector "throw out" volume may be less than intended

Vox Serico shared this bug 3 years ago
Reported

While examining the decompiled code to figure out the rate of ejection of MyShipConnector:s, I discovered that the maximum volume of ejected material is hardcoded as 2.5 and 0.5 m³ (large-grid and small-grid) per update tick.

We know the unit is a measure of volume because the value is compared to the volume of the item being ejected.

Now, the numbers 2.5 and 0.5 is the same as the length of their respective grid-size cube - a unit of length.

This leads me to believe that the intention was to raise these values to the power of 3, but a mistake was made and the exponent was omitted. As to eject ("throw out") their entire inventory volume (8,000 L, 1,152 L, 64L) instead of a fraction (2,500L, 500L, 64L) of it.

Doing so would also incentivize the use of fewer larger connectors instead of many small ejectors, reducing the overall performance hit of mass-ejecting unwanted stone as it is a common practice.

// Sandbox.Game.Entities.Cube.MyShipConnector
private unsafe void TryThrowOutItem()
{
	float num = (base.CubeGrid.GridSizeEnum == MyCubeSize.Large) ? 2.5f : 0.5f;
	List<MyPhysicalInventoryItem> items = this.GetInventory(0).GetItems();
	int i = 0;
	while (i < this.GetInventory(0).GetItems().Count)
	{
		MyPhysicalInventoryItem myPhysicalInventoryItem = items;
		MyPhysicalItemDefinition myPhysicalItemDefinition;
		if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(myPhysicalInventoryItem.Content.GetId(), out myPhysicalItemDefinition))
		{
			float randomFloat = MyUtils.GetRandomFloat(0f, (base.CubeGrid.GridSizeEnum == MyCubeSize.Large) ? 0.5f : 0.07f);
			Vector3 randomVector3CircleNormalized = MyUtils.GetRandomVector3CircleNormalized();
			Vector3D value = Vector3D.Transform(this.ConnectionPosition, *base.CubeGrid.PositionComp.WorldMatrixRef);
			MatrixD matrixD = *base.PositionComp.WorldMatrixRef;
			Vector3D value2 = value + matrixD.Right * (double)randomVector3CircleNormalized.X * (double)randomFloat;
			matrixD = *base.PositionComp.WorldMatrixRef;
			Vector3D vector3D = value2 + matrixD.Up * (double)randomVector3CircleNormalized.Z * (double)randomFloat;
			MyFixedPoint myFixedPoint = (MyFixedPoint)(num / myPhysicalItemDefinition.Volume);
			if (myPhysicalInventoryItem.Content.TypeId != typeof(MyObjectBuilder_Ore) && myPhysicalInventoryItem.Content.TypeId != typeof(MyObjectBuilder_Ingot))
			{
				myFixedPoint = MyFixedPoint.Ceiling(myFixedPoint);
			}
			MyFixedPoint myFixedPoint2 = 0;
			MyPhysicalInventoryItem myPhysicalInventoryItem2;
			if (myPhysicalInventoryItem.Amount < myFixedPoint)
			{
				num -= (float)myPhysicalInventoryItem.Amount * myPhysicalItemDefinition.Volume;
				myFixedPoint2 = myPhysicalInventoryItem.Amount;
				myPhysicalInventoryItem2 = myPhysicalInventoryItem;
				this.GetInventory(0).RemoveItems(myPhysicalInventoryItem.ItemId, null, true, false, null, null);
				i++;
			}
			else
			{
				myPhysicalInventoryItem2 = new MyPhysicalInventoryItem(myPhysicalInventoryItem.GetObjectBuilder())
				{
					Amount = myFixedPoint
				};
				myFixedPoint2 = myFixedPoint;
				this.GetInventory(0).RemoveItems(myPhysicalInventoryItem.ItemId, new MyFixedPoint?(myFixedPoint), true, false, null, null);
			}

Replies (1)

photo
1

Hello, Vox Serico!

Thank you for letting us know about this issue. This has been reported internally.

Kind Regards

Laura, QA Department

Leave a Comment
 
Attach a file