@poma This is just a rewrite of OP's code. It has the same features and defects, but it performs better.
@ayrtep said in RoomPosition.isWalkable:
https://gist.github.com/anonymous/bc4ccac0cea464d0e98a9a176035808f#file-gistfile1-txt
@poma This is just a rewrite of OP's code. It has the same features and defects, but it performs better.
@ayrtep said in RoomPosition.isWalkable:
https://gist.github.com/anonymous/bc4ccac0cea464d0e98a9a176035808f#file-gistfile1-txt
I know this is quite old, but the code @ayrtep came up with can be simplified a lot using lodash, and made more efficient by creating a lookup of obstacle types. This makes the function time complexity linear over the number of entities at the position (O(n)) instead of quadratic over the number of entities and the number of obstacle types (O(n2)).
const isObstacle = _.transform(
OBSTACLE_OBJECT_TYPES,
(o, type) => { o[type] = true; },
{}
);
function isEnterable(pos) {
return _.every(pos.look(), item =>
item.type === 'terrain' ?
item.terrain !== 'wall' :
!isObstacle[item.structureType]
);
}