diff options
author | rubidium <rubidium@openttd.org> | 2010-08-28 19:00:21 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-08-28 19:00:21 +0000 |
commit | 3e67b4fe5fd94d181e44d8291d389868cd86182b (patch) | |
tree | 0a68b6b4b63fcf3545294ea006a546ba49d5b859 /src | |
parent | d4403cb64937bbce065b1c84faa207194fd19262 (diff) | |
download | openttd-3e67b4fe5fd94d181e44d8291d389868cd86182b.tar.xz |
(svn r20667) -Codechange: implement the autoslope callback for objects
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_callbacks.h | 2 | ||||
-rw-r--r-- | src/object_cmd.cpp | 22 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h index 3ec682214..5001cdc8e 100644 --- a/src/newgrf_callbacks.h +++ b/src/newgrf_callbacks.h @@ -271,7 +271,7 @@ enum CallbackID { CBID_OBJECT_FUND_MORE_TEXT = 0x15C, // 15 bit callback, not implemented /** Called to determine if one can alter the ground below an object tile */ - CBID_OBJECT_AUTOSLOPE = 0x15D, // 15 bit callback, not implemented + CBID_OBJECT_AUTOSLOPE = 0x15D, // 15 bit callback }; /** diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index aabf30c0c..d16cfeb78 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -621,7 +621,27 @@ static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, uin CommandCost ret = CheckTileOwnership(tile); if (ret.Succeeded()) return CommandCost(); } else if (AutoslopeEnabled() && type != OBJECT_TRANSMITTER && type != OBJECT_LIGHTHOUSE) { - if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + /* Behaviour: + * - Both new and old slope must not be steep. + * - TileMaxZ must not be changed. + * - Allow autoslope by default. + * - Disallow autoslope if callback succeeds and returns non-zero. + */ + Slope tileh_old = GetTileSlope(tile, NULL); + /* TileMaxZ must not be changed. Slopes must not be steep. */ + if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) { + const ObjectSpec *spec = ObjectSpec::Get(type); + + /* Call callback 'disable autosloping for objects'. */ + if (HasBit(spec->callback_mask, CBM_OBJ_AUTOSLOPE)) { + /* If the callback fails, allow autoslope. */ + uint16 res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile); + if ((res == 0) || (res == CALLBACK_FAILED)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + } else if (spec->enabled) { + /* allow autoslope */ + return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]); + } + } } return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |