I was wondering if there was any reliable way to detect if the party can move towards a tile.
Right now I was using the following function:
SpoilerShow
Code: Select all
function collisionAhead(entity, direction)
if not(entity) then return false end;
local level, x, y = entity.level, entity.x, entity.y;
local facing = direction or entity.facing;
local dx, dy = getForward(facing);
-- Check for solid wall
if isWall(level, x+dx, y+dy) then
return true;
end
-- Check for doors on current tile
for e in entitiesAt(level, x, y) do
if e.setDoorState and e:isClosed() and e.facing == facing then
return true;
end
end
-- Check for entities on next tile
local c;
for e in entitiesAt(level, x+dx, y+dy) do
if e.setDoorState and e:isClosed() and (e.facing+2)%4 == facing then
return true;
end
c = e.class;
if c == "Monster" or c == "Blockage" or c == "Crystal" or c == "Altar" or c == "Party" then
return true;
end
end
return false;
endOne thing I thought would be to put a check in all monster's onMove hooks (doable with the framework) that would mark the square as "blocked" and free it 0.5s later. But then is the monster onMove called anytime the monster tries to move to a cell even if it's blocked, or is it only when the monster is actually really moving that way unless you return false?
And would there be any simpler solution I'm not aware of?