bool CTilegenState::ParseAction( KeyValues *pKeyValues ) { ITilegenAction *pNewAction = NULL; ITilegenExpression< bool > *pCondition = NULL; if ( CreateActionAndCondition( pKeyValues, &pNewAction, &pCondition ) ) { AddAction( pNewAction, pCondition ); return true; } else { return false; } }
bool CTilegenAction_NestedActions::LoadFromKeyValues( KeyValues *pKeyValues ) { for ( KeyValues *pSubKey = pKeyValues->GetFirstSubKey(); pSubKey != NULL; pSubKey = pSubKey->GetNextKey() ) { if ( Q_stricmp( pSubKey->GetName(), "action" ) == 0 ) { ITilegenAction *pAction; ITilegenExpression< bool > *pCondition; if ( !CreateActionAndCondition( pSubKey, &pAction, &pCondition ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Error creating nested action/condition pair in CTilegenAction_NestedActions.\n" ); return false; } m_NestedActions.AddToTail( ActionConditionPair_t( pAction, pCondition ) ); } } // Load up an optional "while" loop condition return CreateExpressionFromKeyValuesBlock( pKeyValues, "while", GetTypeName(), &m_pWhileCondition, true ); }
CLayoutSystem::CLayoutSystem() : m_nRandomSeed( 0 ), m_pGlobalActionState( NULL ), m_pCurrentState( NULL ), m_pMapLayout( NULL ), m_ActionData( DefLessFunc( ITilegenAction *) ), m_bLayoutError( false ), m_bGenerating( false ), m_nIterations( 0 ), m_nUselessIterations( 0 ) { m_States.SetLayoutSystem( this ); } CLayoutSystem::~CLayoutSystem() { m_TilegenListeners.PurgeAndDeleteElements(); delete m_pGlobalActionState; } bool CLayoutSystem::LoadFromKeyValues( KeyValues *pKeyValues ) { // Make sure all tilegen class factories have been registered. RegisterAllTilegenClasses(); for ( KeyValues *pSubKey = pKeyValues->GetFirstSubKey(); pSubKey != NULL; pSubKey = pSubKey->GetNextKey() ) { if ( Q_stricmp( pSubKey->GetName(), "state" ) == 0 ) { CTilegenState *pNewState = new CTilegenState( this, NULL ); if ( !pNewState->LoadFromKeyValues( pSubKey ) ) { delete pNewState; return false; } m_States.AddState( pNewState ); } else if ( Q_stricmp( pSubKey->GetName(), "action" ) == 0 ) { // Global actions, executed at the beginning of every state ITilegenAction *pNewAction = NULL; ITilegenExpression< bool > *pCondition = NULL; if ( CreateActionAndCondition( pSubKey, &pNewAction, &pCondition ) ) { if ( m_pGlobalActionState == NULL ) { m_pGlobalActionState = new CTilegenState( this, NULL ); } m_pGlobalActionState->AddAction( pNewAction, pCondition ); } else { return false; } } else if ( Q_stricmp( pSubKey->GetName(), "mission_settings" ) == 0 ) { m_nRandomSeed = pSubKey->GetInt( "RandomSeed", 0 ); } } return true; }