1309 } |
1309 } |
1310 |
1310 |
1311 return tfdd; |
1311 return tfdd; |
1312 } |
1312 } |
1313 |
1313 |
|
1314 /* Send a train to the nearest depot |
|
1315 p1 = index of the train |
|
1316 p2 = bit 0 = do not stop in depot |
|
1317 bit 1 = set v->set_for_replacement |
|
1318 bit 2 = clear v->set_for_replacement */ |
1314 int32 CmdTrainGotoDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1319 int32 CmdTrainGotoDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
1315 { |
1320 { |
1316 Vehicle *v = GetVehicle(p1); |
1321 Vehicle *v = GetVehicle(p1); |
1317 TrainFindDepotData tfdd; |
1322 TrainFindDepotData tfdd; |
|
1323 |
|
1324 if (!CheckOwnership(v->owner)) |
|
1325 return CMD_ERROR; |
|
1326 |
|
1327 if (HASBIT(p2, 0)) v->set_for_replacement = true; |
|
1328 if (HASBIT(p2, 2)) v->set_for_replacement = false; |
|
1329 |
|
1330 if (HASBIT(p2, 1) || HASBIT(p2, 2)) return CMD_ERROR; // vehicle has a depot in schedule. It just needed to alter set_for_replacement |
|
1331 |
1318 |
1332 |
1319 if (v->current_order.type == OT_GOTO_DEPOT) { |
1333 if (v->current_order.type == OT_GOTO_DEPOT) { |
1320 if (flags & DC_EXEC) { |
1334 if (flags & DC_EXEC) { |
1321 if (v->current_order.flags & OF_UNLOAD) { |
1335 if (v->current_order.flags & OF_UNLOAD) { |
1322 v->u.rail.days_since_order_progr = 0; |
1336 v->u.rail.days_since_order_progr = 0; |
1335 return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO); |
1349 return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO); |
1336 |
1350 |
1337 if (flags & DC_EXEC) { |
1351 if (flags & DC_EXEC) { |
1338 v->dest_tile = tfdd.tile; |
1352 v->dest_tile = tfdd.tile; |
1339 v->current_order.type = OT_GOTO_DEPOT; |
1353 v->current_order.type = OT_GOTO_DEPOT; |
1340 v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD; |
1354 v->current_order.flags = HASBIT(p2, 0) ? 0 : OF_NON_STOP | OF_FULL_LOAD; |
1341 v->current_order.station = GetDepotByTile(tfdd.tile); |
1355 v->current_order.station = GetDepotByTile(tfdd.tile); |
1342 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1356 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1343 } |
1357 } |
1344 |
1358 |
1345 return 0; |
1359 return 0; |
1769 return false; |
1783 return false; |
1770 } |
1784 } |
1771 |
1785 |
1772 if (v->current_order.type == OT_GOTO_DEPOT && |
1786 if (v->current_order.type == OT_GOTO_DEPOT && |
1773 (v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1787 (v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) && |
1774 !VehicleNeedsService(v)) { |
1788 !VehicleNeedsService(v) && !v->set_for_replacement) { |
1775 v->cur_order_index++; |
1789 v->cur_order_index++; |
1776 } |
1790 } |
1777 |
1791 |
1778 // check if we've reached the waypoint? |
1792 // check if we've reached the waypoint? |
1779 if (v->current_order.type == OT_GOTO_WAYPOINT && v->tile == v->dest_tile) { |
1793 if (v->current_order.type == OT_GOTO_WAYPOINT && v->tile == v->dest_tile) { |
1881 { |
1895 { |
1882 Order b = v->current_order; |
1896 Order b = v->current_order; |
1883 v->current_order.type = OT_LEAVESTATION; |
1897 v->current_order.type = OT_LEAVESTATION; |
1884 v->current_order.flags = 0; |
1898 v->current_order.flags = 0; |
1885 |
1899 |
|
1900 if (v->current_order.type != OT_GOTO_DEPOT && v->owner == _local_player) { |
|
1901 // only the vehicle owner needs to calculate the rest (locally) |
|
1902 if ((_autoreplace_array[v->engine_type] != v->engine_type) || |
|
1903 (_patches.autorenew && v->age - v->max_age > (_patches.autorenew_months * 30))) { |
|
1904 byte flags = 1; |
|
1905 // the flags means, bit 0 = needs to go to depot, bit 1 = have depot in orders |
|
1906 if (VehicleHasDepotOrders(v)) SETBIT(flags, 1); |
|
1907 if (!(HASBIT(flags, 1) && v->set_for_replacement)) { |
|
1908 _current_player = _local_player; |
|
1909 DoCommandP(v->tile, v->index, flags, NULL, CMD_TRAIN_GOTO_DEPOT | CMD_SHOW_NO_ERROR); |
|
1910 _current_player = OWNER_NONE; |
|
1911 } |
|
1912 } else { // no need to go to a depot |
|
1913 if (v->set_for_replacement) { |
|
1914 // it seems that the user clicked "Stop replacing" |
|
1915 _current_player = _local_player; |
|
1916 DoCommandP(v->tile, v->index, 1 | (1 << 2), NULL, CMD_TRAIN_GOTO_DEPOT | CMD_SHOW_NO_ERROR); |
|
1917 _current_player = OWNER_NONE; |
|
1918 } |
|
1919 } |
|
1920 } |
1886 // If this was not the final order, don't remove it from the list. |
1921 // If this was not the final order, don't remove it from the list. |
1887 if (!(b.flags & OF_NON_STOP)) |
1922 if (!(b.flags & OF_NON_STOP)) |
1888 return; |
1923 return; |
1889 } |
1924 } |
1890 } |
1925 } |