summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-17 23:13:04 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-17 23:13:04 +0200
commit7d43c4e7ad6b83a23516b26b4aebf74f398c251b (patch)
treea6bd3b9f8e52c33615291ec4dc19f5ee9c9bb789
parentf66cf28c8b4d80122896c87dba8af74ea1872eba (diff)
Fix a bug in entity linking.
-rw-r--r--src/common.hpp2
-rw-r--r--src/game.cpp2
-rw-r--r--src/world.cpp11
3 files changed, 11 insertions, 4 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 75dd17d..6798ec8 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -1,5 +1,5 @@
#include <iostream>
-#include <cstdint>
+#include <cinttypes>
#include <cmath>
#include <cassert>
#include <map>
diff --git a/src/game.cpp b/src/game.cpp
index 2af7736..59b8ad9 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -56,7 +56,7 @@ void state_t::tick(void)
}
if (human.stalin < -4.0f)
- human.stalin = 2.0f;
+ human.stalin = (float)rand() / RAND_MAX * 3.0f;
}
}
diff --git a/src/world.cpp b/src/world.cpp
index 06369f6..c18a7ab 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -192,7 +192,7 @@ void entity_t::link(world_t *world)
for (int64_t y = 0; y < (int64_t)ysecs; y++)
for (int64_t x = 0; x < (int64_t)xsecs; x++) {
- sector_index_t index = sector_index_at(v2f_t(base[0] + x, base[1] + y));
+ sector_index_t index = base + sector_index_t(x, y);
sector_t *sector;
sector = world->get_sector(index);
@@ -202,8 +202,15 @@ void entity_t::link(world_t *world)
void entity_t::unlink(void)
{
- for (sector_t *sector : parents)
+ for (sector_t *sector : parents) {
+ if (sector->ents.find(this) == sector->ents.end()) {
+ printf("entity_t::unlink: %p should belong to %p (%" PRIi64", %" PRIi64") but it doesn't\n",
+ this, sector, sector->index[0], sector->index[1]);
+ continue;
+ }
+
sector->ents.erase(sector->ents.find(this));
+ }
parents.clear();
parent_world = nullptr;