diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e91daeb0..f116edd9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -506,6 +506,7 @@ if(RUN_TESTS) test/lighting_test.cpp test/main.cpp test/missiles_test.cpp + test/monster_test.cpp test/pack_test.cpp test/player_test.cpp test/scrollrt_test.cpp diff --git a/Source/monster.cpp b/Source/monster.cpp index 78fbd4baf..969fcf7f3 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -4783,7 +4783,7 @@ bool LineClear(bool (*Clear)(int, Point), int entity, Point startPoint, Point en dincH = 2 * (dx + dy); yincD = -1; } - while (position != endPoint) { + while (!done && position != endPoint) { if ((d <= 0) ^ (yincD < 0)) { d += dincD; } else { diff --git a/test/monster_test.cpp b/test/monster_test.cpp new file mode 100644 index 000000000..39c523530 --- /dev/null +++ b/test/monster_test.cpp @@ -0,0 +1,26 @@ +#include + +#include "cursor.h" +#include "inv.h" +#include "player.h" + +using namespace devilution; + +bool TestGrid[5][5]; + +bool CheckNoSolid(int entity, Point position) +{ + SDL_Log("%ix%i", position.x, position.y); + + return true;//TestGrid[position.x][position.y]; +} + +TEST(Monster, LineClearSolid) +{ + SDL_Log("05"); + EXPECT_EQ(LineClear(CheckNoSolid, 0, { 0, 0 }, { 5, 1 }), true); + SDL_Log("50"); + EXPECT_EQ(LineClear(CheckNoSolid, 0, { 5, 1 }, { 0, 0 }), true); + SDL_Log("05,2"); + EXPECT_EQ(LineClear(CheckNoSolid, 0, { 0, 0 }, { 5, 2 }), true); +}