Trace restrict slots: Add support for slot operations at PBS end signal

This commit is contained in:
Jonathan G Rennison
2018-06-17 21:13:53 +01:00
parent 1b4db7d86c
commit e9f5d80440
8 changed files with 110 additions and 6 deletions

View File

@@ -519,6 +519,22 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp
if (input.permitted_slot_operations & TRPISP_RELEASE_FRONT) slot->Vacate(v->index);
break;
case TRSCOF_PBS_RES_END_ACQ_WAIT:
if (input.permitted_slot_operations & TRPISP_PBS_RES_END_ACQUIRE) {
if (!slot->Occupy(v->index)) out.flags |= TRPRF_PBS_RES_END_WAIT;
} else if (input.permitted_slot_operations & TRPISP_PBS_RES_END_ACQ_DRY) {
if (!slot->OccupyDryRun(v->index)) out.flags |= TRPRF_PBS_RES_END_WAIT;
}
break;
case TRSCOF_PBS_RES_END_ACQ_TRY:
if (input.permitted_slot_operations & TRPISP_PBS_RES_END_ACQUIRE) slot->Occupy(v->index);
break;
case TRSCOF_PBS_RES_END_RELEASE:
if (input.permitted_slot_operations & TRPISP_PBS_RES_END_RELEASE) slot->Vacate(v->index);
break;
default:
NOT_REACHED();
break;
@@ -673,6 +689,15 @@ CommandCost TraceRestrictProgram::Validate(const std::vector<TraceRestrictItem>
actions_used_flags |= TRPAUF_SLOT_RELEASE_FRONT;
break;
case TRSCOF_PBS_RES_END_ACQ_WAIT:
actions_used_flags |= TRPAUF_PBS_RES_END_SLOT | TRPAUF_PBS_RES_END_WAIT;
break;
case TRSCOF_PBS_RES_END_ACQ_TRY:
case TRSCOF_PBS_RES_END_RELEASE:
actions_used_flags |= TRPAUF_PBS_RES_END_SLOT;
break;
default:
NOT_REACHED();
break;
@@ -1467,6 +1492,18 @@ bool TraceRestrictSlot::Occupy(VehicleID id, bool force)
return true;
}
/**
* Dry-run adding vehicle ID to occupants if possible and not already an occupant
* @param id Vehicle ID
* @return whether vehicle IDwould be an occupant
*/
bool TraceRestrictSlot::OccupyDryRun(VehicleID id)
{
if (this->IsOccupant(id)) return true;
if (this->occupants.size() >= this->max_occupancy) return false;
return true;
}
/**
* Remove vehicle ID from occupants
* @param id Vehicle ID