- if (worldmap->at(tile_pos)->getData() & Tile::WORLDMAP_STOP ||
- (special_tile && !special_tile->passive_message) ||
- worldmap->at_level())
- {
- if(special_tile && !special_tile->map_message.empty() &&
- !special_tile->passive_message)
- worldmap->passive_message_timer.start(0);
- stop();
- }
- else
- {
- const Tile* tile = worldmap->at(tile_pos);
- if (direction != input_direction)
- {
- // Turn to a new direction
- const Tile* tile = worldmap->at(tile_pos);
-
- if((tile->getData() & Tile::WORLDMAP_NORTH
- && input_direction == D_NORTH) ||
- (tile->getData() & Tile::WORLDMAP_SOUTH
- && input_direction == D_SOUTH) ||
- (tile->getData() & Tile::WORLDMAP_EAST
- && input_direction == D_EAST) ||
- (tile->getData() & Tile::WORLDMAP_WEST
- && input_direction == D_WEST))
- { // player has changed direction during auto-movement
- direction = input_direction;
- back_direction = reverse_dir(direction);
- }
- else
- { // player has changed to impossible tile
- back_direction = reverse_dir(direction);
- stop();
- }
- }
- else
- {
- Direction dir = D_NONE;
-
- if (tile->getData() & Tile::WORLDMAP_NORTH
- && back_direction != D_NORTH)
- dir = D_NORTH;
- else if (tile->getData() & Tile::WORLDMAP_SOUTH
- && back_direction != D_SOUTH)
- dir = D_SOUTH;
- else if (tile->getData() & Tile::WORLDMAP_EAST
- && back_direction != D_EAST)
- dir = D_EAST;
- else if (tile->getData() & Tile::WORLDMAP_WEST
- && back_direction != D_WEST)
- dir = D_WEST;
-
- if (dir != D_NONE)
- {
- direction = dir;
- input_direction = direction;
- back_direction = reverse_dir(direction);
- }
- else
- {
- // Should never be reached if tiledata is good
- stop();
- return;
- }
- }
-
- // Walk automatically to the next tile
- if(direction != D_NONE)
- {
- Vector next_tile;
- if (worldmap->path_ok(direction, tile_pos, &next_tile))
- {
- tile_pos = next_tile;
- }
- else
- {
- puts("Tilemap data is buggy");
- stop();
- }
- }
- }
- }