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

Added a new method to copy data from CCueEvents while losing all atta… #200

Merged
merged 1 commit into from
Oct 18, 2020
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
27 changes: 27 additions & 0 deletions DRODLib/CueEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ const CUEEVENT_ID CIDA_MonsterStabbed[3] = {
//Public methods.
//

//***************************************************************************************
void CCueEvents::SetMembers(const CCueEvents& Src)
//Sets members to value of other CCueEvents, but all data becomes unattached
{
this->Clear();

//Copy all data

this->wEventCount = Src.wEventCount;
this->wNextPrivateDataIndex = Src.wNextPrivateDataIndex;
this->wNextCID = Src.wNextCID;

for (UINT wCID=CUEEVENT_COUNT; wCID--; )
{
this->barrIsCIDSet[wCID] = Src.barrIsCIDSet[wCID];

vector<CID_PRIVDATA_NODE>::const_iterator pSeek = Src.CIDPrivateData[wCID].begin();
while (pSeek != Src.CIDPrivateData[wCID].end())
{
ASSERT(pSeek->pvPrivateData);

this->CIDPrivateData[wCID].push_back(CID_PRIVDATA_NODE(false, pSeek->pvPrivateData));
++pSeek;
}
}
}

//***************************************************************************************
void CCueEvents::Clear()
//Frees resources and resets members.
Expand Down
2 changes: 2 additions & 0 deletions DRODLib/CueEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ class CCueEvents
CCueEvents() {Zero();}
virtual ~CCueEvents() {Clear();}

void SetMembers(const CCueEvents& Src);

void Add(const CUEEVENT_ID eCID, const CAttachableObject *pvPrivateData = NULL, const bool bIsAttached=false);
void Clear();
void ClearEvent(const CUEEVENT_ID eCID, const bool bDeleteAttached=true);
Expand Down
8 changes: 6 additions & 2 deletions DRODLib/Monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,15 +2148,19 @@ void CMonster::Move(
switch (pMonster->wType)
{
case M_CHARACTER:
{
const bool bCanStrike = bIsStalwart(pMonster->GetIdentity()) ||
this->CanDaggerStep(pMonster->GetIdentity(), false);
ASSERT(bIsSmitemaster(pMonster->GetIdentity()) ||
pMonster->GetIdentity() == M_BEETHRO_IN_DISGUISE ||
bIsStalwart(pMonster->GetIdentity()));
if (bIsStalwart(pMonster->GetIdentity()))
bCanStrike);
if (bCanStrike)
{
pCueEvents->Add(CID_MonsterDiedFromStab, pMonster);
room.KillMonster(pMonster, *pCueEvents, false, this); //will return false if it's a critical NPC
pMonster->SetKillInfo(GetOrientation(this->wX, this->wY, wDestX, wDestY));
}
}
break;
case M_STALWART: case M_STALWART2:
pCueEvents->Add(CID_MonsterDiedFromStab, pMonster);
Expand Down
18 changes: 17 additions & 1 deletion DRODLibTests/src/CAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ const char* MakeLogMessage(const char* file, int line) {
return message.str().c_str();
}

void Assert::Event(const char* file, int line, const CUEEVENT_ID eEventType) {
INFO(MakeLogMessage(file, line));

CCueEvents& CueEvents = Runner::GetLastCueEvents();

REQUIRE(CueEvents.HasOccurred(eEventType));
}

void Assert::NoEvent(const char* file, int line, const CUEEVENT_ID eEventType) {
INFO(MakeLogMessage(file, line));

CCueEvents& CueEvents = Runner::GetLastCueEvents();

REQUIRE(!CueEvents.HasOccurred(eEventType));
}

void Assert::PlayerAt(const char* file, int line, const UINT wExpectedX, const UINT wExpectedY) {
INFO(MakeLogMessage(file, line));

Expand Down Expand Up @@ -119,6 +135,6 @@ bool Assert::HasTile(const UINT wExpectedX, const UINT wExpectedY, const UINT wE

default:
FAIL("Unknown tile layer");
break;
return false;
}
}
4 changes: 4 additions & 0 deletions DRODLibTests/src/CAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Assert{
friend class RoomBuilder;

public:
static void Event(const char* file, int line, const CUEEVENT_ID eEventType);
static void NoEvent(const char* file, int line, const CUEEVENT_ID eEventType);
static void PlayerAt(const char* file, int line, const UINT wExpectedX, const UINT wExpectedY);
static void PlayerIsAlive(const char* file, int line);
static void PlayerIsDead(const char* file, int line);
Expand All @@ -34,6 +36,8 @@ private :
static bool HasTile(const UINT wExpectedX, const UINT wExpectedY, const UINT wExpectedType);
};

#define AssertEvent(eEventType) Assert::Event(__FILE__, __LINE__, eEventType);
#define AssertNoEvent(eEventType) Assert::NoEvent(__FILE__, __LINE__, eEventType);
#define AssertPlayerAt(wExpectedX, wExpectedY) Assert::PlayerAt(__FILE__, __LINE__, wExpectedX, wExpectedY);
#define AssertPlayerIsAlive() Assert::PlayerIsAlive(__FILE__, __LINE__);
#define AssertPlayerIsDead() Assert::PlayerIsDead(__FILE__, __LINE__);
Expand Down
4 changes: 3 additions & 1 deletion DRODLibTests/src/RoomBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void RoomBuilder::ClearRoom(){
}

CCharacter* RoomBuilder::AddCharacter(const UINT wX, const UINT wY, const UINT wO, const UINT identity){
CMonster *pMonster = GetRoom()->AddNewMonster(M_CHARACTER, wX, wY);
CMonster *pMonster = GetRoom()->AddNewMonster(M_CHARACTER, wX, wY, false);
pMonster->wO = wO;

CCharacter *pCharacter = DYN_CAST(CCharacter*, CMonster*, pMonster);
Expand All @@ -23,6 +23,8 @@ CCharacter* RoomBuilder::AddVisibleCharacter(const UINT wX, const UINT wY, const
CCharacter *pCharacter = RoomBuilder::AddCharacter(wX, wY, wO, identity);
pCharacter->bVisible = true;

GetRoom()->SetMonsterSquare(pCharacter);

return pCharacter;
}

Expand Down
9 changes: 9 additions & 0 deletions DRODLibTests/src/Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "catch.hpp"

CCurrentGame* Runner::currentGame = NULL;
CCueEvents Runner::lastCueEvents;
UINT Runner::wLastErrorLogSize;
char* Runner::pErrorLogPath;

Expand All @@ -32,21 +33,29 @@ CCurrentGame* Runner::GetCurrentGame() {
return Runner::currentGame;
}

CCueEvents& Runner::GetLastCueEvents() {
return Runner::lastCueEvents;
}

void Runner::ExecuteCommand(const UINT command, const UINT repeats){
CCueEvents CueEvents;

for (UINT i = 0; i < repeats; ++i){
CueEvents.Clear();
Runner::currentGame->ProcessCommand(command, CueEvents);
}
Runner::lastCueEvents.SetMembers(CueEvents);
}

void Runner::ExecuteCommand(const UINT command, CCueEvents &CueEvents){
Runner::currentGame->ProcessCommand(command, CueEvents);
Runner::lastCueEvents.SetMembers(CueEvents);
}

void Runner::PlaceDouble(const UINT wX, const UINT wY, CCueEvents& CueEvents) {
REQUIRE(Runner::currentGame->swordsman.wPlacingDoubleType);
Runner::currentGame->ProcessCommand(CMD_DOUBLE, CueEvents, wX, wY);
Runner::lastCueEvents.SetMembers(CueEvents);
}

void Runner::ClickClone(const UINT wX, const UINT wY) {
Expand Down
2 changes: 2 additions & 0 deletions DRODLibTests/src/Runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class Runner{

static void InitializeDatPath();
static CCurrentGame* GetCurrentGame();
static CCueEvents& GetLastCueEvents();

private:
static char *pErrorLogPath;
static UINT GetErrorLogSize();
static CCurrentGame* currentGame;
static CCueEvents lastCueEvents;
static CDbRoom* GetRoom();
static UINT wLastErrorLogSize;
};
Expand Down
39 changes: 38 additions & 1 deletion DRODLibTests/src/tests/Monsters/ArmedMonsters/RearmedGuards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST_CASE("Guards wielding different weapons", "[game][guard][weapon]") {
REQUIRE(CueEvents.HasOccurred(CID_MonsterKilledPlayer));
}

SECTION("Guard with a dagger will body-kill"){
SECTION("Guard with a dagger will body-kill player"){
RoomBuilder::AddMonsterWithWeapon(M_GUARD, WT_Dagger, 10, 10, W);

CCueEvents CueEvents;
Expand Down Expand Up @@ -55,6 +55,43 @@ TEST_CASE("Guards wielding different weapons", "[game][guard][weapon]") {
REQUIRE(monster->wType == M_GUARD);
}

SECTION("Guard with a dagger will kill-step vulnerable characters") {
RoomBuilder::AddMonsterWithWeapon(M_GUARD, WT_Dagger, 10, 10, N);
RoomBuilder::AddVisibleCharacter(11, 10, S, M_BRAIN);

CCurrentGame* game = Runner::StartGame(13, 10, S);
Runner::ExecuteCommand(CMD_WAIT);

AssertEvent(CID_MonsterDiedFromStab);
AssertMonsterType(11, 10, M_GUARD);
}

SECTION("Guard with a dagger will walk around invulnerable characters") {
RoomBuilder::AddMonsterWithWeapon(M_GUARD, WT_Dagger, 10, 10, N);
CCharacter* pCharacter = RoomBuilder::AddVisibleCharacter(11, 10, S, M_BRAIN);
RoomBuilder::AddCommand(pCharacter, CCharacterCommand::CC_Imperative, ScriptFlag::Invulnerable);

CCurrentGame* game = Runner::StartGame(13, 10, S);
Runner::ExecuteCommand(CMD_WAIT);

AssertNoEvent(CID_MonsterDiedFromStab);
AssertMonsterType(11, 10, M_CHARACTER);
AssertMonsterType(11, 9, M_GUARD);
}

SECTION("Guard with a dagger will walk around pushable-by-weapon characters") {
RoomBuilder::AddMonsterWithWeapon(M_GUARD, WT_Dagger, 10, 10, N);
CCharacter* pCharacter = RoomBuilder::AddVisibleCharacter(11, 10, S, M_BRAIN);
RoomBuilder::AddCommand(pCharacter, CCharacterCommand::CC_Imperative, ScriptFlag::PushableByWeapon);

CCurrentGame* game = Runner::StartGame(13, 10, S);
Runner::ExecuteCommand(CMD_WAIT);

AssertNoEvent(CID_MonsterDiedFromStab);
AssertMonsterType(11, 10, M_CHARACTER);
AssertMonsterType(11, 9, M_GUARD);
}

SECTION("Guard with a dagger won't kill-step other guards") {
RoomBuilder::AddMonsterWithWeapon(M_GUARD, WT_Dagger, 10, 10, N);
RoomBuilder::AddMonsterWithWeapon(M_GUARD, WT_Sword, 11, 10, S);
Expand Down
2 changes: 1 addition & 1 deletion DRODLibTests/src/tests/Scripting/SetPlayerWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace {
void AddScript_IfSetWeapon(const WeaponType eType) {
CCharacter* pScript = RoomBuilder::AddCharacter(1, 1);
CCharacter* pScript = RoomBuilder::AddCharacter(2, 2);
RoomBuilder::AddCommand(pScript, CCharacterCommand::CC_WaitForPlayerInput, CMD_EXEC_COMMAND);
RoomBuilder::AddCommand(pScript, CCharacterCommand::CC_If);
RoomBuilder::AddCommand(pScript, CCharacterCommand::CC_SetPlayerWeapon, eType);
Expand Down