Exemple #1
0
void load(fs_t& fs) {
    // this is just some silly test code - find a random model
    std::auto_ptr<techtrees_t> techtrees(new techtrees_t(fs));
    const strings_t techtrees_ = techtrees->get_techtrees();
    const std::string techtree_ = techtrees_[rand()%techtrees_.size()];
    techtree.reset(new techtree_t(fs,techtree_));
    const strings_t factions = techtree->get_factions();
    const std::string faction_ = factions[rand()%factions.size()];
    faction_t& faction = techtree->get_faction(faction_);
    const strings_t units = fs.list_dirs(faction.path+"/units");
    const std::string unit_ = units[rand()%units.size()];
    const std::string unit = faction.path+"/units/"+unit_;
    const std::string xml_name = unit+"/"+unit_+".xml";
    const strings_t models = fs.list_files(unit+"/models");
    std::string g3d;
    for(strings_t::const_iterator i=models.begin(); i!=models.end(); i++)
        if(i->find(".g3d") == (i->size()-4)) {
            g3d = unit + "/models/" + *i;
            break;
        }
    if(!g3d.size()) data_error("no G3D models in "<<unit<<"/models");
    std::cout << "loading "<<g3d<<std::endl;
    fs_file_t::ptr_t g3d_file(fs.get(g3d));
    istream_t::ptr_t gstream(g3d_file->reader());
    model = std::auto_ptr<model_g3d_t>(new model_g3d_t(*gstream));
    // and load it
    std::cout << "loading "<<xml_name<<std::endl;
    fs_file_t::ptr_t xml_file(fs.get(xml_name));
    istream_t::ptr_t xstream(xml_file->reader());
    unit_type = std::auto_ptr<unit_type_t>(new unit_type_t(faction,unit_));
    unit_type->load_xml(*xstream);
    //new ui_xml_editor_t(*unit_type);
}
Exemple #2
0
bool LoadSolutionRebus(Puzzle * puz,
                       const std::string & table,
                       const std::string & grid)
{
    // NB: In the grid rebus section (GRBS), the index is 1 greater than the
    // index in the rebus table section (RTBL).

    if (grid.size() !=  puz->GetGrid().GetWidth() * puz->GetGrid().GetHeight())
        return false;

    // Read the rebus table (RTBL)
    // Format: index ':' string ';'
    //   - Index is a number, padded to two digits with a space if needed.
    std::map<unsigned char, std::string> rebusTable;

    std::istringstream tstream(table);
    istream_wrapper table_stream(tstream);

    for (;;)
    {
        std::string key;

        // Read the index
        try {
            key = table_stream.ReadString(':');
        }
        catch(std::ios::failure &) {
            break;
        }

        int index = atoi(key.c_str());
        if (index == 0 && key != " 0")
            return false;

        // The index value in the rebus-table section is 1 less than the
        // index in the grid-rebus, so we need add 1 here.
        ++index;

        std::string value = table_stream.ReadString(';');

        rebusTable[static_cast<unsigned char>(index)] = value;
    }
    if (! table_stream.CheckEof())
        return false;


    // Set the grid rebus solution
    std::istringstream gstream(grid);
    istream_wrapper grid_stream(gstream);

    for (Square * square = puz->GetGrid().First();
         square != NULL;
         square = square->Next())
    {
        const unsigned char index = grid_stream.ReadChar();
        if (index > 0)
        {
            // Look for this index in the rebus table
            std::map<unsigned char, std::string>::const_iterator it;
            it = rebusTable.find(index);
            if (it == rebusTable.end())
                return false;

            // Don't overwrite the plain solution
            square->SetSolutionRebus(decode_puz(it->second));
        }
    }
    if (! grid_stream.CheckEof())
        return false;
    return true;
}