Skip to content

Commit

Permalink
Move available_directions in worldmap sector out into separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Nov 16, 2024
1 parent b0ca668 commit f629c37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/worldmap/worldmap_sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,19 @@ WorldMapSector::update(float dt_sec)
{
/* Check level action */
auto level_ = at_object<LevelTile>();
auto tux_pos = m_tux->get_tile_pos();
if (!level_) {
//Respawn if player on a tile with no level and nowhere to go.
int tile_data = tile_data_at(m_tux->get_tile_pos());
if (!( tile_data & ( Tile::WORLDMAP_NORTH | Tile::WORLDMAP_SOUTH | Tile::WORLDMAP_WEST | Tile::WORLDMAP_EAST ))){
log_warning << "Player at illegal position " << m_tux->get_tile_pos().x << ", " << m_tux->get_tile_pos().y << " respawning." << std::endl;
// Respawn if player on a tile with no level and nowhere to go.
if (!is_valid_path_at(tux_pos)) {
log_warning << "Player at illegal position " << tux_pos.x << ", " << tux_pos.y << " respawning." << std::endl;
move_to_spawnpoint(DEFAULT_SPAWNPOINT_NAME);
return;
}
log_warning << "No level to enter at: " << m_tux->get_tile_pos().x << ", " << m_tux->get_tile_pos().y << std::endl;
log_warning << "No level to enter at: " << tux_pos.x << ", " << tux_pos.y << std::endl;
return;
}

if (level_->get_tile_pos() == m_tux->get_tile_pos()) {
if (level_->get_tile_pos() == tux_pos) {
try {
Vector shrinkpos = Vector(level_->get_pos().x + 16 - m_camera->get_offset().x,
level_->get_pos().y + 8 - m_camera->get_offset().y);
Expand Down Expand Up @@ -437,6 +437,13 @@ WorldMapSector::tile_data_at(const Vector& p) const
return dirs;
}

bool
WorldMapSector::is_valid_path_at(const Vector& p) const
{
const auto tile_data = tile_data_at(p);
return tile_data & (Tile::WORLDMAP_NORTH | Tile::WORLDMAP_SOUTH |
Tile::WORLDMAP_WEST | Tile::WORLDMAP_EAST);
}

size_t
WorldMapSector::level_count() const
Expand Down
6 changes: 6 additions & 0 deletions src/worldmap/worldmap_sector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class WorldMapSector final : public Base::Sector
position */
int tile_data_at(const Vector& pos) const;

/**
* returns true if the specified position contains a valid path.
* @param pos Position to check
*/
bool is_valid_path_at(const Vector& pos) const;

size_t level_count() const;
size_t solved_level_count() const;

Expand Down

0 comments on commit f629c37

Please sign in to comment.