TBTR: Delete orphaned virtual trains on client disconnection

This commit is contained in:
Jonathan G Rennison
2020-10-09 19:26:07 +01:00
parent 348178e9eb
commit cce6d731a1
9 changed files with 41 additions and 23 deletions

View File

@@ -1508,6 +1508,20 @@ void CallVehicleTicks()
_vehicles_to_pay_repair.clear();
}
void RemoveVirtualTrainsOfUser(uint32 user)
{
if (!_tick_caches_valid || HasChickenBit(DCBF_VEH_TICK_CACHE)) RebuildVehicleTickCaches();
Backup<CompanyID> cur_company(_current_company, FILE_LINE);
for (const Train *front : _tick_train_front_cache) {
if (front->IsVirtual() && front->motion_counter == user) {
cur_company.Change(front->owner);
DoCommandP(0, front->index, 0, CMD_DELETE_VIRTUAL_TRAIN);
}
}
cur_company.Restore();
}
/**
* Add vehicle sprite for drawing to the screen.
* @param v Vehicle to draw.