Trucks do nod adhere to Logistic Zones when dumping

Vehicles & Roads
hreintke · 1 year ago

Issue description

What I have is :
A Logistic Zone called Island Connections.
In there a MineTower which allowes dumping of rock, slag and dirt.
What I see is trucks from the default zone dumping rock into the dumping area of that minetower.

I expected that only trucks from the Island Connections zone to be dumping there.

Edit : I know my code analyses below is wrong, the symptons of wrong zone behavior is as reported.

As my save is using mods, I tried to investigate the root cause.

I made a Harmony Patch which checks when Dumping jobs are intanciated.

[HarmonyPostfix]
[HarmonyPatch(typeof(BalancingJobSpec), MethodType.Constructor,
new Type[] { typeof(Truck),
				 typeof(TerrainDesignation),
				 typeof(Lyst<TerrainDesignation>),
				 typeof(RegisteredOutputBuffer),
				 typeof(ProductQuantity)
})]
static void pf1(BalancingJobSpec __instance)
{
	string az = __instance.Truck.AssignedZone.HasValue ? __instance.Truck.AssignedZone.Value.Name.ToString() : "Default";
	string dt;
	if (!__instance.DumpDesignation.Value.m_tower.HasValue)
	{
		dt = "No Tower";
	}
	else
	{
		if (!(__instance.DumpDesignation.Value.m_tower.Value is MineTower mt))
		{
			dt = "No MineTower";
		}
		else
		{
			dt = $"twr {mt.Id.ToString()} " + printZoneMask(" ", mt.ZoneMask);
			LogWrite.Info($"BJ " + printZoneMask("opb", __instance.OutputBuffer.Value.ZoneMask) +
			  printZoneMask(" trc", __instance.Truck.ZoneMask) + " " + dt + " " + __instance.ProductQuantity.ToString() + __instance.OutputBuffer.Value.Entity.GetType().Name);
		}
	}
}

From that I see that there are DumpingJobs, which include MineTowers that have different ZoneMasks than the OutputBuffer.

I 12:38:48,076 S9992588 ~Sim: VehicleJobMod : ===>  134 296576 BJ opb zm 2 IslandC trc zm 2 IslandC twr 41038   zm 4 LeftExt 180 of Product_Rock (loose)OreSortingPlant

From that I came to : in

BalancingJobSpec? balanceBuffersForProduct(
VehicleBuffersRegistry.RegisteredBuffers buffers,
out bool hadEligibleTruck)
foreach (VehicleBuffersRegistry.TruckData truckData in this.m_allTrucksPerProductCache)
{
  if (((long) zoneMask & (long) truckData.ZoneMask) != 0L && !(outputBuffer.OptimalQuantityOrMaxCached.Min(truckData.Capacity) > outputBuffer.AvailableQuantityCached) && outputBuffer.CanBeServedBy((Vehicle) truckData.Truck, true) && (!truckData.AssignedBuilding.HasValue || truckData.AssignedBuilding.Value == outputBuffer.Entity) && !truckData.UnreachableEntities.Contains((IEntity) outputBuffer.Entity))
  {
	this.m_terrainDesignationsCache.Clear();
	TerrainDesignation bestDesignation;
	if (this.m_dumpingManager.Value.TryFindClosestReadyToDump(outputBuffer.Entity.CenterTile.Tile2i, outputBuffer, (Option<LooseProductProto>) dumpableProduct.Value, truckData.Truck, out bestDesignation, this.m_terrainDesignationsCache))
	{
	  Quantity quantity3 = truckData.Capacity.Min(outputBuffer.AvailableQuantityCached);
	  return new BalancingJobSpec?(new BalancingJobSpec(truckData.Truck, bestDesignation, new Lyst<TerrainDesignation>((IEnumerable<TerrainDesignation>) this.m_terrainDesignationsCache), outputBuffer, new ProductQuantity((ProductProto) dumpableProduct.Value, quantity3)));
	}
  }

Then in TerrainDumpingManager

public bool TryFindClosestReadyToDump(Tile2i position, Option<LooseProductProto> product, Truck servicingVehicle, ulong? zoneMask, out TerrainDesignation bestDesignation,            IIndexable<MineTower> towersToEnforce = null, bool tryIgnoreReservations = false, Lyst<TerrainDesignation> additionalNearbyDesignations = null)

Which includes

IndexableEnumerator<MineTower> enumerator3 = m_towersManager.Towers.GetEnumerator();
while (enumerator3.MoveNext())
{
	MineTower current3 = enumerator3.Current;
	if (current3.IsEnabled && (current3.AllowNonAssignedOutput || !current3.HasOutputStorageOrTowerAssigned) && doesTowerAllowDumpOfAll(current3, m_cargoCache))
	{
		m_towersThatCanDumpTmp.Add(current3);
	}
}

That doesn't check for the returned MineTower having the correct ZoneMask.

Maybe I am completely on the wrong track, then sorry for the wrong analysis.

Reproduction steps

Use output buffer ouside Logistic zone.

Game version and build number

v0.79 b495

Operating system

Windows

Attachments

I can supply a save together with the very limited mods needed to run.

flamaster2016 [github] · 1 year ago

I have the same issue - I have trucks that are supposed to stay on one of the islands via a logistics zone, pick up from that island, ignore dumping zones within that island that they should respect, and travel across the map to another dumping zone (obviously outside the logistics zone). I can supply a save without mods if required.

flamaster2016 [github] · 1 year ago

I re-named the remote dumping tower and it got the trucks to reset and stay in their logistics zone.

Timsonrobl [github] · 1 year ago

I re-named the remote dumping tower and it got the trucks to reset and stay in their logistics zone.

Didn't work, tried renaming Control Towers, renaming zones, moving zones.
Trucks seems to completely ignore Logistic Zones when doing dumping designations on my save after the update

utdrmac [github] · 1 year ago

I have a somewhat similar issue where trucks assigned to zone D are leaving that zone to dump products if they cannot find a place in zone D. This is not acceptable. Zones are supposed to 100%, without exception, restrict trucks to the zone. What should have happened, is that an error appeared in the alerts saying 'truck has no dumping destination', or 'truck can't find path', etc.

hreintke · 1 year ago

I know my code analyses in the original error report is wrong.
But the symptons, trucks leaving zones, is an issue that prevents to use zones as intended.

On discord I see multiple people having the same issue.

As said, I can provide a save file with very limited mods, for which I can provide the binaries.

Do you want me to attach those, or do any other investigation ?

17 Showing 1–8 of 8