equal
deleted
inserted
replaced
18 #include "station_base.h" |
18 #include "station_base.h" |
19 #include "news_func.h" |
19 #include "news_func.h" |
20 #include "engine_func.h" |
20 #include "engine_func.h" |
21 #include "player_func.h" |
21 #include "player_func.h" |
22 #include "player_base.h" |
22 #include "player_base.h" |
23 #include "depot.h" |
23 #include "depot_base.h" |
|
24 #include "depot_func.h" |
24 #include "waypoint.h" |
25 #include "waypoint.h" |
25 #include "vehicle_gui.h" |
26 #include "vehicle_gui.h" |
26 #include "train.h" |
27 #include "train.h" |
27 #include "bridge.h" |
28 #include "bridge.h" |
28 #include "newgrf_callbacks.h" |
29 #include "newgrf_callbacks.h" |
676 if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE); |
677 if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE); |
677 |
678 |
678 /* Check if the train is actually being built in a depot belonging |
679 /* Check if the train is actually being built in a depot belonging |
679 * to the player. Doesn't matter if only the cost is queried */ |
680 * to the player. Doesn't matter if only the cost is queried */ |
680 if (!(flags & DC_QUERY_COST)) { |
681 if (!(flags & DC_QUERY_COST)) { |
681 if (!IsTileDepotType(tile, TRANSPORT_RAIL)) return CMD_ERROR; |
682 if (!IsRailDepotTile(tile)) return CMD_ERROR; |
682 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
683 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
683 } |
684 } |
684 |
685 |
685 const RailVehicleInfo *rvi = RailVehInfo(p1); |
686 const RailVehicleInfo *rvi = RailVehInfo(p1); |
686 |
687 |
804 int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped) |
805 int CheckTrainInDepot(const Vehicle *v, bool needs_to_be_stopped) |
805 { |
806 { |
806 TileIndex tile = v->tile; |
807 TileIndex tile = v->tile; |
807 |
808 |
808 /* check if stopped in a depot */ |
809 /* check if stopped in a depot */ |
809 if (!IsTileDepotType(tile, TRANSPORT_RAIL) || v->cur_speed != 0) return -1; |
810 if (!IsRailDepotTile(tile) || v->cur_speed != 0) return -1; |
810 |
811 |
811 int count = 0; |
812 int count = 0; |
812 for (; v != NULL; v = v->Next()) { |
813 for (; v != NULL; v = v->Next()) { |
813 /* This count is used by the depot code to determine the number of engines |
814 /* This count is used by the depot code to determine the number of engines |
814 * in the consist. Exclude articulated parts so that autoreplacing to |
815 * in the consist. Exclude articulated parts so that autoreplacing to |
1301 * @param flags type of operation |
1302 * @param flags type of operation |
1302 * @param p1 the wagon/engine index |
1303 * @param p1 the wagon/engine index |
1303 * @param p2 the selling mode |
1304 * @param p2 the selling mode |
1304 * - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines) |
1305 * - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines) |
1305 * - p2 = 1: sell the vehicle and all vehicles following it in the chain |
1306 * - p2 = 1: sell the vehicle and all vehicles following it in the chain |
1306 if the wagon is dragged, don't delete the possibly belonging rear-engine to some front |
1307 * if the wagon is dragged, don't delete the possibly belonging rear-engine to some front |
1307 * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines; |
1308 * - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines; |
1308 * all wagons of the same type will go on the same line. Used by the AI currently |
1309 * all wagons of the same type will go on the same line. Used by the AI currently |
1309 */ |
1310 */ |
1310 CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1311 CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1311 { |
1312 { |
1785 } |
1786 } |
1786 |
1787 |
1787 |
1788 |
1788 static void ReverseTrainDirection(Vehicle *v) |
1789 static void ReverseTrainDirection(Vehicle *v) |
1789 { |
1790 { |
1790 if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) { |
1791 if (IsRailDepotTile(v->tile)) { |
1791 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1792 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1792 } |
1793 } |
1793 |
1794 |
1794 /* Check if we were approaching a rail/road-crossing */ |
1795 /* Check if we were approaching a rail/road-crossing */ |
1795 TileIndex crossing = TrainApproachingCrossingTile(v); |
1796 TileIndex crossing = TrainApproachingCrossingTile(v); |
1805 ReverseTrainSwapVeh(v, l++, r--); |
1806 ReverseTrainSwapVeh(v, l++, r--); |
1806 } while (l <= r); |
1807 } while (l <= r); |
1807 |
1808 |
1808 AdvanceWagonsAfterSwap(v); |
1809 AdvanceWagonsAfterSwap(v); |
1809 |
1810 |
1810 if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) { |
1811 if (IsRailDepotTile(v->tile)) { |
1811 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1812 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
1812 } |
1813 } |
1813 |
1814 |
1814 ToggleBit(v->u.rail.flags, VRF_TOGGLE_REVERSE); |
1815 ToggleBit(v->u.rail.flags, VRF_TOGGLE_REVERSE); |
1815 |
1816 |
2033 tfdd.owner = v->owner; |
2034 tfdd.owner = v->owner; |
2034 tfdd.best_length = UINT_MAX; |
2035 tfdd.best_length = UINT_MAX; |
2035 tfdd.reverse = false; |
2036 tfdd.reverse = false; |
2036 |
2037 |
2037 TileIndex tile = v->tile; |
2038 TileIndex tile = v->tile; |
2038 if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
2039 if (IsRailDepotTile(tile)) { |
2039 tfdd.tile = tile; |
2040 tfdd.tile = tile; |
2040 tfdd.best_length = 0; |
2041 tfdd.best_length = 0; |
2041 return tfdd; |
2042 return tfdd; |
2042 } |
2043 } |
2043 |
2044 |
2152 v->vehstatus & VS_HIDDEN) { |
2153 v->vehstatus & VS_HIDDEN) { |
2153 continue; |
2154 continue; |
2154 } |
2155 } |
2155 |
2156 |
2156 /* No smoke in depots or tunnels */ |
2157 /* No smoke in depots or tunnels */ |
2157 if (IsTileDepotType(v->tile, TRANSPORT_RAIL) || IsTunnelTile(v->tile)) continue; |
2158 if (IsRailDepotTile(v->tile) || IsTunnelTile(v->tile)) continue; |
2158 |
2159 |
2159 /* No sparks for electric vehicles on nonelectrified tracks */ |
2160 /* No sparks for electric vehicles on nonelectrified tracks */ |
2160 if (!HasPowerOnRail(v->u.rail.railtype, GetTileRailType(v->tile))) continue; |
2161 if (!HasPowerOnRail(v->u.rail.railtype, GetTileRailType(v->tile))) continue; |
2161 |
2162 |
2162 if (effect_type == 0) { |
2163 if (effect_type == 0) { |
3147 |
3148 |
3148 /* check if the wagon was on a road/rail-crossing */ |
3149 /* check if the wagon was on a road/rail-crossing */ |
3149 if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile); |
3150 if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile); |
3150 |
3151 |
3151 /* Update signals */ |
3152 /* Update signals */ |
3152 if (IsTileType(tile, MP_TUNNELBRIDGE) || IsTileDepotType(tile, TRANSPORT_RAIL)) { |
3153 if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) { |
3153 UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner); |
3154 UpdateSignalsOnSegment(tile, INVALID_DIAGDIR, owner); |
3154 } else { |
3155 } else { |
3155 SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)), owner); |
3156 SetSignalsOnBothDir(tile, (Track)(FIND_FIRST_BIT(track)), owner); |
3156 } |
3157 } |
3157 } |
3158 } |
3204 } while ((u = u->Next()) != NULL); |
3205 } while ((u = u->Next()) != NULL); |
3205 } |
3206 } |
3206 |
3207 |
3207 if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v); |
3208 if (state <= 240 && !(v->tick_counter & 3)) ChangeTrainDirRandomly(v); |
3208 |
3209 |
3209 if (state >= 4440 && !(v->tick_counter&0x1F)) { |
3210 if (state >= 4440 && !(v->tick_counter & 0x1F)) { |
3210 DeleteLastWagon(v); |
3211 DeleteLastWagon(v); |
3211 InvalidateWindow(WC_REPLACE_VEHICLE, (v->group_id << 16) | VEH_TRAIN); |
3212 InvalidateWindow(WC_REPLACE_VEHICLE, (v->group_id << 16) | VEH_TRAIN); |
3212 } |
3213 } |
3213 } |
3214 } |
3214 |
3215 |
3309 DiagDirection dir = GetTunnelBridgeDirection(tile); |
3310 DiagDirection dir = GetTunnelBridgeDirection(tile); |
3310 if (DiagDirToDir(dir) == v->direction) return false; |
3311 if (DiagDirToDir(dir) == v->direction) return false; |
3311 } |
3312 } |
3312 |
3313 |
3313 /* entering a depot? */ |
3314 /* entering a depot? */ |
3314 if (IsTileDepotType(tile, TRANSPORT_RAIL)) { |
3315 if (IsRailDepotTile(tile)) { |
3315 DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile)); |
3316 DiagDirection dir = ReverseDiagDir(GetRailDepotDirection(tile)); |
3316 if (DiagDirToDir(dir) == v->direction) return false; |
3317 if (DiagDirToDir(dir) == v->direction) return false; |
3317 } |
3318 } |
3318 |
3319 |
3319 return true; |
3320 return true; |