summaryrefslogtreecommitdiff
path: root/src/world.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-11-07 12:06:19 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-11-07 12:06:19 +0100
commit7471347839f30a85e985891b945a721967fcfb86 (patch)
tree762a37e4792672b0af7a0878b41b828508c91e2a /src/world.cpp
parentf951af3cfdef3d23fd5875078a29c15ebf9120e9 (diff)
Avoid walking into walls.
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp53
1 files changed, 53 insertions, 0 deletions
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<entity_t*> 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<coord_t, 2> 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);