MCPcopy Create free account
hub / github.com/DFHack/dfhack / fix_tile

Function fix_tile

plugins/fix-occupancy.cpp:222–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222static void fix_tile(color_ostream &out, df::coord pos, bool dry_run) {
223 auto occ = Maps::getTileOccupancy(pos);
224 auto block = Maps::getTileBlock(pos);
225 if (!occ || !block) {
226 WARN(log,out).print("invalid tile: ({}, {}, {})\n", pos.x, pos.y, pos.z);
227 return;
228 }
229
230 Expected expected;
231
232 // building occupancy (scan all buildings since we can't depend on Buildings::findAtTile)
233 size_t num_buildings = 0;
234 for (auto bld : world->buildings.all) {
235 if (Buildings::containsTile(bld, pos)) {
236 ++num_buildings;
237 scan_building(out, bld, expected);
238 }
239 }
240
241 // unit occupancy (make sure we pick up wagons that might be overlapping the tile)
242 vector<df::unit *> units;
243 Units::getUnitsInBox(units, pos.x-1, pos.y-1, pos.z, pos.x+1, pos.y+1, pos.z);
244 size_t num_units = units.size();
245 for (auto unit : units)
246 scan_unit(unit, expected);
247
248 // check/fix order of map block item vector
249 normalize_item_vector(out, block, dry_run);
250
251 // scan for items at that position in the map block
252 // this won't catch issues with items that are members of an incorrect map block. use fix_map for that.
253 size_t num_items = 0;
254 for (auto item_id : block->items) {
255 if (auto item = df::item::find(item_id)) {
256 ++num_items;
257 scan_item(item, expected);
258 }
259 }
260
261 // check/fix occupancy
262 auto expected_occ = expected.occ(pos);
263 auto expected_bld = expected.bld(pos);
264 if (expected_bld && expected_occ)
265 reconcile_map_tile(out, *expected_bld, *expected_occ, block->occupancy[pos.x&15][pos.y&15], dry_run, pos.x, pos.y, pos.z);
266
267 INFO(log,out).print("verified {} building(s), {} unit(s), {} item(s), 1 map block(s), and 1 map tile(s)\n",
268 num_buildings, num_units, num_items);
269}
270
271static void reconcile_block_items(color_ostream &out, std::set<int32_t> * expected_items, df::map_block * block, bool dry_run) {
272 vector<int32_t> & block_items = block->items;

Callers

nothing calls this directly

Calls 13

getTileOccupancyFunction · 0.85
getTileBlockFunction · 0.85
scan_buildingFunction · 0.85
getUnitsInBoxFunction · 0.85
scan_unitFunction · 0.85
normalize_item_vectorFunction · 0.85
reconcile_map_tileFunction · 0.85
occMethod · 0.80
bldMethod · 0.80
scan_itemFunction · 0.70
findFunction · 0.50
printMethod · 0.45

Tested by

no test coverage detected