diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp index 51a52b61ba2..11adf5ff4e7 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp @@ -805,30 +805,39 @@ int CLuaColShapeDefs::RemoveColPolygonPoint(lua_State* luaVM) return luaL_error(luaVM, argStream.GetFullErrorMessage()); } -std::tuple CLuaColShapeDefs::GetColPolygonHeight(CColPolygon* pColPolygon) +CLuaMultiReturn CLuaColShapeDefs::GetColPolygonHeight(CColShape* shape) { - float fFloor, fCeil; - pColPolygon->GetHeight(fFloor, fCeil); - return std::make_tuple(fFloor, fCeil); + if (shape->GetShapeType() != COLSHAPE_POLYGON) + { + throw std::invalid_argument("Shape must be a polygon"); + } + + auto* polygon = static_cast(shape); + + float floor; + float ceil; + + polygon->GetHeight(floor, ceil); + + return {floor, ceil}; } -bool CLuaColShapeDefs::SetColPolygonHeight(CColPolygon* pColPolygon, std::variant floor, std::variant ceil) +bool CLuaColShapeDefs::SetColPolygonHeight(CColShape* shape, std::variant floor, std::variant ceil) { - // bool SetColPolygonHeight ( colshape theColShape, float floor, float ceil ) - float fFloor, fCeil; + if (shape->GetShapeType() != COLSHAPE_POLYGON) + { + throw std::invalid_argument("Shape must be a polygon"); + } - if (std::holds_alternative(floor)) - fFloor = std::numeric_limits::lowest(); - else - fFloor = std::get(floor); + auto* polygon = static_cast(shape); - if (std::holds_alternative(ceil)) - fCeil = std::numeric_limits::max(); - else - fCeil = std::get(ceil); + float lowest = std::holds_alternative(floor) ? std::numeric_limits::lowest() : std::get(floor); + float highest = std::holds_alternative(ceil) ? std::numeric_limits::max() : std::get(ceil); - if (fFloor > fCeil) - std::swap(fFloor, fCeil); + if (lowest > highest) + { + std::swap(lowest, highest); + } - return CStaticFunctionDefinitions::SetColPolygonHeight(pColPolygon, fFloor, fCeil); + return CStaticFunctionDefinitions::SetColPolygonHeight(polygon, lowest, highest); } diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h index 1787bc3feca..cf57a783345 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h @@ -41,6 +41,6 @@ class CLuaColShapeDefs : public CLuaDefs LUA_DECLARE(IsInsideColShape); LUA_DECLARE(GetColShapeType); - static std::tuple GetColPolygonHeight(CColPolygon* pColPolygon); - static bool SetColPolygonHeight(CColPolygon* pColPolygon, std::variant floor, std::variant ceil); + static CLuaMultiReturn GetColPolygonHeight(CColShape* shape); + static bool SetColPolygonHeight(CColShape* shape, std::variant floor, std::variant ceil); };