(svn r17558) -Feature [NewGRF]: callbacks for houses to disable drawing foundations and to disable slope changes, like industry tile callbacks 30 and 3C.

This commit is contained in:
rubidium 2009-09-16 19:10:50 +00:00
parent 24e9ee8ab4
commit 430ce19418
4 changed files with 46 additions and 3 deletions

View File

@ -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
};
/**

View File

@ -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));

View File

@ -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);

View File

@ -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);