Add get/set wrappers for order xdata/xdata2 sub-fields

This commit is contained in:
Jonathan G Rennison 2024-09-04 01:00:11 +01:00
parent 318f5ff471
commit bc67c0f179
7 changed files with 128 additions and 71 deletions

View File

@ -98,7 +98,7 @@ static uint8_t GetDepartureConditionalOrderMode(const Order *order, const Vehicl
}
if (order->GetConditionVariable() == OCV_DISPATCH_SLOT) {
if (GB(order->GetConditionValue(), ODCB_SRC_START, ODCB_SRC_COUNT) == ODCS_VEH) {
auto record = records.find(std::make_pair(GB(order->GetXData(), 0, 16), v->index));
auto record = records.find(std::make_pair(order->GetConditionDispatchScheduleID(), v->index));
if (record != records.end()) {
/* SchdispatchCacheEntry contains a last dispatch entry, use that instead of the one stored in the vehicle */
extern bool EvaluateDispatchSlotConditionalOrderVehicleRecord(const Order *order, const LastDispatchRecord &record);

View File

@ -145,7 +145,7 @@ private:
inline uint8_t &GetXFlagsRef()
{
CheckExtraInfoAlloced();
this->CheckExtraInfoAlloced();
return this->extra->xflags;
}
@ -155,23 +155,63 @@ public:
return this->extra != nullptr ? this->extra->xdata : 0;
}
inline uint16_t GetXDataLow() const
{
return (uint16_t)GB(this->GetXData(), 0, 16);
}
inline uint16_t GetXDataHigh() const
{
return (uint16_t)GB(this->GetXData(), 16, 16);
}
inline uint32_t &GetXDataRef()
{
CheckExtraInfoAlloced();
this->CheckExtraInfoAlloced();
return this->extra->xdata;
}
inline void SetXDataLow(uint16_t data)
{
SB(this->GetXDataRef(), 0, 16, data);
}
inline void SetXDataHigh(uint16_t data)
{
SB(this->GetXDataRef(), 16, 16, data);
}
inline uint32_t GetXData2() const
{
return this->extra != nullptr ? this->extra->xdata2 : 0;
}
inline uint16_t GetXData2Low() const
{
return (uint16_t)GB(this->GetXData2(), 0, 16);
}
inline uint16_t GetXData2High() const
{
return (uint16_t)GB(this->GetXData2(), 16, 16);
}
inline uint32_t &GetXData2Ref()
{
CheckExtraInfoAlloced();
this->CheckExtraInfoAlloced();
return this->extra->xdata2;
}
inline void SetXData2Low(uint16_t data)
{
SB(this->GetXData2Ref(), 0, 16, data);
}
inline void SetXData2High(uint16_t data)
{
SB(this->GetXData2Ref(), 16, 16, data);
}
inline uint16_t GetRawFlags() const
{
return this->flags;
@ -405,6 +445,14 @@ public:
inline int8_t GetJumpCounter() const { return GB(this->GetXData(), 0, 8); }
/** Get counter operation */
inline uint8_t GetCounterOperation() const { return GB(this->flags, 0, 8); }
/** Get condition station ID */
inline StationID GetConditionStationID() const { return (StationID)(this->GetXData2Low() - 1); }
/** Has condition via station ID */
inline bool HasConditionViaStation() const { return this->GetXDataHigh() != 0; }
/** Get condition via station ID */
inline StationID GetConditionViaStationID() const { return (StationID)(this->GetXDataHigh() - 2); }
/** Get condition dispatch scheduled ID */
inline uint16_t GetConditionDispatchScheduleID() const { return this->GetXDataLow(); }
/** Set how the consist must be loaded. */
inline void SetLoadType(OrderLoadFlags load_type)
@ -470,6 +518,14 @@ public:
inline void SetJumpCounter(int8_t jump_counter) { SB(this->GetXDataRef(), 0, 8, jump_counter); }
/** Set counter operation */
inline void SetCounterOperation(uint8_t op) { SB(this->flags, 0, 8, op); }
/** Set condition station ID */
inline void SetConditionStationID(StationID st) { this->SetXData2Low(st + 1); }
/** Set condition via station ID */
inline void SetConditionViaStationID(StationID st) { this->SetXDataHigh(st + 2); }
/** Clear condition via station ID */
inline void ClearConditionViaStation() { this->SetXDataHigh(0); }
/** Set condition dispatch scheduled ID */
inline void SetConditionDispatchScheduleID(uint16_t slot) { this->SetXDataLow(slot); }
/* As conditional orders write their "skip to" order all over the flags, we cannot check the
* flags to find out if timetabling is enabled. However, as conditional orders are never

View File

@ -973,12 +973,12 @@ TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
TileIndex Order::GetAuxiliaryLocation(bool secondary) const
{
if (this->IsType(OT_CONDITIONAL)) {
if (secondary && ConditionVariableTestsCargoWaitingAmount(this->GetConditionVariable()) && GB(this->GetXData(), 16, 16) != 0) {
const Station *st = Station::GetIfValid(GB(this->GetXData(), 16, 16) - 2);
if (secondary && ConditionVariableTestsCargoWaitingAmount(this->GetConditionVariable()) && this->HasConditionViaStation()) {
const Station *st = Station::GetIfValid(this->GetConditionViaStationID());
if (st != nullptr) return st->xy;
}
if (ConditionVariableHasStationID(this->GetConditionVariable())) {
const Station *st = Station::GetIfValid(GB(this->GetXData2(), 0, 16) - 1);
const Station *st = Station::GetIfValid(this->GetConditionStationID());
if (st != nullptr) return st->xy;
}
}
@ -2129,7 +2129,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32_t p1, uin
case OCV_CARGO_WAITING_AMOUNT:
case OCV_CARGO_WAITING_AMOUNT_PERCENTAGE:
if (!(data == NEW_STATION || Station::GetIfValid(data) != nullptr)) return CMD_ERROR;
if (GB(order->GetXData2(), 0, 16) - 1 == data) return CMD_ERROR;
if (order->GetConditionStationID() == data) return CMD_ERROR;
break;
default:
@ -2408,7 +2408,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32_t p1, uin
case OCV_CARGO_WAITING_AMOUNT:
case OCV_CARGO_WAITING_AMOUNT_PERCENTAGE:
case OCV_COUNTER_VALUE:
SB(order->GetXDataRef(), 0, 16, data);
order->SetXDataLow(data);
break;
default:
@ -2420,11 +2420,11 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32_t p1, uin
case MOF_COND_VALUE_2:
switch (order->GetConditionVariable()) {
case OCV_COUNTER_VALUE:
SB(order->GetXDataRef(), 16, 16, data);
order->SetXDataHigh(data);
break;
case OCV_DISPATCH_SLOT:
SB(order->GetXDataRef(), 0, 16, data);
order->SetConditionDispatchScheduleID(data);
break;
default:
@ -2434,7 +2434,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32_t p1, uin
break;
case MOF_COND_VALUE_3:
SB(order->GetXDataRef(), 16, 16, data + 2);
order->SetConditionViaStationID(data);
break;
case MOF_COND_VALUE_4:
@ -2442,10 +2442,10 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32_t p1, uin
break;
case MOF_COND_STATION_ID:
SB(order->GetXData2Ref(), 0, 16, data + 1);
if (ConditionVariableTestsCargoWaitingAmount(order->GetConditionVariable()) && data == GB(order->GetXData(), 16, 16) - 2) {
order->SetConditionStationID(data);
if (ConditionVariableTestsCargoWaitingAmount(order->GetConditionVariable()) && data == order->GetConditionViaStationID()) {
/* Clear via if station is set to the same ID */
SB(order->GetXDataRef(), 16, 16, 0);
order->ClearConditionViaStation();
}
break;
@ -3074,10 +3074,10 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool
OrderType ot = o->GetType();
if (ot == OT_CONDITIONAL) {
if (type == OT_GOTO_STATION && ConditionVariableTestsCargoWaitingAmount(o->GetConditionVariable())) {
if (GB(order->GetXData(), 16, 16) - 2 == destination) SB(order->GetXDataRef(), 16, 16, INVALID_STATION + 2);
if (order->GetConditionViaStationID() == destination) order->SetConditionViaStationID(INVALID_STATION);
}
if (type == OT_GOTO_STATION && ConditionVariableHasStationID(o->GetConditionVariable())) {
if (GB(order->GetXData2(), 0, 16) - 1 == destination) SB(order->GetXData2Ref(), 0, 16, INVALID_STATION + 1);
if (order->GetConditionStationID() == destination) order->SetConditionStationID(INVALID_STATION);
}
return false;
}
@ -3259,7 +3259,7 @@ bool EvaluateDispatchSlotConditionalOrderVehicleRecord(const Order *order, const
bool EvaluateDispatchSlotConditionalOrder(const Order *order, const Vehicle *v, StateTicks state_ticks, bool *predicted)
{
uint16_t schedule_index = static_cast<uint16_t>(GB(order->GetXData(), 0, 16));
uint16_t schedule_index = order->GetConditionDispatchScheduleID();
if (schedule_index >= v->orders->GetScheduledDispatchScheduleCount()) return false;
const DispatchSchedule &sched = v->orders->GetDispatchScheduleByIndex(schedule_index);
@ -3387,31 +3387,31 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, Pro
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
case OCV_UNCONDITIONALLY: skip_order = true; break;
case OCV_CARGO_WAITING: {
StationID next_station = GB(order->GetXData2(), 0, 16) - 1;
StationID next_station = order->GetConditionStationID();
if (Station::IsValidID(next_station)) skip_order = OrderConditionCompare(occ, (Station::Get(next_station)->goods[value].CargoAvailableCount() > 0), value);
break;
}
case OCV_CARGO_WAITING_AMOUNT: {
StationID next_station = GB(order->GetXData2(), 0, 16) - 1;
StationID next_station = order->GetConditionStationID();
if (Station::IsValidID(next_station)) {
if (GB(order->GetXData(), 16, 16) == 0) {
skip_order = OrderConditionCompare(occ, Station::Get(next_station)->goods[value].CargoAvailableCount(), GB(order->GetXData(), 0, 16));
if (!order->HasConditionViaStation()) {
skip_order = OrderConditionCompare(occ, Station::Get(next_station)->goods[value].CargoAvailableCount(), order->GetXDataLow());
} else {
skip_order = OrderConditionCompare(occ, Station::Get(next_station)->goods[value].CargoAvailableViaCount(GB(order->GetXData(), 16, 16) - 2), GB(order->GetXData(), 0, 16));
skip_order = OrderConditionCompare(occ, Station::Get(next_station)->goods[value].CargoAvailableViaCount(order->GetConditionViaStationID()), order->GetXDataLow());
}
}
break;
}
case OCV_CARGO_WAITING_AMOUNT_PERCENTAGE: {
StationID next_station = GB(order->GetXData2(), 0, 16) - 1;
StationID next_station = order->GetConditionStationID();
if (Station::IsValidID(next_station)) {
const bool refit_mode = HasBit(order->GetXData2(), 16);
const CargoID cargo = static_cast<CargoID>(value);
uint32_t waiting;
if (GB(order->GetXData(), 16, 16) == 0) {
if (!order->HasConditionViaStation()) {
waiting = Station::Get(next_station)->goods[cargo].CargoAvailableCount();
} else {
waiting = Station::Get(next_station)->goods[cargo].CargoAvailableViaCount(GB(order->GetXData(), 16, 16) - 2);
waiting = Station::Get(next_station)->goods[cargo].CargoAvailableViaCount(order->GetConditionViaStationID());
}
uint32_t veh_capacity = 0;
@ -3441,7 +3441,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, Pro
const_cast<Vehicle *>(u)->cargo_subtype = temp_subtype;
}
}
uint32_t percentage = GB(order->GetXData(), 0, 16);
uint32_t percentage = order->GetXDataLow();
uint32_t threshold = static_cast<uint32_t>(((uint64_t)veh_capacity * percentage) / 100);
skip_order = OrderConditionCompare(occ, waiting, threshold);
@ -3449,7 +3449,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, Pro
break;
}
case OCV_CARGO_ACCEPTANCE: {
StationID next_station = GB(order->GetXData2(), 0, 16) - 1;
StationID next_station = order->GetConditionStationID();
if (Station::IsValidID(next_station)) skip_order = OrderConditionCompare(occ, HasBit(Station::Get(next_station)->goods[value].status, GoodsEntry::GES_ACCEPTANCE), value);
break;
}
@ -3490,7 +3490,7 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, Pro
break;
}
case OCV_FREE_PLATFORMS: {
StationID next_station = GB(order->GetXData2(), 0, 16) - 1;
StationID next_station = order->GetConditionStationID();
if (Station::IsValidID(next_station)) skip_order = OrderConditionCompare(occ, GetFreeStationPlatforms(next_station), value);
break;
}
@ -3505,14 +3505,14 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v, Pro
}
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(DateDeltaToYearDelta(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1).base(), 0), value); break;
case OCV_COUNTER_VALUE: {
const TraceRestrictCounter* ctr = TraceRestrictCounter::GetIfValid(GB(order->GetXData(), 16, 16));
const TraceRestrictCounter* ctr = TraceRestrictCounter::GetIfValid(order->GetXDataHigh());
if (ctr != nullptr) {
int32_t value = ctr->value;
if (mode == PCO_DEFERRED) {
auto iter = _pco_deferred_counter_values.find(ctr->index);
if (iter != _pco_deferred_counter_values.end()) value = iter->second;
}
skip_order = OrderConditionCompare(occ, value, GB(order->GetXData(), 0, 16));
skip_order = OrderConditionCompare(occ, value, order->GetXDataLow());
}
break;
}

View File

@ -983,7 +983,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
case OT_CONDITIONAL: {
auto set_station_id = [&order](uint index, StringParameters &sp = _global_string_params) {
const Station *st = Station::GetIfValid(GB(order->GetXData2(), 0, 16) - 1);
const Station *st = Station::GetIfValid(order->GetConditionStationID());
if (st == nullptr) {
sp.SetParam(index, STR_ORDER_CONDITIONAL_UNDEFINED_STATION);
} else {
@ -1060,24 +1060,24 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
auto output_condition_value = [&](int param_offset) {
if (percent_mode) {
auto capacity_params = MakeParameters(GB(order->GetXData(), 0, 16), CargoSpec::Get(order->GetConditionValue())->name);
auto capacity_params = MakeParameters(order->GetXDataLow(), CargoSpec::Get(order->GetConditionValue())->name);
bool refit = HasBit(order->GetXData2(), 16);
StringID capacity_str = refit ? STR_ORDER_CONDITIONAL_CARGO_WAITING_PERCENT_CAPACITY_REFIT : STR_ORDER_CONDITIONAL_CARGO_WAITING_PERCENT_CAPACITY;
_temp_special_strings[0] = GetStringWithArgs(capacity_str, capacity_params);
tmp_params.SetParam(param_offset, SPECSTR_TEMP_START);
} else {
tmp_params.SetParam(param_offset, order->GetConditionValue());
tmp_params.SetParam(param_offset + 1, GB(order->GetXData(), 0, 16));
tmp_params.SetParam(param_offset + 1, order->GetXDataLow());
}
};
if (GB(order->GetXData(), 16, 16) == 0) {
if (!order->HasConditionViaStation()) {
substr = percent_mode ? STR_ORDER_CONDITIONAL_CARGO_WAITING_GENERAL_DISPLAY : STR_ORDER_CONDITIONAL_CARGO_WAITING_AMOUNT_DISPLAY;
tmp_params.SetParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + order->GetConditionComparator());
output_condition_value(5);
} else {
substr = percent_mode ? STR_ORDER_CONDITIONAL_CARGO_WAITING_GENERAL_VIA_DISPLAY : STR_ORDER_CONDITIONAL_CARGO_WAITING_AMOUNT_VIA_DISPLAY;
const Station *via_st = Station::GetIfValid(GB(order->GetXData(), 16, 16) - 2);
const Station *via_st = Station::GetIfValid(order->GetConditionViaStationID());
if (via_st == nullptr) {
tmp_params.SetParam(4, STR_ORDER_CONDITIONAL_UNDEFINED_STATION);
} else {
@ -1090,15 +1090,15 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
_temp_special_strings[0] = GetStringWithArgs(substr, tmp_params);
SetDParam(0, SPECSTR_TEMP_START);
} else if (ocv == OCV_COUNTER_VALUE) {
if (TraceRestrictCounter::IsValidID(GB(order->GetXData(), 16, 16))) {
if (TraceRestrictCounter::IsValidID(order->GetXDataHigh())) {
SetDParam(0, STR_ORDER_CONDITIONAL_COUNTER);
SetDParam(2, GB(order->GetXData(), 16, 16));
SetDParam(2, order->GetXDataHigh());
} else {
SetDParam(0, STR_ORDER_CONDITIONAL_INVALID_COUNTER);
SetDParam(2, STR_TRACE_RESTRICT_VARIABLE_UNDEFINED);
}
SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + order->GetConditionComparator());
SetDParam(4, GB(order->GetXData(), 0, 16));
SetDParam(4, order->GetXDataLow());
} else if (ocv == OCV_TIME_DATE) {
SetDParam(0, (order->GetConditionValue() == TRTDVF_HOUR_MINUTE) ? STR_ORDER_CONDITIONAL_TIME_HHMM : STR_ORDER_CONDITIONAL_NUM);
SetDParam(2, STR_TRACE_RESTRICT_TIME_MINUTE_ITEM + order->GetConditionValue());
@ -1112,10 +1112,11 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
} else if (ocv == OCV_DISPATCH_SLOT) {
const DispatchSchedule *selected_schedule = nullptr;
SetDParam(0, STR_ORDER_CONDITIONAL_DISPATCH_SLOT_DISPLAY);
if (GB(order->GetXData(), 0, 16) != UINT16_MAX) {
uint16_t schedule_id = order->GetConditionDispatchScheduleID();
if (schedule_id != UINT16_MAX) {
bool have_name = false;
if (GB(order->GetXData(), 0, 16) < v->orders->GetScheduledDispatchScheduleCount()) {
const DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(GB(order->GetXData(), 0, 16));
if (schedule_id < v->orders->GetScheduledDispatchScheduleCount()) {
const DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(schedule_id);
selected_schedule = &ds;
if (!ds.ScheduleName().empty()) {
_temp_special_strings[0] = ds.ScheduleName();
@ -1123,7 +1124,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
}
}
if (!have_name) {
auto tmp_params = MakeParameters(GB(order->GetXData(), 0, 16) + 1);
auto tmp_params = MakeParameters(schedule_id + 1);
_temp_special_strings[0] = GetStringWithArgs(STR_TIMETABLE_ASSIGN_SCHEDULE_ID, tmp_params);
}
SetDParam(2, SPECSTR_TEMP_START);
@ -2350,7 +2351,7 @@ public:
}
aux_sel->SetDisplayedPlane(DP_COND_AUX_CARGO);
} else if (is_counter) {
TraceRestrictCounterID ctr_id = (order != nullptr && TraceRestrictCounter::IsValidID(GB(order->GetXData(), 16, 16)) ? GB(order->GetXData(), 16, 16) : INVALID_TRACE_RESTRICT_COUNTER_ID);
TraceRestrictCounterID ctr_id = (order != nullptr && TraceRestrictCounter::IsValidID(order->GetXDataHigh()) ? order->GetXDataHigh() : INVALID_TRACE_RESTRICT_COUNTER_ID);
this->GetWidget<NWidgetCore>(WID_O_COND_COUNTER)->widget_data = (ctr_id != INVALID_TRACE_RESTRICT_COUNTER_ID) ? STR_TRACE_RESTRICT_COUNTER_NAME : STR_TRACE_RESTRICT_VARIABLE_UNDEFINED;
aux_sel->SetDisplayedPlane(DP_COND_COUNTER);
@ -2640,7 +2641,7 @@ public:
case OCV_CARGO_WAITING_AMOUNT:
case OCV_CARGO_WAITING_AMOUNT_PERCENTAGE:
case OCV_COUNTER_VALUE:
value = GB(order->GetXData(), 0, 16);
value = order->GetXDataLow();
break;
default:
@ -2680,7 +2681,7 @@ public:
const Order *order = this->vehicle->GetOrder(sel);
if (order != nullptr && order->IsType(OT_CONDITIONAL)) {
TraceRestrictCounterID value = GB(order->GetXData(), 16, 16);
TraceRestrictCounterID value = order->GetXDataHigh();
SetDParam(0, value);
}
break;
@ -2690,7 +2691,7 @@ public:
VehicleOrderID sel = this->OrderGetSel();
const Order *order = this->vehicle->GetOrder(sel);
uint schedule_index = GB(order->GetXData(), 0, 16);
uint schedule_index = order->GetConditionDispatchScheduleID();
if (order != nullptr && order->IsType(OT_CONDITIONAL) && order->GetConditionVariable() == OCV_DISPATCH_SLOT && schedule_index != UINT16_MAX) {
if (schedule_index < this->vehicle->orders->GetScheduledDispatchScheduleCount()) {
const DispatchSchedule &ds = this->vehicle->orders->GetDispatchScheduleByIndex(schedule_index);
@ -3092,7 +3093,7 @@ public:
case WID_O_COND_COUNTER: {
int selected;
TraceRestrictCounterID value = GB(this->vehicle->GetOrder(this->OrderGetSel())->GetXData(), 16, 16);
TraceRestrictCounterID value = this->vehicle->GetOrder(this->OrderGetSel())->GetXDataHigh();
DropDownList list = GetCounterDropDownList(this->vehicle->owner, value, selected);
if (!list.empty()) ShowDropDownList(this, std::move(list), selected, WID_O_COND_COUNTER, 0, DDMF_NONE, DDSF_SHARED);
break;
@ -3111,7 +3112,7 @@ public:
}
case WID_O_COND_SCHED_SELECT: {
int selected = GB(this->vehicle->GetOrder(this->OrderGetSel())->GetXData(), 0, 16);
int selected = this->vehicle->GetOrder(this->OrderGetSel())->GetConditionDispatchScheduleID();
if (selected == UINT16_MAX) selected = -1;
uint count = this->vehicle->orders->GetScheduledDispatchScheduleCount();
@ -3164,7 +3165,7 @@ public:
case WID_O_COND_AUX_VIA: {
if (this->goto_type != OPOS_NONE) {
ResetObjectToPlace();
} else if (GB(this->vehicle->GetOrder(this->OrderGetSel())->GetXData(), 16, 16) != 0) {
} else if (this->vehicle->GetOrder(this->OrderGetSel())->HasConditionViaStation()) {
this->ModifyOrder(this->OrderGetSel(), MOF_COND_VALUE_3 | NEW_STATION << 8);
} else {
this->OrderClick_Goto(OPOS_COND_VIA);
@ -3228,7 +3229,7 @@ public:
const DispatchSchedule *ds = nullptr;
uint16_t slot_flags = 0;
uint schedule_index = GB(o->GetXData(), 0, 16);
uint schedule_index = o->GetConditionDispatchScheduleID();
if (schedule_index < this->vehicle->orders->GetScheduledDispatchScheduleCount()) {
ds = &(this->vehicle->orders->GetDispatchScheduleByIndex(schedule_index));
for (const DispatchSlot &slot : ds->GetScheduledDispatch()) {
@ -3305,7 +3306,7 @@ public:
case OCV_CARGO_WAITING_AMOUNT:
case OCV_CARGO_WAITING_AMOUNT_PERCENTAGE:
case OCV_COUNTER_VALUE:
value = GB(order->GetXData(), 0, 16);
value = order->GetXDataLow();
break;
default:

View File

@ -4135,14 +4135,14 @@ bool AfterLoadGame()
/* Fixup station ID for OCV_CARGO_WAITING, OCV_CARGO_ACCEPTANCE, OCV_FREE_PLATFORMS, OCV_CARGO_WAITING_AMOUNT, OCV_CARGO_WAITING_AMOUNT_PERCENTAGE */
if (order->IsType(OT_CONDITIONAL) && ConditionVariableHasStationID(order->GetConditionVariable())) {
StationID next_id = get_real_station(order);
SB(order->GetXData2Ref(), 0, 16, next_id + 1);
if (next_id != INVALID_STATION && GB(order->GetXData(), 16, 16) - 2 == next_id) {
order->SetConditionStationID(next_id);
if (next_id != INVALID_STATION && order->GetConditionViaStationID() == next_id) {
/* Duplicate next and via, remove via */
SB(order->GetXDataRef(), 16, 16, 0);
order->ClearConditionViaStation();
}
if (GB(order->GetXData(), 16, 16) != 0 && !Station::IsValidID(GB(order->GetXData(), 16, 16) - 2)) {
if (order->HasConditionViaStation() && !Station::IsValidID(order->GetConditionViaStationID())) {
/* Via station is invalid */
SB(order->GetXDataRef(), 16, 16, INVALID_STATION + 2);
order->SetConditionViaStationID(INVALID_STATION);
}
}
}

View File

@ -421,13 +421,13 @@ CommandCost CmdScheduledDispatchRemoveSchedule(TileIndex tile, DoCommandFlag fla
o->SetDispatchScheduleIndex(idx - 1);
}
if (o->IsType(OT_CONDITIONAL) && o->GetConditionVariable() == OCV_DISPATCH_SLOT) {
uint16_t dispatch_slot = GB(o->GetXData(), 0, 16);
if (dispatch_slot == UINT16_MAX) {
uint16_t order_schedule = o->GetConditionDispatchScheduleID();
if (order_schedule == UINT16_MAX) {
/* do nothing */
} else if (dispatch_slot == schedule_index) {
SB(o->GetXDataRef(), 0, 16, UINT16_MAX);
} else if (dispatch_slot > schedule_index) {
SB(o->GetXDataRef(), 0, 16, (uint16_t)(dispatch_slot - 1));
} else if (order_schedule == schedule_index) {
o->SetConditionDispatchScheduleID(UINT16_MAX);
} else if (order_schedule > schedule_index) {
o->SetConditionDispatchScheduleID((uint16_t)(order_schedule - 1));
}
}
}
@ -687,11 +687,11 @@ CommandCost CmdScheduledDispatchSwapSchedules(TileIndex tile, DoCommandFlag flag
o->SetDispatchScheduleIndex((int)schedule_index_1);
}
if (o->IsType(OT_CONDITIONAL) && o->GetConditionVariable() == OCV_DISPATCH_SLOT) {
uint16_t dispatch_slot = GB(o->GetXData(), 0, 16);
if (dispatch_slot == schedule_index_1) {
SB(o->GetXDataRef(), 0, 16, schedule_index_2);
} else if (dispatch_slot == schedule_index_2) {
SB(o->GetXDataRef(), 0, 16, schedule_index_1);
uint16_t order_schedule = o->GetConditionDispatchScheduleID();
if (order_schedule == schedule_index_1) {
o->SetConditionDispatchScheduleID(schedule_index_2);
} else if (order_schedule == schedule_index_2) {
o->SetConditionDispatchScheduleID(schedule_index_1);
}
}
}

View File

@ -3165,8 +3165,8 @@ void TraceRestrictRemoveCounterID(TraceRestrictCounterID index)
for (Order *o : Order::Iterate()) {
if (o->IsType(OT_CONDITIONAL) &&
(o->GetConditionVariable() == OCV_COUNTER_VALUE) &&
GB(o->GetXData(), 16, 16) == index) {
SB(o->GetXDataRef(), 16, 16, INVALID_TRACE_RESTRICT_COUNTER_ID);
o->GetXDataHigh() == index) {
o->SetXDataHigh(INVALID_TRACE_RESTRICT_COUNTER_ID);
changed_order = true;
}
if (o->IsType(OT_COUNTER) && o->GetDestination() == index) {