///// overmap legacy deserialization, replaced with json serialization June 2015 // throws std::exception (most likely as JsonError) void overmap::unserialize_legacy(std::istream & fin) { // DEBUG VARS int nummg = 0; char datatype; int cx, cy, cz, cs, cp, cd, cdying, horde, tx, ty, intr; std::string cstr; city tmp; std::list<item> npc_inventory; if ( fin.peek() == '#' ) { std::string vline; getline(fin, vline); } int z = 0; // assumption while (fin >> datatype) { if (datatype == 'L') { // Load layer data, and switch to layer fin >> z; std::string tmp_ter; oter_id tmp_otid(0); if (z >= 0 && z < OVERMAP_LAYERS) { int count = 0; std::unordered_map<tripoint, std::string> needs_conversion; for (int j = 0; j < OMAPY; j++) { for (int i = 0; i < OMAPX; i++) { if (count == 0) { fin >> tmp_ter >> count; if( obsolete_terrain( tmp_ter ) ) { for( int p = i; p < i+count; p++ ) { needs_conversion.emplace( tripoint( p, j, z-OVERMAP_DEPTH ), tmp_ter ); } tmp_otid = oter_id( 0 ); } else if( oter_str_id( tmp_ter ).is_valid() ) { tmp_otid = oter_id( tmp_ter ); } else if( tmp_ter.compare( 0, 7, "mall_a_" ) == 0 && oter_str_id( tmp_ter + "_north" ).is_valid() ) { tmp_otid = oter_id( tmp_ter + "_north" ); } else if( tmp_ter.compare( 0, 13, "necropolis_a_" ) == 0 && oter_str_id( tmp_ter + "_north" ).is_valid() ) { tmp_otid = oter_id( tmp_ter + "_north" ); } else { debugmsg("Loaded bad ter! ter %s", tmp_ter.c_str()); tmp_otid = oter_id( 0 ); } } count--; layer[z].terrain[i][j] = tmp_otid; //otermap[tmp_ter].loadid; layer[z].visible[i][j] = false; } } convert_terrain( needs_conversion ); } else {
static int max_upgrade_by_type( const std::string &type ) { int max = -1; const std::string faction_base = faction_encode( type ); while( oter_str_id( faction_base + to_string( max + 1 ) ).is_valid() ) { max += 1; } return max; }
std::string recipe::get_consistency_error() const { if( !item::type_is_defined( result_ ) && category != "CC_BUILDING" ) { return "defines invalid result"; } if( category == "CC_BUILDING" && !oter_str_id( result_.c_str() ).is_valid() ) { return "defines invalid result"; } if( charges >= 0 && !item::count_by_charges( result_ ) ) { return "specifies charges but result is not counted by charges"; } const auto is_invalid_bp = []( const std::pair<itype_id, int> &elem ) { return !item::type_is_defined( elem.first ); }; if( std::any_of( byproducts.begin(), byproducts.end(), is_invalid_bp ) ) { return "defines invalid byproducts"; } if( !contained && container != "null" ) { return "defines container but not contained"; } if( !item::type_is_defined( container ) ) { return "specifies unknown container"; } const auto is_invalid_skill = []( const std::pair<skill_id, int> &elem ) { return !elem.first.is_valid(); }; if( ( skill_used && !skill_used.is_valid() ) || std::any_of( required_skills.begin(), required_skills.end(), is_invalid_skill ) ) { return "uses invalid skill"; } const auto is_invalid_book = []( const std::pair<itype_id, int> &elem ) { return !item::find_type( elem.first )->book; }; if( std::any_of( booksets.begin(), booksets.end(), is_invalid_book ) ) { return "defines invalid book"; } return std::string(); }
// recipes and craft support functions std::map<std::string, std::string> basecamp::recipe_deck( const std::string &dir ) const { if( dir == "ALL" || dir == "COOK" || dir == "BASE" || dir == "FARM" || dir == "SMITH" ) { return recipe_group::get_recipes( dir ); } std::map<std::string, std::string> cooking_recipes; auto e = expansions.find( dir ); if( e == expansions.end() ) { return cooking_recipes; } const std::string building = faction_encode( e->second.type ); int building_max = max_upgrade_by_type( e->second.type ); for( int building_cur = e->second.cur_level; building_cur <= building_max; building_cur++ ) { const std::string building_level = building + to_string( building_cur ); if( !oter_str_id( building_level ) ) { continue; } std::map<std::string, std::string> test_s = recipe_group::get_recipes( building_level ); cooking_recipes.insert( test_s.begin(), test_s.end() ); } return cooking_recipes; }