* 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 */
| 1917 | * @return index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order |
| 1918 | */ |
| 1919 | VehicleOrderID 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. |
no test coverage detected