Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions drodrpg/DROD/GameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2688,9 +2688,14 @@ void CGameScreen::OnKeyDown(
break;

case CMD_SCORE_KEY:
{
ASSERT(this->pCurrentGame);
ASSERT(this->pCurrentGame->pPlayer);
ShowScoreDialog(g_pTheDB->GetMessageText(MID_Score), this->pCurrentGame->pPlayer->st);
PlayerStats st = this->pCurrentGame->pPlayer->st; //temp copy for display
st.ATK = this->pCurrentGame->getPlayerATK();
st.DEF = this->pCurrentGame->getPlayerDEF();
ShowScoreDialog(g_pTheDB->GetMessageText(MID_Score), st);
}
break;

case CMD_EXTRA_SAVE_GAME:
Expand Down Expand Up @@ -4758,14 +4763,12 @@ void CGameScreen::FadeRoom(const bool bFadeIn, const Uint32 dwDuration, CCueEven
}

//*****************************************************************************
void CGameScreen::ScoreCheckpoint(const WCHAR* pScoreIDText)
void CGameScreen::ScoreCheckpoint(const ScoreCheckpointData& scoreData)
//Displays score checkpoint stats and uploads the score.
{
//Stats involved in score tallying.
ASSERT(this->pCurrentGame);
ASSERT(this->pCurrentGame->pPlayer);
const PlayerStats& st = this->pCurrentGame->pPlayer->st;
UINT dwTotalScore = this->pCurrentGame->GetScore();
UINT dwTotalScore = this->pCurrentGame->GetScore(scoreData.stats);

/*
wstrLevelStats += wszCRLF;
Expand All @@ -4774,10 +4777,10 @@ void CGameScreen::ScoreCheckpoint(const WCHAR* pScoreIDText)
this->pRoomWidget, wstrLevelStats.c_str(), F_Stats, 5000, 8000, true));
*/

SendAchievement(UnicodeToUTF8(pScoreIDText).c_str(), dwTotalScore);
SendAchievement(UnicodeToUTF8(scoreData.scorepointName).c_str(), dwTotalScore);

//Display.
ShowScoreDialog(pScoreIDText, st);
ShowScoreDialog(scoreData.scorepointName, scoreData.stats);
}

void CGameScreen::ShowScoreDialog(const WSTRING pTitle, const PlayerStats& st)
Expand All @@ -4791,8 +4794,8 @@ void CGameScreen::ShowScoreDialog(const WSTRING pTitle, const PlayerStats& st)
//Stats involved in score tallying.
ASSERT(this->pCurrentGame);
dwHP = st.HP;
dwATK = this->pCurrentGame->getPlayerATK();
dwDEF = this->pCurrentGame->getPlayerDEF();
dwATK = st.ATK;
dwDEF = st.DEF;
dwYKeys = st.yellowKeys;
dwGKeys = st.greenKeys;
dwBKeys = st.blueKeys;
Expand All @@ -4811,7 +4814,7 @@ void CGameScreen::ShowScoreDialog(const WSTRING pTitle, const PlayerStats& st)
dwBKeysScore = CCurrentGame::CalculateStatScore(dwBKeys, st.scoreBlueKeys);
dwSKeysScore = CCurrentGame::CalculateStatScore(dwSKeys, st.scoreSkeletonKeys);
dwShovelsScore = CCurrentGame::CalculateStatScore(dwShovels, st.scoreShovels);
dwTotalScore = this->pCurrentGame->GetScore();
dwTotalScore = this->pCurrentGame->GetScore(st);

CTilesWidget* pTilesWidget = DYN_CAST(CTilesWidget*, CWidget*, this->pScoreDialog->GetWidget(TAG_SCORETILES));
pTilesWidget->ClearTiles();
Expand Down Expand Up @@ -7094,11 +7097,11 @@ SCREENTYPE CGameScreen::ProcessCueEventsAfterRoomDraw(
for (pObj = CueEvents.GetFirstPrivateData(CID_ScoreCheckpoint);
pObj != NULL; pObj = CueEvents.GetNextPrivateData())
{
const CDbMessageText *pScoreIDText = DYN_CAST(const CDbMessageText*, const CAttachableObject*, pObj);
ASSERT((const WCHAR*)(*pScoreIDText));
const ScoreCheckpointData* pScoreData = DYN_CAST(const ScoreCheckpointData*, const CAttachableObject*, pObj);
ASSERT(pScoreData);
if (!g_pTheSound->IsSoundEffectPlaying(SEID_LEVELCOMPLETE))
g_pTheSound->PlaySoundEffect(SEID_LEVELCOMPLETE); //SEID_AREACLEAR is jarring over other music
ScoreCheckpoint((const WCHAR*)(*pScoreIDText));
ScoreCheckpoint(*pScoreData);
}
}

Expand Down
2 changes: 1 addition & 1 deletion drodrpg/DROD/GameScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class CGameScreen : public CRoomScreen
bool ProcessSpeechSpeaker(CFiredCharacterCommand *pCommand);
void ReattachRetainedSubtitles();
void RestartRoom(int nCommand, CCueEvents& CueEvents);
void ScoreCheckpoint(const WCHAR* pScoreIDText);
void ScoreCheckpoint(const ScoreCheckpointData& scoreData);
WSTRING GetScoreCheckpointLine(const MID_CONSTANT statName, const UINT statAMount, const int scoreMultiplier, const UINT statScore);
void SendAchievement(const char* achievement, const UINT dwScore=0);
void ShowBigMap();
Expand Down
14 changes: 8 additions & 6 deletions drodrpg/DRODLib/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3294,13 +3294,15 @@ void CCharacter::Process(
if (bNotFrozen || //when playing back commands, don't do this stuff
this->pCurrentGame->IsValidatingPlayback()) //unless we're validating
{
CDbMessageText* pScoreIDText = new CDbMessageText();
*pScoreIDText = command.label.c_str();
CueEvents.Add(CID_ScoreCheckpoint, pScoreIDText, true);
PlayerStats stats = player.st;
stats.ATK = pGame->getPlayerATK();
stats.DEF = pGame->getPlayerDEF();
ScoreCheckpointData* pScoreData = new ScoreCheckpointData(stats, command.label);
CueEvents.Add(CID_ScoreCheckpoint, pScoreData, true);
//Score save and local highscore data will be created at end of turn process
//Creating a score during turn processing can cause problems with validation, as it
//will only check the end state of a turn. We also don't know if this turn will finish
//yet - it might have to be rewound due to blocked or stalled combat.
//Creating a score during turn processing can cause problems with validation, as
//we don't know if this turn will finish yet - it might have to be rewound due to
//blocked or stalled combat. (or the player might die)
}
}
bProcessNextCommand = true;
Expand Down
9 changes: 9 additions & 0 deletions drodrpg/DRODLib/CueEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ const CUEEVENT_ID CIDA_PlayerDied[6] = {
CID_MonsterKilledPlayer, CID_ExplosionKilledPlayer, CID_BriarKilledPlayer,
CID_CriticalNPCDied, CID_PlayerFellIntoPit, CID_PlayerDrownedInWater}; //CID_NPCBeethroDied

//Did something happen that will prevent a scorepoint from being valid?
//Leaving a room in anyway other than winning the game, or making an illegal move that
//has to be rewound.
const CUEEVENT_ID CIDA_ScoreCheckpointBlocked[12] = {
CID_ExitRoomPending, CID_ExitRoom, CID_ExitLevelPending, CID_ExitToWorldMapPending,
CID_MonsterKilledPlayer, CID_ExplosionKilledPlayer, CID_BriarKilledPlayer,
CID_CriticalNPCDied, CID_PlayerFellIntoPit, CID_PlayerDrownedInWater,
CID_InvalidAttackMove, CID_StalledCombat};

//Did a monster die?
const CUEEVENT_ID CIDA_MonsterDied[2] = {
CID_SnakeDiedFromTruncation, CID_MonsterDiedFromStab}; //, CID_MonsterBurned};
Expand Down
5 changes: 4 additions & 1 deletion drodrpg/DRODLib/CueEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ enum CUEEVENT_ID

//A score checkpoint is triggered.
//
//Private data: CDbMessageText *pScoreIDText (one)
//Private data: ScoreCheckpointData *pScoreData (one)
CID_ScoreCheckpoint,

//If any calls to CDbRoom::Plot() were made in the current room, this event will
Expand Down Expand Up @@ -754,6 +754,9 @@ extern const CUEEVENT_ID CIDA_PlayerLeftRoom[11];
//project-wide changes to code.
extern const CUEEVENT_ID CIDA_PlayerDied[6];

//Did something happen that will prevent a scorepoint from being valid?
extern const CUEEVENT_ID CIDA_ScoreCheckpointBlocked[12];

//Did a monster die?
extern const CUEEVENT_ID CIDA_MonsterDied[2];

Expand Down
36 changes: 15 additions & 21 deletions drodrpg/DRODLib/CurrentGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3320,15 +3320,14 @@ void CCurrentGame::ProcessCommand(
//Create any pending scorepoint saves and local highscore entries.
//Due to how validation works, it's not valid to make a scorepoint when leaving a room
if (CueEvents.HasOccurred(CID_ScoreCheckpoint) && !this->Commands.IsFrozen() &&
!CueEvents.HasAnyOccurred(IDCOUNT(CIDA_PlayerLeftRoom), CIDA_PlayerLeftRoom)) {
!CueEvents.HasAnyOccurred(IDCOUNT(CIDA_ScoreCheckpointBlocked), CIDA_ScoreCheckpointBlocked)) {
for (const CAttachableObject* pObj = CueEvents.GetFirstPrivateData(CID_ScoreCheckpoint);
pObj != NULL; pObj = CueEvents.GetNextPrivateData())
{
const CDbMessageText* pScoreIDText = DYN_CAST(const CDbMessageText*, const CAttachableObject*, pObj);
ASSERT((const WCHAR*)(*pScoreIDText));
const WSTRING wstrScoreIDText((WSTRING)(*pScoreIDText));
this->WriteScoreCheckpointSave(wstrScoreIDText);
this->WriteLocalHighScore(wstrScoreIDText);
const ScoreCheckpointData* pScoreData = DYN_CAST(const ScoreCheckpointData*, const CAttachableObject*, pObj);
ASSERT(pScoreData);
this->WriteScoreCheckpointSave(*pScoreData);
this->WriteLocalHighScore(*pScoreData);
}
}
}
Expand Down Expand Up @@ -8511,7 +8510,7 @@ UINT CCurrentGame::WriteCurrentRoomConquerDemo()
*/

//***************************************************************************************
UINT CCurrentGame::WriteLocalHighScore(const WSTRING& name)
UINT CCurrentGame::WriteLocalHighScore(const ScoreCheckpointData& scoreData)
//Creates or updates a high score record for the given scorepoint.
//
//Returns:
Expand All @@ -8520,10 +8519,6 @@ UINT CCurrentGame::WriteLocalHighScore(const WSTRING& name)
if (this->bNoSaves)
return 0; //playing a dummy game session -- don't save scores

PlayerStats st = this->pPlayer->st; //temp copy
st.ATK = getPlayerATK();
st.DEF = getPlayerDEF();

CDbPlayer* pPlayer = g_pTheDB->GetCurrentPlayer();
ASSERT(pPlayer);
bool showLocalMessage = true;
Expand All @@ -8534,19 +8529,19 @@ UINT CCurrentGame::WriteLocalHighScore(const WSTRING& name)
}

CDbLocalHighScore* pHighScore = NULL;
int score = GetScore(st);
int score = GetScore(scoreData.stats);
CDb db;
UINT holdID = this->pHold->dwHoldID;
UINT playerID = pPlayer->dwPlayerID;
CDbPackedVars stats;
st.Pack(stats);
scoreData.stats.Pack(stats);

db.HighScores.FilterByHold(holdID);
db.HighScores.FilterByPlayer(playerID);

if (db.HighScores.HasScorepoint(name)) {
if (db.HighScores.HasScorepoint(scoreData.scorepointName)) {
//Update existing score if a new best has been achieved
UINT id = db.HighScores.GetIDForScorepoint(name);
UINT id = db.HighScores.GetIDForScorepoint(scoreData.scorepointName);
ASSERT(id);
pHighScore = db.HighScores.GetByID(id);
ASSERT(pHighScore);
Expand All @@ -8572,7 +8567,7 @@ UINT CCurrentGame::WriteLocalHighScore(const WSTRING& name)
pHighScore->dwHoldID = holdID;
pHighScore->dwPlayerID = playerID;
pHighScore->score = score;
pHighScore->scorepointName = name;
pHighScore->scorepointName = scoreData.scorepointName;
pHighScore->stats = stats;
pHighScore->Update();

Expand All @@ -8587,7 +8582,7 @@ UINT CCurrentGame::WriteLocalHighScore(const WSTRING& name)
}

//***************************************************************************************
UINT CCurrentGame::WriteScoreCheckpointSave(const WSTRING& name)
UINT CCurrentGame::WriteScoreCheckpointSave(const ScoreCheckpointData& scoreData)
//Writes a saved game record containing the saved game's stats info for upload.
//
//Returns:
Expand All @@ -8601,12 +8596,11 @@ UINT CCurrentGame::WriteScoreCheckpointSave(const WSTRING& name)

//Insert the current ATK/DEF levels for the record made for score upload.
PlayerStats st = this->pPlayer->st; //temp copy
this->pPlayer->st.ATK = getPlayerATK();
this->pPlayer->st.DEF = getPlayerDEF();
this->pPlayer->st = scoreData.stats;

PackData(this->stats); //data must be packed at current stat values in order to upload
//score values correctly, since room move sequence will not be replayed on the server
SaveGame(ST_ScoreCheckpoint, name);
SaveGame(ST_ScoreCheckpoint, scoreData.scorepointName);
this->pPlayer->st = st; //revert
this->stats = tempStats;

Expand All @@ -8630,7 +8624,7 @@ UINT CCurrentGame::WriteScoreCheckpointSave(const WSTRING& name)
{
//Uploads are to be handled by front end to avoid delay here.
CCurrentGame::scoresForUpload.push(new SCORE_UPLOAD(text, GetScore(),
name, this->dwSavedGameID));
scoreData.scorepointName, this->dwSavedGameID));
}
}
} else {
Expand Down
14 changes: 12 additions & 2 deletions drodrpg/DRODLib/CurrentGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ struct TarstuffStab {
CMonster* pTarstuffMonster;
};

//*******************************************************************************
class ScoreCheckpointData : public CAttachableObject {
public:
ScoreCheckpointData(const PlayerStats& ps, const WSTRING& name)
: stats(ps), scorepointName(name) {}
~ScoreCheckpointData() {}
PlayerStats stats;
WSTRING scorepointName;
};

typedef pair<ScriptVars::MapIcon, ScriptVars::MapIconState> MapIconPair;

//*******************************************************************************
Expand Down Expand Up @@ -384,8 +394,8 @@ class CCurrentGame : public CDbSavedGame
bool UseAccessory(CCueEvents &CueEvents);
bool WalkDownStairs();
// UINT WriteCurrentRoomDieDemo();
UINT WriteLocalHighScore(const WSTRING& name);
UINT WriteScoreCheckpointSave(const WSTRING& name);
UINT WriteLocalHighScore(const ScoreCheckpointData& scoreData);
UINT WriteScoreCheckpointSave(const ScoreCheckpointData& scoreData);

bool PrepTempGameForRoomDisplay(const UINT roomID);

Expand Down
34 changes: 16 additions & 18 deletions drodrpg/DRODLib/Db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ bool CDb::ValidateSavedGame(
//
//Params:
const UINT savedGameID,
WSTRING& scoreCheckpointName, //(out) name of last score checkpoint encountered
PlayerStats& ps) //(out) player stats when last checkpoint is encountered
std::vector<ScoreCheckpointData>& scoresData) //(out) scorepoints when last checkpoint is encountered
{
CDbSavedGame *pSavedGame = this->SavedGames.GetByID(savedGameID);
if (!pSavedGame)
Expand All @@ -291,7 +290,7 @@ bool CDb::ValidateSavedGame(
const CStretchyBuffer& moveSequence = pSavedGameMoves->getMoves();

const UINT holdID = this->SavedGames.GetHoldIDofSavedGame(savedGameID);
const bool bGood = ValidateMoveSequence(holdID, moveSequence, scoreCheckpointName, ps);
const bool bGood = ValidateMoveSequence(holdID, moveSequence, scoresData);

delete pSavedGameMoves;
delete pSavedGame;
Expand All @@ -308,8 +307,7 @@ bool CDb::ValidateMoveSequence(
//Params:
const UINT holdID,
const CStretchyBuffer& moves, //full move sequence
WSTRING& scoreCheckpointName, //(out) name of last score checkpoint encountered
PlayerStats& ps) //(out) player stats when last checkpoint is encountered
std::vector<ScoreCheckpointData>& scoresData) //(out) scorepoints when last checkpoint is encountered
{
const UINT bufSize = moves.Size();

Expand Down Expand Up @@ -338,7 +336,7 @@ bool CDb::ValidateMoveSequence(
break;
}

if (!ValidateMoveSequenceCheckCueEvents(CueEvents, pGame, command, bGood, scoreCheckpointName, ps))
if (!ValidateMoveSequenceCheckCueEvents(CueEvents, pGame, command, bGood, scoresData))
break;

if (CueEvents.HasAnyOccurred(IDCOUNT(CIDA_PlayerLeftRoom), CIDA_PlayerLeftRoom))
Expand Down Expand Up @@ -430,7 +428,7 @@ bool CDb::ValidateMoveSequence(
{
CueEvents.Clear();
pGame->ProcessCommand(CMD_ADVANCE_COMBAT, CueEvents);
if (!ValidateMoveSequenceCheckCueEvents(CueEvents, pGame, CMD_ADVANCE_COMBAT, bGood, scoreCheckpointName, ps))
if (!ValidateMoveSequenceCheckCueEvents(CueEvents, pGame, CMD_ADVANCE_COMBAT, bGood, scoresData))
break;
}

Expand All @@ -442,7 +440,7 @@ bool CDb::ValidateMoveSequence(
//Returns: true if play continues, false if ended
bool CDb::ValidateMoveSequenceCheckCueEvents(
CCueEvents& CueEvents, CCurrentGame* pGame, const UINT command,
bool& bGood, WSTRING& scoreCheckpointName, PlayerStats& ps) //(out)
bool& bGood, std::vector<ScoreCheckpointData>& scoresData) //(out)
const
{
const bool bPlayerDied = CueEvents.HasAnyOccurred(IDCOUNT(CIDA_PlayerDied), CIDA_PlayerDied);
Expand All @@ -455,16 +453,16 @@ const
//Check for a score checkpoint.
if (CueEvents.HasOccurred(CID_ScoreCheckpoint))
{
//Output name of score checkpoint and player stats at that checkpoint.
const CDbMessageText *pScoreIDText = DYN_CAST(const CDbMessageText*, const CAttachableObject*,
CueEvents.GetFirstPrivateData(CID_ScoreCheckpoint));
ASSERT((const WCHAR*)(*pScoreIDText));
scoreCheckpointName = (const WCHAR*)(*pScoreIDText);
ps = pGame->pPlayer->st;

//Alter stats to match how they are scored.
ps.ATK = pGame->getPlayerATK();
ps.DEF = pGame->getPlayerDEF();
//Clear any data from previous turns
scoresData.clear();
for (const CAttachableObject* pObj = CueEvents.GetFirstPrivateData(CID_ScoreCheckpoint);
pObj != NULL; pObj = CueEvents.GetNextPrivateData()) {
//Output name of score checkpoint and player stats at that checkpoint.
const ScoreCheckpointData *pScoreData = DYN_CAST(const ScoreCheckpointData*, const CAttachableObject*,
pObj);
ASSERT(pScoreData);
scoresData.push_back(*pScoreData);
}
}

//Was room exited?
Expand Down
7 changes: 3 additions & 4 deletions drodrpg/DRODLib/Db.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ class CDb : public CDbBase
static bool FreezingTimeStamps() {return bFreezeTimeStamps;}
static void FreezeTimeStamps(const bool bFlag) {bFreezeTimeStamps = bFlag;}

bool ValidateSavedGame(const UINT savedGameID, WSTRING& scoreCheckpointName,
PlayerStats& ps);
bool ValidateSavedGame(const UINT savedGameID, std::vector<ScoreCheckpointData>& scoresData);
bool ValidateMoveSequence(const UINT holdID, const CStretchyBuffer& moves,
WSTRING& scoreCheckpointName, PlayerStats& ps);
std::vector<ScoreCheckpointData>& scoresData);
bool ValidateMoveSequenceCheckCueEvents(
CCueEvents& CueEvents, CCurrentGame* pGame, const UINT command,
bool& bGood, WSTRING& scoreCheckpointName, PlayerStats& ps) const;
bool& bGood, std::vector<ScoreCheckpointData>& scoresData) const;

//Use these members to access data directly. Requires more knowledge of
//the database.
Expand Down
2 changes: 1 addition & 1 deletion drodrpg/DRODLib/GameConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const UINT NEXT_VERSION_NUMBER = 600;
const WCHAR wszVersionReleaseNumber[] = WS("2.0.7.") WS(STRFY_EXPAND(DROD_VERSION_REVISION));
#else
const WCHAR wszVersionReleaseNumber[] = {
We('2'),We('.'),We('0'),We('.'),We('9'),We('.'),We('1'),We('1'),We('0'),We('1'),We(0) // 2.0.* -- full version number plus build number
We('2'),We('.'),We('0'),We('.'),We('9'),We('.'),We('1'),We('1'),We('5'),We('9'),We(0) // 2.0.* -- full version number plus build number
};
#endif

Expand Down
2 changes: 1 addition & 1 deletion drodrpg/DRODLib/PlayerStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ bool PlayerStats::IsGlobalStatIndex(UINT i)
}

//***************************************************************************************
void PlayerStats::Pack(CDbPackedVars& stats)
void PlayerStats::Pack(CDbPackedVars& stats) const
//Writes player (and global) RPG stats to the stats buffer.
{
for (UINT i=PredefinedVarCount; i--; )
Expand Down
Loading
Loading