Now added a System::multi_path which can target to multiple entities.
This commit is contained in:
parent
fc678c6b42
commit
4365aa4bfc
2 changed files with 25 additions and 21 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <chrono>
|
||||
#include <thread>
|
||||
#include "rand.hpp"
|
||||
#include "systems.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using namespace nlohmann;
|
||||
|
@ -23,32 +24,13 @@ json load_test_pathing(const string &fname) {
|
|||
|
||||
TEST_CASE("multiple targets can path", "[pathing]") {
|
||||
GameDB::init();
|
||||
|
||||
auto level = GameDB::create_level();
|
||||
auto& walls_original = level.map->$walls;
|
||||
auto walls_copy = walls_original;
|
||||
|
||||
auto walls_copy = level.map->$walls;
|
||||
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)};
|
||||
|
||||
// first, put everything of this type as a target
|
||||
level.world->query<Position, Combat>(
|
||||
[&](const auto ent, auto& position, auto&) {
|
||||
if(ent != level.player) {
|
||||
paths.set_target(position.location);
|
||||
}
|
||||
});
|
||||
System::multi_path<Combat>(level, paths, walls_copy);
|
||||
|
||||
level.world->query<Collision>(
|
||||
[&](const auto ent, auto& collision) {
|
||||
if(collision.has && ent != level.player) {
|
||||
auto& pos = level.world->get<Position>(ent);
|
||||
walls_copy[pos.location.y][pos.location.x] = WALL_VALUE;
|
||||
}
|
||||
});
|
||||
|
||||
paths.compute_paths(walls_copy);
|
||||
bool diag = Random::uniform<int>(0, 1);
|
||||
|
||||
auto pos = GameDB::player_position().location;
|
||||
auto found = paths.find_path(pos, PATHING_TOWARD, diag);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue