252 StationID sid = GetStationIndex(tile); |
252 StationID sid = GetStationIndex(tile); |
253 |
253 |
254 assert(v->type == VEH_Train); |
254 assert(v->type == VEH_Train); |
255 //When does a train drive through a station |
255 //When does a train drive through a station |
256 //first we deal with the "new nonstop handling" |
256 //first we deal with the "new nonstop handling" |
257 if (_patches.new_nonstop && o->flags & OF_NON_STOP && sid == o->station) { |
257 if (_patches.new_nonstop && o->flags & OF_NON_STOP && sid == o->dest.station) { |
258 return false; |
258 return false; |
259 } |
259 } |
260 |
260 |
261 if (v->last_station_visited == sid) return false; |
261 if (v->last_station_visited == sid) return false; |
262 |
262 |
263 if (sid != o->station && (o->flags & OF_NON_STOP || _patches.new_nonstop)) { |
263 if (sid != o->dest.station && (o->flags & OF_NON_STOP || _patches.new_nonstop)) { |
264 return false; |
264 return false; |
265 } |
265 } |
266 |
266 |
267 return true; |
267 return true; |
268 } |
268 } |
1958 |
1958 |
1959 if (flags & DC_EXEC) { |
1959 if (flags & DC_EXEC) { |
1960 v->dest_tile = tfdd.tile; |
1960 v->dest_tile = tfdd.tile; |
1961 v->current_order.type = OT_GOTO_DEPOT; |
1961 v->current_order.type = OT_GOTO_DEPOT; |
1962 v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD; |
1962 v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD; |
1963 v->current_order.station = GetDepotByTile(tfdd.tile)->index; |
1963 v->current_order.dest.depot = GetDepotByTile(tfdd.tile)->index; |
1964 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1964 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
1965 /* If there is no depot in front, reverse automatically */ |
1965 /* If there is no depot in front, reverse automatically */ |
1966 if (tfdd.reverse) |
1966 if (tfdd.reverse) |
1967 DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
1967 DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
1968 } |
1968 } |
2162 |
2162 |
2163 static void FillWithStationData(TrainTrackFollowerData* fd, const Vehicle* v) |
2163 static void FillWithStationData(TrainTrackFollowerData* fd, const Vehicle* v) |
2164 { |
2164 { |
2165 fd->dest_coords = v->dest_tile; |
2165 fd->dest_coords = v->dest_tile; |
2166 if (v->current_order.type == OT_GOTO_STATION) { |
2166 if (v->current_order.type == OT_GOTO_STATION) { |
2167 fd->station_index = v->current_order.station; |
2167 fd->station_index = v->current_order.dest.station; |
2168 } else { |
2168 } else { |
2169 fd->station_index = INVALID_STATION; |
2169 fd->station_index = INVALID_STATION; |
2170 } |
2170 } |
2171 } |
2171 } |
2172 |
2172 |
2409 |
2409 |
2410 // check if we've reached a non-stop station while TTDPatch nonstop is enabled.. |
2410 // check if we've reached a non-stop station while TTDPatch nonstop is enabled.. |
2411 if (_patches.new_nonstop && |
2411 if (_patches.new_nonstop && |
2412 v->current_order.flags & OF_NON_STOP && |
2412 v->current_order.flags & OF_NON_STOP && |
2413 IsTileType(v->tile, MP_STATION) && |
2413 IsTileType(v->tile, MP_STATION) && |
2414 v->current_order.station == GetStationIndex(v->tile)) { |
2414 v->current_order.dest.station == GetStationIndex(v->tile)) { |
2415 v->cur_order_index++; |
2415 v->cur_order_index++; |
2416 } |
2416 } |
2417 |
2417 |
2418 // Get the current order |
2418 // Get the current order |
2419 if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
2419 if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; |
2429 } |
2429 } |
2430 |
2430 |
2431 // If it is unchanged, keep it. |
2431 // If it is unchanged, keep it. |
2432 if (order->type == v->current_order.type && |
2432 if (order->type == v->current_order.type && |
2433 order->flags == v->current_order.flags && |
2433 order->flags == v->current_order.flags && |
2434 order->station == v->current_order.station) |
2434 order->dest.station == v->current_order.dest.station) |
2435 return false; |
2435 return false; |
2436 |
2436 |
2437 // Otherwise set it, and determine the destination tile. |
2437 // Otherwise set it, and determine the destination tile. |
2438 v->current_order = *order; |
2438 v->current_order = *order; |
2439 |
2439 |
2441 |
2441 |
2442 InvalidateVehicleOrder(v); |
2442 InvalidateVehicleOrder(v); |
2443 |
2443 |
2444 switch (order->type) { |
2444 switch (order->type) { |
2445 case OT_GOTO_STATION: |
2445 case OT_GOTO_STATION: |
2446 if (order->station == v->last_station_visited) |
2446 if (order->dest.station == v->last_station_visited) |
2447 v->last_station_visited = INVALID_STATION; |
2447 v->last_station_visited = INVALID_STATION; |
2448 v->dest_tile = GetStation(order->station)->xy; |
2448 v->dest_tile = GetStation(order->dest.station)->xy; |
2449 break; |
2449 break; |
2450 |
2450 |
2451 case OT_GOTO_DEPOT: |
2451 case OT_GOTO_DEPOT: |
2452 v->dest_tile = GetDepot(order->station)->xy; |
2452 v->dest_tile = GetDepot(order->dest.depot)->xy; |
2453 break; |
2453 break; |
2454 |
2454 |
2455 case OT_GOTO_WAYPOINT: |
2455 case OT_GOTO_WAYPOINT: |
2456 v->dest_tile = GetWaypoint(order->station)->xy; |
2456 v->dest_tile = GetWaypoint(order->dest.waypoint)->xy; |
2457 break; |
2457 break; |
2458 |
2458 |
2459 default: |
2459 default: |
2460 return false; |
2460 return false; |
2461 } |
2461 } |
2572 ); |
2572 ); |
2573 } |
2573 } |
2574 |
2574 |
2575 // Did we reach the final destination? |
2575 // Did we reach the final destination? |
2576 if (v->current_order.type == OT_GOTO_STATION && |
2576 if (v->current_order.type == OT_GOTO_STATION && |
2577 v->current_order.station == station) { |
2577 v->current_order.dest.station == station) { |
2578 // Yeah, keep the load/unload flags |
2578 // Yeah, keep the load/unload flags |
2579 // Non Stop now means if the order should be increased. |
2579 // Non Stop now means if the order should be increased. |
2580 v->current_order.type = OT_LOADING; |
2580 v->current_order.type = OT_LOADING; |
2581 v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER; |
2581 v->current_order.flags &= OF_FULL_LOAD | OF_UNLOAD | OF_TRANSFER; |
2582 v->current_order.flags |= OF_NON_STOP; |
2582 v->current_order.flags |= OF_NON_STOP; |
2583 } else { |
2583 } else { |
2584 // No, just do a simple load |
2584 // No, just do a simple load |
2585 v->current_order.type = OT_LOADING; |
2585 v->current_order.type = OT_LOADING; |
2586 v->current_order.flags = 0; |
2586 v->current_order.flags = 0; |
2587 } |
2587 } |
2588 v->current_order.station = 0; |
2588 v->current_order.dest.station = 0; |
2589 |
2589 |
2590 SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC); |
2590 SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC); |
2591 if (LoadUnloadVehicle(v) != 0) { |
2591 if (LoadUnloadVehicle(v) != 0) { |
2592 InvalidateWindow(WC_TRAINS_LIST, v->owner); |
2592 InvalidateWindow(WC_TRAINS_LIST, v->owner); |
2593 TrainCargoChanged(v); |
2593 TrainCargoChanged(v); |
3501 } |
3501 } |
3502 |
3502 |
3503 depot = GetDepotByTile(tfdd.tile); |
3503 depot = GetDepotByTile(tfdd.tile); |
3504 |
3504 |
3505 if (v->current_order.type == OT_GOTO_DEPOT && |
3505 if (v->current_order.type == OT_GOTO_DEPOT && |
3506 v->current_order.station != depot->index && |
3506 v->current_order.dest.depot != depot->index && |
3507 !CHANCE16(3, 16)) { |
3507 !CHANCE16(3, 16)) { |
3508 return; |
3508 return; |
3509 } |
3509 } |
3510 |
3510 |
3511 v->current_order.type = OT_GOTO_DEPOT; |
3511 v->current_order.type = OT_GOTO_DEPOT; |
3512 v->current_order.flags = OF_NON_STOP; |
3512 v->current_order.flags = OF_NON_STOP; |
3513 v->current_order.station = depot->index; |
3513 v->current_order.dest.depot = depot->index; |
3514 v->dest_tile = tfdd.tile; |
3514 v->dest_tile = tfdd.tile; |
3515 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
3515 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); |
3516 } |
3516 } |
3517 |
3517 |
3518 int32 GetTrainRunningCost(const Vehicle *v) |
3518 int32 GetTrainRunningCost(const Vehicle *v) |
3553 |
3553 |
3554 CheckOrders(v); |
3554 CheckOrders(v); |
3555 |
3555 |
3556 /* update destination */ |
3556 /* update destination */ |
3557 if (v->current_order.type == OT_GOTO_STATION && |
3557 if (v->current_order.type == OT_GOTO_STATION && |
3558 (tile = GetStation(v->current_order.station)->train_tile) != 0) { |
3558 (tile = GetStation(v->current_order.dest.station)->train_tile) != 0) { |
3559 v->dest_tile = tile; |
3559 v->dest_tile = tile; |
3560 } |
3560 } |
3561 |
3561 |
3562 if ((v->vehstatus & VS_STOPPED) == 0) { |
3562 if ((v->vehstatus & VS_STOPPED) == 0) { |
3563 /* running costs */ |
3563 /* running costs */ |