X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fai%2FSpawner.cpp;h=946e3519c3fb359d8d6bba766c36d42adb4440df;hb=b066e776622f96e906600a0c4a08de392bd03676;hp=2ea8a6904e2f80042b9e76656f2e66246348d385;hpb=e1209ec25c4cc91e13889876106f56bd51aa96e2;p=blank.git diff --git a/src/ai/Spawner.cpp b/src/ai/Spawner.cpp index 2ea8a69..946e351 100644 --- a/src/ai/Spawner.cpp +++ b/src/ai/Spawner.cpp @@ -72,7 +72,7 @@ void Spawner::CheckDespawn() noexcept { } bool safe = false; for (const Player &ref : refs) { - glm::vec3 diff(ref.entity->AbsoluteDifference(e)); + glm::vec3 diff(ref.GetEntity().AbsoluteDifference(e)); if (dot(diff, diff) < despawn_range) { safe = true; break; @@ -95,11 +95,15 @@ void Spawner::TrySpawn() { // select random player to punish auto &players = world.Players(); if (players.size() == 0) return; - const Player &player = players[random.Next() % players.size()]; + size_t player_num = random.Next() % players.size(); + auto i = players.begin(), end = players.end(); + for (; player_num > 0 && i != end; ++i, --player_num) { + } + const Player &player = *i; - int index = random.Next() % player.chunks->TotalChunks(); + int index = random.Next() % player.GetChunks().TotalChunks(); - glm::ivec3 chunk(player.chunks->PositionOf(index)); + glm::ivec3 chunk(player.GetChunks().PositionOf(index)); glm::ivec3 pos( random.Next() % Chunk::width, @@ -115,7 +119,7 @@ void Spawner::TrySpawn() { //} // check if the spawn block and the one above it are loaded and inhabitable - BlockLookup spawn_block((*player.chunks)[index], pos); + BlockLookup spawn_block(player.GetChunks()[index], pos); if (!spawn_block || spawn_block.GetType().collide_block) { return; } @@ -125,7 +129,7 @@ void Spawner::TrySpawn() { return; } - Spawn(*player.entity, chunk, glm::vec3(pos) + glm::vec3(0.5f)); + Spawn(player.GetEntity(), chunk, glm::vec3(pos) + glm::vec3(0.5f)); } void Spawner::Spawn(Entity &reference, const glm::ivec3 &chunk, const glm::vec3 &pos) {