MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TerraformTile_Object

Function TerraformTile_Object

src/object_cmd.cpp:904–937  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

902}
903
904static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
905{
906 ObjectType type = GetObjectType(tile);
907
908 if (type == OBJECT_OWNED_LAND) {
909 /* Owned land remains unsold */
910 CommandCost ret = CheckTileOwnership(tile);
911 if (ret.Succeeded()) return CommandCost();
912 } else if (AutoslopeEnabled() && type != OBJECT_TRANSMITTER && type != OBJECT_LIGHTHOUSE) {
913 /* Behaviour:
914 * - Both new and old slope must not be steep.
915 * - TileMaxZ must not be changed.
916 * - Allow autoslope by default.
917 * - Disallow autoslope if callback succeeds and returns non-zero.
918 */
919 Slope tileh_old = GetTileSlope(tile);
920 /* TileMaxZ must not be changed. Slopes must not be steep. */
921 if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
922 const ObjectSpec *spec = ObjectSpec::Get(type);
923
924 /* Call callback 'disable autosloping for objects'. */
925 if (spec->callback_mask.Test(ObjectCallbackMask::Autoslope)) {
926 /* If the callback fails, allow autoslope. */
927 uint16_t res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile);
928 if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
929 } else if (spec->IsEnabled()) {
930 /* allow autoslope */
931 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
932 }
933 }
934 }
935
936 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
937}
938
939static CommandCost CheckBuildAbove_Object(TileIndex tile, DoCommandFlags flags, Axis, int height)
940{

Callers

nothing calls this directly

Calls 13

GetObjectTypeFunction · 0.85
CheckTileOwnershipFunction · 0.85
CommandCostClass · 0.85
AutoslopeEnabledFunction · 0.85
GetTileSlopeFunction · 0.85
IsSteepSlopeFunction · 0.85
GetTileMaxZFunction · 0.85
GetSlopeMaxZFunction · 0.85
GetObjectCallbackFunction · 0.85
ConvertBooleanCallbackFunction · 0.85
SucceededMethod · 0.80
TestMethod · 0.80

Tested by

no test coverage detected