Esempio n. 1
0
bool LoadingState::loadLocalModuleHints()
{
    STRING buffer;

    // Open all the tips
    snprintf(buffer, SDL_arraysize( buffer ), "mp_modules/%s/gamedat/gametips.txt", _loadModule->getFolderName().c_str());
    ReadContext ctxt(buffer);
    if (!ctxt.ensureOpen())
    {
        return false;
    }
    // Load the data
    while (ctxt.skipToColon(true))
    {

        //Read the line
        vfs_read_string_lit(ctxt, buffer, SDL_arraysize(buffer));

        //Make it look nice
        str_add_linebreaks(buffer, SDL_arraysize(buffer), 50);

        _localGameTips.push_back(buffer);
    }

    return !_localGameTips.empty();
}
Esempio n. 2
0
bool LoadingState::loadGlobalHints()
{
    // Open the file with all the tips
    ReadContext ctxt("mp_data/gametips.txt");
    if (!ctxt.ensureOpen())
    {
		Log::get().warn("Unable to load the game tips and hints file `%s`\n", ctxt.getLoadName().c_str());
        return false;
    }

    // Load the data
    while (ctxt.skipToColon(true))
    {
        char buffer[1024+1];

        //Read the line
        vfs_read_string_lit(ctxt, buffer, 1024);

        //Make it look nice
        str_add_linebreaks(buffer, 1024, 50);

        _globalGameTips.push_back(buffer);
    }

    ctxt.close();

    if(_globalGameTips.empty()) {
		Log::get().warn( "Could not load the game tips and hints. (\"basicdat/gametips.txt\")\n" );
    }
 
    return !_globalGameTips.empty();
}
Esempio n. 3
0
//--------------------------------------------------------------------------------------------
bool link_build_vfs( const char * fname, Link_t list[] )
{
    if (!VALID_CSTR(fname)) return false;

    ReadContext ctxt(fname);
    if (!ctxt.ensureOpen()) return false;

    size_t i = 0;
    while (ctxt.skipToColon(true) && i < LINK_COUNT)
    {
        vfs_read_string_lit( ctxt, list[i].modname, SDL_arraysize( list[i].modname ) );
        list[i].valid = true;
        i++;
    }

    return i > 0;
}
Esempio n. 4
0
bool spawn_file_read(ReadContext& ctxt, spawn_file_info_t& info)
{
    info = spawn_file_info_t();

    // Until we hit something else than newlines, whitespaces or comments.
    while (true)
    {
        ctxt.skipWhiteSpaces();
        ctxt.skipNewLines();
        if (ctxt.is('/'))
        {
            ctxt.readSingleLineComment(); /// @todo Add and use ReadContext::skipSingleLineComment().
            continue;
        }
        if (!ctxt.isWhiteSpace() && !ctxt.isNewLine() && !ctxt.is('/'))
        {
            break;
        }
    }
    if (ctxt.isAlpha()||ctxt.is('%')||ctxt.is('_'))
    {
        ctxt._buffer.clear();
        // Read everything into the buffer until a ':', a new line, an error or the end of the input is reached.
        do
        {
            ctxt.saveAndNext();
        } while (!ctxt.is(':') && !ctxt.isNewLine() && !ctxt.is(ReadContext::Traits::endOfInput()) &&
                 !ctxt.is(ReadContext::Traits::error()));
        if (ctxt.is(ReadContext::Traits::error()))
        {
            throw Id::LexicalErrorException(__FILE__, __LINE__, Ego::Script::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                            "read error");
        }
        if (ctxt.is(ReadContext::Traits::endOfInput()))
        {
            return false;
        }
        if (!ctxt.is(':'))
        {
            throw Id::LexicalErrorException(__FILE__, __LINE__, Ego::Script::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                            "expected `:`");
        }
        ctxt.next();

        info.spawn_comment = Ego::trim_ws(ctxt._buffer.toString());      
       
        info.do_spawn = true;

        vfs_read_string_lit(ctxt, info.spawn_name);

        info.pname = &(info.spawn_name);
        if (info.spawn_name == "NONE")
        {
            // A random name is selected.
            info.pname = nullptr;
        }

        info.slot = ctxt.readIntegerLiteral();

        info.pos[kX] = ctxt.readRealLiteral() * Info<float>::Grid::Size();
        info.pos[kY] = ctxt.readRealLiteral() * Info<float>::Grid::Size();
        info.pos[kZ] = ctxt.readRealLiteral() * Info<float>::Grid::Size();

        info.facing = Facing::FACE_NORTH;
        info.attach = ATTACH_NONE;
        char chr = ctxt.readPrintable();
        switch (Ego::toupper(chr))
        {
            case 'S': info.facing = Facing::FACE_SOUTH;       break;
            case 'E': info.facing = Facing::FACE_EAST;        break;
            case 'W': info.facing = Facing::FACE_WEST;        break;
            case 'N': info.facing = Facing::FACE_NORTH;       break;
            case '?': info.facing = Facing(FACE_RANDOM);      break;
            case 'L': info.attach = ATTACH_LEFT;      break;
            case 'R': info.attach = ATTACH_RIGHT;     break;
            case 'I': info.attach = ATTACH_INVENTORY; break;
            default:
            {
                throw Id::SyntacticalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                                    "invalid enumeration element");
            }
        };
        info.money = ctxt.readIntegerLiteral();

        //If the skin type is a '?' character then it means random skin else it's an integer
        ctxt.skipWhiteSpaces();
        if(ctxt.is('?')) {
            info.skin = ObjectProfile::NO_SKIN_OVERRIDE;
            ctxt.next();
        }
        else {
            info.skin = ctxt.readIntegerLiteral();
        }

        info.passage = ctxt.readIntegerLiteral();
        info.content = ctxt.readIntegerLiteral();
        info.level = ctxt.readIntegerLiteral();
        info.stat = ctxt.readBool();

        ctxt.readPrintable();   ///< BAD! Unused ghost value

        chr = ctxt.readPrintable();
        info.team = (chr - 'A') % Team::TEAM_MAX;
        
        return true;
    }
    else if (ctxt.is('#'))
    {
        ctxt.next();
        info.do_spawn = false;

        std::string what = ctxt.readName();
        if (what != "dependency")
        {
            throw Id::SyntacticalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(),ctxt.getLineNumber()),
                                                "syntax error");
        }
        std::string who;
        ctxt.skipWhiteSpaces();
        if (ctxt.is('%'))
        {
            who = ctxt.readReference();
        }
        else
        {
            who = ctxt.readName();
        }
        if (who.empty()) /// @todo Verify that this is unnecessary based on the definition of readName.
        {
            throw Id::SyntacticalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                                "syntax error");
        }
        int slot = ctxt.readIntegerLiteral();
        // Store the data.
        info.spawn_comment = who;
        info.slot = slot;
        return true;
    }
    else if (!ctxt.is(ReadContext::Traits::endOfInput()))
    {
        throw Id::LexicalErrorException(__FILE__, __LINE__, Id::Location(ctxt.getFileName(), ctxt.getLineNumber()),
                                        "junk after end of spawn file");
    }
    return false;
}