diff options
author | Darkvater <Darkvater@openttd.org> | 2006-01-29 18:57:26 +0000 |
---|---|---|
committer | Darkvater <Darkvater@openttd.org> | 2006-01-29 18:57:26 +0000 |
commit | 4014e36aeccf7adb66057f6a80f795089e92fac4 (patch) | |
tree | a71e925a12583a807b9e921fd125c8ae1b8e8721 /train_cmd.c | |
parent | e051091c35f2f854436fe5503bf746460087c386 (diff) | |
download | openttd-4014e36aeccf7adb66057f6a80f795089e92fac4.tar.xz |
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
Diffstat (limited to 'train_cmd.c')
-rw-r--r-- | train_cmd.c | 216 |
1 files changed, 6 insertions, 210 deletions
diff --git a/train_cmd.c b/train_cmd.c index 4b77368cc..131e21cd2 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -19,7 +19,6 @@ #include "player.h" #include "sound.h" #include "depot.h" -#include "debug.h" #include "waypoint.h" #include "vehicle_gui.h" #include "train.h" @@ -1552,81 +1551,10 @@ static void AdvanceWagons(Vehicle *v, bool before) } } -static TileIndex GetVehicleTileOutOfTunnel(const Vehicle* v, bool reverse) -{ - TileIndex tile; - byte direction = (!reverse) ? DirToDiagdir(v->direction) : ReverseDiagdir(v->direction >> 1); - TileIndexDiff delta = TileOffsByDir(direction); - - if (v->u.rail.track != 0x40) return v->tile; - - for (tile = v->tile;; tile += delta) { - if (IsTunnelTile(tile) && GB(_m[tile].m5, 0, 2) != direction && GetTileZ(tile) == v->z_pos) - break; - } - return tile; -} - static void ReverseTrainDirection(Vehicle *v) { int l = 0, r = -1; Vehicle *u; - TileIndex tile; - Trackdir trackdir; - TileIndex pbs_end_tile = v->u.rail.pbs_end_tile; // these may be changed, and we may need - Trackdir pbs_end_trackdir = v->u.rail.pbs_end_trackdir; // the old values, so cache them - - u = GetLastVehicleInChain(v); - tile = GetVehicleTileOutOfTunnel(u, false); - trackdir = ReverseTrackdir(GetVehicleTrackdir(u)); - - if (PBSTileReserved(tile) & (1 << TrackdirToTrack(trackdir))) { - NPFFindStationOrTileData fstd; - NPFFoundTargetData ftd; - - NPFFillWithOrderData(&fstd, v); - - tile = GetVehicleTileOutOfTunnel(u, true); - - DEBUG(pbs, 2) ("pbs: (%i) choose reverse (RV), tile:%x, trackdir:%i",v->unitnumber, u->tile, trackdir); - ftd = NPFRouteToStationOrTile(tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_ANY); - - if (ftd.best_trackdir == 0xFF) { - DEBUG(pbs, 0) ("pbs: (%i) no nodes encountered (RV)", v->unitnumber); - CLRBIT(v->u.rail.flags, VRF_REVERSING); - return; - } - - // we found a way out of the pbs block - if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { - if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED)) { - CLRBIT(v->u.rail.flags, VRF_REVERSING); - return; - } - } - - v->u.rail.pbs_end_tile = ftd.node.tile; - v->u.rail.pbs_end_trackdir = ftd.node.direction; - } - - tile = GetVehicleTileOutOfTunnel(v, false); - trackdir = GetVehicleTrackdir(v); - - if (v->u.rail.pbs_status == PBS_STAT_HAS_PATH) { - TileIndex tile = AddTileIndexDiffCWrap(v->tile, TileIndexDiffCByDir(TrackdirToExitdir(trackdir))); - uint32 ts; - assert(tile != INVALID_TILE); - ts = GetTileTrackStatus(tile, TRANSPORT_RAIL); - ts &= TrackdirReachesTrackdirs(trackdir); - assert(ts != 0 && KillFirstBit2x64(ts) == 0); - trackdir = FindFirstBit2x64(ts); - PBSClearPath(tile, trackdir, pbs_end_tile, pbs_end_trackdir); - v->u.rail.pbs_status = PBS_STAT_NONE; - } else if (PBSTileReserved(tile) & (1 << TrackdirToTrack(trackdir))) { - PBSClearPath(tile, trackdir, pbs_end_tile, pbs_end_trackdir); - if (v->u.rail.track != 0x40) - PBSReserveTrack(tile, trackdir & 7); - }; if (IsTileDepotType(v->tile, TRANSPORT_RAIL)) InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); @@ -2040,8 +1968,6 @@ static bool CheckTrainStayInDepot(Vehicle *v) } if (v->u.rail.force_proceed == 0) { - Trackdir trackdir = GetVehicleTrackdir(v); - if (++v->load_unload_time_rem < 37) { InvalidateWindowClasses(WC_TRAINS_LIST); return true; @@ -2049,35 +1975,12 @@ static bool CheckTrainStayInDepot(Vehicle *v) v->load_unload_time_rem = 0; - if (PBSIsPbsSegment(v->tile, trackdir)) { - NPFFindStationOrTileData fstd; - NPFFoundTargetData ftd; - - if (PBSTileUnavail(v->tile) & (1 << trackdir)) return true; - - NPFFillWithOrderData(&fstd, v); - - DEBUG(pbs, 2) ("pbs: (%i) choose depot (DP), tile:%x, trackdir:%i",v->unitnumber, v->tile, trackdir); - ftd = NPFRouteToStationOrTile(v->tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN); - - // we found a way out of the pbs block - if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { - if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED)) { - return true; - } else { - v->u.rail.pbs_end_tile = ftd.node.tile; - v->u.rail.pbs_end_trackdir = ftd.node.direction; - goto green; - } - } - } - if (UpdateSignalsOnSegment(v->tile, v->direction)) { InvalidateWindowClasses(WC_TRAINS_LIST); return true; } } -green: + VehicleServiceInDepot(v); InvalidateWindowClasses(WC_TRAINS_LIST); TrainPlayLeaveStationSound(v); @@ -2215,29 +2118,13 @@ static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirB NPFFindStationOrTileData fstd; NPFFoundTargetData ftd; Trackdir trackdir; - uint16 pbs_tracks; NPFFillWithOrderData(&fstd, v); /* The enterdir for the new tile, is the exitdir for the old tile */ trackdir = GetVehicleTrackdir(v); assert(trackdir != 0xff); - pbs_tracks = PBSTileReserved(tile); - pbs_tracks |= pbs_tracks << 8; - pbs_tracks &= TrackdirReachesTrackdirs(trackdir); - if (pbs_tracks || (v->u.rail.pbs_status == PBS_STAT_NEED_PATH)) { - DEBUG(pbs, 2) ("pbs: (%i) choosefromblock, tile_org:%x tile_dst:%x trackdir:%i pbs_tracks:%i",v->unitnumber, tile,tile - TileOffsByDir(enterdir), trackdir, pbs_tracks); - // clear the currently planned path - if (v->u.rail.pbs_status != PBS_STAT_NEED_PATH) PBSClearPath(tile, FindFirstBit2x64(pbs_tracks), v->u.rail.pbs_end_tile, v->u.rail.pbs_end_trackdir); - - // try to find a route to a green exit signal - ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_ANY); - - v->u.rail.pbs_end_tile = ftd.node.tile; - v->u.rail.pbs_end_trackdir = ftd.node.direction; - - } else - ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_NONE); + ftd = NPFRouteToStationOrTile(tile - TileOffsByDir(enterdir), trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype); if (ftd.best_trackdir == 0xff) { /* We are already at our target. Just do something */ @@ -2317,8 +2204,7 @@ static bool CheckReverseTrain(Vehicle *v) assert(trackdir != 0xff); assert(trackdir_rev != 0xff); - ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, last->tile, trackdir_rev, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_NONE); - + ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, last->tile, trackdir_rev, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype); if (ftd.best_bird_dist != 0) { /* We didn't find anything, just keep on going straight ahead */ reverse_best = false; @@ -2906,7 +2792,7 @@ static void TrainController(Vehicle *v) } else { /* is not inside depot */ - if ((prev == NULL) && (!TrainCheckIfLineEnds(v))) + if (!TrainCheckIfLineEnds(v)) return; r = VehicleEnterTile(v, gp.new_tile, gp.x, gp.y); @@ -2961,56 +2847,11 @@ static void TrainController(Vehicle *v) } if (prev == NULL) { - byte trackdir; /* Currently the locomotive is active. Determine which one of the * available tracks to choose */ chosen_track = 1 << ChooseTrainTrack(v, gp.new_tile, enterdir, bits); assert(chosen_track & tracks); - trackdir = TrackEnterdirToTrackdir(FIND_FIRST_BIT(chosen_track), enterdir); - assert(trackdir != 0xff); - - if (PBSIsPbsSignal(gp.new_tile,trackdir) && PBSIsPbsSegment(gp.new_tile,trackdir)) { - // encountered a pbs signal, and possible a pbs block - DEBUG(pbs, 3) ("pbs: (%i) arrive AT signal, tile:%x pbs_stat:%i",v->unitnumber, gp.new_tile, v->u.rail.pbs_status); - - if (v->u.rail.pbs_status == PBS_STAT_NONE) { - // we havent planned a path already, so try to find one now - NPFFindStationOrTileData fstd; - NPFFoundTargetData ftd; - - NPFFillWithOrderData(&fstd, v); - - DEBUG(pbs, 2) ("pbs: (%i) choose signal (TC), tile:%x, trackdir:%i",v->unitnumber, gp.new_tile, trackdir); - ftd = NPFRouteToStationOrTile(gp.new_tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN); - - if (v->u.rail.force_proceed != 0) - goto green_light; - - if (ftd.best_trackdir == 0xFF) - goto red_light; - - // we found a way out of the pbs block - if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { - if (NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED)) - goto red_light; - else { - v->u.rail.pbs_end_tile = ftd.node.tile; - v->u.rail.pbs_end_trackdir = ftd.node.direction; - goto green_light; - } - - }; - - } else { - // we have already planned a path through this pbs block - // on entering the block, we reset our status - v->u.rail.pbs_status = PBS_STAT_NONE; - goto green_light; - }; - DEBUG(pbs, 3) ("pbs: (%i) no green light found, or was no pbs-block",v->unitnumber); - }; - /* Check if it's a red signal and that force proceed is not clicked. */ if ( (tracks>>16)&chosen_track && v->u.rail.force_proceed == 0) goto red_light; } else { @@ -3019,9 +2860,6 @@ static void TrainController(Vehicle *v) /* The wagon is active, simply follow the prev vehicle. */ chosen_track = (byte)(_matching_tracks[GetDirectionToVehicle(prev, gp.x, gp.y)] & bits); } -green_light: - if (v->next == NULL) - PBSClearTrack(gp.old_tile, FIND_FIRST_BIT(v->u.rail.track)); /* make sure chosen track is a valid track */ assert(chosen_track==1 || chosen_track==2 || chosen_track==4 || chosen_track==8 || chosen_track==16 || chosen_track==32); @@ -3050,12 +2888,12 @@ green_light: } if (IsFrontEngine(v)) - TrainMovedChangeSignals(gp.new_tile, enterdir); + TrainMovedChangeSignals(gp.new_tile, enterdir); /* Signals can only change when the first * (above) or the last vehicle moves. */ if (v->next == NULL) - TrainMovedChangeSignals(gp.old_tile, (enterdir) ^ 2); + TrainMovedChangeSignals(gp.old_tile, (enterdir) ^ 2); if (prev == NULL) { AffectSpeedByDirChange(v, chosen_dir); @@ -3164,17 +3002,6 @@ static void DeleteLastWagon(Vehicle *v) EndVehicleMove(v); DeleteVehicle(v); - // clear up reserved pbs tracks - if (PBSTileReserved(v->tile) & v->u.rail.track) { - if (v == u) { - PBSClearPath(v->tile, FIND_FIRST_BIT(v->u.rail.track), v->u.rail.pbs_end_tile, v->u.rail.pbs_end_trackdir); - PBSClearPath(v->tile, FIND_FIRST_BIT(v->u.rail.track) + 8, v->u.rail.pbs_end_tile, v->u.rail.pbs_end_trackdir); - }; - if (v->tile != u->tile) { - PBSClearTrack(v->tile, FIND_FIRST_BIT(v->u.rail.track)); - }; - } - if (!(v->u.rail.track & 0xC0)) SetSignalsOnBothDir(v->tile, FIND_FIRST_BIT(v->u.rail.track)); @@ -3302,7 +3129,6 @@ static bool TrainCheckIfLineEnds(Vehicle *v) uint16 break_speed; DiagDirection t; uint32 ts; - byte trackdir; t = v->breakdown_ctr; if (t > 1) { @@ -3339,12 +3165,6 @@ static bool TrainCheckIfLineEnds(Vehicle *v) // determine the track status on the next tile. ts = GetTileTrackStatus(tile, TRANSPORT_RAIL) & _reachable_tracks[t]; - // if there are tracks on the new tile, pick one (trackdir will only be used when its a signal tile, in which case only 1 trackdir is accessible for us) - if (ts & TRACKDIR_BIT_MASK) - trackdir = FindFirstBit2x64(ts & TRACKDIR_BIT_MASK); - else - trackdir = INVALID_TRACKDIR; - /* Calc position within the current tile ?? */ x = v->x_pos & 0xF; y = v->y_pos & 0xF; @@ -3400,28 +3220,6 @@ static bool TrainCheckIfLineEnds(Vehicle *v) return false; } - if (v->u.rail.pbs_status == PBS_STAT_HAS_PATH) - return true; - - if ((trackdir != INVALID_TRACKDIR) && (PBSIsPbsSignal(tile,trackdir) && PBSIsPbsSegment(tile,trackdir)) && !(IsTileType(v->tile, MP_STATION) && (v->current_order.station == _m[v->tile].m2))) { - NPFFindStationOrTileData fstd; - NPFFoundTargetData ftd; - - NPFFillWithOrderData(&fstd, v); - - DEBUG(pbs, 2) ("pbs: (%i) choose signal (CEOL), tile:%x trackdir:%i", v->unitnumber, tile, trackdir); - ftd = NPFRouteToStationOrTile(tile, trackdir, &fstd, TRANSPORT_RAIL, v->owner, v->u.rail.railtype, PBS_MODE_GREEN); - - if (ftd.best_trackdir != 0xFF && NPFGetFlag(&ftd.node, NPF_FLAG_PBS_EXIT)) { - if (!(NPFGetFlag(&ftd.node, NPF_FLAG_PBS_BLOCKED) || NPFGetFlag(&ftd.node, NPF_FLAG_PBS_RED))) { - v->u.rail.pbs_status = PBS_STAT_HAS_PATH; - v->u.rail.pbs_end_tile = ftd.node.tile; - v->u.rail.pbs_end_trackdir = ftd.node.direction; - return true; - } - }; - }; - // slow down v->vehstatus |= VS_TRAIN_SLOWING; break_speed = _breakdown_speeds[x & 0xF]; @@ -3578,8 +3376,6 @@ static void CheckIfTrainNeedsService(Vehicle *v) const Depot* depot; TrainFindDepotData tfdd; - if (PBSTileReserved(v->tile) & v->u.rail.track) return; - if (v->u.rail.pbs_status == PBS_STAT_HAS_PATH) return; if (_patches.servint_trains == 0) return; if (!VehicleNeedsService(v)) return; if (v->vehstatus & VS_STOPPED) return; |