| 289 | } |
| 290 | |
| 291 | InteractiveEntityPtr EntityMap::interactiveEntityNear(Vec2F const& pos, float maxRadius) const { |
| 292 | auto rect = RectF::withCenter(pos, Vec2F::filled(maxRadius)); |
| 293 | InteractiveEntityPtr interactiveEntity; |
| 294 | double bestDistance = maxRadius + 100; |
| 295 | double bestCenterDistance = maxRadius + 100; |
| 296 | m_spatialMap.forEach(m_geometry.splitRect(rect), [&](EntityPtr const& entity) { |
| 297 | if (auto ie = as<InteractiveEntity>(entity)) { |
| 298 | if (ie->isInteractive()) { |
| 299 | if (auto tileEntity = as<TileEntity>(entity)) { |
| 300 | for (Vec2I space : tileEntity->interactiveSpaces()) { |
| 301 | auto dist = m_geometry.diff(pos, centerOfTile(space + tileEntity->tilePosition())).magnitude(); |
| 302 | auto centerDist = m_geometry.diff(tileEntity->metaBoundBox().center() + tileEntity->position(), pos).magnitude(); |
| 303 | if ((dist < bestDistance) || ((dist == bestDistance) && (centerDist < bestCenterDistance))) { |
| 304 | interactiveEntity = ie; |
| 305 | bestDistance = dist; |
| 306 | bestCenterDistance = centerDist; |
| 307 | } |
| 308 | } |
| 309 | } else { |
| 310 | auto box = ie->interactiveBoundBox().translated(entity->position()); |
| 311 | auto dist = m_geometry.diffToNearestCoordInBox(box, pos).magnitude(); |
| 312 | auto centerDist = m_geometry.diff(box.center(), pos).magnitude(); |
| 313 | if ((dist < bestDistance) || ((dist == bestDistance) && (centerDist < bestCenterDistance))) { |
| 314 | interactiveEntity = ie; |
| 315 | bestDistance = dist; |
| 316 | bestCenterDistance = centerDist; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | }); |
| 322 | if (bestDistance <= maxRadius) |
| 323 | return interactiveEntity; |
| 324 | return {}; |
| 325 | } |
| 326 | |
| 327 | bool EntityMap::tileIsOccupied(Vec2I const& pos, bool includeEphemeral) const { |
| 328 | RectF rect(Vec2F(pos[0], pos[1]), Vec2F(pos[0] + 1, pos[1] + 1)); |
no test coverage detected