* Flood fills dirt and wall tiles looking for * an area of at most 40 tiles and disconnected from the map edge. * If it finds one, converts it to lava tiles and sets lavapool to TRUE. */
| 771 | * If it finds one, converts it to lava tiles and sets lavapool to TRUE. |
| 772 | */ |
| 773 | static void DRLG_L3Pool() |
| 774 | { |
| 775 | int i, j, dunx, duny, totarea, poolchance; |
| 776 | BOOL found; |
| 777 | BYTE k; |
| 778 | static BYTE poolsub[15] = { 0, 35, 26, 36, 25, 29, 34, 7, 33, 28, 27, 37, 32, 31, 30 }; |
| 779 | |
| 780 | for (duny = 0; duny < DMAXY; duny++) { |
| 781 | for (dunx = 0; dunx < DMAXY; dunx++) { |
| 782 | if (dungeon[dunx][duny] != 8) { |
| 783 | continue; |
| 784 | } |
| 785 | dungeon[dunx][duny] |= 0x80; |
| 786 | totarea = 1; |
| 787 | if (dunx + 1 < DMAXX) { |
| 788 | found = DRLG_L3Spawn(dunx + 1, duny, &totarea); |
| 789 | } else { |
| 790 | found = TRUE; |
| 791 | } |
| 792 | if (dunx - 1 > 0 && !found) { |
| 793 | found = DRLG_L3Spawn(dunx - 1, duny, &totarea); |
| 794 | } else { |
| 795 | found = TRUE; |
| 796 | } |
| 797 | if (duny + 1 < DMAXY && !found) { |
| 798 | found = DRLG_L3Spawn(dunx, duny + 1, &totarea); |
| 799 | } else { |
| 800 | found = TRUE; |
| 801 | } |
| 802 | if (duny - 1 > 0 && !found) { |
| 803 | found = DRLG_L3Spawn(dunx, duny - 1, &totarea); |
| 804 | } else { |
| 805 | found = TRUE; |
| 806 | } |
| 807 | poolchance = random_(0, 100); |
| 808 | for (j = std::max(duny - totarea, 0); j < std::min(duny + totarea, DMAXY); j++) { |
| 809 | for (i = std::max(dunx - totarea, 0); i < std::min(dunx + totarea, DMAXX); i++) { |
| 810 | // BUGFIX: In the following swap the order to first do the |
| 811 | // index checks and only then access dungeon[i][j] (fixed) |
| 812 | if (dungeon[i][j] & 0x80) { |
| 813 | dungeon[i][j] &= ~0x80; |
| 814 | if (totarea > 4 && poolchance < 25 && !found) { |
| 815 | k = poolsub[dungeon[i][j]]; |
| 816 | if (k != 0 && k <= 37) { |
| 817 | dungeon[i][j] = k; |
| 818 | } |
| 819 | lavapool = TRUE; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | static void DRLG_L3PoolFix() |
| 829 | { |
no test coverage detected