| 162 | } |
| 163 | |
| 164 | bool ChannelManager::manage_one(const df::coord &map_pos, bool set_marker_mode, bool marker_mode) const { |
| 165 | if (Maps::isValidTilePos(map_pos)) { |
| 166 | TRACE(manager).print("manage_one(({}), {}, {})\n", map_pos, set_marker_mode, marker_mode); |
| 167 | df::map_block* block = Maps::getTileBlock(map_pos); |
| 168 | // we calculate the position inside the block* |
| 169 | df::coord local(map_pos); |
| 170 | local.x = local.x % 16; |
| 171 | local.y = local.y % 16; |
| 172 | df::tile_occupancy &tile_occupancy = block->occupancy[Coord(local)]; |
| 173 | // ensure that we aren't on the top-most layers |
| 174 | if (map_pos.z < mapz - 3) { |
| 175 | // do we already know whether to set marker mode? |
| 176 | if (!marker_mode) { |
| 177 | // marker_mode is set to true if it is unsafe to dig |
| 178 | marker_mode = (!set_marker_mode && |
| 179 | (has_group_above(groups, map_pos) || !is_safe_to_dig_down(map_pos))) || |
| 180 | (set_marker_mode && |
| 181 | is_channel_designation(block->designation[Coord(local)]) && !is_safe_to_dig_down(map_pos)); |
| 182 | } |
| 183 | if (marker_mode) { |
| 184 | if (jobs.count(map_pos)) { |
| 185 | cancel_job(map_pos); |
| 186 | } |
| 187 | } else if (!block->flags.bits.designated) { |
| 188 | block->flags.bits.designated = true; |
| 189 | } |
| 190 | tile_occupancy.bits.dig_marked = marker_mode; |
| 191 | TRACE(manager).print("marker mode {}\n", marker_mode ? "ENABLED" : "DISABLED"); |
| 192 | } else { |
| 193 | // if we are though, it should be totally safe to dig |
| 194 | tile_occupancy.bits.dig_marked = false; |
| 195 | } |
| 196 | TRACE(manager).print(" <- manage_one() exits normally\n"); |
| 197 | return true; |
| 198 | } |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | void ChannelManager::mark_done(const df::coord &map_pos) { |
| 203 | groups.remove(map_pos); |
no test coverage detected