From acc9dffab7f33d70435a8ebc86ff778b3687e0d4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 24 Jan 2022 01:18:35 +0000 Subject: [PATCH] Add object mapped variables for slope after foundation applied --- src/newgrf_extension.cpp | 2 ++ src/newgrf_extension.h | 2 ++ src/newgrf_object.cpp | 22 ++++++++++++++++++++++ src/object_cmd.cpp | 4 ++-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index 908ee081a9..dee1d52b93 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -79,6 +79,8 @@ extern const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = { /** Action14 Action2 remappable variable list */ extern const GRFVariableMapDefinition _grf_action2_remappable_variables[] = { + GRFVariableMapDefinition(GSF_OBJECTS, A2VRI_OBJECT_FOUNDATION_SLOPE, "object_foundation_tile_slope"), + GRFVariableMapDefinition(GSF_OBJECTS, A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE, "object_foundation_change_tile_slope"), GRFVariableMapDefinition(), }; diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index f36d182e61..e5f069a84e 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -39,6 +39,8 @@ enum Action0RemapPropertyIds { enum Action2VariableRemapIds { + A2VRI_OBJECT_FOUNDATION_SLOPE = 0x100, + A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE, }; /** Action14 feature definition */ diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index ba09802c07..01e3f36970 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -22,6 +22,7 @@ #include "water.h" #include "clear_func.h" #include "newgrf_animation_base.h" +#include "newgrf_extension.h" #include "safeguards.h" @@ -263,6 +264,12 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, /* Object view */ case 0x48: return this->view; + case A2VRI_OBJECT_FOUNDATION_SLOPE: + return GetTileSlope(this->tile); + + case A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE: + return 0; + /* * Disallow the rest: * 0x40: Relative position is passed as parameter during construction. @@ -333,6 +340,21 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, /* Count of object, distance of closest instance */ case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro.grffile->grfid, this->tile, this->obj); + + case A2VRI_OBJECT_FOUNDATION_SLOPE: { + extern Foundation GetFoundation_Object(TileIndex tile, Slope tileh); + Slope slope = GetTileSlope(this->tile); + ApplyFoundationToSlope(GetFoundation_Object(this->tile, slope), &slope); + return slope; + } + + case A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE: { + extern Foundation GetFoundation_Object(TileIndex tile, Slope tileh); + Slope slope = GetTileSlope(this->tile); + Slope orig_slope = slope; + ApplyFoundationToSlope(GetFoundation_Object(this->tile, slope), &slope); + return slope ^ orig_slope; + } } unhandled: diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index e0d46b92b1..3aa8c2da17 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -566,7 +566,7 @@ CommandCost CmdBuildObjectArea(TileIndex tile, DoCommandFlag flags, uint32 p1, u } -static Foundation GetFoundation_Object(TileIndex tile, Slope tileh); +Foundation GetFoundation_Object(TileIndex tile, Slope tileh); static void DrawTile_Object(TileInfo *ti, DrawTileProcParams params) { @@ -670,7 +670,7 @@ static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y) } } -static Foundation GetFoundation_Object(TileIndex tile, Slope tileh) +Foundation GetFoundation_Object(TileIndex tile, Slope tileh) { if (tileh == SLOPE_FLAT) return FOUNDATION_NONE; switch (GetObjectEffectiveFoundationType(tile)) {