@@ -20,43 +20,41 @@ void ChannelJobs::load_channel_jobs() {
2020 }
2121}
2222
23- bool ChannelJobs::has_cavein_conditions (const df::coord &map_pos) {
24- if likely (Maps::isValidTilePos (map_pos)) {
25- auto p = map_pos;
26- auto ttype = *Maps::getTileType (p);
27- if (!DFHack::isOpenTerrain (ttype)) {
28- // check shared neighbour for cave-in conditions
29- df::coord neighbours[4 ];
30- get_connected_neighbours (map_pos, neighbours);
31- int connectedness = 4 ;
32- for (auto n: neighbours) {
33- if (!Maps::isValidTilePos (n) || active.count (n) || DFHack::isOpenTerrain (*Maps::getTileType (n))) {
34- connectedness--;
35- }
23+ bool ChannelJobs::has_cavein_conditions (const df::coord &map_pos) const {
24+ auto p = map_pos;
25+ auto ttype = *Maps::getTileType (p);
26+ if (!DFHack::isOpenTerrain (ttype)) {
27+ // check shared neighbour for cave-in conditions
28+ df::coord neighbours[4 ];
29+ get_connected_neighbours (map_pos, neighbours);
30+ int connectedness = 4 ;
31+ for (auto n: neighbours) {
32+ if (!Maps::isValidTilePos (n) || active.count (n) || DFHack::isOpenTerrain (*Maps::getTileType (n))) {
33+ connectedness--;
3634 }
37- if (!connectedness) {
38- // do what?
39- p. z --;
40- if (! Maps::isValidTilePos (p)) return false ;
41- ttype = * Maps::getTileType (p);
42- if ( DFHack::isOpenTerrain ( ttype) || DFHack::isFloorTerrain (ttype)) {
43- return true ;
44- }
35+ }
36+ if (!connectedness) {
37+ // do what?
38+ p. z -- ;
39+ if (! Maps::isValidTilePos (p)) return false ;
40+ ttype = * Maps::getTileType (p);
41+ if ( DFHack::isOpenTerrain (ttype) || DFHack::isFloorTerrain (ttype)) {
42+ return true ;
4543 }
4644 }
4745 }
4846 return false ;
4947}
5048
51- bool ChannelJobs::possible_cavein (const df::coord &job_pos) {
52- for (auto iter : active) {
53- if (iter == job_pos) continue ;
54- if (calc_distance (job_pos, iter ) <= 2 ) {
49+ bool ChannelJobs::possible_cavein (const df::coord &job_pos) const {
50+ for (auto dig_pos : active) {
51+ if (dig_pos == job_pos) continue ;
52+ if (calc_distance (job_pos, dig_pos ) <= 2 ) {
5553 // find neighbours
5654 df::coord n1[8 ];
5755 df::coord n2[8 ];
5856 get_neighbours (job_pos, n1);
59- get_neighbours (iter , n2);
57+ get_neighbours (dig_pos , n2);
6058 // find shared neighbours
6159 for (int i = 0 ; i < 7 ; ++i) {
6260 for (int j = i + 1 ; j < 8 ; ++j) {
@@ -181,25 +179,7 @@ void ChannelGroups::scan(bool full_scan) {
181179 full_scan = sometimes_scanFULLY (RNG);
182180 }
183181
184- // save current jobs, then clear and load the current jobs
185- std::set<df::coord> last_jobs;
186- for (auto &pos : jobs) {
187- last_jobs.emplace (pos);
188- }
189- jobs.load_channel_jobs ();
190- // transpose channel jobs to
191- std::set<df::coord> new_jobs;
192- std::set<df::coord> gone_jobs;
193- set_difference (last_jobs, jobs, gone_jobs);
194- set_difference (jobs, last_jobs, new_jobs);
195- INFO (groups).print (" gone jobs: %zd\n new jobs: %zd\n " ,gone_jobs.size (), new_jobs.size ());
196- for (auto &pos : new_jobs) {
197- add (pos);
198- }
199- for (auto &pos : gone_jobs){
200- remove (pos);
201- }
202-
182+ scan_jobs ();
203183 DEBUG (groups).print (" scan()\n " );
204184 // foreach block
205185 for (int32_t z = mapz - 1 ; z >= 0 ; --z) {
@@ -263,6 +243,28 @@ void ChannelGroups::scan(bool full_scan) {
263243 INFO (groups).print (" scan() exits\n " );
264244}
265245
246+ // updates groupings of adjacent channel designations based on changes to the job list
247+ void ChannelGroups::scan_jobs () {
248+ // save current jobs, then clear and load the current jobs
249+ std::set<df::coord> last_jobs;
250+ for (auto &pos : jobs) {
251+ last_jobs.emplace (pos);
252+ }
253+ jobs.load_channel_jobs ();
254+ // transpose channel jobs to
255+ std::set<df::coord> new_jobs;
256+ std::set<df::coord> gone_jobs;
257+ set_difference (last_jobs, jobs, gone_jobs);
258+ set_difference (jobs, last_jobs, new_jobs);
259+ INFO (groups).print (" gone jobs: %zd\n new jobs: %zd\n " ,gone_jobs.size (), new_jobs.size ());
260+ for (auto &pos : new_jobs) {
261+ add (pos);
262+ }
263+ for (auto &pos : gone_jobs){
264+ remove (pos);
265+ }
266+ }
267+
266268// clears out the containers for unloading maps or disabling the plugin
267269void ChannelGroups::clear () {
268270 debug_map ();
0 commit comments