1786 return result != 0; |
1786 return result != 0; |
1787 } |
1787 } |
1788 |
1788 |
1789 void SetSignalsOnBothDir(TileIndex tile, byte track) |
1789 void SetSignalsOnBothDir(TileIndex tile, byte track) |
1790 { |
1790 { |
1791 static const byte _search_dir_1[6] = {1, 3, 1, 3, 5, 3}; |
1791 static const Direction _search_dir_1[] = { DIR_NE, DIR_SE, DIR_NE, DIR_SE, DIR_SW, DIR_SE }; |
1792 static const byte _search_dir_2[6] = {5, 7, 7, 5, 7, 1}; |
1792 static const Direction _search_dir_2[] = { DIR_SW, DIR_NW, DIR_NW, DIR_SW, DIR_NW, DIR_NE }; |
1793 |
1793 |
1794 UpdateSignalsOnSegment(tile, _search_dir_1[track]); |
1794 UpdateSignalsOnSegment(tile, _search_dir_1[track]); |
1795 UpdateSignalsOnSegment(tile, _search_dir_2[track]); |
1795 UpdateSignalsOnSegment(tile, _search_dir_2[track]); |
1796 } |
1796 } |
1797 |
1797 |
2067 static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 }; |
2067 static const byte _fractcoords_enter[4] = { 0x8A, 0x48, 0x84, 0xA8 }; |
2068 static const byte _deltacoord_leaveoffset[8] = { |
2068 static const byte _deltacoord_leaveoffset[8] = { |
2069 -1, 0, 1, 0, /* x */ |
2069 -1, 0, 1, 0, /* x */ |
2070 0, 1, 0, -1 /* y */ |
2070 0, 1, 0, -1 /* y */ |
2071 }; |
2071 }; |
2072 static const byte _enter_directions[4] = {5, 7, 1, 3}; |
|
2073 static const byte _leave_directions[4] = {1, 3, 5, 7}; |
|
2074 static const byte _depot_track_mask[4] = {1, 2, 1, 2}; |
2072 static const byte _depot_track_mask[4] = {1, 2, 1, 2}; |
2075 |
2073 |
2076 static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) |
2074 static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) |
2077 { |
2075 { |
2078 byte fract_coord; |
2076 byte fract_coord; |
2079 byte fract_coord_leave; |
2077 byte fract_coord_leave; |
2080 int dir; |
2078 DiagDirection dir; |
2081 int length; |
2079 int length; |
2082 |
2080 |
2083 // this routine applies only to trains in depot tiles |
2081 // this routine applies only to trains in depot tiles |
2084 if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; |
2082 if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; |
2085 |
2083 |
2100 |
2098 |
2101 if (_fractcoords_behind[dir] == fract_coord) { |
2099 if (_fractcoords_behind[dir] == fract_coord) { |
2102 /* make sure a train is not entering the tile from behind */ |
2100 /* make sure a train is not entering the tile from behind */ |
2103 return 8; |
2101 return 8; |
2104 } else if (_fractcoords_enter[dir] == fract_coord) { |
2102 } else if (_fractcoords_enter[dir] == fract_coord) { |
2105 if (_enter_directions[dir] == v->direction) { |
2103 if (DiagDirToDir(ReverseDiagDir(dir)) == v->direction) { |
2106 /* enter the depot */ |
2104 /* enter the depot */ |
2107 v->u.rail.track = 0x80, |
2105 v->u.rail.track = 0x80, |
2108 v->vehstatus |= VS_HIDDEN; /* hide it */ |
2106 v->vehstatus |= VS_HIDDEN; /* hide it */ |
2109 v->direction ^= 4; |
2107 v->direction = ReverseDir(v->direction); |
2110 if (v->next == NULL) |
2108 if (v->next == NULL) |
2111 TrainEnterDepot(v, tile); |
2109 TrainEnterDepot(v, tile); |
2112 v->tile = tile; |
2110 v->tile = tile; |
2113 InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
2111 InvalidateWindow(WC_VEHICLE_DEPOT, tile); |
2114 return 4; |
2112 return 4; |
2115 } |
2113 } |
2116 } else if (fract_coord_leave == fract_coord) { |
2114 } else if (fract_coord_leave == fract_coord) { |
2117 if (_leave_directions[dir] == v->direction) { |
2115 if (DiagDirToDir(dir) == v->direction) { |
2118 /* leave the depot? */ |
2116 /* leave the depot? */ |
2119 if ((v = v->next) != NULL) { |
2117 if ((v = v->next) != NULL) { |
2120 v->vehstatus &= ~VS_HIDDEN; |
2118 v->vehstatus &= ~VS_HIDDEN; |
2121 v->u.rail.track = _depot_track_mask[dir]; |
2119 v->u.rail.track = _depot_track_mask[dir]; |
2122 assert(v->u.rail.track); |
2120 assert(v->u.rail.track); |