game/shared/econ/econ_item_schema.cpp
bool CEconItemSchema::BInitRecipes( KeyValues *pKVRecipes, CUtlVector<CUtlString> *pVecErrors )
{
	m_mapRecipes.Purge();

	// initialize the rewards sections
	if ( NULL != pKVRecipes )
	{
		int nHighestRecipeIndex = 0;
		FOR_EACH_TRUE_SUBKEY( pKVRecipes, pKVRecipe )
		{
			int nRecipeIndex = Q_atoi( pKVRecipe->GetName() );

			// Remember highest recipe index so we can make more past that 
			if ( nHighestRecipeIndex < nRecipeIndex + 1 )
			{
				nHighestRecipeIndex = nRecipeIndex + 1;
			}

			int nMapIndex = m_mapRecipes.Find( nRecipeIndex );

			// Make sure the recipe index is correct because we use this index as a reference
			SCHEMA_INIT_CHECK( 
				!m_mapRecipes.IsValidIndex( nMapIndex ),
				CFmtStr( "Duplicate recipe definition (%d)", nRecipeIndex ) );

			// Check to make sure the index is positive
			SCHEMA_INIT_CHECK( 
				nRecipeIndex >= 0,
				CFmtStr( "Recipe definition index %d must be greater than or equal to zero", nRecipeIndex ) );

			CEconCraftingRecipeDefinition *recipeDef = CreateCraftingRecipeDefinition();
			SCHEMA_INIT_SUBSTEP( recipeDef->BInitFromKV( pKVRecipe, *this, pVecErrors ) );

			// On clients, toss out any recipes that aren't always known. (Really, the clients
			// shouldn't ever get these, but just in case.)
#if defined(CLIENT_DLL) || defined(GAME_DLL)
			if ( recipeDef->IsAlwaysKnown() )
#endif // !GC_DLL
			{
#ifdef _DEBUG
				// Sanity check in debug builds so that we know we aren't putting the same recipe in
				// multiple times.
				FOR_EACH_MAP_FAST( m_mapRecipes, i )
				{
					Assert( i != nRecipeIndex );
					Assert( m_mapRecipes[i] != recipeDef );
				}
#endif // _DEBUG

				// Store this recipe.
				m_mapRecipes.Insert( nRecipeIndex, recipeDef );
			}
		}

#ifdef CSTRIKE15
		int nSetCount = GetItemSetCount();
		for ( int i = 0; i < nSetCount; ++i )
		{
			const IEconItemSetDefinition *pSet = GetItemSet( i );
			if ( !pSet || pSet->GetCraftReward() <= 0 )
				continue;

			CEconCraftingRecipeDefinition *recipeDef = CreateCraftingRecipeDefinition();
			SCHEMA_INIT_SUBSTEP( recipeDef->BInitFromSet( pSet, *this, pVecErrors ) );
			recipeDef->SetDefinitionIndex( nHighestRecipeIndex );
			recipeDef->SetFilter( CRAFT_FILTER_COLLECT );

			// Disabled for now until we ship collection badges!
			recipeDef->SetDisabled( true );

			m_mapRecipes.Insert( nHighestRecipeIndex, recipeDef );

			nHighestRecipeIndex++;
		}
#endif //#ifdef CSTRIKE15
	}

	return SCHEMA_INIT_SUCCESS();
}
//-----------------------------------------------------------------------------
// Purpose:	Initializes the recipes section of the schema
// Input:	pKVRecipes - The recipes section of the KeyValues 
//				representation of the schema
//			pVecErrors - An optional vector that will contain error messages if 
//				the init fails.
// Output:	True if initialization succeeded, false otherwise
//-----------------------------------------------------------------------------
Initializes the recipes section of the schema
Input: pKVRecipes - The recipes section of the KeyValues
representation of the schema
pVecErrors - An optional vector that will contain error messages if
the init fails.
Output:        True if initialization succeeded, false otherwise
Initializes the recipes section of the schema Input : pKVRecipes - The recipes section of the KeyValues representation of the schema pVecErrors - An optional vector that will contain error messages if the init fails . Output : True if initialization succeeded false otherwise
bool CEconItemSchema::BInitRecipes( KeyValues *pKVRecipes, CUtlVector<CUtlString> *pVecErrors )
{
	m_mapRecipes.Purge();
	if ( NULL != pKVRecipes )
	{
		int nHighestRecipeIndex = 0;
		FOR_EACH_TRUE_SUBKEY( pKVRecipes, pKVRecipe )
		{
			int nRecipeIndex = Q_atoi( pKVRecipe->GetName() );
			if ( nHighestRecipeIndex < nRecipeIndex + 1 )
			{
				nHighestRecipeIndex = nRecipeIndex + 1;
			}
			int nMapIndex = m_mapRecipes.Find( nRecipeIndex );
			SCHEMA_INIT_CHECK( 
				!m_mapRecipes.IsValidIndex( nMapIndex ),
				CFmtStr( "Duplicate recipe definition (%d)", nRecipeIndex ) );
			SCHEMA_INIT_CHECK( 
				nRecipeIndex >= 0,
				CFmtStr( "Recipe definition index %d must be greater than or equal to zero", nRecipeIndex ) );
			CEconCraftingRecipeDefinition *recipeDef = CreateCraftingRecipeDefinition();
			SCHEMA_INIT_SUBSTEP( recipeDef->BInitFromKV( pKVRecipe, *this, pVecErrors ) );
#if defined(CLIENT_DLL) || defined(GAME_DLL)
			if ( recipeDef->IsAlwaysKnown() )
#endif 
			{
#ifdef _DEBUG
				FOR_EACH_MAP_FAST( m_mapRecipes, i )
				{
					Assert( i != nRecipeIndex );
					Assert( m_mapRecipes[i] != recipeDef );
				}
#endif 
				m_mapRecipes.Insert( nRecipeIndex, recipeDef );
			}
		}
#ifdef CSTRIKE15
		int nSetCount = GetItemSetCount();
		for ( int i = 0; i < nSetCount; ++i )
		{
			const IEconItemSetDefinition *pSet = GetItemSet( i );
			if ( !pSet || pSet->GetCraftReward() <= 0 )
				continue;
			CEconCraftingRecipeDefinition *recipeDef = CreateCraftingRecipeDefinition();
			SCHEMA_INIT_SUBSTEP( recipeDef->BInitFromSet( pSet, *this, pVecErrors ) );
			recipeDef->SetDefinitionIndex( nHighestRecipeIndex );
			recipeDef->SetFilter( CRAFT_FILTER_COLLECT );
			recipeDef->SetDisabled( true );
			m_mapRecipes.Insert( nHighestRecipeIndex, recipeDef );
			nHighestRecipeIndex++;
		}
#endif 
	}
	return SCHEMA_INIT_SUCCESS();
}
bool CEconItemSchema :: BInitRecipes ( KeyValues * pKVRecipes , CUtlVector < CUtlString > * pVecErrors ) { m_mapRecipes . Purge ( ) ; if ( NULL != pKVRecipes ) { int nHighestRecipeIndex = 0 ; FOR_EACH_TRUE_SUBKEY ( pKVRecipes , pKVRecipe ) { int nRecipeIndex = Q_atoi ( pKVRecipe -> GetName ( ) ) ; if ( nHighestRecipeIndex < nRecipeIndex + 1 ) { nHighestRecipeIndex = nRecipeIndex + 1 ; } int nMapIndex = m_mapRecipes . Find ( nRecipeIndex ) ; SCHEMA_INIT_CHECK ( ! m_mapRecipes . IsValidIndex ( nMapIndex ) , CFmtStr ( " " , nRecipeIndex ) ) ; SCHEMA_INIT_CHECK ( nRecipeIndex >= 0 , CFmtStr ( " " , nRecipeIndex ) ) ; CEconCraftingRecipeDefinition * recipeDef = CreateCraftingRecipeDefinition ( ) ; SCHEMA_INIT_SUBSTEP ( recipeDef -> BInitFromKV ( pKVRecipe , * this , pVecErrors ) ) ; #if defined ( CLIENT_DLL ) || defined ( GAME_DLL ) if ( recipeDef -> IsAlwaysKnown ( ) ) #endif { #ifdef _DEBUG FOR_EACH_MAP_FAST ( m_mapRecipes , i ) { Assert ( i != nRecipeIndex ) ; Assert ( m_mapRecipes [ i ] != recipeDef ) ; } #endif m_mapRecipes . Insert ( nRecipeIndex , recipeDef ) ; } } #ifdef CSTRIKE15 int nSetCount = GetItemSetCount ( ) ; for ( int i = 0 ; i < nSetCount ; ++ i ) { const IEconItemSetDefinition * pSet = GetItemSet ( i ) ; if ( ! pSet || pSet -> GetCraftReward ( ) <= 0 ) continue ; CEconCraftingRecipeDefinition * recipeDef = CreateCraftingRecipeDefinition ( ) ; SCHEMA_INIT_SUBSTEP ( recipeDef -> BInitFromSet ( pSet , * this , pVecErrors ) ) ; recipeDef -> SetDefinitionIndex ( nHighestRecipeIndex ) ; recipeDef -> SetFilter ( CRAFT_FILTER_COLLECT ) ; recipeDef -> SetDisabled ( true ) ; m_mapRecipes . Insert ( nHighestRecipeIndex , recipeDef ) ; nHighestRecipeIndex ++ ; } #endif } return SCHEMA_INIT_SUCCESS ( ) ; }
Purpose:       Initializes the recipes section of the schema
Input: pKVRecipes - The recipes section of the KeyValues
representation of the schema
pVecErrors - An optional vector that will contain error messages if
the init fails.
Purpose : Initializes the recipes section of the schema Input : pKVRecipes - The recipes section of the KeyValues representation of the schema pVecErrors - An optional vector that will contain error messages if the init fails .
// initialize the rewards sections // Remember highest recipe index so we can make more past that  // Make sure the recipe index is correct because we use this index as a reference // Check to make sure the index is positive // On clients, toss out any recipes that aren't always known. (Really, the clients // shouldn't ever get these, but just in case.) // !GC_DLL // Sanity check in debug builds so that we know we aren't putting the same recipe in // multiple times. // _DEBUG // Store this recipe. // Disabled for now until we ship collection badges! //#ifdef CSTRIKE15