Add trace restrict slot membership conditional.

pull/16/head^2
Jonathan G Rennison 7 years ago
parent 6417fb16c3
commit 927323dcb1

@ -2403,6 +2403,7 @@ STR_TRACE_RESTRICT_VARIABLE_ENTRY_DIRECTION :entry direction
STR_TRACE_RESTRICT_VARIABLE_PBS_ENTRY_SIGNAL :PBS entry signal
STR_TRACE_RESTRICT_VARIABLE_PBS_ENTRY_SIGNAL_LONG :entered signal of PBS block
STR_TRACE_RESTRICT_VARIABLE_TRAIN_GROUP :train group
STR_TRACE_RESTRICT_VARIABLE_TRAIN_SLOT :slot
STR_TRACE_RESTRICT_VARIABLE_TRAIN_WEIGHT :weight
STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER :power
STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE :max T.E.
@ -2426,6 +2427,8 @@ STR_TRACE_RESTRICT_CONDITIONAL_ENTRY_SIGNAL_FACE :{STRING} train
STR_TRACE_RESTRICT_CONDITIONAL_TILE_INDEX :{STRING} {STRING} {STRING} at {NUM} x {NUM} then
STR_TRACE_RESTRICT_CONDITIONAL_GROUP :{STRING} train {STRING} in group: {GROUP} then
STR_TRACE_RESTRICT_CONDITIONAL_GROUP_STR :{STRING} train {STRING} in group: {STRING} {BLACK}{STRING}then
STR_TRACE_RESTRICT_CONDITIONAL_SLOT :{STRING} train {STRING} in slot: {TRSLOT} then
STR_TRACE_RESTRICT_CONDITIONAL_SLOT_STR :{STRING} train {STRING} in slot: {STRING} {BLACK}{STRING}then
STR_TRACE_RESTRICT_CONDITIONAL_UNDEFINED :{STRING} {STRING} {STRING} {RED}undefined {BLACK}{STRING}then
STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_UNDEFINED :{STRING} {RED}undefined {BLACK}{STRING}then
STR_TRACE_RESTRICT_PF_PENALTY_ITEM :Add pathfinder penalty: {COMMA}

@ -354,6 +354,12 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp
break;
}
case TRIT_COND_SLOT: {
const TraceRestrictSlot *slot = TraceRestrictSlot::GetIfValid(GetTraceRestrictValue(item));
result = TestBinaryConditionCommon(item, slot != NULL && slot->IsOccupant(v->index));
break;
}
case TRIT_COND_PHYS_PROP: {
switch (static_cast<TraceRestrictPhysPropCondAuxField>(GetTraceRestrictAuxField(item))) {
case TRPPCAF_WEIGHT:
@ -563,6 +569,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector<TraceRestrictItem>
case TRIT_COND_ENTRY_DIRECTION:
case TRIT_COND_PBS_ENTRY_SIGNAL:
case TRIT_COND_TRAIN_GROUP:
case TRIT_COND_SLOT:
case TRIT_COND_PHYS_PROP:
case TRIT_COND_PHYS_RATIO:
break;
@ -1482,7 +1489,7 @@ void TraceRestrictRemoveSlotID(TraceRestrictSlotID index)
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_SLOT && GetTraceRestrictValue(item) == index) {
if ((GetTraceRestrictType(item) == TRIT_SLOT || GetTraceRestrictType(item) == TRIT_COND_SLOT) && GetTraceRestrictValue(item) == index) {
SetTraceRestrictValueDefault(item, TRVT_SLOT_INDEX); // this updates the instruction in-place
}
if (IsTraceRestrictDoubleItem(item)) i++;

@ -133,6 +133,7 @@ enum TraceRestrictItemType {
TRIT_COND_TRAIN_GROUP = 18, ///< Test train group membership
TRIT_COND_PHYS_PROP = 19, ///< Test train physical property
TRIT_COND_PHYS_RATIO = 20, ///< Test train physical property ratio
TRIT_COND_SLOT = 21, ///< Test train slot membership
//TRIT_COND_TRAIN_OWNER = 24, ///< Test train owner: reserved for future use
/* space up to 31 */
};
@ -551,6 +552,11 @@ static inline TraceRestrictTypePropertySet GetTraceRestrictTypeProperties(TraceR
out.cond_type = TRCOT_BINARY;
break;
case TRIT_COND_SLOT:
out.value_type = TRVT_SLOT_INDEX;
out.cond_type = TRCOT_BINARY;
break;
case TRIT_COND_PHYS_PROP:
switch (static_cast<TraceRestrictPhysPropCondAuxField>(GetTraceRestrictAuxField(item))) {
case TRPPCAF_WEIGHT:

@ -327,6 +327,7 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictG
STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE,
STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER_WEIGHT_RATIO,
STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE_WEIGHT_RATIO,
STR_TRACE_RESTRICT_VARIABLE_TRAIN_SLOT,
STR_TRACE_RESTRICT_VARIABLE_UNDEFINED,
INVALID_STRING_ID,
};
@ -345,6 +346,7 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictG
TRIT_COND_PHYS_PROP | (TRPPCAF_MAX_TE << 16),
TRIT_COND_PHYS_RATIO | (TRPPRCAF_POWER_WEIGHT << 16),
TRIT_COND_PHYS_RATIO | (TRPPRCAF_MAX_TE_WEIGHT << 16),
TRIT_COND_SLOT,
TRIT_COND_UNDEFINED,
};
static const TraceRestrictDropDownListSet set_cond = {
@ -912,6 +914,19 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric
DrawInstructionStringConditionalIntegerCommon(item, properties);
break;
case TRVT_SLOT_INDEX:
SetDParam(0, _program_cond_type[GetTraceRestrictCondFlags(item)]);
SetDParam(1, GetDropDownStringByValue(GetCondOpDropDownListSet(properties), GetTraceRestrictCondOp(item)));
if (GetTraceRestrictValue(item) == INVALID_TRACE_RESTRICT_SLOT_ID) {
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_SLOT_STR;
SetDParam(2, STR_TRACE_RESTRICT_VARIABLE_UNDEFINED_RED);
SetDParam(3, selected ? STR_TRACE_RESTRICT_WHITE : STR_EMPTY);
} else {
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_SLOT;
SetDParam(2, GetTraceRestrictValue(item));
}
break;
default:
NOT_REACHED();
break;
@ -2132,9 +2147,11 @@ private:
break;
case TRVT_SLOT_INDEX:
middle_sel->SetDisplayedPlane(DPM_SLOT_OP);
right_sel->SetDisplayedPlane(DPR_VALUE_DROPDOWN);
this->EnableWidget(TR_WIDGET_SLOT_OP);
if (!IsTraceRestrictConditional(item)) {
middle_sel->SetDisplayedPlane(DPM_SLOT_OP);
this->EnableWidget(TR_WIDGET_SLOT_OP);
}
const TraceRestrictSlot *slot;
FOR_ALL_TRACE_RESTRICT_SLOTS(slot) {

Loading…
Cancel
Save