Skip to content

Commit

Permalink
Make all Replays follow the mods used on the score
Browse files Browse the repository at this point in the history
for now
also specified the change from before requiring replays to have score keys before starting. all dead replays should now be impossible to run
  • Loading branch information
poco0317 committed Oct 18, 2019
1 parent 4b85287 commit af59834
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/Etterna/Models/Misc/PlayerAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ map<int, vector<TapReplayResult>> PlayerAI::m_ReplayTapMap;
map<int, vector<HoldReplayResult>> PlayerAI::m_ReplayHoldMap;
map<int, vector<TapReplayResult>> PlayerAI::m_ReplayExactTapMap;
map<int, ReplaySnapshot> PlayerAI::m_ReplaySnapshotMap;
float PlayerAI::replayRate = 1.f;
RString PlayerAI::replayModifiers = "";
RString PlayerAI::oldModifiers = "";
float PlayerAI::oldRate = 1.f;

TapNoteScore
PlayerAI::GetTapNoteScore(const PlayerState* pPlayerState)
Expand Down Expand Up @@ -65,6 +69,10 @@ PlayerAI::ResetScoreData()
m_ReplayHoldMap.clear();
m_ReplayExactTapMap.clear();
m_ReplaySnapshotMap.clear();
replayRate = 1.f;
replayModifiers.clear();
oldModifiers.clear();
oldRate = 1.f;
}

void
Expand Down
5 changes: 5 additions & 0 deletions src/Etterna/Models/Misc/PlayerAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class PlayerAI
// of the Replay at that moment
static map<int, ReplaySnapshot> m_ReplaySnapshotMap;

static RString oldModifiers;
static RString replayModifiers;
static float replayRate;
static float oldRate;

// For use in Autoplay if we ever want to do funny things to the judgments
static TapNoteScore GetTapNoteScore(const PlayerState* pPlayerState);

Expand Down
27 changes: 25 additions & 2 deletions src/Etterna/Screen/Gameplay/ScreenGameplayReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ ScreenGameplayReplay::ScreenGameplayReplay()
{
ASSERT_M(PlayerAI::pScoreData != nullptr,
"Replay Highscore Info was empty.");

// Save current noteskin
auto ns =
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred().m_sNoteSkin;

// Set up rate
GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate = PlayerAI::replayRate;
// Set up mods
GAMESTATE->m_pPlayerState->m_PlayerOptions.Init();
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred().FromString(
PlayerAI::replayModifiers);

// Undo noteskin change
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred().FromOneModString(
ns, RString());
}

void
Expand All @@ -57,9 +72,17 @@ ScreenGameplayReplay::~ScreenGameplayReplay()
{
if (PREFSMAN->m_verbose_log > 1)
LOG->Trace("ScreenGameplayReplay::~ScreenGameplayReplay()");
if (!GAMESTATE->m_bRestartedGameplay)

if (!GAMESTATE->m_bRestartedGameplay) {
GAMESTATE->m_pPlayerState->m_PlayerOptions.Init();
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred().FromString(
PlayerAI::oldModifiers);
GAMESTATE->m_SongOptions.Init();
GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate =
PlayerAI::oldRate;
GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate = PlayerAI::oldRate;
PlayerAI::ResetScoreData();
else
} else
PlayerAI::SetScoreData();
}

Expand Down
30 changes: 18 additions & 12 deletions src/Etterna/Screen/Others/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,11 +1607,10 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
// get the highscore from lua and make the AI load it
HighScore* hs = Luna<HighScore>::check(L, 1);

// collect the noterows/timestamps early
// and abort if we shouldn't continue
auto timestamps = hs->GetCopyOfSetOnlineReplayTimestampVector();
auto noterows = hs->GetNoteRowVector();
if (noterows.empty() && timestamps.empty()) {
// Sometimes the site doesn't send a replay when we ask for one.
// This is not our fault.
// All scores should have keys.
if (hs->GetScoreKey().empty()) {
SCREENMAN->SystemMessage(
"Replay appears to be empty. Report this score to developers.");
lua_pushboolean(L, false);
Expand All @@ -1634,6 +1633,8 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
// site, since order is deterministic we'll just auto set the noterows
// from the existing, if the score was cc off then we need to fill in
// extra rows for each tap in the chord -mina
auto timestamps = hs->GetCopyOfSetOnlineReplayTimestampVector();
auto noterows = hs->GetNoteRowVector();
if (!timestamps.empty() &&
noterows.empty()) { // if we have noterows from newer uploads, just
// use them -mina
Expand Down Expand Up @@ -1686,16 +1687,20 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>

// prepare old mods to return to
const RString oldMods =
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetCurrent().GetString();
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred().GetString(
true);

// set the heck out of the current rate to make sure everything runs
// correctly
float scoreRate = hs->GetMusicRate();
float oldRate = GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate;
GAMESTATE->m_SongOptions.GetSong().m_fMusicRate = scoreRate;
GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate = scoreRate;
GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate = scoreRate;
MESSAGEMAN->Broadcast("RateChanged");
// GAMESTATE->m_SongOptions.GetSong().m_fMusicRate = scoreRate;
// GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate = scoreRate;
// GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate = scoreRate;
// MESSAGEMAN->Broadcast("RateChanged");
PlayerAI::replayRate = scoreRate;
PlayerAI::oldModifiers = oldMods;
PlayerAI::oldRate = oldRate;

// set mods based on the score, hopefully
// it is known that xmod->cmod and back does not work most of the time.
Expand All @@ -1711,6 +1716,7 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
// Set mirror mode on if mirror was on in the replay
// Also get ready to reset the turn mods to what they were before
RString mods = hs->GetModifiers();
PlayerAI::replayModifiers = mods;
vector<RString> oldTurns;
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetSong().GetTurnMods(
oldTurns);
Expand All @@ -1729,7 +1735,7 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
GAMESTATE->m_pPlayerState->m_PlayerOptions.GetPreferred()
.m_bTurns[PlayerOptions::TURN_MIRROR] = false;
}
GAMEMAN->m_bResetTurns = true;
// GAMEMAN->m_bResetTurns = true;
GAMEMAN->m_vTurnsToReset = oldTurns;

// lock the game into replay mode and GO
Expand All @@ -1739,7 +1745,7 @@ class LunaScreenSelectMusic : public Luna<ScreenSelectMusic>
GAMESTATE->m_pPlayerState->m_PlayerController = PC_REPLAY;

// set mods back to what they were before
GAMEMAN->m_bResetModifiers = true;
// GAMEMAN->m_bResetModifiers = true;
GAMEMAN->m_fPreviousRate = oldRate;
GAMEMAN->m_sModsToReset = oldMods;
return 1;
Expand Down

0 comments on commit af59834

Please sign in to comment.