Hand the driver over when a locomotive is moved to the head

The locomotive put first takes the driver, in cab A; the one it pushed
behind is left unstaffed. Stepping a card left or right is now an ordinary
move, so it also recouples the train and frees the coupler at its back.
This commit is contained in:
maj00r
2026-10-04 18:08:14 +02:00
parent bfa899718c
commit 72b4e44c43
2 changed files with 59 additions and 8 deletions

View File

@@ -289,36 +289,51 @@ public sealed class Consist : IReadOnlyList<ConsistItem>
{
int i = _items.IndexOf(item);
if (i > 0)
{
(_items[i - 1], _items[i]) = (_items[i], _items[i - 1]);
Raise();
}
Move(i, i - 1);
}
public void MoveRight(ConsistItem item)
{
int i = _items.IndexOf(item);
if (i >= 0 && i < _items.Count - 1)
{
(_items[i + 1], _items[i]) = (_items[i], _items[i + 1]);
Raise();
}
Move(i, i + 1);
}
public void Move(int from, int to)
{
if (from < 0 || from >= _items.Count) return;
var previousHead = _items[0];
var item = _items[from];
_items.RemoveAt(from);
to = Math.Clamp(to, 0, _items.Count);
_items.Insert(to, item);
HandOverLead(previousHead);
Selected = item;
AutoConnectAll();
Raise();
}
/// <summary>
/// A locomotive that comes to the head of the train takes over the driver of
/// the one it put behind, which is left unstaffed: the train is driven from its
/// front, from cab A.
/// </summary>
private void HandOverLead(ConsistItem previousHead)
{
var head = _items[0];
if (ReferenceEquals(head, previousHead) || !IsPowered(head) ||
previousHead.Driver is not (eDriverType.Headdriver or eDriverType.Reardriver))
return;
previousHead.Driver = eDriverType.Nobody;
foreach (var car in previousHead.Cars)
car.DriverType = eDriverType.Nobody;
Crew(head, eDriverType.Headdriver);
}
public void Remove(ConsistItem item)
{
int gap = _items.IndexOf(item);