* mark a region of the map as "dangerous" for a turn. * @param pos is the epicenter of the explosion. * @param radius how far to spread out. * @param unit the unit that is triggering this action. */
| 2870 | * @param unit the unit that is triggering this action. |
| 2871 | */ |
| 2872 | void TileEngine::setDangerZone(Position pos, int radius, BattleUnit *unit) |
| 2873 | { |
| 2874 | Tile *tile = _save->getTile(pos); |
| 2875 | if (!tile) |
| 2876 | { |
| 2877 | return; |
| 2878 | } |
| 2879 | // set the epicenter as dangerous |
| 2880 | tile->setDangerous(); |
| 2881 | Position originVoxel = (pos * Position(16,16,24)) + Position(8,8,12 + -tile->getTerrainLevel()); |
| 2882 | Position targetVoxel; |
| 2883 | for (int x = -radius; x != radius; ++x) |
| 2884 | { |
| 2885 | for (int y = -radius; y != radius; ++y) |
| 2886 | { |
| 2887 | // we can skip the epicenter |
| 2888 | if (x != 0 || y != 0) |
| 2889 | { |
| 2890 | // make sure we're within the radius |
| 2891 | if ((x*x)+(y*y) <= (radius*radius)) |
| 2892 | { |
| 2893 | tile = _save->getTile(pos + Position(x,y,0)); |
| 2894 | if (tile) |
| 2895 | { |
| 2896 | targetVoxel = ((pos + Position(x,y,0)) * Position(16,16,24)) + Position(8,8,12 + -tile->getTerrainLevel()); |
| 2897 | std::vector<Position> trajectory; |
| 2898 | // we'll trace a line here, ignoring all units, to check if the explosion will reach this point |
| 2899 | // granted this won't properly account for explosions tearing through walls, but then we can't really |
| 2900 | // know that kind of information before the fact, so let's have the AI assume that the wall (or tree) |
| 2901 | // is enough to protect them. |
| 2902 | if (calculateLine(originVoxel, targetVoxel, false, &trajectory, unit, true, false, unit) == V_EMPTY) |
| 2903 | { |
| 2904 | if (trajectory.size() && (trajectory.back() / Position(16,16,24)) == pos + Position(x,y,0)) |
| 2905 | { |
| 2906 | tile->setDangerous(); |
| 2907 | } |
| 2908 | } |
| 2909 | } |
| 2910 | } |
| 2911 | } |
| 2912 | } |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | } |
no test coverage detected