diff --git a/src/scenario/scenario.cpp b/src/scenario/scenario.cpp index f3f4eef17..c747426a7 100644 --- a/src/scenario/scenario.cpp +++ b/src/scenario/scenario.cpp @@ -609,4 +609,34 @@ std::string cScenario::get_sdf_name(int row, int col) { if(sdf_names[row].find(col) == sdf_names[row].end()) return ""; return sdf_names[row][col]; +} + +void cScenario::for_each_special(std::function callback) { + for_each_scen_special(callback); + for(int town = 0; town < towns.size(); ++town){ + for_each_town_special(town, callback); + } + for(int x = 0; x < outdoors.width(); ++x){ + for(int y = 0; y < outdoors.height(); ++y){ + for_each_out_special(x, y, callback); + } + } +} + +void cScenario::for_each_scen_special(std::function callback) { + for(cSpecial special : scen_specials){ + callback(special); + } +} + +void cScenario::for_each_town_special(int town, std::function callback) { + for(cSpecial special : towns[town]->specials){ + callback(special); + } +} + +void cScenario::for_each_out_special(int sector_x, int sector_y, std::function callback) { + for(cSpecial special : outdoors[sector_x][sector_y]->specials){ + callback(special); + } } \ No newline at end of file diff --git a/src/scenario/scenario.hpp b/src/scenario/scenario.hpp index 22d03bea3..3f512e383 100644 --- a/src/scenario/scenario.hpp +++ b/src/scenario/scenario.hpp @@ -58,6 +58,12 @@ class cScenario { cItemStorage& operator = (legacy::item_storage_shortcut_type& old); }; void destroy_terrain(); + // Iterate through EVERY special node with a callback. + void for_each_special(std::function callback); + // Factored into 3 separate functions in case there's ever a reason to be more selective: + void for_each_scen_special(std::function callback); + void for_each_town_special(int town, std::function callback); + void for_each_out_special(int sector_x, int sector_y, std::function callback); public: unsigned short difficulty,intro_pic,default_ground; int bg_out, bg_fight, bg_town, bg_dungeon;