changeset 16015:296046761962 draft

(svn r20708) -Fix [FS#4101]: upon company bankruptcy some objects weren't removed properly
author rubidium <rubidium@openttd.org>
date Wed, 01 Sep 2010 06:15:26 +0000
parents 3ce1da2ab196
children 68db5e7ccacc
files src/object_cmd.cpp src/saveload/object_sl.cpp
diffstat 2 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -331,6 +331,17 @@
 	return IsOwnedLand(tile) ? FOUNDATION_NONE : FlatteningFoundation(tileh);
 }
 
+/**
+ * Perform the actual removal of the object from the map.
+ * @param o The object to really clear.
+ */
+static void ReallyClearObjectTile(Object *o)
+{
+	Object::DecTypeCount(GetObjectType(o->location.tile));
+	TILE_AREA_LOOP(tile_cur, o->location) MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
+	delete o;
+}
+
 static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
 {
 	ObjectType type = GetObjectType(tile);
@@ -391,11 +402,7 @@
 			break;
 	}
 
-	if (flags & DC_EXEC) {
-		Object::DecTypeCount(type);
-		TILE_AREA_LOOP(tile_cur, ta) MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
-		delete o;
-	}
+	if (flags & DC_EXEC) ReallyClearObjectTile(o);
 
 	return cost;
 }
@@ -602,12 +609,12 @@
 			SetBit(t->statues, new_owner);
 			SetTileOwner(tile, new_owner);
 		} else {
-			DoClearSquare(tile);
+			ReallyClearObjectTile(Object::GetByTile(tile));
 		}
 
 		SetWindowDirty(WC_TOWN_AUTHORITY, t->index);
 	} else {
-		DoClearSquare(tile);
+		ReallyClearObjectTile(Object::GetByTile(tile));
 	}
 }
 
--- a/src/saveload/object_sl.cpp
+++ b/src/saveload/object_sl.cpp
@@ -52,7 +52,12 @@
 	Object *o;
 	FOR_ALL_OBJECTS(o) {
 		SlObject(o, _object_desc);
-		Object::IncTypeCount(GetObjectType(o->location.tile));
+		if (CheckSavegameVersion(148) && !IsTileType(o->location.tile, MP_OBJECT)) {
+			/* Due to a small bug stale objects could remain. */
+			delete o;
+		} else {
+			Object::IncTypeCount(GetObjectType(o->location.tile));
+		}
 	}
 }