diff options
-rw-r--r-- | src/newgrf_callbacks.h | 8 | ||||
-rw-r--r-- | src/newgrf_house.cpp | 11 | ||||
-rw-r--r-- | src/newgrf_industrytiles.cpp | 2 | ||||
-rw-r--r-- | src/town_cmd.cpp | 28 |
4 files changed, 46 insertions, 3 deletions
diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h index 5c4eb0f35..3b1d26d26 100644 --- a/src/newgrf_callbacks.h +++ b/src/newgrf_callbacks.h @@ -214,6 +214,12 @@ enum CallbackID { /** 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 @@ enum HouseCallbackMask { 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 }; /** diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 10dbe3272..da57d68d9 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -426,7 +426,16 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id) 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)); diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index a8c125727..a661fd018 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -244,7 +244,7 @@ bool DrawNewIndustryTile(TileInfo *ti, Industry *i, IndustryGfx gfx, const Indus 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); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index b7719c879..246313663 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -257,6 +257,19 @@ static uint GetSlopeZ_Town(TileIndex tile, uint x, uint y) /** 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 @@ static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlag flags, uint /* 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); |