changeset 13060:0ea9c5ed1b7a draft

(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.
author rubidium <rubidium@openttd.org>
date Wed, 16 Sep 2009 19:10:50 +0000
parents da49b7fa34f7
children 6e313cb3553a
files src/newgrf_callbacks.h src/newgrf_house.cpp src/newgrf_industrytiles.cpp src/town_cmd.cpp
diffstat 4 files changed, 46 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -214,6 +214,12 @@
 
 	/** Called on the Get Tile Description for an house tile. */
 	CBID_HOUSE_CUSTOM_NAME               = 0x14D, // 15 bit callback
+
+	/** Called to determine the type (if any) of foundation to draw for house tile. */
+	CBID_HOUSE_DRAW_FOUNDATIONS          = 0x14E, // 15 bit callback
+
+	/** Called to determine if one can alter the ground below a house tile */
+	CBID_HOUSE_AUTOSLOPE                 = 0x14F, // 15 bit callback
 };
 
 /**
@@ -257,6 +263,8 @@
 	CBM_HOUSE_ACCEPT_CARGO              =  8, ///< decides accepted types
 	CBM_HOUSE_PRODUCE_CARGO             =  9, ///< custom cargo production
 	CBM_HOUSE_DENY_DESTRUCTION          = 10, ///< conditional protection
+	CBM_HOUSE_DRAW_FOUNDATIONS          = 11, ///< decides if default foundations need to be drawn
+	CBM_HOUSE_AUTOSLOPE                 = 12, ///< decides allowance of autosloping
 };
 
 /**
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -426,7 +426,16 @@
 	const SpriteGroup *group;
 	ResolverObject object;
 
-	if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
+	if (ti->tileh != SLOPE_FLAT) {
+		bool draw_old_one = true;
+		if (HasBit(hs->callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS)) {
+			/* Called to determine the type (if any) of foundation to draw for the house tile */
+			uint32 callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
+			draw_old_one = (callback_res != 0);
+		}
+
+		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
+	}
 
 	NewHouseResolver(&object, house_id, ti->tile, Town::GetByTile(ti->tile));
 
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -244,7 +244,7 @@
 		if (HasBit(inds->callback_mask, CBM_INDT_DRAW_FOUNDATIONS)) {
 			/* Called to determine the type (if any) of foundation to draw for industry tile */
 			uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, i, ti->tile);
-			draw_old_one = callback_res != 0;
+			draw_old_one = (callback_res != 0);
 		}
 
 		if (draw_old_one) DrawFoundation(ti, FOUNDATION_LEVELED);
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -257,6 +257,19 @@
 /** Tile callback routine */
 static Foundation GetFoundation_Town(TileIndex tile, Slope tileh)
 {
+	HouseID hid = GetHouseType(tile);
+
+	/* For NewGRF house tiles we might not be drawing a foundation. We need to
+	 * account for this, as other structures should
+	 * draw the wall of the foundation in this case.
+	 */
+	if (hid >= NEW_HOUSE_OFFSET) {
+		const HouseSpec *hs = HouseSpec::Get(hid);
+		if (hs->spritegroup != NULL && HasBit(hs->callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS)) {
+			uint32 callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, hid, Town::GetByTile(tile), tile);
+			if (callback_res == 0) return FOUNDATION_NONE;
+		}
+	}
 	return FlatteningFoundation(tileh);
 }
 
@@ -2895,7 +2908,20 @@
 
 		/* Here we differ from TTDP by checking TILE_NOT_SLOPED */
 		if (((hs->building_flags & TILE_NOT_SLOPED) == 0) && !IsSteepSlope(tileh_new) &&
-			(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
+				(GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
+			bool allow_terraform = true;
+
+			/* Call the autosloping callback per tile, not for the whole building at once. */
+			house = GetHouseType(tile);
+			hs = HouseSpec::Get(house);
+			if (HasBit(hs->callback_mask, CBM_HOUSE_AUTOSLOPE)) {
+				/* If the callback fails, allow autoslope. */
+				uint16 res = GetHouseCallback(CBID_HOUSE_AUTOSLOPE, 0, 0, house, Town::GetByTile(tile), tile);
+				if ((res != 0) && (res != CALLBACK_FAILED)) allow_terraform = false;
+			}
+
+			if (allow_terraform) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform);
+		}
 	}
 
 	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);