summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-01-17 19:49:06 +0000
committersmatz <smatz@openttd.org>2008-01-17 19:49:06 +0000
commit822242f4110b6e4188bca31599a23966be0b2dd4 (patch)
tree34528ac5e4eacd82e0b40b87f08e3bae4aa5c964
parent35135222b56687a699181bf57271b0e2a08e1d32 (diff)
downloadopenttd-822242f4110b6e4188bca31599a23966be0b2dd4.tar.xz
(svn r11908) -Fix: update crossing when merging a company, when building a crossing and after loading older savegame
-rw-r--r--src/economy.cpp7
-rw-r--r--src/openttd.cpp8
-rw-r--r--src/rail_cmd.cpp1
-rw-r--r--src/road_cmd.cpp10
-rw-r--r--src/road_func.h2
-rw-r--r--src/train_cmd.cpp12
6 files changed, 28 insertions, 12 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 9377a7a80..1156befb7 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -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());
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 2dfd6e050..b1753490a 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -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();
}
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 0627580da..3e9b94cc9 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -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;
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index dcb3871c6..ee530a225 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -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;
diff --git a/src/road_func.h b/src/road_func.h
index 6cc9b6a94..a93e1af78 100644
--- a/src/road_func.h
+++ b/src/road_func.h
@@ -136,4 +136,6 @@ bool ValParamRoadType(const RoadType rt);
*/
RoadTypes GetPlayerRoadtypes(const PlayerID p);
+void UpdateLevelCrossing(TileIndex tile);
+
#endif /* ROAD_FUNC_H */
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 7f1f23747..68c5080f2 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -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)) {