Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fegundos will now explode when moving against diagonal gentryii chain… #89

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions DRODLib/DbRooms.cpp
Expand Up @@ -2826,8 +2826,8 @@ const
}

//*****************************************************************************
bool CDbRoom::DoesSquarePreventDiagonal(
//Does a 4-connected space prevent diagonal movement?
bool CDbRoom::DoesOrthoSquarePreventDiagonal(
//Does an ortho-square prevent diagonal movement between the two tiles?
//The current square and destination square are both checked for these.
//
//Params:
Expand All @@ -2852,10 +2852,26 @@ const
if (GetFSquare(x2, y2) == T_NODIAGONAL)
return true;

return DoesGentryiiPreventDiagonal(wX, wY, x2, y2);
return false;
}


//*****************************************************************************
bool CDbRoom::DoesSquarePreventDiagonal(
//Does anything on source/target square prevent moving in the specified diagonal?
//
//Params:
const UINT wX, const UINT wY, //(in) Square to check
const int dx, const int dy) //(in) Directional offset
//
//Returns:
//True if an ortho square or gentryii chain prevents diagonal movement
const
{
return DoesOrthoSquarePreventDiagonal(wX, wY, dx, dy)
|| DoesGentryiiPreventDiagonal(wX, wY, wX + dx, wY + dy);
}

//*****************************************************************************
bool CDbRoom::DoesSquareContainTeleportationObstacle(
// Checks if an entity of given type can teleport to this position.
Expand Down
2 changes: 2 additions & 0 deletions DRODLib/DbRooms.h
Expand Up @@ -243,6 +243,8 @@ class CDbRoom : public CDbBase
const UINT wO, bool& bMonsterObstacle) const;
bool DoesSquarePreventDiagonal(const UINT wX, const UINT wY,
const int dx, const int dy) const;
bool DoesOrthoSquarePreventDiagonal(const UINT wX, const UINT wY,
const int dx, const int dy) const;
bool DoesSquareContainTeleportationObstacle(const UINT wX, const UINT wY, const UINT wIdentity) const;
bool DoubleCanActivateToken(RoomTokenType type) const;

Expand Down
25 changes: 23 additions & 2 deletions DRODLib/Fegundo.cpp
Expand Up @@ -127,8 +127,7 @@ void CFegundo::Process(
SetOrientation(dxFirst, dyFirst);

//If can't move and something solid is in the way, explode.
if (!dx && !dy && !DoesArrowPreventMovement(this->wX, this->wY, dxFirst, dyFirst) &&
!this->pCurrentGame->pRoom->DoesSquarePreventDiagonal(this->wX, this->wY, dxFirst, dyFirst))
if (!dx && !dy && !DoesMovePreventExplosion(this->wX, this->wY, dxFirst, dyFirst))
{
CMonster *pMonster = this->pCurrentGame->pRoom->GetMonsterAtSquare(
this->wX + dxFirst, this->wY + dyFirst);
Expand Down Expand Up @@ -191,3 +190,25 @@ void CFegundo::Explode(CCueEvents &CueEvents)

room.ConvertUnstableTar(CueEvents);
}


//*****************************************************************************
bool CFegundo::DoesMovePreventExplosion(
// Checks if obstacles during a given move can prevent explosions from occuring
const UINT wX, const UINT wY, //(in) Coords of square from which to move. Must be valid.
const int dx, const int dy //(in) Directional coords to move
)
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line

// Arrows prevent explosion even if they are placed on top of an obstacle, even if they are
// behind gentryii chain diagonal
if (DoesArrowPreventMovement(wX, wY, dx, dy))
return true;

// Ditto for ortho squares, must NOT use DoesSquarePreventDiagonal, otherwise gentryii chain
// diagonals will also prevent explosion
if (this->pCurrentGame->pRoom->DoesOrthoSquarePreventDiagonal(wX, wY, dx, dy))
return true;

return false;
}
1 change: 1 addition & 0 deletions DRODLib/Fegundo.h
Expand Up @@ -46,6 +46,7 @@ class CFegundo : public CMonster
virtual bool CanFindSwordsman() const;
virtual bool DoesSquareContainObstacle(const UINT wCol, const UINT wRow) const;
virtual void Process(const int nLastCommand, CCueEvents &CueEvents);
bool DoesMovePreventExplosion(const UINT wX, const UINT wY, const int dx, const int dy);
virtual bool OnStabbed(CCueEvents &/*CueEvents*/,
const UINT /*wX*/=(UINT)-1, const UINT /*wY*/=(UINT)-1,
WeaponType /*weaponType*/=WT_Sword)
Expand Down
2 changes: 2 additions & 0 deletions DRODLibTests/DRODLibTest.2019.vcxproj
Expand Up @@ -258,6 +258,7 @@
<ClCompile Include="src\RoomBuilder.cpp" />
<ClCompile Include="src\Runner.cpp" />
<ClCompile Include="src\tests\Crashes\DisablingProcessedFiretrapCrash.cpp" />
<ClCompile Include="src\tests\Elements\Briars.cpp" />
<ClCompile Include="src\tests\Elements\Bridges.cpp" />
<ClCompile Include="src\tests\Monsters\ArmedMonsters\BeingKilledByMonsters.cpp" />
<ClCompile Include="src\tests\Monsters\ArmedMonsters\MovingIntoPuffs.cpp" />
Expand All @@ -268,6 +269,7 @@
<ClCompile Include="src\tests\Monsters\ArmedMonsters\StrikingWhenStunned.cpp" />
<ClCompile Include="src\tests\Monsters\Aumtlich\CrackedOrbs.cpp" />
<ClCompile Include="src\tests\Monsters\Aumtlich\GenericAumtlich.cpp" />
<ClCompile Include="src\tests\Monsters\Fegundo.cpp" />
<ClCompile Include="src\tests\Monsters\Puff\PuffPushingArrowsOrthosquares.cpp" />
<ClCompile Include="src\tests\Monsters\Puff\PuffTargetsVisibleClone.cpp" />
<ClCompile Include="src\tests\Monsters\Puff\PushFluffOntoTarstuffMother.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions DRODLibTests/DRODLibTest.2019.vcxproj.filters
Expand Up @@ -150,6 +150,12 @@
<ClCompile Include="src\tests\Scripting\Imperative_BrainPathmapObstacle.cpp">
<Filter>Tests\Scripting</Filter>
</ClCompile>
<ClCompile Include="src\tests\Elements\Briars.cpp">
<Filter>Tests\Elements</Filter>
</ClCompile>
<ClCompile Include="src\tests\Monsters\Fegundo.cpp">
<Filter>Tests\Monsters</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\catch.hpp" />
Expand Down
117 changes: 117 additions & 0 deletions DRODLibTests/src/tests/Monsters/Fegundo.cpp
@@ -0,0 +1,117 @@
#include "../../catch.hpp"
#include "../../CAssert.h"
#include "../../CTestDb.h"
#include "../../Runner.h"
#include "../../RoomBuilder.h"
#include "../../../../DRODLib/CurrentGame.h"
#include "../../../../DRODLib/Character.h"
#include "../../../../DRODLib/CharacterCommand.h"

void TestAlive() {
Runner::StartGame(1, 1, SE);
Runner::ExecuteCommand(CMD_WAIT);

AssertMonsterType(10, 10, M_FEGUNDO);
}

void TestExploded() {
Runner::StartGame(1, 1, SE);
Runner::ExecuteCommand(CMD_WAIT);

AssertMonsterType(10, 10, M_FEGUNDOASHES);
}

TEST_CASE("Fegundo", "[game]") {
RoomBuilder::ClearRoom();
RoomBuilder::PlotToken(RoomTokenType::PowerTarget, 1, 1);
RoomBuilder::AddMonster(M_FEGUNDO, 10, 10, SE);

SECTION("Fegundo flying into a wall should explode") {
RoomBuilder::Plot(T_WALL, 11, 11);

TestExploded();
}

SECTION("Fegundo flying into an opposite arrow should not explode") {
RoomBuilder::Plot(T_ARROW_NW, 11, 11);
TestAlive();
}

SECTION("Fegundo flying from an opposite arrow should not explode") {
RoomBuilder::Plot(T_ARROW_NW, 10, 10);
TestAlive();
}

SECTION("Fegundo flying diagonally onto ortho square should not explode") {
RoomBuilder::Plot(T_NODIAGONAL, 11, 11);
TestAlive();
}

SECTION("Fegundo flying diagonally from ortho square should not explode") {
RoomBuilder::Plot(T_NODIAGONAL, 10, 10);
TestAlive();
}

SECTION("Fegundo flying into gentryii chain...") {
// ....
// .F.. - Fegundo
// ##C. - Gentryii Chain
// #G.. - Gentryii surrounded by walls

CGentryii* gentryii = DYN_CAST(CGentryii*, CMonster*, RoomBuilder::AddMonster(M_GENTRYII, 10, 12, SW));
RoomBuilder::AddGentryiiPiece(gentryii, 11, 11);
RoomBuilder::PlotRect(T_WALL, 9, 11, 10, 12);

SECTION("Should explode if nothing else is there") {
TestExploded();
}
SECTION("Should not explode if moving into blocking force arrow") {
RoomBuilder::Plot(T_ARROW_NW, 11, 11);
TestAlive();
}
SECTION("Should not explode if moving against blocking force arrow") {
RoomBuilder::Plot(T_ARROW_NW, 10, 10);
TestAlive();
}
SECTION("Should not explode if moving into ortho square") {
RoomBuilder::Plot(T_NODIAGONAL, 11, 11);
TestAlive();
}
SECTION("Should not explode if moving against ortho square") {
RoomBuilder::Plot(T_NODIAGONAL, 10, 10);
TestAlive();
}
}

SECTION("Fegundo flying diagonally between gentryii chains...") {
// .....
// . FC. - Fegundo
// ##C.. - Gentryii Chain
// #G... - Gentryii surrounded by walls

CGentryii* gentryii = DYN_CAST(CGentryii*, CMonster*, RoomBuilder::AddMonster(M_GENTRYII, 9, 12, SW));
RoomBuilder::AddGentryiiPiece(gentryii, 10, 11);
RoomBuilder::AddGentryiiPiece(gentryii, 11, 10);
RoomBuilder::PlotRect(T_WALL, 8, 11, 9, 12);

SECTION("Should explode if nothing else is there") {
TestExploded();
}
SECTION("Should not explode if moving into blocking force arrow") {
RoomBuilder::Plot(T_ARROW_NW, 11, 11);
TestAlive();
}
SECTION("Should not explode if moving against blocking force arrow") {
RoomBuilder::Plot(T_ARROW_NW, 10, 10);
TestAlive();
}
SECTION("Should not explode if moving into ortho square") {
RoomBuilder::Plot(T_NODIAGONAL, 11, 11);
TestAlive();
}
SECTION("Should not explode if moving against ortho square") {
RoomBuilder::Plot(T_NODIAGONAL, 10, 10);
TestAlive();
}
}
}