Tracerestrict: Add slot action mode, try to acquire (only on reserve)

This commit is contained in:
Jonathan G Rennison
2021-08-15 22:11:08 +01:00
parent be4c2be35b
commit b8d5113c5a
6 changed files with 22 additions and 3 deletions

View File

@@ -3010,6 +3010,7 @@ STR_TRACE_RESTRICT_COUNTER_OP :Counter operati
STR_TRACE_RESTRICT_PF_PENALTY_CONTROL :Penalty config STR_TRACE_RESTRICT_PF_PENALTY_CONTROL :Penalty config
STR_TRACE_RESTRICT_SLOT_ACQUIRE_WAIT :Acquire or wait STR_TRACE_RESTRICT_SLOT_ACQUIRE_WAIT :Acquire or wait
STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE :Try to acquire STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE :Try to acquire
STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE_ON_RES :Try to acquire (on reserve)
STR_TRACE_RESTRICT_SLOT_RELEASE_FRONT :Release (front) STR_TRACE_RESTRICT_SLOT_RELEASE_FRONT :Release (front)
STR_TRACE_RESTRICT_SLOT_RELEASE_BACK :Release (back) STR_TRACE_RESTRICT_SLOT_RELEASE_BACK :Release (back)
STR_TRACE_RESTRICT_SLOT_PBS_RES_END_ACQUIRE_WAIT :PBS end: Acquire or wait STR_TRACE_RESTRICT_SLOT_PBS_RES_END_ACQUIRE_WAIT :PBS end: Acquire or wait
@@ -3017,6 +3018,7 @@ STR_TRACE_RESTRICT_SLOT_PBS_RES_END_TRY_ACQUIRE :PBS end: Try to
STR_TRACE_RESTRICT_SLOT_PBS_RES_END_RELEASE :PBS end: Release STR_TRACE_RESTRICT_SLOT_PBS_RES_END_RELEASE :PBS end: Release
STR_TRACE_RESTRICT_SLOT_ACQUIRE_WAIT_ITEM :Acquire slot: {STRING1}{BLACK}{STRING}, or wait at PBS signal STR_TRACE_RESTRICT_SLOT_ACQUIRE_WAIT_ITEM :Acquire slot: {STRING1}{BLACK}{STRING}, or wait at PBS signal
STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE_ITEM :Try to acquire slot: {STRING1}{BLACK}{STRING}, or continue anyway STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE_ITEM :Try to acquire slot: {STRING1}{BLACK}{STRING}, or continue anyway
STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE_ITEM_RES_ONLY :Try to acquire (on PBS reserve) slot: {STRING1}{BLACK}{STRING}, or continue anyway
STR_TRACE_RESTRICT_SLOT_RELEASE_FRONT_ITEM :Release slot: {STRING1}{BLACK}{STRING} (front of train) STR_TRACE_RESTRICT_SLOT_RELEASE_FRONT_ITEM :Release slot: {STRING1}{BLACK}{STRING} (front of train)
STR_TRACE_RESTRICT_SLOT_RELEASE_BACK_ITEM :Release slot: {STRING1}{BLACK}{STRING} (back of train) STR_TRACE_RESTRICT_SLOT_RELEASE_BACK_ITEM :Release slot: {STRING1}{BLACK}{STRING} (back of train)
STR_TRACE_RESTRICT_SLOT_PBS_RES_END_ACQUIRE_WAIT_ITEM :PBS reservation ending here: Acquire slot: {STRING1}{BLACK}{STRING}, or wait at start STR_TRACE_RESTRICT_SLOT_PBS_RES_END_ACQUIRE_WAIT_ITEM :PBS reservation ending here: Acquire slot: {STRING1}{BLACK}{STRING}, or wait at start

View File

@@ -68,7 +68,7 @@ static uint32 saveLC(const SlxiSubChunkInfo *info, bool dry_run);
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_VERSION_LABEL, XSCF_IGNORABLE_ALL, 1, 1, "version_label", saveVL, loadVL, nullptr }, { XSLFI_VERSION_LABEL, XSCF_IGNORABLE_ALL, 1, 1, "version_label", saveVL, loadVL, nullptr },
{ XSLFI_TRACE_RESTRICT, XSCF_NULL, 11, 11, "tracerestrict", nullptr, nullptr, "TRRM,TRRP,TRRS" }, { XSLFI_TRACE_RESTRICT, XSCF_NULL, 12, 12, "tracerestrict", nullptr, nullptr, "TRRM,TRRP,TRRS" },
{ XSLFI_TRACE_RESTRICT_OWNER, XSCF_NULL, 1, 1, "tracerestrict_owner", nullptr, nullptr, nullptr }, { XSLFI_TRACE_RESTRICT_OWNER, XSCF_NULL, 1, 1, "tracerestrict_owner", nullptr, nullptr, nullptr },
{ XSLFI_TRACE_RESTRICT_ORDRCND, XSCF_NULL, 3, 3, "tracerestrict_order_cond", nullptr, nullptr, nullptr }, { XSLFI_TRACE_RESTRICT_ORDRCND, XSCF_NULL, 3, 3, "tracerestrict_order_cond", nullptr, nullptr, nullptr },
{ XSLFI_TRACE_RESTRICT_STATUSCND,XSCF_NULL, 1, 1, "tracerestrict_status_cond", nullptr, nullptr, nullptr }, { XSLFI_TRACE_RESTRICT_STATUSCND,XSCF_NULL, 1, 1, "tracerestrict_status_cond", nullptr, nullptr, nullptr },

View File

@@ -671,6 +671,10 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp
if (input.permitted_slot_operations & TRPISP_PBS_RES_END_RELEASE) slot->Vacate(v->index); if (input.permitted_slot_operations & TRPISP_PBS_RES_END_RELEASE) slot->Vacate(v->index);
break; break;
case TRSCOF_ACQUIRE_TRY_ON_RESERVE:
if (input.permitted_slot_operations & TRPISP_ACQUIRE_ON_RES) slot->Occupy(v->index);
break;
default: default:
NOT_REACHED(); NOT_REACHED();
break; break;
@@ -924,6 +928,10 @@ CommandCost TraceRestrictProgram::Validate(const std::vector<TraceRestrictItem>
actions_used_flags |= TRPAUF_PBS_RES_END_SLOT; actions_used_flags |= TRPAUF_PBS_RES_END_SLOT;
break; break;
case TRSCOF_ACQUIRE_TRY_ON_RESERVE:
actions_used_flags |= TRPAUF_SLOT_ACQUIRE_ON_RES;
break;
default: default:
NOT_REACHED(); NOT_REACHED();
break; break;

View File

@@ -327,6 +327,7 @@ enum TraceRestrictSlotCondOpField {
TRSCOF_PBS_RES_END_ACQ_WAIT = 4, ///< PBS reservations ending at this signal: acquire a slot, or wait TRSCOF_PBS_RES_END_ACQ_WAIT = 4, ///< PBS reservations ending at this signal: acquire a slot, or wait
TRSCOF_PBS_RES_END_ACQ_TRY = 5, ///< PBS reservations ending at this signal: acquire a slot, or carry on otherwise TRSCOF_PBS_RES_END_ACQ_TRY = 5, ///< PBS reservations ending at this signal: acquire a slot, or carry on otherwise
TRSCOF_PBS_RES_END_RELEASE = 6, ///< PBS reservations ending at this signal: release a slot TRSCOF_PBS_RES_END_RELEASE = 6, ///< PBS reservations ending at this signal: release a slot
TRSCOF_ACQUIRE_TRY_ON_RESERVE = 7, ///< try to acquire a slot (on reserve), or carry on otherwise
/* space up to 8 */ /* space up to 8 */
}; };
@@ -403,6 +404,7 @@ enum TraceRestrictProgramActionsUsedFlags {
TRPAUF_TRAIN_NOT_STUCK = 1 << 11, ///< Train is not stuck TRPAUF_TRAIN_NOT_STUCK = 1 << 11, ///< Train is not stuck
TRPAUF_CHANGE_COUNTER = 1 << 12, ///< Change counter value is present TRPAUF_CHANGE_COUNTER = 1 << 12, ///< Change counter value is present
TRPAUF_NO_PBS_BACK_PENALTY = 1 << 13, ///< No PBS back penalty is present TRPAUF_NO_PBS_BACK_PENALTY = 1 << 13, ///< No PBS back penalty is present
TRPAUF_SLOT_ACQUIRE_ON_RES = 1 << 14, ///< Slot acquire (on reserve) action is present
}; };
DECLARE_ENUM_AS_BIT_SET(TraceRestrictProgramActionsUsedFlags) DECLARE_ENUM_AS_BIT_SET(TraceRestrictProgramActionsUsedFlags)
@@ -417,6 +419,7 @@ enum TraceRestrictProgramInputSlotPermissions {
TRPISP_PBS_RES_END_ACQ_DRY = 1 << 4, ///< Dry-run slot acquire (PBS reservations ending at this signal) is permitted TRPISP_PBS_RES_END_ACQ_DRY = 1 << 4, ///< Dry-run slot acquire (PBS reservations ending at this signal) is permitted
TRPISP_PBS_RES_END_RELEASE = 1 << 5, ///< Slot release (PBS reservations ending at this signal) is permitted TRPISP_PBS_RES_END_RELEASE = 1 << 5, ///< Slot release (PBS reservations ending at this signal) is permitted
TRPISP_CHANGE_COUNTER = 1 << 6, ///< Change counter value is permitted TRPISP_CHANGE_COUNTER = 1 << 6, ///< Change counter value is permitted
TRPISP_ACQUIRE_ON_RES = 1 << 7, ///< Slot acquire (reserving route) is permitted
}; };
DECLARE_ENUM_AS_BIT_SET(TraceRestrictProgramInputSlotPermissions) DECLARE_ENUM_AS_BIT_SET(TraceRestrictProgramInputSlotPermissions)

View File

@@ -722,6 +722,7 @@ static const StringID _slot_op_cond_ops_str[] = {
STR_TRACE_RESTRICT_SLOT_PBS_RES_END_ACQUIRE_WAIT, STR_TRACE_RESTRICT_SLOT_PBS_RES_END_ACQUIRE_WAIT,
STR_TRACE_RESTRICT_SLOT_PBS_RES_END_TRY_ACQUIRE, STR_TRACE_RESTRICT_SLOT_PBS_RES_END_TRY_ACQUIRE,
STR_TRACE_RESTRICT_SLOT_PBS_RES_END_RELEASE, STR_TRACE_RESTRICT_SLOT_PBS_RES_END_RELEASE,
STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE_ON_RES,
INVALID_STRING_ID, INVALID_STRING_ID,
}; };
static const uint _slot_op_cond_ops_val[] = { static const uint _slot_op_cond_ops_val[] = {
@@ -732,6 +733,7 @@ static const uint _slot_op_cond_ops_val[] = {
TRSCOF_PBS_RES_END_ACQ_WAIT, TRSCOF_PBS_RES_END_ACQ_WAIT,
TRSCOF_PBS_RES_END_ACQ_TRY, TRSCOF_PBS_RES_END_ACQ_TRY,
TRSCOF_PBS_RES_END_RELEASE, TRSCOF_PBS_RES_END_RELEASE,
TRSCOF_ACQUIRE_TRY_ON_RESERVE,
}; };
/** cargo conditional operators dropdown list set */ /** cargo conditional operators dropdown list set */
static const TraceRestrictDropDownListSet _slot_op_cond_ops = { static const TraceRestrictDropDownListSet _slot_op_cond_ops = {
@@ -1409,6 +1411,10 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric
instruction_string = STR_TRACE_RESTRICT_SLOT_PBS_RES_END_RELEASE_ITEM; instruction_string = STR_TRACE_RESTRICT_SLOT_PBS_RES_END_RELEASE_ITEM;
break; break;
case TRSCOF_ACQUIRE_TRY_ON_RESERVE:
instruction_string = STR_TRACE_RESTRICT_SLOT_TRY_ACQUIRE_ITEM_RES_ONLY;
break;
default: default:
NOT_REACHED(); NOT_REACHED();
break; break;

View File

@@ -4067,10 +4067,10 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
if (track != INVALID_TRACK && HasPbsSignalOnTrackdir(tile, TrackEnterdirToTrackdir(track, enterdir))) { if (track != INVALID_TRACK && HasPbsSignalOnTrackdir(tile, TrackEnterdirToTrackdir(track, enterdir))) {
if (IsRestrictedSignal(tile) && v->force_proceed != TFP_SIGNAL) { if (IsRestrictedSignal(tile) && v->force_proceed != TFP_SIGNAL) {
const TraceRestrictProgram *prog = GetExistingTraceRestrictProgram(tile, track); const TraceRestrictProgram *prog = GetExistingTraceRestrictProgram(tile, track);
if (prog && prog->actions_used_flags & (TRPAUF_WAIT_AT_PBS | TRPAUF_SLOT_ACQUIRE | TRPAUF_TRAIN_NOT_STUCK)) { if (prog && prog->actions_used_flags & (TRPAUF_WAIT_AT_PBS | TRPAUF_SLOT_ACQUIRE | TRPAUF_SLOT_ACQUIRE_ON_RES | TRPAUF_TRAIN_NOT_STUCK)) {
TraceRestrictProgramResult out; TraceRestrictProgramResult out;
TraceRestrictProgramInput input(tile, TrackEnterdirToTrackdir(track, enterdir), nullptr, nullptr); TraceRestrictProgramInput input(tile, TrackEnterdirToTrackdir(track, enterdir), nullptr, nullptr);
input.permitted_slot_operations = TRPISP_ACQUIRE; input.permitted_slot_operations = TRPISP_ACQUIRE | TRPISP_ACQUIRE_ON_RES;
prog->Execute(v, input, out); prog->Execute(v, input, out);
if (out.flags & TRPRF_TRAIN_NOT_STUCK) { if (out.flags & TRPRF_TRAIN_NOT_STUCK) {
v->wait_counter = 0; v->wait_counter = 0;