From afc090ca73b9eff0f1fca5273f953a19ac780eaa Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Fri, 27 Jun 2014 20:20:50 -0600 Subject: [PATCH] Changed GAMESTATE:SetCurrentSteps and GAMESTATE:SetCurrentTrail to attempt to set a compatible style if AutoSetStyle is true. --- src/GameState.cpp | 52 +++++++++++++++++++++++++++++++++++++++++------ src/GameState.h | 1 + 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/GameState.cpp b/src/GameState.cpp index b1c5eb90c2..879c403608 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -1205,6 +1205,21 @@ void GameState::SetCurrentStyle( const Style *pStyle ) } } +bool GameState::SetCompatibleStyle(StepsType stype) +{ + if(CommonMetrics::AUTO_SET_STYLE) + { + const Style* compatible_style= GAMEMAN->GetFirstCompatibleStyle( + m_pCurGame, GetNumSidesJoined(), stype); + if(!compatible_style) + { + return false; + } + SetCurrentStyle(compatible_style); + } + return stype == m_pCurStyle->m_StepsType; +} + bool GameState::IsPlayerEnabled( PlayerNumber pn ) const { // In rave, all players are present. Non-human players are CPU controlled. @@ -2256,6 +2271,17 @@ public: else { Song *pS = Luna::check( L, 1, true ); p->m_pCurSong.Set( pS ); } return 0; } + static void SetCompatibleStyleOrError(T* p, lua_State* L, StepsType stype) + { + if(!p->SetCompatibleStyle(stype)) + { + luaL_error(L, "No compatible style for steps/trail."); + } + if(!p->m_pCurStyle) + { + luaL_error(L, "No style set and AutoSetStyle is false, cannot set steps/trail."); + } + } static int GetCurrentSteps( T* p, lua_State *L ) { PlayerNumber pn = Enum::Check(L, 1); @@ -2267,10 +2293,16 @@ public: static int SetCurrentSteps( T* p, lua_State *L ) { PlayerNumber pn = Enum::Check(L, 1); - if( lua_isnil(L,2) ) { p->m_pCurSteps[pn].Set( NULL ); } - else { Steps *pS = Luna::check(L,2); p->m_pCurSteps[pn].Set( pS ); } - ASSERT( p->m_pCurSteps[pn] == NULL || - p->m_pCurSteps[pn]->m_StepsType == p->m_pCurStyle->m_StepsType); + if(lua_isnil(L,2)) + { + p->m_pCurSteps[pn].Set(NULL); + } + else + { + Steps *pS = Luna::check(L,2); + SetCompatibleStyleOrError(p, L, pS->m_StepsType); + p->m_pCurSteps[pn].Set(pS); + } return 0; } static int GetCurrentCourse( T* p, lua_State *L ) { if(p->m_pCurCourse) p->m_pCurCourse->PushSelf(L); else lua_pushnil(L); return 1; } @@ -2291,8 +2323,16 @@ public: static int SetCurrentTrail( T* p, lua_State *L ) { PlayerNumber pn = Enum::Check(L, 1); - if( lua_isnil(L,2) ) { p->m_pCurTrail[pn].Set( NULL ); } - else { Trail *pS = Luna::check(L,2); p->m_pCurTrail[pn].Set( pS ); } + if(lua_isnil(L,2)) + { + p->m_pCurTrail[pn].Set(NULL); + } + else + { + Trail *pS = Luna::check(L,2); + SetCompatibleStyleOrError(p, L, pS->m_StepsType); + p->m_pCurTrail[pn].Set(pS); + } return 0; } static int GetPreferredSong( T* p, lua_State *L ) { if(p->m_pPreferredSong) p->m_pPreferredSong->PushSelf(L); else lua_pushnil(L); return 1; } diff --git a/src/GameState.h b/src/GameState.h index 58eee84f07..824d658325 100644 --- a/src/GameState.h +++ b/src/GameState.h @@ -128,6 +128,7 @@ public: const Game* GetCurrentGame(); const Style* GetCurrentStyle() const; void SetCurrentStyle( const Style *pStyle ); + bool SetCompatibleStyle(StepsType stype); void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut ); bool IsPlayerEnabled( PlayerNumber pn ) const;