예제 #1
0
bool CLevel::Validate()
{
    unsigned int itemCount;

    // There may be more checks in the future

    if ( !CheckMaxNumberOfItems( &itemCount ) ){
        // Log there is a problem
        theLog.WriteLine ("Options         => !!! Level file is incorrect (Too many items: %d of %d allowed).", itemCount, MAX_ITEMS);
        return false;
    }
    
    return true;
}
예제 #2
0
bool COptions::LoadLevel( const char *filename )
{
    //-----------------------------------
    // Allocate data and name for 1 level
    //-----------------------------------

    AllocateLevels(1);
    
    //------------------------------------------------------
    // Load all the level files detected earlier
    //------------------------------------------------------
    
    bool ErrorOccurred = false;    
    
    // Open the existing level file for reading
    ifstream in;
    in.open( filename, ios_base::in );

    // If it failed
    if (!in.is_open())
    {
        cerr << "Loading level file " << filename << " failed." << endl;
        // Stop loading levels
        return false;
    }

    // This is the first line for the level files beginning with version 2 (therefore "V2plus")
    string headerV2plus( "; Bombermaaan level file version=" );

    string s;
    getline( in, s );
    int LevelVersion;

    // When header string is found at the beginning of the string, find() returns 0 (offset 0)
    if ( s.find( headerV2plus ) == 0 ) {
        // We can look for the level version now
        LevelVersion = atoi( s.substr( headerV2plus.length() ).c_str() );
    }
    else
    {
        LevelVersion = 1;
    }
    
    switch ( LevelVersion ) {

        case 1:
            if (!LoadLevel_Version1( in, 0 ) ) {
                ErrorOccurred = true;
            }
            break;

        case 2:
            if (!LoadLevel_Version2( filename, 0 ) ) {
                ErrorOccurred = true;
            }
            break;

        default:
            printf ("Options         => !!! Unsupported version of level file %s.", filename);
            ErrorOccurred = true;
            break;

    }

	// Close the level file
    in.close();
    
    unsigned int sumOfMaxItems;

    // too many items?
    if (!ErrorOccurred && !CheckMaxNumberOfItems( 0, &sumOfMaxItems ))
    {
        // Log there is a problem
        cerr << "!!! Level file is incorrect (Too many items: " << sumOfMaxItems << " of " << MAX_ITEMS << " allowed)." << endl;

        // Stop loading levels
        ErrorOccurred = true;
    }

    // If we had to stop then there is a problem.
    if (ErrorOccurred)
        return false;

    // Everything went right
    return true;
}