| 175 | } |
| 176 | |
| 177 | SmallList<pair<EntityId, HitType>, 4> DamageManager::queryHit(DamageSource const& source, EntityId causingId) const { |
| 178 | SmallList<pair<EntityId, HitType>, 4> resultList; |
| 179 | auto doQueryHit = [&source, &resultList, causingId, this](EntityPtr const& targetEntity) { |
| 180 | if (targetEntity->entityId() == causingId) |
| 181 | return; |
| 182 | |
| 183 | if (!source.team.canDamage(targetEntity->getTeam(), targetEntity->entityId() == source.sourceEntityId)) |
| 184 | return; |
| 185 | |
| 186 | if (source.rayCheck) { |
| 187 | if (auto poly = source.damageArea.ptr<PolyF>()) { |
| 188 | if (auto sourceEntity = m_world->entity(source.sourceEntityId)) { |
| 189 | auto overlap = m_world->geometry().rectOverlap(targetEntity->metaBoundBox().translated(targetEntity->position()), poly->boundBox()); |
| 190 | if (!overlap.isEmpty() && m_world->lineTileCollision(overlap.center(), sourceEntity->position())) |
| 191 | return; |
| 192 | } |
| 193 | } else if (auto line = source.damageArea.ptr<Line2F>()) { |
| 194 | if (auto hitPoly = targetEntity->hitPoly()) { |
| 195 | if (auto intersection = m_world->geometry().lineIntersectsPolyAt(*line, *hitPoly)) { |
| 196 | if (m_world->lineTileCollision(line->min(), *intersection)) |
| 197 | return; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (auto hitResult = targetEntity->queryHit(source)) |
| 204 | resultList.append({targetEntity->entityId(), *hitResult}); |
| 205 | |
| 206 | return; |
| 207 | }; |
| 208 | |
| 209 | if (auto poly = source.damageArea.ptr<PolyF>()) |
| 210 | m_world->forEachEntity(poly->boundBox(), doQueryHit); |
| 211 | else if (auto line = source.damageArea.ptr<Line2F>()) |
| 212 | m_world->forEachEntityLine(line->min(), line->max(), doQueryHit); |
| 213 | |
| 214 | return resultList; |
| 215 | } |
| 216 | |
| 217 | bool DamageManager::isAuthoritative(EntityPtr const& causingEntity, EntityPtr const& targetEntity) { |
| 218 | // Damage manager is authoritative if either one of the entities is |
nothing calls this directly
no test coverage detected