From 7471347839f30a85e985891b945a721967fcfb86 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 7 Nov 2017 12:06:19 +0100 Subject: Avoid walking into walls. --- src/world.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index 778e463..2339dbf 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -230,6 +230,59 @@ std::list world_t::get_render_entities(rectf_t rect) return list; } +bool world_t::test_rect(const cmodel_t *cmodel, const entity_t *ignore) +{ + static size_t cookie = 0; + + cookie++; + + for (sector_t *sector : get_sectors(cmodel->bounds)) { + rect_t bounds; + tile_index_t index; + + bounds[0] = (cmodel->bounds[0] - sector->bounds[0]).floor(); + bounds[1] = (cmodel->bounds[1] - sector->bounds[0]).floor(); + + if (bounds[0][0] < 0) + bounds[0][0] = 0; + if (bounds[0][1] < 0) + bounds[0][1] = 0; + if (bounds[1][0] >= (coord_t)SECTOR_SIZE) + bounds[1][0] = SECTOR_SIZE - 1; + if (bounds[1][1] >= (coord_t)SECTOR_SIZE) + bounds[1][1] = SECTOR_SIZE - 1; + + for (index[1] = bounds[0][1]; index[1] <= bounds[1][1]; index[1]++) + for (index[0] = bounds[0][0]; index[0] <= bounds[1][0]; index[0]++) { + tile_t *tile; + + tile = sector->tiles + index[1] * SECTOR_SIZE + index[0]; + if (tile->type != TILE_DIRT) + return true; + } + + for (entity_t *ent : sector->ents) { + if (ent == ignore) + continue; + + if (ent->cookie == cookie) + continue; + + ent->cookie = cookie; + + if (!(ent->cmodel.cflags & cmodel->cflags)) + continue; + + if (!(cmodel->bounds && ent->cmodel.bounds)) + continue; + + return true; + } + } + + return false; +} + void world_t::debug_point(sf::Vector2f point) { sector_index_t index = sector_index_at(point); -- cgit