* * Check the orders of a vehicle, to see if there are invalid orders and stuff * */
| 1679 | * |
| 1680 | */ |
| 1681 | void CheckOrders(const Vehicle *v) |
| 1682 | { |
| 1683 | /* Does the user wants us to check things? */ |
| 1684 | if (_settings_client.gui.order_review_system == 0) return; |
| 1685 | |
| 1686 | /* Do nothing for crashed vehicles */ |
| 1687 | if (v->vehstatus.Test(VehState::Crashed)) return; |
| 1688 | |
| 1689 | /* Do nothing for stopped vehicles if setting is '1' */ |
| 1690 | if (_settings_client.gui.order_review_system == 1 && v->vehstatus.Test(VehState::Stopped)) return; |
| 1691 | |
| 1692 | /* do nothing we we're not the first vehicle in a share-chain */ |
| 1693 | if (v->FirstShared() != v) return; |
| 1694 | |
| 1695 | /* Only check every 20 days, so that we don't flood the message log */ |
| 1696 | if (v->owner == _local_company && v->day_counter % 20 == 0) { |
| 1697 | StringID message = INVALID_STRING_ID; |
| 1698 | |
| 1699 | /* Check the order list */ |
| 1700 | int n_st = 0; |
| 1701 | |
| 1702 | for (const Order &order : v->Orders()) { |
| 1703 | /* Dummy order? */ |
| 1704 | if (order.IsType(OT_DUMMY)) { |
| 1705 | message = STR_NEWS_VEHICLE_HAS_VOID_ORDER; |
| 1706 | break; |
| 1707 | } |
| 1708 | /* Does station have a load-bay for this vehicle? */ |
| 1709 | if (order.IsType(OT_GOTO_STATION)) { |
| 1710 | const Station *st = Station::Get(order.GetDestination().ToStationID()); |
| 1711 | |
| 1712 | n_st++; |
| 1713 | if (!CanVehicleUseStation(v, st)) { |
| 1714 | message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY; |
| 1715 | } else if (v->type == VEH_AIRCRAFT && |
| 1716 | (AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) && |
| 1717 | st->airport.GetFTA()->flags.Test(AirportFTAClass::Flag::ShortStrip) && |
| 1718 | !_cheats.no_jetcrash.value && |
| 1719 | message == INVALID_STRING_ID) { |
| 1720 | message = STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY; |
| 1721 | } |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | /* Check if the last and the first order are the same */ |
| 1726 | if (v->GetNumOrders() > 1) { |
| 1727 | auto orders = v->Orders(); |
| 1728 | |
| 1729 | if (orders.front().Equals(orders.back())) { |
| 1730 | message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY; |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | /* Do we only have 1 station in our order list? */ |
| 1735 | if (n_st < 2 && message == INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS; |
| 1736 | |
| 1737 | #ifdef WITH_ASSERT |
| 1738 | if (v->orders != nullptr) v->orders->DebugCheckSanity(); |
no test coverage detected