| 21 | { |
| 22 | |
| 23 | Collision TileMap::findCollision(Vec3<float> lineSegmentStart, Vec3<float> lineSegmentEnd, |
| 24 | const std::set<TileObject::Type> validTypes, |
| 25 | sp<TileObject> ignoredObject, bool useLOS, bool check_full_path, |
| 26 | unsigned maxRange, bool recordPassedTiles, |
| 27 | StateRef<Organisation> ignoreOwnedProjectiles) const |
| 28 | { |
| 29 | bool typeChecking = validTypes.size() > 0; |
| 30 | bool rangeChecking = maxRange > 0.0f; |
| 31 | const Tile *lastT = nullptr; |
| 32 | // We apply a median value accumulated in all tiles passed every time we pass a tile |
| 33 | // This makes it so that we do not over or under-apply smoke when going diagonally |
| 34 | float blockageAccumulatedSoFar = 0.0f; |
| 35 | int distanceToLastTile = 0; |
| 36 | float accumulatedSinceLastTile = 0; |
| 37 | int numberTilesWithBlockage = 0; |
| 38 | // Init collision parameters |
| 39 | Collision c; |
| 40 | c.obj = nullptr; |
| 41 | Vec3<int> tileSize = voxelMapSize; |
| 42 | Vec3<float> tileSizef = voxelMapSize; |
| 43 | Vec3<int> lineSegmentStartVoxel = lineSegmentStart * tileSizef; |
| 44 | Vec3<int> lineSegmentEndVoxel = lineSegmentEnd * tileSizef; |
| 45 | LineSegment<int, true> line{lineSegmentStartVoxel, lineSegmentEndVoxel}; |
| 46 | |
| 47 | // "point" is the coordinate measured in voxel scale units, meaning, |
| 48 | // voxel point coordinate within map |
| 49 | for (auto &point : line) |
| 50 | { |
| 51 | auto tile = point / tileSize; |
| 52 | // We need to check if `point` is negative instead of `tile` because negative values |
| 53 | // will round towards zero |
| 54 | if (point.x < 0 || tile.x >= size.x || point.y < 0 || tile.y >= size.y || point.z < 0 || |
| 55 | tile.z >= size.z) |
| 56 | { |
| 57 | if (check_full_path) |
| 58 | { |
| 59 | continue; |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | return c; |
| 64 | } |
| 65 | } |
| 66 | const Tile *t = this->getTile(tile); |
| 67 | if (rangeChecking) |
| 68 | { |
| 69 | if (!lastT) |
| 70 | { |
| 71 | lastT = t; |
| 72 | if (recordPassedTiles) |
| 73 | { |
| 74 | c.passedTiles.push_back(tile); |
| 75 | } |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | if (t != lastT) |
| 80 | { |