| 366 | } |
| 367 | |
| 368 | df::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 | |
| 415 | static unordered_map<int32_t, df::coord> corner1; |
| 416 | static unordered_map<int32_t, df::coord> corner2; |
nothing calls this directly
no test coverage detected