station_cmd.c
changeset 1239 133586622b78
parent 1231 5fa7581377a9
child 1245 3822f77cbc53
--- a/station_cmd.c	Sun Jan 30 21:06:09 2005 +0000
+++ b/station_cmd.c	Sun Jan 30 22:04:14 2005 +0000
@@ -2398,6 +2398,43 @@
 		if (++st->delete_ctr >= 8)
 			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(misc, 1) ("Bus Slot Desync! cleaning up (Don't panic)");
+						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(misc, 1) ("Truck Slot Desync! cleaning up (Don't panic)");
+						v->u.road.slot = NULL;
+						v->u.road.slot_age = 0;
+						rs->slot[k] = INVALID_SLOT;
+					}
+				}
+			}
+		}
+	}
 }
 
 static inline void byte_inc_sat(byte *p) { byte b = *p + 1; if (b != 0) *p = b; }