Changed GAMESTATE:SetCurrentSteps and GAMESTATE:SetCurrentTrail to attempt to set a compatible style if AutoSetStyle is true.

This commit is contained in:
Kyzentun
2014-06-27 20:20:50 -06:00
parent b08d766657
commit afc090ca73
2 changed files with 47 additions and 6 deletions
+46 -6
View File
@@ -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<Song>::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<PlayerNumber>(L, 1);
@@ -2267,10 +2293,16 @@ public:
static int SetCurrentSteps( T* p, lua_State *L )
{
PlayerNumber pn = Enum::Check<PlayerNumber>(L, 1);
if( lua_isnil(L,2) ) { p->m_pCurSteps[pn].Set( NULL ); }
else { Steps *pS = Luna<Steps>::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<Steps>::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<PlayerNumber>(L, 1);
if( lua_isnil(L,2) ) { p->m_pCurTrail[pn].Set( NULL ); }
else { Trail *pS = Luna<Trail>::check(L,2); p->m_pCurTrail[pn].Set( pS ); }
if(lua_isnil(L,2))
{
p->m_pCurTrail[pn].Set(NULL);
}
else
{
Trail *pS = Luna<Trail>::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; }
+1
View File
@@ -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;