summaryrefslogtreecommitdiff
path: root/station_cmd.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-04-08 22:44:06 +0000
committerDarkvater <darkvater@openttd.org>2005-04-08 22:44:06 +0000
commit7ef681eaed3dae29c3145829aab37a78b30b83bd (patch)
tree03255e464a7b6b59f6adf9af778478eb33638e18 /station_cmd.c
parenta9c52454c80c6cc128dd98e59d9ea0f02d827484 (diff)
downloadopenttd-7ef681eaed3dae29c3145829aab37a78b30b83bd.tar.xz
(svn r2168) - Fix: Various stages of invisible trains, and wrong v->u.rail.track combinations. When a vehicle was sold its (possibly) assigned road slot for multislot was not cleared, thus resulting in a bug confusion. This should fix [ 1178520 ] Assertion failure in ai.c (invalid v->u.rail.track). With big thanks to TrueLight for the demo-recording patch, BJH for the wonderful savegame, Hackykid for his brilliant suggestions of the problem and Celestar for... ehm, making it all possible ;p
Diffstat (limited to 'station_cmd.c')
-rw-r--r--station_cmd.c73
1 files changed, 27 insertions, 46 deletions
diff --git a/station_cmd.c b/station_cmd.c
index 05c560eb4..06745044d 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2418,6 +2418,30 @@ void DeleteAllPlayerStations(void)
}
}
+static void CheckOrphanedSlots(const Station *st, RoadStopType rst)
+{
+ RoadStop *rs;
+ int k;
+
+ for (rs = GetPrimaryRoadStop(st, rst); rs != NULL; rs = rs->next) {
+ for (k = 0; k < NUM_SLOTS; k++) {
+ if (rs->slot[k] != INVALID_SLOT) {
+ Vehicle *v = GetVehicle(rs->slot[k]);
+
+ assert(v->type == VEH_Road);
+ if (v->u.road.slot != rs) {
+ DEBUG(ms, 1) ("Multistop: %s slot desync between stop at 0x%X of station %d "
+ "and Vehicle %d at going to 0x%X! (don't panic)", (v->cargo_type == CT_PASSENGERS) ? "Bus" : "Truck",
+ rs->xy, st->index, v->unitnumber, v->dest_tile);
+ v->u.road.slot = NULL;
+ v->u.road.slot_age = 0;
+ rs->slot[k] = INVALID_SLOT;
+ }
+ }
+ }
+ }
+}
+
/* this function is called for one station each tick */
static void StationHandleBigTick(Station *st)
{
@@ -2428,52 +2452,9 @@ static void StationHandleBigTick(Station *st)
DeleteStation(st);
}
- //Here we saveguard against orphaned slots
- {
- RoadStop *rs;
-
- for (rs = GetPrimaryRoadStop(st, RS_BUS); rs != NULL; rs = rs->next) {
- int k;
- for (k = 0; k < NUM_SLOTS; k++) {
- if (rs->slot[k] != INVALID_SLOT) {
- Vehicle *v = GetVehicle(rs->slot[k]);
-
- if (v->u.road.slot != rs) {
- DEBUG(ms, 1) ("Multistop: Truck Slot Desync between stop at "
- "0x%x of station %d (at 0x%x) and Vehicle %d at 0x%x, "
- "going to 0x%x! "
- "cleaning up (Don't panic)",
- rs->xy, st->index, st->xy, v->unitnumber, v->tile,
- v->dest_tile);
- v->u.road.slot = NULL;
- v->u.road.slot_age = 0;
- rs->slot[k] = INVALID_SLOT;
- }
- }
- }
- }
-
- for (rs = GetPrimaryRoadStop(st, RS_TRUCK); rs != NULL; rs = rs->next) {
- int k;
- for (k = 0; k < NUM_SLOTS; k++) {
- if (rs->slot[k] != INVALID_SLOT) {
- Vehicle *v = GetVehicle(rs->slot[k]);
-
- if (v->u.road.slot != rs) {
- DEBUG(ms, 1) ("Multistop: Truck Slot Desync between stop at "
- "0x%x of station %d (at 0x%x) and Vehicle %d at 0x%x, "
- "going to 0x%x! "
- "cleaning up (Don't panic)",
- rs->xy, st->index, st->xy, v->unitnumber, v->tile,
- v->dest_tile);
- v->u.road.slot = NULL;
- v->u.road.slot_age = 0;
- rs->slot[k] = INVALID_SLOT;
- }
- }
- }
- }
- }
+ // Here we saveguard against orphaned slots
+ CheckOrphanedSlots(st, RS_BUS);
+ CheckOrphanedSlots(st, RS_TRUCK);
}
static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; }