Prevent doors closing through occupants

This commit is contained in:
Your Name 2026-08-12 00:21:53 -04:00
parent bf09a8844a
commit 9731202739
5 changed files with 108 additions and 6 deletions

View file

@ -284,6 +284,28 @@ function World:isSwitchPressed(room, switch)
return target ~= nil or (player and player:occupiesCell(switch:getGridPos())) or false
end
-- Check every rendered/colliding colour layer. A red or green player/box can
-- visibly occupy a blue door cell, so checking only the door's own layer lets
-- wired doors close through an apparent occupant. Other door layers at the
-- same location are intentionally ignored: they are one layered doorway.
function World:doorCanClose(room, door)
local cells = door.getOccupiedCells and door:getOccupiedCells() or {door:getGridPos()}
for _, cell in ipairs(cells) do
for _, player in pairs(room.player or {}) do
if player:occupiesCell(cell) then return false end
end
for _, entities in pairs(room.collideables or {}) do
for _, entity in ipairs(entities) do
if entity ~= door and not entity.isDoor and entity:occupiesCell(cell) and
not (entity.canPassOver and entity:canPassOver()) then
return false
end
end
end
end
return true
end
function World:rebuildCircuitMatrices()
self.wireMatrix = {}
self.wiredSwitchMatrix = {}
@ -448,7 +470,7 @@ function World:resolveCircuits()
doorPowered[door] = powered
-- locked/collision is a projection of world state onto the physical
-- room entity so the existing movement renderer can consume it.
door:setPowered(powered)
door:setPowered(powered, self:doorCanClose(device.room, door))
end
end
end