Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/scenario/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(const cSpecial&)> 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<void(const cSpecial&)> callback) {
for(cSpecial special : scen_specials){
callback(special);
}
}

void cScenario::for_each_town_special(int town, std::function<void(const cSpecial&)> callback) {
for(cSpecial special : towns[town]->specials){
callback(special);
}
}

void cScenario::for_each_out_special(int sector_x, int sector_y, std::function<void(const cSpecial&)> callback) {
for(cSpecial special : outdoors[sector_x][sector_y]->specials){
callback(special);
}
}
6 changes: 6 additions & 0 deletions src/scenario/scenario.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(const cSpecial&)> callback);
// Factored into 3 separate functions in case there's ever a reason to be more selective:
void for_each_scen_special(std::function<void(const cSpecial&)> callback);
void for_each_town_special(int town, std::function<void(const cSpecial&)> callback);
void for_each_out_special(int sector_x, int sector_y, std::function<void(const cSpecial&)> callback);
public:
unsigned short difficulty,intro_pic,default_ground;
int bg_out, bg_fight, bg_town, bg_dungeon;
Expand Down
Loading