871 } |
871 } |
872 |
872 |
873 return ret; |
873 return ret; |
874 } |
874 } |
875 |
875 |
876 /** Start/Stop a ship. |
|
877 * @param tile unused |
|
878 * @param flags type of operation |
|
879 * @param p1 ship ID to start/stop |
|
880 * @param p2 unused |
|
881 */ |
|
882 CommandCost CmdStartStopShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
|
883 { |
|
884 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
|
885 |
|
886 Vehicle *v = GetVehicle(p1); |
|
887 |
|
888 if (v->type != VEH_SHIP || !CheckOwnership(v->owner)) return CMD_ERROR; |
|
889 |
|
890 /* Check if this ship can be started/stopped. The callback will fail or |
|
891 * return 0xFF if it can. */ |
|
892 uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
|
893 if (callback != CALLBACK_FAILED && GB(callback, 0, 8) != 0xFF) { |
|
894 StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
|
895 return_cmd_error(error); |
|
896 } |
|
897 |
|
898 if (flags & DC_EXEC) { |
|
899 if (v->IsStoppedInDepot()) { |
|
900 DeleteVehicleNews(p1, STR_981C_SHIP_IS_WAITING_IN_DEPOT); |
|
901 } |
|
902 |
|
903 v->vehstatus ^= VS_STOPPED; |
|
904 v->cur_speed = 0; |
|
905 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
|
906 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
907 InvalidateWindowClasses(WC_SHIPS_LIST); |
|
908 } |
|
909 |
|
910 return CommandCost(); |
|
911 } |
|
912 |
|
913 bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) |
876 bool Ship::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) |
914 { |
877 { |
915 const Depot *depot = FindClosestShipDepot(this); |
878 const Depot *depot = FindClosestShipDepot(this); |
916 |
879 |
917 if (depot == NULL) return false; |
880 if (depot == NULL) return false; |