Browse Source

Refactor CrawlTable (#4833)

pull/4836/head
Vladimir Olteanu 4 years ago committed by GitHub
parent
commit
5a5111f1d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      Source/debug.cpp
  2. 15
      Source/engine/displacement.hpp
  3. 406
      Source/lighting.cpp
  4. 4
      Source/lighting.h
  5. 22
      Source/missiles.cpp
  6. 9
      test/lighting_test.cpp

14
Source/debug.cpp

@ -722,10 +722,9 @@ std::string DebugCmdSpawnUniqueMonster(const string_view parameter)
int spawnedMonster = 0;
for (int k : CrawlNum) {
int ck = k + 2;
for (auto j = static_cast<uint8_t>(CrawlTable[k]); j > 0; j--, ck += 2) {
Point pos = myPlayer.position.tile + Displacement { CrawlTable[ck - 1], CrawlTable[ck] };
for (const auto &table : CrawlTable) {
for (auto displacement : table) {
Point pos = myPlayer.position.tile + displacement;
if (dPlayer[pos.x][pos.y] != 0 || dMonster[pos.x][pos.y] != 0)
continue;
if (!IsTileWalkable(pos))
@ -808,10 +807,9 @@ std::string DebugCmdSpawnMonster(const string_view parameter)
int spawnedMonster = 0;
for (int k : CrawlNum) {
int ck = k + 2;
for (auto j = static_cast<uint8_t>(CrawlTable[k]); j > 0; j--, ck += 2) {
Point pos = myPlayer.position.tile + Displacement { CrawlTable[ck - 1], CrawlTable[ck] };
for (const auto &table : CrawlTable) {
for (auto displacement : table) {
Point pos = myPlayer.position.tile + displacement;
if (dPlayer[pos.x][pos.y] != 0 || dMonster[pos.x][pos.y] != 0)
continue;
if (!IsTileWalkable(pos))

15
Source/engine/displacement.hpp

@ -237,6 +237,21 @@ struct Displacement {
return Displacement { deltaX * cosine - deltaY * sine, deltaX * sine + deltaY * cosine };
}
constexpr Displacement flipX()
{
return { -deltaX, deltaY };
}
constexpr Displacement flipY()
{
return { deltaX, -deltaY };
}
constexpr Displacement flipXY()
{
return { -deltaX, -deltaY };
}
#ifdef BUILD_TESTING
/**
* @brief Format displacements nicely in test failure messages

406
Source/lighting.cpp

@ -24,6 +24,40 @@ std::array<uint8_t, LIGHTSIZE> LightTables;
bool DisableLighting;
bool UpdateLighting;
namespace {
std::vector<Displacement> CrawlFlips(const std::vector<Displacement> displacements)
{
std::vector<Displacement> ret;
for (auto displacement : displacements) {
if (displacement.deltaX != 0)
ret.push_back(displacement.flipX());
ret.push_back(displacement);
if (displacement.deltaX != 0 && displacement.deltaY != 0)
ret.push_back(displacement.flipXY());
if (displacement.deltaY != 0)
ret.push_back(displacement.flipY());
}
return ret;
}
std::vector<Displacement> CrawlRow(int row)
{
if (row == 0)
return { { 0, 0 } };
std::vector<Displacement> ret;
for (int i = 0; i < row; i++)
ret.push_back({ i, row });
if (row > 1)
ret.push_back({ row - 1, row - 1 });
for (int i = 0; i < row; i++)
ret.push_back({ row, i });
return CrawlFlips(ret);
}
} // namespace
/**
* CrawlTable specifies X- and Y-coordinate deltas from a missile target coordinate.
*
@ -47,373 +81,13 @@ bool UpdateLighting;
* | 526
* +-------> x
*/
const int8_t CrawlTable[2749] = {
// clang-format off
1, // Table 0, offset 0
0, 0,
4, // Table 1, offset 3
0, 1, 0, -1, -1, 0, 1, 0,
16, // Table 2, offset 12
0, 2, 0, -2, -1, 2, 1, 2,
-1, -2, 1, -2, -1, 1, 1, 1,
-1, -1, 1, -1, -2, 1, 2, 1,
-2, -1, 2, -1, -2, 0, 2, 0,
24, // Table 3, offset 45
0, 3, 0, -3, -1, 3, 1, 3,
-1, -3, 1, -3, -2, 3, 2, 3,
-2, -3, 2, -3, -2, 2, 2, 2,
-2, -2, 2, -2, -3, 2, 3, 2,
-3, -2, 3, -2, -3, 1, 3, 1,
-3, -1, 3, -1, -3, 0, 3, 0,
32, // Table 4, offset 94
0, 4, 0, -4, -1, 4, 1, 4,
-1, -4, 1, -4, -2, 4, 2, 4,
-2, -4, 2, -4, -3, 4, 3, 4,
-3, -4, 3, -4, -3, 3, 3, 3,
-3, -3, 3, -3, -4, 3, 4, 3,
-4, -3, 4, -3, -4, 2, 4, 2,
-4, -2, 4, -2, -4, 1, 4, 1,
-4, -1, 4, -1, -4, 0, 4, 0,
40, // Table 5, offset 159
0, 5, 0, -5, -1, 5, 1, 5,
-1, -5, 1, -5, -2, 5, 2, 5,
-2, -5, 2, -5, -3, 5, 3, 5,
-3, -5, 3, -5, -4, 5, 4, 5,
-4, -5, 4, -5, -4, 4, 4, 4,
-4, -4, 4, -4, -5, 4, 5, 4,
-5, -4, 5, -4, -5, 3, 5, 3,
-5, -3, 5, -3, -5, 2, 5, 2,
-5, -2, 5, -2, -5, 1, 5, 1,
-5, -1, 5, -1, -5, 0, 5, 0,
48, // Table 6, offset 240
0, 6, 0, -6, -1, 6, 1, 6,
-1, -6, 1, -6, -2, 6, 2, 6,
-2, -6, 2, -6, -3, 6, 3, 6,
-3, -6, 3, -6, -4, 6, 4, 6,
-4, -6, 4, -6, -5, 6, 5, 6,
-5, -6, 5, -6, -5, 5, 5, 5,
-5, -5, 5, -5, -6, 5, 6, 5,
-6, -5, 6, -5, -6, 4, 6, 4,
-6, -4, 6, -4, -6, 3, 6, 3,
-6, -3, 6, -3, -6, 2, 6, 2,
-6, -2, 6, -2, -6, 1, 6, 1,
-6, -1, 6, -1, -6, 0, 6, 0,
56, // Table 7, offset 337
0, 7, 0, -7, -1, 7, 1, 7,
-1, -7, 1, -7, -2, 7, 2, 7,
-2, -7, 2, -7, -3, 7, 3, 7,
-3, -7, 3, -7, -4, 7, 4, 7,
-4, -7, 4, -7, -5, 7, 5, 7,
-5, -7, 5, -7, -6, 7, 6, 7,
-6, -7, 6, -7, -6, 6, 6, 6,
-6, -6, 6, -6, -7, 6, 7, 6,
-7, -6, 7, -6, -7, 5, 7, 5,
-7, -5, 7, -5, -7, 4, 7, 4,
-7, -4, 7, -4, -7, 3, 7, 3,
-7, -3, 7, -3, -7, 2, 7, 2,
-7, -2, 7, -2, -7, 1, 7, 1,
-7, -1, 7, -1, -7, 0, 7, 0,
64, // Table 8, offset 450
0, 8, 0, -8, -1, 8, 1, 8,
-1, -8, 1, -8, -2, 8, 2, 8,
-2, -8, 2, -8, -3, 8, 3, 8,
-3, -8, 3, -8, -4, 8, 4, 8,
-4, -8, 4, -8, -5, 8, 5, 8,
-5, -8, 5, -8, -6, 8, 6, 8,
-6, -8, 6, -8, -7, 8, 7, 8,
-7, -8, 7, -8, -7, 7, 7, 7,
-7, -7, 7, -7, -8, 7, 8, 7,
-8, -7, 8, -7, -8, 6, 8, 6,
-8, -6, 8, -6, -8, 5, 8, 5,
-8, -5, 8, -5, -8, 4, 8, 4,
-8, -4, 8, -4, -8, 3, 8, 3,
-8, -3, 8, -3, -8, 2, 8, 2,
-8, -2, 8, -2, -8, 1, 8, 1,
-8, -1, 8, -1, -8, 0, 8, 0,
72, // Table 9, offset 579
0, 9, 0, -9, -1, 9, 1, 9,
-1, -9, 1, -9, -2, 9, 2, 9,
-2, -9, 2, -9, -3, 9, 3, 9,
-3, -9, 3, -9, -4, 9, 4, 9,
-4, -9, 4, -9, -5, 9, 5, 9,
-5, -9, 5, -9, -6, 9, 6, 9,
-6, -9, 6, -9, -7, 9, 7, 9,
-7, -9, 7, -9, -8, 9, 8, 9,
-8, -9, 8, -9, -8, 8, 8, 8,
-8, -8, 8, -8, -9, 8, 9, 8,
-9, -8, 9, -8, -9, 7, 9, 7,
-9, -7, 9, -7, -9, 6, 9, 6,
-9, -6, 9, -6, -9, 5, 9, 5,
-9, -5, 9, -5, -9, 4, 9, 4,
-9, -4, 9, -4, -9, 3, 9, 3,
-9, -3, 9, -3, -9, 2, 9, 2,
-9, -2, 9, -2, -9, 1, 9, 1,
-9, -1, 9, -1, -9, 0, 9, 0,
80, // Table 10, offset 724
0, 10, 0, -10, -1, 10, 1, 10,
-1, -10, 1, -10, -2, 10, 2, 10,
-2, -10, 2, -10, -3, 10, 3, 10,
-3, -10, 3, -10, -4, 10, 4, 10,
-4, -10, 4, -10, -5, 10, 5, 10,
-5, -10, 5, -10, -6, 10, 6, 10,
-6, -10, 6, -10, -7, 10, 7, 10,
-7, -10, 7, -10, -8, 10, 8, 10,
-8, -10, 8, -10, -9, 10, 9, 10,
-9, -10, 9, -10, -9, 9, 9, 9,
-9, -9, 9, -9, -10, 9, 10, 9,
-10, -9, 10, -9, -10, 8, 10, 8,
-10, -8, 10, -8, -10, 7, 10, 7,
-10, -7, 10, -7, -10, 6, 10, 6,
-10, -6, 10, -6, -10, 5, 10, 5,
-10, -5, 10, -5, -10, 4, 10, 4,
-10, -4, 10, -4, -10, 3, 10, 3,
-10, -3, 10, -3, -10, 2, 10, 2,
-10, -2, 10, -2, -10, 1, 10, 1,
-10, -1, 10, -1, -10, 0, 10, 0,
88, // Table 11, offset 885
0, 11, 0, -11, -1, 11, 1, 11,
-1, -11, 1, -11, -2, 11, 2, 11,
-2, -11, 2, -11, -3, 11, 3, 11,
-3, -11, 3, -11, -4, 11, 4, 11,
-4, -11, 4, -11, -5, 11, 5, 11,
-5, -11, 5, -11, -6, 11, 6, 11,
-6, -11, 6, -11, -7, 11, 7, 11,
-7, -11, 7, -11, -8, 11, 8, 11,
-8, -11, 8, -11, -9, 11, 9, 11,
-9, -11, 9, -11, -10, 11, 10, 11,
-10, -11, 10, -11, -10, 10, 10, 10,
-10, -10, 10, -10, -11, 10, 11, 10,
-11, -10, 11, -10, -11, 9, 11, 9,
-11, -9, 11, -9, -11, 8, 11, 8,
-11, -8, 11, -8, -11, 7, 11, 7,
-11, -7, 11, -7, -11, 6, 11, 6,
-11, -6, 11, -6, -11, 5, 11, 5,
-11, -5, 11, -5, -11, 4, 11, 4,
-11, -4, 11, -4, -11, 3, 11, 3,
-11, -3, 11, -3, -11, 2, 11, 2,
-11, -2, 11, -2, -11, 1, 11, 1,
-11, -1, 11, -1, -11, 0, 11, 0,
96, // Table 12, offset 1062
0, 12, 0, -12, -1, 12, 1, 12,
-1, -12, 1, -12, -2, 12, 2, 12,
-2, -12, 2, -12, -3, 12, 3, 12,
-3, -12, 3, -12, -4, 12, 4, 12,
-4, -12, 4, -12, -5, 12, 5, 12,
-5, -12, 5, -12, -6, 12, 6, 12,
-6, -12, 6, -12, -7, 12, 7, 12,
-7, -12, 7, -12, -8, 12, 8, 12,
-8, -12, 8, -12, -9, 12, 9, 12,
-9, -12, 9, -12, -10, 12, 10, 12,
-10, -12, 10, -12, -11, 12, 11, 12,
-11, -12, 11, -12, -11, 11, 11, 11,
-11, -11, 11, -11, -12, 11, 12, 11,
-12, -11, 12, -11, -12, 10, 12, 10,
-12, -10, 12, -10, -12, 9, 12, 9,
-12, -9, 12, -9, -12, 8, 12, 8,
-12, -8, 12, -8, -12, 7, 12, 7,
-12, -7, 12, -7, -12, 6, 12, 6,
-12, -6, 12, -6, -12, 5, 12, 5,
-12, -5, 12, -5, -12, 4, 12, 4,
-12, -4, 12, -4, -12, 3, 12, 3,
-12, -3, 12, -3, -12, 2, 12, 2,
-12, -2, 12, -2, -12, 1, 12, 1,
-12, -1, 12, -1, -12, 0, 12, 0,
104, // Table 13, offset 1255
0, 13, 0, -13, -1, 13, 1, 13,
-1, -13, 1, -13, -2, 13, 2, 13,
-2, -13, 2, -13, -3, 13, 3, 13,
-3, -13, 3, -13, -4, 13, 4, 13,
-4, -13, 4, -13, -5, 13, 5, 13,
-5, -13, 5, -13, -6, 13, 6, 13,
-6, -13, 6, -13, -7, 13, 7, 13,
-7, -13, 7, -13, -8, 13, 8, 13,
-8, -13, 8, -13, -9, 13, 9, 13,
-9, -13, 9, -13, -10, 13, 10, 13,
-10, -13, 10, -13, -11, 13, 11, 13,
-11, -13, 11, -13, -12, 13, 12, 13,
-12, -13, 12, -13, -12, 12, 12, 12,
-12, -12, 12, -12, -13, 12, 13, 12,
-13, -12, 13, -12, -13, 11, 13, 11,
-13, -11, 13, -11, -13, 10, 13, 10,
-13, -10, 13, -10, -13, 9, 13, 9,
-13, -9, 13, -9, -13, 8, 13, 8,
-13, -8, 13, -8, -13, 7, 13, 7,
-13, -7, 13, -7, -13, 6, 13, 6,
-13, -6, 13, -6, -13, 5, 13, 5,
-13, -5, 13, -5, -13, 4, 13, 4,
-13, -4, 13, -4, -13, 3, 13, 3,
-13, -3, 13, -3, -13, 2, 13, 2,
-13, -2, 13, -2, -13, 1, 13, 1,
-13, -1, 13, -1, -13, 0, 13, 0,
112, // Table 14, offset 1464
0, 14, 0, -14, -1, 14, 1, 14,
-1, -14, 1, -14, -2, 14, 2, 14,
-2, -14, 2, -14, -3, 14, 3, 14,
-3, -14, 3, -14, -4, 14, 4, 14,
-4, -14, 4, -14, -5, 14, 5, 14,
-5, -14, 5, -14, -6, 14, 6, 14,
-6, -14, 6, -14, -7, 14, 7, 14,
-7, -14, 7, -14, -8, 14, 8, 14,
-8, -14, 8, -14, -9, 14, 9, 14,
-9, -14, 9, -14, -10, 14, 10, 14,
-10, -14, 10, -14, -11, 14, 11, 14,
-11, -14, 11, -14, -12, 14, 12, 14,
-12, -14, 12, -14, -13, 14, 13, 14,
-13, -14, 13, -14, -13, 13, 13, 13,
-13, -13, 13, -13, -14, 13, 14, 13,
-14, -13, 14, -13, -14, 12, 14, 12,
-14, -12, 14, -12, -14, 11, 14, 11,
-14, -11, 14, -11, -14, 10, 14, 10,
-14, -10, 14, -10, -14, 9, 14, 9,
-14, -9, 14, -9, -14, 8, 14, 8,
-14, -8, 14, -8, -14, 7, 14, 7,
-14, -7, 14, -7, -14, 6, 14, 6,
-14, -6, 14, -6, -14, 5, 14, 5,
-14, -5, 14, -5, -14, 4, 14, 4,
-14, -4, 14, -4, -14, 3, 14, 3,
-14, -3, 14, -3, -14, 2, 14, 2,
-14, -2, 14, -2, -14, 1, 14, 1,
-14, -1, 14, -1, -14, 0, 14, 0,
120, // Table 15, offset 1689
0, 15, 0, -15, -1, 15, 1, 15,
-1, -15, 1, -15, -2, 15, 2, 15,
-2, -15, 2, -15, -3, 15, 3, 15,
-3, -15, 3, -15, -4, 15, 4, 15,
-4, -15, 4, -15, -5, 15, 5, 15,
-5, -15, 5, -15, -6, 15, 6, 15,
-6, -15, 6, -15, -7, 15, 7, 15,
-7, -15, 7, -15, -8, 15, 8, 15,
-8, -15, 8, -15, -9, 15, 9, 15,
-9, -15, 9, -15, -10, 15, 10, 15,
-10, -15, 10, -15, -11, 15, 11, 15,
-11, -15, 11, -15, -12, 15, 12, 15,
-12, -15, 12, -15, -13, 15, 13, 15,
-13, -15, 13, -15, -14, 15, 14, 15,
-14, -15, 14, -15, -14, 14, 14, 14,
-14, -14, 14, -14, -15, 14, 15, 14,
-15, -14, 15, -14, -15, 13, 15, 13,
-15, -13, 15, -13, -15, 12, 15, 12,
-15, -12, 15, -12, -15, 11, 15, 11,
-15, -11, 15, -11, -15, 10, 15, 10,
-15, -10, 15, -10, -15, 9, 15, 9,
-15, -9, 15, -9, -15, 8, 15, 8,
-15, -8, 15, -8, -15, 7, 15, 7,
-15, -7, 15, -7, -15, 6, 15, 6,
-15, -6, 15, -6, -15, 5, 15, 5,
-15, -5, 15, -5, -15, 4, 15, 4,
-15, -4, 15, -4, -15, 3, 15, 3,
-15, -3, 15, -3, -15, 2, 15, 2,
-15, -2, 15, -2, -15, 1, 15, 1,
-15, -1, 15, -1, -15, 0, 15, 0,
(char)128, // Table 16, offset 1930
0, 16, 0, -16, -1, 16, 1, 16,
-1, -16, 1, -16, -2, 16, 2, 16,
-2, -16, 2, -16, -3, 16, 3, 16,
-3, -16, 3, -16, -4, 16, 4, 16,
-4, -16, 4, -16, -5, 16, 5, 16,
-5, -16, 5, -16, -6, 16, 6, 16,
-6, -16, 6, -16, -7, 16, 7, 16,
-7, -16, 7, -16, -8, 16, 8, 16,
-8, -16, 8, -16, -9, 16, 9, 16,
-9, -16, 9, -16, -10, 16, 10, 16,
-10, -16, 10, -16, -11, 16, 11, 16,
-11, -16, 11, -16, -12, 16, 12, 16,
-12, -16, 12, -16, -13, 16, 13, 16,
-13, -16, 13, -16, -14, 16, 14, 16,
-14, -16, 14, -16, -15, 16, 15, 16,
-15, -16, 15, -16, -15, 15, 15, 15,
-15, -15, 15, -15, -16, 15, 16, 15,
-16, -15, 16, -15, -16, 14, 16, 14,
-16, -14, 16, -14, -16, 13, 16, 13,
-16, -13, 16, -13, -16, 12, 16, 12,
-16, -12, 16, -12, -16, 11, 16, 11,
-16, -11, 16, -11, -16, 10, 16, 10,
-16, -10, 16, -10, -16, 9, 16, 9,
-16, -9, 16, -9, -16, 8, 16, 8,
-16, -8, 16, -8, -16, 7, 16, 7,
-16, -7, 16, -7, -16, 6, 16, 6,
-16, -6, 16, -6, -16, 5, 16, 5,
-16, -5, 16, -5, -16, 4, 16, 4,
-16, -4, 16, -4, -16, 3, 16, 3,
-16, -3, 16, -3, -16, 2, 16, 2,
-16, -2, 16, -2, -16, 1, 16, 1,
-16, -1, 16, -1, -16, 0, 16, 0,
(char)136, // Table 16, offset 2187
0, 17, 0, -17, -1, 17, 1, 17,
-1, -17, 1, -17, -2, 17, 2, 17,
-2, -17, 2, -17, -3, 17, 3, 17,
-3, -17, 3, -17, -4, 17, 4, 17,
-4, -17, 4, -17, -5, 17, 5, 17,
-5, -17, 5, -17, -6, 17, 6, 17,
-6, -17, 6, -17, -7, 17, 7, 17,
-7, -17, 7, -17, -8, 17, 8, 17,
-8, -17, 8, -17, -9, 17, 9, 17,
-9, -17, 9, -17, -10, 17, 10, 17,
-10, -17, 10, -17, -11, 17, 11, 17,
-11, -17, 11, -17, -12, 17, 12, 17,
-12, -17, 12, -17, -13, 17, 13, 17,
-13, -17, 13, -17, -14, 17, 14, 17,
-14, -17, 14, -17, -15, 17, 15, 17,
-15, -17, 15, -17, -16, 17, 16, 17,
-16, -17, 16, -17, -16, 16, 16, 16,
-16, -16, 16, -16, -17, 16, 17, 16,
-17, -16, 17, -16, -17, 15, 17, 15,
-17, -15, 17, -15, -17, 14, 17, 14,
-17, -14, 17, -14, -17, 13, 17, 13,
-17, -13, 17, -13, -17, 12, 17, 12,
-17, -12, 17, -12, -17, 11, 17, 11,
-17, -11, 17, -11, -17, 10, 17, 10,
-17, -10, 17, -10, -17, 9, 17, 9,
-17, -9, 17, -9, -17, 8, 17, 8,
-17, -8, 17, -8, -17, 7, 17, 7,
-17, -7, 17, -7, -17, 6, 17, 6,
-17, -6, 17, -6, -17, 5, 17, 5,
-17, -5, 17, -5, -17, 4, 17, 4,
-17, -4, 17, -4, -17, 3, 17, 3,
-17, -3, 17, -3, -17, 2, 17, 2,
-17, -2, 17, -2, -17, 1, 17, 1,
-17, -1, 17, -1, -17, 0, 17, 0,
(char)144, // Table 16, offset 2460
0, 18, 0, -18, -1, 18, 1, 18,
-1, -18, 1, -18, -2, 18, 2, 18,
-2, -18, 2, -18, -3, 18, 3, 18,
-3, -18, 3, -18, -4, 18, 4, 18,
-4, -18, 4, -18, -5, 18, 5, 18,
-5, -18, 5, -18, -6, 18, 6, 18,
-6, -18, 6, -18, -7, 18, 7, 18,
-7, -18, 7, -18, -8, 18, 8, 18,
-8, -18, 8, -18, -9, 18, 9, 18,
-9, -18, 9, -18, -10, 18, 10, 18,
-10, -18, 10, -18, -11, 18, 11, 18,
-11, -18, 11, -18, -12, 18, 12, 18,
-12, -18, 12, -18, -13, 18, 13, 18,
-13, -18, 13, -18, -14, 18, 14, 18,
-14, -18, 14, -18, -15, 18, 15, 18,
-15, -18, 15, -18, -16, 18, 16, 18,
-16, -18, 16, -18, -17, 18, 17, 18,
-17, -18, 17, -18, -17, 17, 17, 17,
-17, -17, 17, -17, -18, 17, 18, 17,
-18, -17, 18, -17, -18, 16, 18, 16,
-18, -16, 18, -16, -18, 15, 18, 15,
-18, -15, 18, -15, -18, 14, 18, 14,
-18, -14, 18, -14, -18, 13, 18, 13,
-18, -13, 18, -13, -18, 12, 18, 12,
-18, -12, 18, -12, -18, 11, 18, 11,
-18, -11, 18, -11, -18, 10, 18, 10,
-18, -10, 18, -10, -18, 9, 18, 9,
-18, -9, 18, -9, -18, 8, 18, 8,
-18, -8, 18, -8, -18, 7, 18, 7,
-18, -7, 18, -7, -18, 6, 18, 6,
-18, -6, 18, -6, -18, 5, 18, 5,
-18, -5, 18, -5, -18, 4, 18, 4,
-18, -4, 18, -4, -18, 3, 18, 3,
-18, -3, 18, -3, -18, 2, 18, 2,
-18, -2, 18, -2, -18, 1, 18, 1,
-18, -1, 18, -1, -18, 0, 18, 0,
// clang-format on
};
const int CrawlNum[19] = { 0, 3, 12, 45, 94, 159, 240, 337, 450, 579, 724, 885, 1062, 1255, 1464, 1689, 1930, 2187, 2460 };
const std::vector<std::vector<Displacement>> CrawlTable = [] {
std::vector<std::vector<Displacement>> ret;
for (int i = 0; i < 19; i++)
ret.push_back(CrawlRow(i));
return ret;
}();
/*
* X- Y-coordinate offsets of lighting visions.

4
Source/lighting.h

@ -6,6 +6,7 @@
#pragma once
#include <array>
#include <vector>
#include "automap.h"
#include "engine.h"
@ -75,8 +76,7 @@ void lighting_color_cycling();
/* rdata */
extern DVL_API_FOR_TEST const int8_t CrawlTable[2749];
extern DVL_API_FOR_TEST const int CrawlNum[19];
extern DVL_API_FOR_TEST const std::vector<std::vector<Displacement>> CrawlTable;
extern const uint8_t VisionCrawlTable[23][30];
} // namespace devilution

22
Source/missiles.cpp

@ -1224,10 +1224,8 @@ void AddJester(Missile &missile, const AddMissileParameter &parameter)
void AddStealPotions(Missile &missile, const AddMissileParameter & /*parameter*/)
{
for (int i = 0; i < 3; i++) {
int k = CrawlNum[i];
int ck = k + 2;
for (auto j = static_cast<uint8_t>(CrawlTable[k]); j > 0; j--, ck += 2) {
Point target = missile.position.start + Displacement { CrawlTable[ck - 1], CrawlTable[ck] };
for (auto displacement : CrawlTable[i]) {
Point target = missile.position.start + displacement;
if (!InDungeonBounds(target))
continue;
int8_t pnum = dPlayer[target.x][target.y];
@ -2993,10 +2991,8 @@ void MI_FireRing(Missile &missile)
uint8_t lvl = missile._micaster == TARGET_MONSTERS ? Players[src]._pLevel : currlevel;
int dmg = 16 * (GenerateRndSum(10, 2) + lvl + 2) / 2;
int k = CrawlNum[3];
int ck = k + 2;
for (auto j = static_cast<uint8_t>(CrawlTable[k]); j > 0; j--, ck += 2) {
Point target { missile.var1 + CrawlTable[ck - 1], missile.var2 + CrawlTable[ck] };
for (auto displacement : CrawlTable[3]) {
Point target = Point { missile.var1, missile.var2 } + displacement;
if (!InDungeonBounds(target))
continue;
int dp = dPiece[target.x][target.y];
@ -3340,14 +3336,10 @@ void MI_Chain(Missile &missile)
Point dst { missile.var1, missile.var2 };
Direction dir = GetDirection(position, dst);
AddMissile(position, dst, dir, MIS_LIGHTCTRL, TARGET_MONSTERS, id, 1, missile._mispllvl);
int rad = missile._mispllvl + 3;
if (rad > 19)
rad = 19;
int rad = std::min(missile._mispllvl + 3, (int)CrawlTable.size() - 1);
for (int i = 1; i < rad; i++) {
int k = CrawlNum[i];
int ck = k + 2;
for (auto j = static_cast<uint8_t>(CrawlTable[k]); j > 0; j--, ck += 2) {
Point target = position + Displacement { CrawlTable[ck - 1], CrawlTable[ck] };
for (auto displacement : CrawlTable[i]) {
Point target = position + displacement;
if (InDungeonBounds(target) && dMonster[target.x][target.y] > 0) {
dir = GetDirection(position, target);
AddMissile(position, target, dir, MIS_LIGHTCTRL, TARGET_MONSTERS, id, 1, missile._mispllvl);

9
test/lighting_test.cpp

@ -10,13 +10,12 @@ TEST(Lighting, CrawlTables)
bool added[40][40];
memset(added, 0, sizeof(added));
for (int j = 0; j < 19; j++) {
for (size_t j = 0; j < CrawlTable.size(); j++) {
int x = 20;
int y = 20;
int cr = CrawlNum[j] + 1;
for (unsigned i = (uint8_t)CrawlTable[cr - 1]; i > 0; i--, cr += 2) {
int dx = x + CrawlTable[cr];
int dy = y + CrawlTable[cr + 1];
for (unsigned i = 0; i < CrawlTable[j].size(); i++) {
int dx = x + CrawlTable[j][i].deltaX;
int dy = y + CrawlTable[j][i].deltaY;
EXPECT_EQ(added[dx][dy], false) << "location " << i << ":" << j << " added twice";
added[dx][dy] = true;
}

Loading…
Cancel
Save