+bool MapState::CheckBlocking() const {
+ const Tile &tile(map->TileAt(controlled->Position()));
+ Vector<int> nextPosition;
+ switch (nextDirection) {
+ case Entity::ORIENTATION_NORTH:
+ if (tile.BlocksNorth()) {
+ return true;
+ } else {
+ nextPosition = Vector<int>(
+ controlled->Position().X(),
+ controlled->Position().Y() - map->Tileset()->Height());
+ }
+ break;
+ case Entity::ORIENTATION_EAST:
+ if (tile.BlocksEast()) {
+ return true;
+ } else {
+ nextPosition = Vector<int>(
+ controlled->Position().X() + map->Tileset()->Width(),
+ controlled->Position().Y());
+ }
+ break;
+ case Entity::ORIENTATION_SOUTH:
+ if (tile.BlocksSouth()) {
+ return true;
+ } else {
+ nextPosition = Vector<int>(
+ controlled->Position().X(),
+ controlled->Position().Y() + map->Tileset()->Height());
+ }
+ break;
+ case Entity::ORIENTATION_WEST:
+ if (tile.BlocksWest()) {
+ return true;
+ } else {
+ nextPosition = Vector<int>(
+ controlled->Position().X() - map->Tileset()->Width(),
+ controlled->Position().Y());
+ }
+ break;
+ default:
+ return false;
+ }
+ Vector<int> nextTileCoords(map->TileCoordinates(nextPosition));
+ for (std::vector<Entity *>::const_iterator i(entities.begin()), end(entities.end()); i != end; ++i) {
+ const Entity &e(**i);
+ if (map->TileCoordinates(e.Position()) == nextTileCoords && e.Blocking()) {
+ return true;
+ }
+ }
+ return false;
+}
+