(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame

This commit is contained in:
smatz 2008-01-17 19:49:06 +00:00
parent 35135222b5
commit 822242f411
6 changed files with 28 additions and 12 deletions

View File

@ -41,6 +41,7 @@
#include "sound_func.h"
#include "track_type.h"
#include "track_func.h"
#include "road_func.h"
#include "rail_map.h"
#include "signal_func.h"
#include "gfx_func.h"
@ -432,7 +433,9 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
if (new_player != PLAYER_SPECTATOR) {
/* Update all signals because there can be new segment that was owned by two players
* and signals were not propagated */
* and signals were not propagated
* Similiar with crossings - it is needed to bar crossings that weren't before
* because of different owner of crossing and approaching train */
tile = 0;
do {
@ -442,6 +445,8 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
Track track = RemoveFirstTrack(&tracks);
if (HasSignalOnTrack(tile, track)) AddTrackToSignalBuffer(tile, track, new_player);
} while (tracks != TRACK_BIT_NONE);
} else if (IsLevelCrossingTile(tile) && IsTileOwner(tile, new_player)) {
UpdateLevelCrossing(tile);
}
} while (++tile != MapSize());

View File

@ -65,6 +65,7 @@
#include "vehicle_func.h"
#include "sound_func.h"
#include "variables.h"
#include "road_func.h"
#include "bridge_map.h"
#include "clear_map.h"
@ -2313,6 +2314,13 @@ bool AfterLoadGame()
}
}
if (CheckSavegameVersion(86)) {
/* Now all crossings should be in correct state */
for (TileIndex t = 0; t < map_size; t++) {
if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t);
}
}
return InitializeWindowsAndCaches();
}

View File

@ -383,6 +383,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
(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);
}
break;
}

View File

@ -32,6 +32,7 @@
#include "vehicle_func.h"
#include "vehicle_base.h"
#include "sound_func.h"
#include "road_func.h"
#include "table/sprites.h"
#include "table/strings.h"
@ -486,6 +487,7 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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);
MarkTileDirtyByTile(tile);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price.build_road * (rt == ROADTYPE_ROAD ? 2 : 4));
@ -1343,11 +1345,9 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int
{
switch (GetRoadTileType(tile)) {
case ROAD_TILE_CROSSING:
if (v->type == VEH_TRAIN && !IsCrossingBarred(tile)) {
/* train crossing a road */
SndPlayVehicleFx(SND_0E_LEVEL_CROSSING, v);
BarCrossing(tile);
MarkTileDirtyByTile(tile);
if (v->type == VEH_TRAIN) {
/* it should be barred */
assert(IsCrossingBarred(tile));
}
break;

View File

@ -136,4 +136,6 @@ bool ValParamRoadType(const RoadType rt);
*/
RoadTypes GetPlayerRoadtypes(const PlayerID p);
void UpdateLevelCrossing(TileIndex tile);
#endif /* ROAD_FUNC_H */

View File

@ -1685,7 +1685,7 @@ static Vehicle *TrainApproachingCrossing(TileIndex tile)
* @param tile tile to update
* @pre tile is a rail-road crossing
*/
void UpdateTrainCrossing(TileIndex tile)
void UpdateLevelCrossing(TileIndex tile)
{
assert(IsLevelCrossingTile(tile));
@ -1773,11 +1773,11 @@ static void ReverseTrainDirection(Vehicle *v)
ClrBit(v->u.rail.flags, VRF_REVERSING);
/* update crossing we were approaching */
if (crossing != INVALID_TILE) UpdateTrainCrossing(crossing);
if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
/* maybe we are approaching crossing now, after reversal */
crossing = TrainApproachingCrossingTile(v);
if (crossing != INVALID_TILE) UpdateTrainCrossing(crossing);
if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
}
/** Reverse train.
@ -2856,7 +2856,7 @@ static void SetVehicleCrashed(Vehicle *v)
END_ENUM_WAGONS(v)
/* must be updated after the train has been marked crashed */
if (crossing != INVALID_TILE) UpdateTrainCrossing(crossing);
if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
}
static uint CountPassengersInTrain(const Vehicle* v)
@ -3148,7 +3148,7 @@ static void TrainController(Vehicle *v, bool update_image)
* (above) or the last vehicle moves. */
if (v->Next() == NULL) {
TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
if (IsLevelCrossingTile(gp.old_tile)) UpdateTrainCrossing(gp.old_tile);
if (IsLevelCrossingTile(gp.old_tile)) UpdateLevelCrossing(gp.old_tile);
}
}
}
@ -3211,7 +3211,7 @@ static void DeleteLastWagon(Vehicle *v)
v = NULL; // make sure nobody will won't try to read 'v' anymore
/* check if the wagon was on a road/rail-crossing */
if (IsLevelCrossingTile(tile)) UpdateTrainCrossing(tile);
if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile);
/* Update signals */
if (IsTileType(tile, MP_TUNNELBRIDGE) || IsTileDepotType(tile, TRANSPORT_RAIL)) {