void recipe_dictionary::finalize() { DynamicDataLoader::get_instance().load_deferred( deferred ); // remove abstract recipes delete_if( []( const recipe & element ) { return element.abstract; } ); finalize_internal( recipe_dict.recipes ); finalize_internal( recipe_dict.uncraft ); for( auto &e : recipe_dict.recipes ) { auto &r = e.second; for( const auto &bk : r.booksets ) { const itype *booktype = item::find_type( bk.first ); int req = bk.second > 0 ? bk.second : std::max( booktype->book->req, r.difficulty ); islot_book::recipe_with_description_t desc{ &r, req, r.result_name(), false }; const_cast<islot_book &>( *booktype->book ).recipes.insert( desc ); } // if reversible and no specific uncraft recipe exists use this recipe if( r.reversible && !recipe_dict.uncraft.count( recipe_id( r.result() ) ) ) { recipe_dict.uncraft[ recipe_id( r.result() ) ] = r; } } // add pseudo uncrafting recipes for( const itype *e : item_controller->all() ) { const itype_id id = e->get_id(); const recipe_id rid = recipe_id( id ); // books that don't already have an uncrafting recipe if( e->book && !recipe_dict.uncraft.count( rid ) && e->volume > 0 ) { int pages = e->volume / units::from_milliliter( 12.5 ); auto &bk = recipe_dict.uncraft[rid]; bk.ident_ = rid; bk.result_ = id; bk.reversible = true; bk.requirements_ = *requirement_id( "uncraft_book" ) * pages; bk.time = pages * 10; // @todo: allow specifying time in requirement_data } } // Cache auto-learn recipes for( const auto &e : recipe_dict.recipes ) { if( e.second.autolearn ) { recipe_dict.autolearn.insert( &e.second ); } } }
void recipe_dictionary::finalize_internal( std::map<std::string, recipe> &obj ) { for( auto &elem : obj ) { elem.second.finalize(); } // remove any blacklisted or invalid recipes... delete_if( []( const recipe & elem ) { if( elem.is_blacklisted() ) { return true; } const std::string error = elem.get_consistency_error(); if( !error.empty() ) { debugmsg( "Recipe %s %s.", elem.ident().c_str(), error.c_str() ); } return !error.empty(); } ); }
int main(int argc, char **argv) { char *tun = NULL; char *dev_node = NULL; char *name = argv[0]; int opt, brief = 0, if_fd, ip_fd; operation_t op = NOP; while((opt = getopt(argc, argv, "bd:f:t:u:")) > 0){ switch(opt) { case 'b': brief = 1; break; case 'd': op = DELETE; tun = optarg; break; case 'f': dev_node = optarg; break; case 't': op = ADD; tun = optarg; break; case 'h': default: Usage(name); } } argv += optind; argc -= optind; if(argc > 0) Usage(name); if(tun == NULL) Usage(name); if(dev_node == NULL) dev_node = get_dev_node(tun); if ((ip_fd = open(IP_NODE, O_RDWR)) < 0){ perror("open"); fprintf(stderr,"Can't open %s\n", IP_NODE); exit(1); } if((if_fd = open(dev_node, O_RDWR)) < 0){ perror("open"); fprintf(stderr, "Can't open '%s'\n", dev_node); exit(1); } switch(op){ case(DELETE): delete_if(ip_fd, if_fd, tun); break; case(ADD): add_if(ip_fd, if_fd, tun, brief, dev_node); break; default: break; } close(ip_fd); close(if_fd); exit(0); }