Apply game commands in the order specificed so that earlier, possibly depenant commands are applied first
This commit is contained in:
@@ -139,21 +139,25 @@ bool GameCommand::DescribesCurrentMode( PlayerNumber pn ) const
|
|||||||
void GameCommand::Load( int iIndex, const Commands& cmds )
|
void GameCommand::Load( int iIndex, const Commands& cmds )
|
||||||
{
|
{
|
||||||
m_iIndex = iIndex;
|
m_iIndex = iIndex;
|
||||||
|
|
||||||
m_bInvalid = false;
|
m_bInvalid = false;
|
||||||
|
m_Commands = cmds;
|
||||||
|
|
||||||
FOREACH_CONST( Command, cmds.v, command )
|
FOREACH_CONST( Command, cmds.v, cmd )
|
||||||
|
LoadOne( *cmd );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameCommand::LoadOne( const Command& cmd )
|
||||||
{
|
{
|
||||||
CString sName = command->GetName();
|
CString sName = cmd.GetName();
|
||||||
if( sName.empty() )
|
if( sName.empty() )
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
CString sValue;
|
CString sValue;
|
||||||
for( unsigned i = 1; i < command->m_vsArgs.size(); ++i )
|
for( unsigned i = 1; i < cmd.m_vsArgs.size(); ++i )
|
||||||
{
|
{
|
||||||
if( i > 1 )
|
if( i > 1 )
|
||||||
sValue += ",";
|
sValue += ",";
|
||||||
sValue += (CString) command->GetArg(i);
|
sValue += (CString) cmd.GetArg(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( sName == "game" )
|
if( sName == "game" )
|
||||||
@@ -291,8 +295,8 @@ void GameCommand::Load( int iIndex, const Commands& cmds )
|
|||||||
|
|
||||||
else if( sName == "setenv" )
|
else if( sName == "setenv" )
|
||||||
{
|
{
|
||||||
if( command->m_vsArgs.size() == 3 )
|
if( cmd.m_vsArgs.size() == 3 )
|
||||||
m_SetEnv[ command->m_vsArgs[1] ] = command->m_vsArgs[2];
|
m_SetEnv[ cmd.m_vsArgs[1] ] = cmd.m_vsArgs[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( sName == "songgroup" )
|
else if( sName == "songgroup" )
|
||||||
@@ -384,12 +388,11 @@ void GameCommand::Load( int iIndex, const Commands& cmds )
|
|||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CString sWarning = ssprintf( "Command '%s' is not valid.", command->GetOriginalCommandString().c_str() );
|
CString sWarning = ssprintf( "Command '%s' is not valid.", cmd.GetOriginalCommandString().c_str() );
|
||||||
LOG->Warn( sWarning );
|
LOG->Warn( sWarning );
|
||||||
Dialog::OK( sWarning, "INVALID_GAME_COMMAND" );
|
Dialog::OK( sWarning, "INVALID_GAME_COMMAND" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int GetNumCreditsPaid()
|
int GetNumCreditsPaid()
|
||||||
{
|
{
|
||||||
@@ -606,6 +609,17 @@ static HighScore MakeRandomHighScore()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GameCommand::Apply( const vector<PlayerNumber> &vpns ) const
|
void GameCommand::Apply( const vector<PlayerNumber> &vpns ) const
|
||||||
|
{
|
||||||
|
FOREACH_CONST( Command, m_Commands.v, cmd )
|
||||||
|
{
|
||||||
|
GameCommand gc;
|
||||||
|
gc.m_bInvalid = false;
|
||||||
|
gc.LoadOne( *cmd );
|
||||||
|
gc.ApplySelf( vpns );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
|
||||||
{
|
{
|
||||||
const PlayMode OldPlayMode = GAMESTATE->m_PlayMode;
|
const PlayMode OldPlayMode = GAMESTATE->m_PlayMode;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "PlayerNumber.h"
|
#include "PlayerNumber.h"
|
||||||
#include "Difficulty.h"
|
#include "Difficulty.h"
|
||||||
#include "LuaReference.h"
|
#include "LuaReference.h"
|
||||||
|
#include "Command.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class Song;
|
class Song;
|
||||||
@@ -16,19 +17,20 @@ class Trail;
|
|||||||
class Character;
|
class Character;
|
||||||
class Style;
|
class Style;
|
||||||
class Game;
|
class Game;
|
||||||
class Commands;
|
|
||||||
|
|
||||||
struct GameCommand // used in SelectMode
|
struct GameCommand // used in SelectMode
|
||||||
{
|
{
|
||||||
GameCommand() { Init(); }
|
GameCommand() { Init(); }
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
void Load( int iIndex, const Commands& acs );
|
void Load( int iIndex, const Commands& cmds );
|
||||||
|
void LoadOne( const Command& cmd );
|
||||||
|
|
||||||
void ApplyToAllPlayers() const;
|
void ApplyToAllPlayers() const;
|
||||||
void Apply( PlayerNumber pn ) const;
|
void Apply( PlayerNumber pn ) const;
|
||||||
private:
|
private:
|
||||||
void Apply( const vector<PlayerNumber> &vpns ) const;
|
void Apply( const vector<PlayerNumber> &vpns ) const;
|
||||||
|
void ApplySelf( const vector<PlayerNumber> &vpns ) const;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool DescribesCurrentMode( PlayerNumber pn ) const;
|
bool DescribesCurrentMode( PlayerNumber pn ) const;
|
||||||
@@ -36,6 +38,10 @@ public:
|
|||||||
bool IsPlayable( CString *why = NULL ) const;
|
bool IsPlayable( CString *why = NULL ) const;
|
||||||
bool IsZero() const;
|
bool IsZero() const;
|
||||||
|
|
||||||
|
// Same as what was passed to Load. We need to keep the original commands
|
||||||
|
// so that we know the order of commands when it comes time to Apply.
|
||||||
|
Commands m_Commands;
|
||||||
|
|
||||||
CString m_sName; // display name
|
CString m_sName; // display name
|
||||||
bool m_bInvalid;
|
bool m_bInvalid;
|
||||||
CString m_sInvalidReason;
|
CString m_sInvalidReason;
|
||||||
|
|||||||
Reference in New Issue
Block a user