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

Method findAtTile

library/modules/Buildings.cpp:368–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366}
367
368df::building *Buildings::findAtTile(df::coord pos)
369{
370 auto occ = Maps::getTileOccupancy(pos);
371 if (!occ || !occ->bits.building)
372 return NULL;
373
374 // Try cache lookup in case it works:
375 auto cached = locationToBuilding.find(pos);
376 if (cached != locationToBuilding.end())
377 {
378 auto building = df::building::find(cached->second);
379
380 if (building && building->z == pos.z &&
381 building->isSettingOccupancy() &&
382 containsTile(building, pos))
383 {
384 return building;
385 }
386 }
387
388 // The authentic method, i.e. how the game generally does this:
389 auto &vec = df::building::get_vector();
390 for (size_t i = 0; i < vec.size(); i++)
391 {
392 auto bld = vec[i];
393
394 if (pos.z != bld->z ||
395 pos.x < bld->x1 || pos.x > bld->x2 ||
396 pos.y < bld->y1 || pos.y > bld->y2)
397 continue;
398
399 if (!bld->isSettingOccupancy())
400 continue;
401
402 if (bld->room.extents && bld->isExtentShaped())
403 {
404 auto etile = getExtentTile(bld->room, pos);
405 if (!etile || !*etile)
406 continue;
407 }
408
409 return bld;
410 }
411
412 return NULL;
413}
414
415static unordered_map<int32_t, df::coord> corner1;
416static unordered_map<int32_t, df::coord> corner2;

Callers

nothing calls this directly

Calls 6

getTileOccupancyFunction · 0.85
getExtentTileFunction · 0.85
findFunction · 0.50
findMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected