Skip to content

Commit

Permalink
Merge pull request #5270 from NicksWorld/fix/checkfreetiles
Browse files Browse the repository at this point in the history
Fix regression in checkFreeTiles
  • Loading branch information
myk002 authored Feb 13, 2025
2 parents 4a5c766 + cfb2cac commit 768e3f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library/include/modules/Buildings.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ DFHACK_EXPORT bool getCorrectSize(df::coord2d &size, df::coord2d &center,
* Checks if the tiles are free to be built upon.
*/
DFHACK_EXPORT bool checkFreeTiles(df::coord pos, df::coord2d size,
df::building *bld,
df::building *bld = nullptr,
bool create_ext = false,
bool allow_occupied = false,
bool allow_wall = false,
Expand Down
15 changes: 6 additions & 9 deletions library/modules/Buildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,7 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size,
bool allow_wall,
bool allow_flow)
{
CHECK_NULL_POINTER(bld);

bool found_any = false;
auto & room = bld->room;

for (int dx = 0; dx < size.x; dx++)
{
Expand All @@ -748,9 +745,9 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size,
df::building_extents_type *etile = NULL;

// Exclude using extents
if (room.extents)
if (bld && bld->room.extents)
{
etile = getExtentTile(room, tile);
etile = getExtentTile(bld->room, tile);
if (!etile || !*etile)
continue;
}
Expand Down Expand Up @@ -784,13 +781,13 @@ bool Buildings::checkFreeTiles(df::coord pos, df::coord2d size,
found_any = true;
else
{
if (!create_ext)
if (!bld || !create_ext)
return false;

if (!room.extents)
if (!bld->room.extents)
{
init_extents(room, pos, size);
etile = getExtentTile(room, tile);
init_extents(bld->room, pos, size);
etile = getExtentTile(bld->room, tile);
}

if (!etile)
Expand Down

0 comments on commit 768e3f2

Please sign in to comment.