Trace restrict: add train ownership conditional.
Infra sharing whitespace fix.
This commit is contained in:
@@ -348,6 +348,11 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp
|
||||
break;
|
||||
}
|
||||
|
||||
case TRIT_COND_TRAIN_OWNER: {
|
||||
result = TestBinaryConditionCommon(item, v->owner == condvalue);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
}
|
||||
@@ -476,6 +481,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector<TraceRestrictItem>
|
||||
case TRIT_COND_CARGO:
|
||||
case TRIT_COND_ENTRY_DIRECTION:
|
||||
case TRIT_COND_PBS_ENTRY_SIGNAL:
|
||||
case TRIT_COND_TRAIN_OWNER:
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -569,6 +575,11 @@ void SetTraceRestrictValueDefault(TraceRestrictItem &item, TraceRestrictValueTyp
|
||||
SetTraceRestrictAuxField(item, TRPPAF_PRESET);
|
||||
break;
|
||||
|
||||
case TRVT_OWNER:
|
||||
SetTraceRestrictValue(item, INVALID_OWNER);
|
||||
SetTraceRestrictAuxField(item, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
break;
|
||||
@@ -1091,3 +1102,27 @@ void TraceRestrictRemoveDestinationID(TraceRestrictOrderCondAuxField type, uint1
|
||||
// update windows
|
||||
InvalidateWindowClassesData(WC_TRACE_RESTRICT);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when a company is about to be deleted or taken over
|
||||
* Scan program pool and change any references to it to the new company ID, to avoid dangling references
|
||||
*/
|
||||
void TraceRestrictUpdateCompanyID(CompanyID old_company, CompanyID new_company)
|
||||
{
|
||||
TraceRestrictProgram *prog;
|
||||
|
||||
FOR_ALL_TRACE_RESTRICT_PROGRAMS(prog) {
|
||||
for (size_t i = 0; i < prog->items.size(); i++) {
|
||||
TraceRestrictItem &item = prog->items[i]; // note this is a reference,
|
||||
if (GetTraceRestrictType(item) == TRIT_COND_TRAIN_OWNER) {
|
||||
if (GetTraceRestrictValue(item) == old_company) {
|
||||
SetTraceRestrictValue(item, new_company); // this updates the instruction in-place
|
||||
}
|
||||
}
|
||||
if (IsTraceRestrictDoubleItem(item)) i++;
|
||||
}
|
||||
}
|
||||
|
||||
// update windows
|
||||
InvalidateWindowClassesData(WC_TRACE_RESTRICT);
|
||||
}
|
||||
|
Reference in New Issue
Block a user