Mercurial > hg > openttd
changeset 8344:6312fafcfe47 draft
(svn r11910) -Fix: play 'ding-ding' crossing sound in more cases (except gameload and crossing construction)
-Fix: crossing sound is bound to tile, not to vehicle
author | smatz <smatz@openttd.org> |
---|---|
date | Thu, 17 Jan 2008 20:41:33 +0000 |
parents | 8ee8a732be4e |
children | fa1c3904e50d |
files | src/openttd.cpp src/rail_cmd.cpp src/road_cmd.cpp src/road_func.h src/road_map.h src/train_cmd.cpp |
diffstat | 6 files changed, 28 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -2317,7 +2317,7 @@ if (CheckSavegameVersion(86)) { /* Now all crossings should be in correct state */ for (TileIndex t = 0; t < map_size; t++) { - if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t); + if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false); } }
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -383,7 +383,7 @@ (track == TRACK_Y && road == ROAD_X)) { if (flags & DC_EXEC) { MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile)); - UpdateLevelCrossing(tile); + UpdateLevelCrossing(tile, false); } break; }
--- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -487,7 +487,7 @@ YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile))); /* Always add road to the roadtypes (can't draw without it) */ MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2); - UpdateLevelCrossing(tile); + UpdateLevelCrossing(tile, false); MarkTileDirtyByTile(tile); } return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
--- a/src/road_func.h +++ b/src/road_func.h @@ -136,6 +136,6 @@ */ RoadTypes GetPlayerRoadtypes(const PlayerID p); -void UpdateLevelCrossing(TileIndex tile); +void UpdateLevelCrossing(TileIndex tile, bool sound = true); #endif /* ROAD_FUNC_H */
--- a/src/road_map.h +++ b/src/road_map.h @@ -191,23 +191,26 @@ return AxisToTrackBits(OtherAxis(GetCrossingRoadAxis(tile))); } +static inline bool IsCrossingBarred(TileIndex t) +{ + assert(GetRoadTileType(t) == ROAD_TILE_CROSSING); + return HasBit(_m[t].m4, 5); +} + +static inline void SetCrossingBarred(TileIndex t, bool barred) +{ + assert(GetRoadTileType(t) == ROAD_TILE_CROSSING); + SB(_m[t].m4, 5, 1, barred); +} static inline void UnbarCrossing(TileIndex t) { - assert(GetRoadTileType(t) == ROAD_TILE_CROSSING); - ClrBit(_m[t].m4, 5); + SetCrossingBarred(t, false); } static inline void BarCrossing(TileIndex t) { - assert(GetRoadTileType(t) == ROAD_TILE_CROSSING); - SetBit(_m[t].m4, 5); -} - -static inline bool IsCrossingBarred(TileIndex t) -{ - assert(GetRoadTileType(t) == ROAD_TILE_CROSSING); - return HasBit(_m[t].m4, 5); + SetCrossingBarred(t, true); } #define IsOnDesert IsOnSnow
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1683,20 +1683,23 @@ /** * Sets correct crossing state * @param tile tile to update + * @param sound should we play sound? * @pre tile is a rail-road crossing */ -void UpdateLevelCrossing(TileIndex tile) +void UpdateLevelCrossing(TileIndex tile, bool sound) { assert(IsLevelCrossingTile(tile)); - UnbarCrossing(tile); - /* train on crossing || train approaching crossing */ - if (VehicleFromPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile)) { - BarCrossing(tile); + bool new_state = VehicleFromPos(tile, NULL, &TrainOnTileEnum) || TrainApproachingCrossing(tile); + + if (new_state != IsCrossingBarred(tile)) { + if (new_state && sound) { + SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile); + } + SetCrossingBarred(tile, new_state); + MarkTileDirtyByTile(tile); } - - MarkTileDirtyByTile(tile); } @@ -3458,7 +3461,7 @@ /* approaching a rail/road crossing? then make it red */ if (IsLevelCrossingTile(tile) && !IsCrossingBarred(tile)) { BarCrossing(tile); - SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v); + SndPlayTileFx(SND_0E_LEVEL_CROSSING, tile); MarkTileDirtyByTile(tile); }