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
				
			
		
							
								
								
									
										22
									
								
								systems.hpp
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								systems.hpp
									
										
									
									
									
								
							|  | @ -3,6 +3,7 @@ | |||
| #include <SFML/Graphics/RenderTexture.hpp> | ||||
| #include "map.hpp" | ||||
| #include "spatialmap.hpp" | ||||
| #include "game_level.hpp" | ||||
| 
 | ||||
| namespace System { | ||||
|   using namespace components; | ||||
|  | @ -43,4 +44,25 @@ namespace System { | |||
| 
 | ||||
|   void set_position(DinkyECS::World& world, SpatialMap& collision, Entity entity, Position pos); | ||||
|   bool use_item(const std::string& slot_name); | ||||
| 
 | ||||
|   template <typename T> | ||||
|   void multi_path(GameDB::Level& level, Pathing& paths, Matrix& walls) { | ||||
|     // first, put everything of this type as a target
 | ||||
|     level.world->query<Position, T>( | ||||
|       [&](const auto ent, auto& position, auto&) { | ||||
|         if(ent != level.player) { | ||||
|           paths.set_target(position.location); | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     level.world->query<Collision>( | ||||
|       [&](const auto ent, auto& collision) { | ||||
|         if(collision.has && ent != level.player) { | ||||
|           auto& pos = level.world->get<Position>(ent); | ||||
|           walls[pos.location.y][pos.location.x] = WALL_VALUE; | ||||
|         } | ||||
|     }); | ||||
| 
 | ||||
|     paths.compute_paths(walls); | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -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
	
	 Zed A. Shaw
						Zed A. Shaw