wrap GameState difficulties

This commit is contained in:
Chris Danford
2005-02-26 08:32:49 +00:00
parent 8a0f4d7cca
commit 70663436bb
8 changed files with 55 additions and 28 deletions
+19 -13
View File
@@ -42,11 +42,13 @@ GameState* GAMESTATE = NULL; // global and accessable from anywhere in our progr
#define NAMES_BLACKLIST_FILE "Data/NamesBlacklist.dat"
GameState::GameState() :
m_pCurSong( MESSAGE_CURRENT_SONG_CHANGED ),
m_pCurSteps( MESSAGE_CURRENT_STEPS_P1_CHANGED ),
m_stEdit( MESSAGE_EDIT_STEPS_TYPE_CHANGED ),
m_pEditSourceSteps( MESSAGE_EDIT_SOURCE_STEPS_CHANGED ),
m_stEditSource( MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED )
m_pCurSong( MESSAGE_CURRENT_SONG_CHANGED ),
m_pCurSteps( MESSAGE_CURRENT_STEPS_P1_CHANGED ),
m_stEdit( MESSAGE_EDIT_STEPS_TYPE_CHANGED ),
m_pEditSourceSteps( MESSAGE_EDIT_SOURCE_STEPS_CHANGED ),
m_stEditSource( MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED ),
m_PreferredDifficulty( MESSAGE_EDIT_PREFERRED_DIFFICULTY_P1_CHANGED ),
m_PreferredCourseDifficulty( MESSAGE_EDIT_PREFERRED_COURSE_DIFFICULTY_P1_CHANGED )
{
m_pCurStyle = NULL;
@@ -138,8 +140,8 @@ void GameState::Reset()
m_bChangedFailType = false;
FOREACH_PlayerNumber( p )
{
m_PreferredDifficulty[p] = DIFFICULTY_INVALID;
m_PreferredCourseDifficulty[p] = DIFFICULTY_MEDIUM;
m_PreferredDifficulty[p].Set( DIFFICULTY_INVALID );
m_PreferredCourseDifficulty[p].Set( DIFFICULTY_MEDIUM );
}
m_PreferredSortOrder = SORT_INVALID;
m_PlayMode = PLAY_MODE_INVALID;
@@ -302,9 +304,9 @@ void GameState::PlayersFinalized()
if( m_PreferredSortOrder == SORT_INVALID && pProfile->m_SortOrder != SORT_INVALID )
m_PreferredSortOrder = pProfile->m_SortOrder;
if( pProfile->m_LastDifficulty != DIFFICULTY_INVALID )
m_PreferredDifficulty[pn] = pProfile->m_LastDifficulty;
m_PreferredDifficulty[pn].Set( pProfile->m_LastDifficulty );
if( pProfile->m_LastCourseDifficulty != DIFFICULTY_INVALID )
m_PreferredCourseDifficulty[pn] = pProfile->m_LastCourseDifficulty;
m_PreferredCourseDifficulty[pn].Set( pProfile->m_LastCourseDifficulty );
if( m_pPreferredSong == NULL )
m_pPreferredSong = pProfile->m_lastSong.ToSong();
if( m_pPreferredCourse == NULL )
@@ -1647,10 +1649,11 @@ bool GameState::DifficultiesLocked()
bool GameState::ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc )
{
this->m_PreferredDifficulty[pn] = dc;
m_PreferredDifficulty[pn].Set( dc );
if( DifficultiesLocked() )
FOREACH_PlayerNumber( p )
m_PreferredDifficulty[p] = m_PreferredDifficulty[pn];
if( p != pn )
m_PreferredDifficulty[p].Set( m_PreferredDifficulty[pn] );
return true;
}
@@ -1729,11 +1732,12 @@ void GameState::GetCourseDifficultiesToShow( set<CourseDifficulty> &ret )
bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd )
{
m_PreferredCourseDifficulty[pn] = cd;
m_PreferredCourseDifficulty[pn].Set( cd );
if( PREFSMAN->m_bLockCourseDifficulties )
FOREACH_PlayerNumber( p )
m_PreferredCourseDifficulty[p] = m_PreferredCourseDifficulty[pn];
if( p != pn )
m_PreferredCourseDifficulty[p].Set( m_PreferredCourseDifficulty[pn] );
return true;
}
@@ -1876,6 +1880,7 @@ public:
else { lua_pushnil(L); }
return 1;
}
static int GetPreferredDifficulty( T* p, lua_State *L ) { lua_pushnumber(L, p->m_PreferredDifficulty[IArg(1)] ); return 1; }
static void Register(lua_State *L)
{
@@ -1894,6 +1899,7 @@ public:
ADD_METHOD( SetEnv )
ADD_METHOD( GetEnv )
ADD_METHOD( GetEditSourceSteps )
ADD_METHOD( GetPreferredDifficulty )
Luna<T>::Register( L );
// Add global singleton if constructed already. If it's not constructed yet,
+2 -2
View File
@@ -55,7 +55,7 @@ public:
int m_iCoins; // not "credits"
PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides
bool m_bIsOnSystemMenu; // system screens will not be effected by the operator key -- Miryokuteki
CourseDifficulty m_PreferredCourseDifficulty[NUM_PLAYERS]; // used in nonstop
BroadcastOnChange1D<CourseDifficulty,NUM_PLAYERS> m_PreferredCourseDifficulty;// used in nonstop
bool DifficultiesLocked();
bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc );
bool ChangePreferredDifficulty( PlayerNumber pn, int dir );
@@ -101,7 +101,7 @@ public:
CString m_sLoadingMessage; // used in loading screen
CString m_sPreferredSongGroup; // GROUP_ALL_MUSIC denotes no preferred group
bool m_bChangedFailType; // true if FailType was changed in the song options screen
Difficulty m_PreferredDifficulty[NUM_PLAYERS];
BroadcastOnChange1D<Difficulty,NUM_PLAYERS> m_PreferredDifficulty;
SortOrder m_PreferredSortOrder; // used by MusicWheel
bool m_bEditing; // NoteField does special stuff when this is true
bool m_bDemonstrationOrJukebox; // ScreenGameplay does special stuff when this is true
+21
View File
@@ -22,6 +22,10 @@ enum Message
MESSAGE_EDIT_STEPS_TYPE_CHANGED,
MESSAGE_EDIT_SOURCE_STEPS_CHANGED,
MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED,
MESSAGE_EDIT_PREFERRED_DIFFICULTY_P1_CHANGED,
MESSAGE_EDIT_PREFERRED_DIFFICULTY_P2_CHANGED,
MESSAGE_EDIT_PREFERRED_COURSE_DIFFICULTY_P1_CHANGED,
MESSAGE_EDIT_PREFERRED_COURSE_DIFFICULTY_P2_CHANGED,
NUM_MESSAGES,
MESSAGE_INVALID
};
@@ -41,6 +45,23 @@ public:
operator T () const { return val; }
};
template<class T, int N>
class BroadcastOnChange1D
{
private:
Message mSendWhenChanged;
typedef BroadcastOnChange<T> MyType;
vector<MyType> val;
public:
BroadcastOnChange1D( Message m )
{
for( unsigned i=0; i<N; i++ )
val.push_back( BroadcastOnChange<T>((Message)(m+i)) );
}
const BroadcastOnChange<T>& operator[]( unsigned i ) const { return val[i]; }
BroadcastOnChange<T>& operator[]( unsigned i ) { return val[i]; }
};
template<class T>
class BroadcastOnChangePtr
{
+6 -6
View File
@@ -277,10 +277,10 @@ void ModeSwitcher::ChangeMode(PlayerNumber pn, int dir)
{
switch(GAMESTATE->m_PreferredDifficulty[pn])
{
case DIFFICULTY_BEGINNER: GAMESTATE->m_PreferredDifficulty[pn] = DIFFICULTY_EASY; break;
case DIFFICULTY_EASY: GAMESTATE->m_PreferredDifficulty[pn] = DIFFICULTY_MEDIUM; break;
case DIFFICULTY_MEDIUM: GAMESTATE->m_PreferredDifficulty[pn] = DIFFICULTY_HARD; break;
case DIFFICULTY_HARD: GAMESTATE->m_PreferredDifficulty[pn] = DIFFICULTY_CHALLENGE; break;
case DIFFICULTY_BEGINNER: GAMESTATE->m_PreferredDifficulty[pn].Set( DIFFICULTY_EASY ); break;
case DIFFICULTY_EASY: GAMESTATE->m_PreferredDifficulty[pn].Set( DIFFICULTY_MEDIUM ); break;
case DIFFICULTY_MEDIUM: GAMESTATE->m_PreferredDifficulty[pn].Set( DIFFICULTY_HARD ); break;
case DIFFICULTY_HARD: GAMESTATE->m_PreferredDifficulty[pn].Set( DIFFICULTY_CHALLENGE ); break;
}
m_Stylename.SetText(GetStyleName());
m_Nextmode.SetText(GetNextStyleName());
@@ -290,9 +290,9 @@ void ModeSwitcher::ChangeMode(PlayerNumber pn, int dir)
else
{
if(GAMESTATE->IsPlayerEnabled(PLAYER_1))
GAMESTATE->m_PreferredDifficulty[PLAYER_1] = DIFFICULTY_CHALLENGE;
GAMESTATE->m_PreferredDifficulty[PLAYER_1].Set( DIFFICULTY_CHALLENGE );
if(GAMESTATE->IsPlayerEnabled(PLAYER_2))
GAMESTATE->m_PreferredDifficulty[PLAYER_2] = DIFFICULTY_CHALLENGE;
GAMESTATE->m_PreferredDifficulty[PLAYER_2].Set( DIFFICULTY_CHALLENGE );
}
}
+2 -2
View File
@@ -177,7 +177,7 @@ void MusicWheel::Load()
{
GAMESTATE->m_pCurSteps[p].Set( pSteps );
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions = po;
GAMESTATE->m_PreferredDifficulty[p] = pSteps->GetDifficulty();
GAMESTATE->m_PreferredDifficulty[p].Set( pSteps->GetDifficulty() );
}
GAMESTATE->m_SongOptions = so;
}
@@ -992,7 +992,7 @@ void MusicWheel::Update( float fDeltaTime )
{
FOREACH_PlayerNumber( p )
if( GAMESTATE->IsPlayerEnabled(p) )
GAMESTATE->m_PreferredDifficulty[p] = dc;
GAMESTATE->m_PreferredDifficulty[p].Set( dc );
}
SCREENMAN->PostMessageToTopScreen( SM_SongChanged, 0 );
+2 -2
View File
@@ -546,7 +546,7 @@ void ScreenEz2SelectMusic::EasierDifficulty( PlayerNumber pn )
m_iSelection[pn]--;
// the user explicity switched difficulties. Update the preferred difficulty
GAMESTATE->m_PreferredDifficulty[pn] = m_arrayNotes[pn][ m_iSelection[pn] ]->GetDifficulty();
GAMESTATE->m_PreferredDifficulty[pn].Set( m_arrayNotes[pn][ m_iSelection[pn] ]->GetDifficulty() );
// m_soundChangeNotes.Play();
@@ -591,7 +591,7 @@ void ScreenEz2SelectMusic::HarderDifficulty( PlayerNumber pn )
m_iSelection[pn]++;
// the user explicity switched difficulties. Update the preferred difficulty
GAMESTATE->m_PreferredDifficulty[pn] = m_arrayNotes[pn][ m_iSelection[pn] ]->GetDifficulty();
GAMESTATE->m_PreferredDifficulty[pn].Set( m_arrayNotes[pn][ m_iSelection[pn] ]->GetDifficulty() );
// m_soundChangeNotes.Play();
+1 -1
View File
@@ -31,7 +31,7 @@ void ScreenInstructions::Init()
{
Difficulty easiestDifficulty = (Difficulty)(NUM_DIFFICULTIES-1);
FOREACH_HumanPlayer(p)
easiestDifficulty = min( easiestDifficulty, GAMESTATE->m_PreferredDifficulty[p] );
easiestDifficulty = min( easiestDifficulty, GAMESTATE->m_PreferredDifficulty[p].Get() );
if( easiestDifficulty > DIFFICULTY_EASY )
{
+2 -2
View File
@@ -371,7 +371,7 @@ void ScreenNetSelectMusic::MenuDown( PlayerNumber pn, const InputEventType type
}
UpdateDifficulties( pn );
GAMESTATE->m_PreferredDifficulty[pn] = m_DC[pn];
GAMESTATE->m_PreferredDifficulty[pn].Set( m_DC[pn] );
}
void ScreenNetSelectMusic::MenuStart( PlayerNumber pn )
@@ -443,7 +443,7 @@ void ScreenNetSelectMusic::StartSelectedSong()
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType; //STEPS_TYPE_DANCE_SINGLE;
FOREACH_EnabledPlayer (pn)
{
GAMESTATE->m_PreferredDifficulty[pn] = m_DC[pn];
GAMESTATE->m_PreferredDifficulty[pn].Set( m_DC[pn] );
Steps * pSteps = pSong->GetStepsByDifficulty(st,m_DC[pn]);
GAMESTATE->m_pCurSteps[pn].Set( pSteps );
}