Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,30 +805,39 @@ int CLuaColShapeDefs::RemoveColPolygonPoint(lua_State* luaVM)
return luaL_error(luaVM, argStream.GetFullErrorMessage());
}

std::tuple<float, float> CLuaColShapeDefs::GetColPolygonHeight(CColPolygon* pColPolygon)
CLuaMultiReturn<float, float> 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<CColPolygon*>(shape);

float floor;
float ceil;

polygon->GetHeight(floor, ceil);

return {floor, ceil};
}

bool CLuaColShapeDefs::SetColPolygonHeight(CColPolygon* pColPolygon, std::variant<bool, float> floor, std::variant<bool, float> ceil)
bool CLuaColShapeDefs::SetColPolygonHeight(CColShape* shape, std::variant<bool, float> floor, std::variant<bool, float> 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<bool>(floor))
fFloor = std::numeric_limits<float>::lowest();
else
fFloor = std::get<float>(floor);
auto* polygon = static_cast<CColPolygon*>(shape);

if (std::holds_alternative<bool>(ceil))
fCeil = std::numeric_limits<float>::max();
else
fCeil = std::get<float>(ceil);
float lowest = std::holds_alternative<bool>(floor) ? std::numeric_limits<float>::lowest() : std::get<float>(floor);
float highest = std::holds_alternative<bool>(ceil) ? std::numeric_limits<float>::max() : std::get<float>(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);
}
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ class CLuaColShapeDefs : public CLuaDefs
LUA_DECLARE(IsInsideColShape);
LUA_DECLARE(GetColShapeType);

static std::tuple<float, float> GetColPolygonHeight(CColPolygon* pColPolygon);
static bool SetColPolygonHeight(CColPolygon* pColPolygon, std::variant<bool, float> floor, std::variant<bool, float> ceil);
static CLuaMultiReturn<float, float> GetColPolygonHeight(CColShape* shape);
static bool SetColPolygonHeight(CColShape* shape, std::variant<bool, float> floor, std::variant<bool, float> ceil);
};
Loading