MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ProcessConditionalOrder

Function ProcessConditionalOrder

src/order_cmd.cpp:1919–1940  ·  view source on GitHub ↗

* Process a conditional order and determine the next order. * @param order the order the vehicle currently has * @param v the vehicle to update * @return index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order */

Source from the content-addressed store, hash-verified

1917 * @return index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order
1918 */
1919VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
1920{
1921 if (order->GetType() != OT_CONDITIONAL) return INVALID_VEH_ORDER_ID;
1922
1923 bool skip_order = false;
1924 OrderConditionComparator occ = order->GetConditionComparator();
1925 uint16_t value = order->GetConditionValue();
1926
1927 switch (order->GetConditionVariable()) {
1928 case OrderConditionVariable::LoadPercentage: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, nullptr), value); break;
1929 case OrderConditionVariable::Reliability: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
1930 case OrderConditionVariable::MaxReliability: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break;
1931 case OrderConditionVariable::MaxSpeed: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
1932 case OrderConditionVariable::Age: skip_order = OrderConditionCompare(occ, TimerGameCalendar::DateToYear(v->age), value); break;
1933 case OrderConditionVariable::RequiresService: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
1934 case OrderConditionVariable::Unconditionally: skip_order = true; break;
1935 case OrderConditionVariable::RemainingLifetime: skip_order = OrderConditionCompare(occ, std::max(TimerGameCalendar::DateToYear(v->max_age - v->age + CalendarTime::DAYS_IN_LEAP_YEAR - 1), TimerGameCalendar::Year(0)), value); break;
1936 default: NOT_REACHED();
1937 }
1938
1939 return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID;
1940}
1941
1942/**
1943 * Update the vehicle's destination tile from an order.

Callers 2

UpdateOrderDestFunction · 0.85
SwitchToNextOrderMethod · 0.85

Calls 12

OrderConditionCompareFunction · 0.85
CalcPercentVehicleFilledFunction · 0.85
ToPercent16Function · 0.85
NOT_REACHEDFunction · 0.85
GetConditionValueMethod · 0.80
GetConditionVariableMethod · 0.80
NeedsServicingMethod · 0.80
GetTypeMethod · 0.45
GetEngineMethod · 0.45
GetDisplayMaxSpeedMethod · 0.45

Tested by

no test coverage detected