28 #include "newgrf_engine.h" |
28 #include "newgrf_engine.h" |
29 #include "newgrf_text.h" |
29 #include "newgrf_text.h" |
30 #include "newgrf_sound.h" |
30 #include "newgrf_sound.h" |
31 #include "yapf/yapf.h" |
31 #include "yapf/yapf.h" |
32 #include "date.h" |
32 #include "date.h" |
|
33 #include "cargotype.h" |
33 |
34 |
34 static const uint16 _roadveh_images[63] = { |
35 static const uint16 _roadveh_images[63] = { |
35 0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
36 0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, |
36 0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
37 0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, |
37 0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
38 0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, |
636 |
637 |
637 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
638 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
638 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
639 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
639 |
640 |
640 if (!PlayVehicleSound(v, VSE_BREAKDOWN)) { |
641 if (!PlayVehicleSound(v, VSE_BREAKDOWN)) { |
641 SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? |
642 SndPlayVehicleFx((_opt.landscape != LT_TOYLAND) ? |
642 SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
643 SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, v); |
643 } |
644 } |
644 |
645 |
645 if (!(v->vehstatus & VS_HIDDEN)) { |
646 if (!(v->vehstatus & VS_HIDDEN)) { |
646 Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
647 Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
703 if (order->dest == v->last_station_visited) { |
704 if (order->dest == v->last_station_visited) { |
704 v->last_station_visited = INVALID_STATION; |
705 v->last_station_visited = INVALID_STATION; |
705 } |
706 } |
706 |
707 |
707 rs = GetStation(order->dest)->GetPrimaryRoadStop( |
708 rs = GetStation(order->dest)->GetPrimaryRoadStop( |
708 v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK |
709 IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK |
709 ); |
710 ); |
710 |
711 |
711 if (rs != NULL) { |
712 if (rs != NULL) { |
712 TileIndex dest = rs->xy; |
713 TileIndex dest = rs->xy; |
713 uint mindist = DistanceManhattan(v->tile, rs->xy); |
714 uint mindist = DistanceManhattan(v->tile, rs->xy); |
841 return u; |
842 return u; |
842 } |
843 } |
843 |
844 |
844 static void RoadVehArrivesAt(const Vehicle* v, Station* st) |
845 static void RoadVehArrivesAt(const Vehicle* v, Station* st) |
845 { |
846 { |
846 if (v->cargo_type == CT_PASSENGERS) { |
847 if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
847 /* Check if station was ever visited before */ |
848 /* Check if station was ever visited before */ |
848 if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
849 if (!(st->had_vehicle_of_type & HVOT_BUS)) { |
849 uint32 flags; |
850 uint32 flags; |
850 |
851 |
851 st->had_vehicle_of_type |= HVOT_BUS; |
852 st->had_vehicle_of_type |= HVOT_BUS; |
1089 if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir) { |
1090 if (!IsTileOwner(tile, v->owner) || GetRoadStopDir(tile) == enterdir) { |
1090 /* different station owner or wrong orientation */ |
1091 /* different station owner or wrong orientation */ |
1091 trackdirs = TRACKDIR_BIT_NONE; |
1092 trackdirs = TRACKDIR_BIT_NONE; |
1092 } else { |
1093 } else { |
1093 /* Our station */ |
1094 /* Our station */ |
1094 RoadStop::Type rstype = (v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
1095 RoadStop::Type rstype = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
1095 |
1096 |
1096 if (GetRoadStopType(tile) != rstype) { |
1097 if (GetRoadStopType(tile) != rstype) { |
1097 /* Wrong station type */ |
1098 /* Wrong station type */ |
1098 trackdirs = TRACKDIR_BIT_NONE; |
1099 trackdirs = TRACKDIR_BIT_NONE; |
1099 } else { |
1100 } else { |
1544 * a through route, do not stop) */ |
1545 * a through route, do not stop) */ |
1545 if ((IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) && |
1546 if ((IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) && |
1546 _road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_opt.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) || |
1547 _road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_opt.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) || |
1547 (IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) && |
1548 (IS_BYTE_INSIDE(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) && |
1548 v->current_order.dest == GetStationIndex(v->tile) && |
1549 v->current_order.dest == GetStationIndex(v->tile) && |
1549 GetRoadStopType(v->tile) == ((v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) && |
1550 GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK) && |
1550 v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME)) { |
1551 v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME)) { |
1551 |
1552 |
1552 RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
1553 RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile)); |
1553 Station* st = GetStationByTile(v->tile); |
1554 Station* st = GetStationByTile(v->tile); |
1554 |
1555 |
1560 /* Vehicle has arrived at a bay in a road stop */ |
1561 /* Vehicle has arrived at a bay in a road stop */ |
1561 Order old_order; |
1562 Order old_order; |
1562 |
1563 |
1563 if (IsDriveThroughStopTile(v->tile)) { |
1564 if (IsDriveThroughStopTile(v->tile)) { |
1564 TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction)); |
1565 TileIndex next_tile = TILE_ADD(v->tile, TileOffsByDir(v->direction)); |
1565 RoadStop::Type type = (v->cargo_type == CT_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
1566 RoadStop::Type type = IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK; |
1566 |
1567 |
1567 assert(HASBIT(v->u.road.state, RVS_IS_STOPPING)); |
1568 assert(HASBIT(v->u.road.state, RVS_IS_STOPPING)); |
1568 |
1569 |
1569 /* Check if next inline bay is free */ |
1570 /* Check if next inline bay is free */ |
1570 if (IsDriveThroughStopTile(next_tile) && (GetRoadStopType(next_tile) == type)) { |
1571 if (IsDriveThroughStopTile(next_tile) && (GetRoadStopType(next_tile) == type)) { |
1752 if (v->vehstatus & VS_STOPPED) return; |
1753 if (v->vehstatus & VS_STOPPED) return; |
1753 |
1754 |
1754 /* update destination */ |
1755 /* update destination */ |
1755 if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) { |
1756 if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) { |
1756 Station* st = GetStation(v->current_order.dest); |
1757 Station* st = GetStation(v->current_order.dest); |
1757 RoadStop* rs = st->GetPrimaryRoadStop(v->cargo_type == CT_PASSENGERS ? RoadStop::BUS : RoadStop::TRUCK); |
1758 RoadStop* rs = st->GetPrimaryRoadStop(IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? RoadStop::BUS : RoadStop::TRUCK); |
1758 RoadStop* best = NULL; |
1759 RoadStop* best = NULL; |
1759 |
1760 |
1760 if (rs != NULL) { |
1761 if (rs != NULL) { |
1761 /* We try to obtain a slot if: |
1762 /* We try to obtain a slot if: |
1762 * 1) we're reasonably close to the primary road stop |
1763 * 1) we're reasonably close to the primary road stop |
1855 v = GetVehicle(p1); |
1856 v = GetVehicle(p1); |
1856 |
1857 |
1857 if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
1858 if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; |
1858 if (!IsRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
1859 if (!IsRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); |
1859 |
1860 |
1860 if (new_cid > NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
1861 if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR; |
1861 |
1862 |
1862 SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
1863 SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN); |
1863 |
1864 |
1864 if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { |
1865 if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) { |
1865 /* Back up the cargo type */ |
1866 /* Back up the cargo type */ |