From 2619a247910cf46577952f20446af26ec67d1d5a Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 11 May 2004 06:11:08 +0000 Subject: [PATCH] GameState::GetEasiestNotesDifficulty and lua binding --- stepmania/src/GameState.cpp | 23 +++++++++++++++++------ stepmania/src/GameState.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 06654f4f45..d4f09fa48e 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1204,12 +1204,7 @@ void GameState::AdjustFailType() return; /* Find the easiest difficulty notes selected by either player. */ - Difficulty dc = DIFFICULTY_INVALID; - FOREACH_HumanPlayer( p ) - { - ASSERT( this->m_pCurNotes[p] ); - dc = min(dc, this->m_pCurNotes[p]->GetDifficulty()); - } + const Difficulty dc = GetEasiestNotesDifficulty(); /* Reset the fail type to the default. */ SongOptions so; @@ -1643,6 +1638,21 @@ bool GameState::ChangeCourseDifficulty( PlayerNumber pn, int dir ) return true; } +Difficulty GameState::GetEasiestNotesDifficulty() const +{ + Difficulty dc = DIFFICULTY_INVALID; + FOREACH_HumanPlayer( p ) + { + if( this->m_pCurNotes[p] == NULL ) + { + LOG->Warn( "GetEasiestNotesDifficulty called but p%i hasn't chosen notes", p+1 ); + continue; + } + dc = min( dc, this->m_pCurNotes[p]->GetDifficulty() ); + } + return dc; +} + bool PlayerIsUsingModifier( PlayerNumber pn, const CString sModifier ) { PlayerOptions po = GAMESTATE->m_PlayerOptions[pn]; @@ -1670,6 +1680,7 @@ LuaFunction_NoArgs( PlayModeName, PlayModeToString(GAMESTATE->m_PlayMode) ) LuaFunction_NoArgs( CurStyleName, CString( GAMESTATE->m_CurStyle == STYLE_INVALID? "none": GAMESTATE->GetCurrentStyleDef()->m_szName ) ) LuaFunction_NoArgs( GetNumPlayersEnabled, GAMESTATE->GetNumPlayersEnabled() ) LuaFunction_NoArgs( PlayerUsingBothSides, GAMESTATE->PlayerUsingBothSides() ) +LuaFunction_NoArgs( GetEasiestNotesDifficulty, GAMESTATE->GetEasiestNotesDifficulty() ) /* Return an integer into SONGMAN->m_pSongs. This lets us do input checking, which we * can't easily do if we return pointers. */ diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index b885091389..e4df2db4b8 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -65,6 +65,7 @@ public: bool ChangeDifficulty( PlayerNumber pn, Difficulty dc ); bool ChangeDifficulty( PlayerNumber pn, int dir ); bool ChangeCourseDifficulty( PlayerNumber pn, int dir ); + Difficulty GetEasiestNotesDifficulty() const; RageTimer m_timeGameStarted; // from the moment the first player pressed Start /* This is set to a random number per-game/round; it can be used for a random seed. */