HCI::optional HCI::getConnHandle(device &dev) { conn_info info; info.req.conn_num = 1; info.req.dev_id = _dev_id; if(ioctl(_hci_sock, HCIGETCONNLIST, &info) < 0) { err::code = err::LIB_SYS; return optional(); } uint16_t handle; for(hci_conn_info &x: info.info) { if(bacmp(&x.bdaddr, &dev.bdaddr) == 0) { handle = x.handle; return optional(handle); } } return optional(); }
static fb_metadata_t *parse_metadata(fb_parser_t *P) { fb_token_t *t, *t0; fb_metadata_t *md = 0; if (!(t0 = optional(P, '('))) { return 0; } if ((t = optional(P, LEX_TOK_ID))) for (;;) { fb_add_metadata(P, &md); md->ident = t; if (optional(P, ':')) { parse_value(P, &md->value, allow_string_value, "scalar or string value expected"); } if (P->failed >= FLATCC_MAX_ERRORS) { return md; } if (!optional(P, ',')) { break; } if (!(t = match(P, LEX_TOK_ID, "attribute name expected identifier after ','"))) { break; } } advance(P, ')', "metadata expected ')' to match", t0); revert_metadata(&md); return md; }
void furn_t::load( JsonObject &jo ) { mandatory( jo, was_loaded, "name", name, translated_string_reader ); mandatory( jo, was_loaded, "move_cost_mod", movecost ); mandatory( jo, was_loaded, "required_str", move_str_req ); optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE ); optional( jo, was_loaded, "crafting_pseudo_item", crafting_pseudo_item, "" ); load_symbol( jo ); transparent = false; for( auto & flag : jo.get_string_array( "flags" ) ) { set_flag( flag ); } if( jo.has_member( "examine_action" ) ) { examine = iexamine_function_from_string( jo.get_string( "examine_action" ) ); } else { examine = iexamine_function_from_string( "none" ); } optional( jo, was_loaded, "open", open, string_id_reader<furn_t> {}, NULL_ID ); optional( jo, was_loaded, "close", close, string_id_reader<furn_t> {}, NULL_ID ); bash.load( jo, "bash", true ); deconstruct.load( jo, "deconstruct", true ); }
bool dto_complex::parse( const rapidjson::Value& json ) { if( json.IsObject() && json.HasMember( key() ) && json[key()].IsObject() ) { for( auto& child : get_children() ) { child->set_client( client() ); if( !child->parse( json[key()] ) && !optional() ) { return false; } } return true; } else if( json.IsObject() ) { for( auto& child : get_children() ) { child->set_client( client() ); if( !child->parse( json ) && !optional() ) { return false; } } return true; } set_present( false ); return optional(); }
/* `enum` must already be matched. */ static void parse_enum_decl(fb_parser_t *P, fb_compound_type_t *ct) { fb_token_t *t, *t0; fb_member_t *member; if (!(ct->symbol.ident = match(P, LEX_TOK_ID, "enum declaration expected identifier"))) { goto fail; } if (optional(P, ':')) { parse_type(P, &ct->type); if (ct->type.type != vt_scalar_type) { error_tok(P, ct->type.t, "integral type expected"); } else { switch (ct->type.t->id) { case tok_kw_float: case tok_kw_double: error_tok(P, ct->type.t, "integral type expected"); default: break; } } } ct->metadata = parse_metadata(P); if (!((t0 = match(P, '{', "enum declaration expected '{'")))) { goto fail; } for (;;) { if (!(t = match(P, LEX_TOK_ID, "member identifier expected"))) { goto fail; } if (P->failed >= FLATCC_MAX_ERRORS) { goto fail; } member = fb_add_member(P, &ct->members); member->symbol.ident = t; if (optional(P, '=')) { t = P->token; parse_value(P, &member->value, 0, "integral constant expected"); /* Leave detailed type (e.g. no floats) and range checking to a later stage. */ } /* * Trailing comma is optional in flatc but not in grammar, we * follow flatc. */ if (!optional(P, ',') || P->token->id == '}') { break; } P->doc = 0; } if (t0) { advance(P, '}', "enum missing closing '}' to match", t0); } revert_symbols(&ct->members); return; fail: recover(P, '}', 1); }
/* ':' must already be matched */ static void parse_type(fb_parser_t *P, fb_value_t *v) { fb_token_t *t = 0; fb_token_t *t0 = P->token; int vector = 0; v->type = vt_invalid; while ((t = optional(P, '['))) { ++vector; } if (vector > 1) { error_tok(P, t0, "vector type can only be one-dimensional"); } switch (P->token->id) { case tok_kw_int: case tok_kw_bool: case tok_kw_byte: case tok_kw_long: case tok_kw_uint: case tok_kw_float: case tok_kw_short: case tok_kw_ubyte: case tok_kw_ulong: case tok_kw_ushort: case tok_kw_double: v->t = P->token; v->type = vector ? vt_vector_type : vt_scalar_type; next(P); break; case tok_kw_string: v->t = P->token; v->type = vector ? vt_vector_string_type : vt_string_type; next(P); break; case LEX_TOK_ID: parse_ref(P, &v->ref); v->type = vector ? vt_vector_type_ref : vt_type_ref; break; case ']': error_tok(P, t, "vector type cannot be empty"); break; default: error_tok(P, t, "invalid type specifier"); break; } while (optional(P, ']') && vector--) { } if (vector) { error_tok_2(P, t, "vector type missing ']' to match", t0); } if ((t = optional(P, ']'))) { error_tok_2(P, t, "extra ']' not matching", t0); while (optional(P, ']')) { } } }
void overmap_connection::subtype::load( JsonObject &jo ) { static const typed_flag_reader<decltype( connection_subtype_flag_map )> flag_reader{ connection_subtype_flag_map, "invalid connection subtype flag" }; mandatory( jo, false, "terrain", terrain ); mandatory( jo, false, "locations", locations ); optional( jo, false, "basic_cost", basic_cost, 0 ); optional( jo, false, "flags", flags, flag_reader ); }
void species_type::load( JsonObject &jo, const std::string & ) { const auto flag_reader = enum_flags_reader<m_flag> { "monster flag" }; optional( jo, was_loaded, "flags", flags, flag_reader ); const auto trigger_reader = enum_flags_reader<mon_trigger> { "monster trigger" }; optional( jo, was_loaded, "anger_triggers", anger, trigger_reader ); optional( jo, was_loaded, "placate_triggers", placate, trigger_reader ); optional( jo, was_loaded, "fear_triggers", fear, trigger_reader ); }
void profession::load( JsonObject &jo, const std::string & ) { //If the "name" is an object then we have to deal with gender-specific titles, if( jo.has_object( "name" ) ) { JsonObject name_obj = jo.get_object( "name" ); _name_male = pgettext( "profession_male", name_obj.get_string( "male" ).c_str() ); _name_female = pgettext( "profession_female", name_obj.get_string( "female" ).c_str() ); } else if( jo.has_string( "name" ) ) { // Same profession names for male and female in English. // Still need to different names in other languages. const std::string name = jo.get_string( "name" ); _name_female = pgettext( "profession_female", name.c_str() ); _name_male = pgettext( "profession_male", name.c_str() ); } else if( !was_loaded ) { jo.throw_error( "missing mandatory member \"name\"" ); } if( !was_loaded || jo.has_member( "description" ) ) { const std::string desc = jo.get_string( "description" ); // These also may differ depending on the language settings! _description_male = pgettext( "prof_desc_male", desc.c_str() ); _description_female = pgettext( "prof_desc_female", desc.c_str() ); } mandatory( jo, was_loaded, "points", _point_cost ); if( !was_loaded || jo.has_member( "items" ) ) { JsonObject items_obj = jo.get_object( "items" ); if( items_obj.has_array( "both" ) ) { optional( items_obj, was_loaded, "both", legacy_starting_items, item_reader {} ); } if( items_obj.has_object( "both" ) ) { _starting_items = item_group::load_item_group( *items_obj.get_raw( "both" ), "collection" ); } if( items_obj.has_array( "male" ) ) { optional( items_obj, was_loaded, "male", legacy_starting_items_male, item_reader {} ); } if( items_obj.has_object( "male" ) ) { _starting_items_male = item_group::load_item_group( *items_obj.get_raw( "male" ), "collection" ); } if( items_obj.has_array( "female" ) ) { optional( items_obj, was_loaded, "female", legacy_starting_items_female, item_reader {} ); } if( items_obj.has_object( "female" ) ) { _starting_items_female = item_group::load_item_group( *items_obj.get_raw( "female" ), "collection" ); } } optional( jo, was_loaded, "no_bonus", no_bonus ); optional( jo, was_loaded, "skills", _starting_skills, skilllevel_reader {} ); optional( jo, was_loaded, "addictions", _starting_addictions, addiction_reader {} ); // TODO: use string_id<bionic_type> or so optional( jo, was_loaded, "CBMs", _starting_CBMs, auto_flags_reader<bionic_id> {} ); // TODO: use string_id<mutation_branch> or so optional( jo, was_loaded, "traits", _starting_traits, auto_flags_reader<trait_id> {} ); optional( jo, was_loaded, "flags", flags, auto_flags_reader<> {} ); }
void species_type::load( JsonObject &jo ) { MonsterGenerator &gen = MonsterGenerator::generator(); const typed_flag_reader<decltype( gen.flag_map )> flag_reader{ gen.flag_map, "invalid monster flag" }; optional( jo, was_loaded, "flags", flags, flag_reader ); const typed_flag_reader<decltype( gen.trigger_map )> trigger_reader{ gen.trigger_map, "invalid monster trigger" }; optional( jo, was_loaded, "anger_triggers", anger_trig, trigger_reader ); optional( jo, was_loaded, "placate_triggers", placate_trig, trigger_reader ); optional( jo, was_loaded, "fear_triggers", fear_trig, trigger_reader ); }
void mission_type::load( JsonObject &jo, const std::string & ) { mandatory( jo, was_loaded, "name", name, translated_string_reader ); mandatory( jo, was_loaded, "difficulty", difficulty ); mandatory( jo, was_loaded, "value", value ); auto djo = jo.get_object( "dialogue" ); // @todo There should be a cleaner way to do it mandatory( djo, was_loaded, "describe", dialogue[ "describe" ] ); mandatory( djo, was_loaded, "offer", dialogue[ "offer" ] ); mandatory( djo, was_loaded, "accepted", dialogue[ "accepted" ] ); mandatory( djo, was_loaded, "rejected", dialogue[ "rejected" ] ); mandatory( djo, was_loaded, "advice", dialogue[ "advice" ] ); mandatory( djo, was_loaded, "inquire", dialogue[ "inquire" ] ); mandatory( djo, was_loaded, "success", dialogue[ "success" ] ); mandatory( djo, was_loaded, "success_lie", dialogue[ "success_lie" ] ); mandatory( djo, was_loaded, "failure", dialogue[ "failure" ] ); optional( jo, was_loaded, "urgent", urgent ); optional( jo, was_loaded, "item", item_id ); optional( jo, was_loaded, "count", item_count, 1 ); goal = jo.get_enum_value<decltype(goal)>( "goal" ); assign_function( jo, "place", place, tripoint_function_map ); assign_function( jo, "start", start, mission_function_map ); assign_function( jo, "end", end, mission_function_map ); assign_function( jo, "fail", fail, mission_function_map ); if( jo.has_int( "deadline_low" ) ) { deadline_low = DAYS( jo.get_int( "deadline_low" ) ); } if( jo.has_int( "deadline_high" ) ) { deadline_high = DAYS( jo.get_int( "deadline_high" ) ); } if( jo.has_member( "origins" ) ) { origins.clear(); for( auto &m : jo.get_tags( "origins" ) ) { origins.emplace_back( io::string_to_enum_look_up( io::origin_map, m ) ); } } if( jo.has_member( "followup" ) ) { follow_up = mission_type_id( jo.get_string( "followup" ) ); } if( jo.has_member( "destination" ) ) { target_id = oter_id( jo.get_string( "destination" ) ); } }
// Command line parsing std::pair<bool, etix::tool::opt_parse> parse_cmdline(int argc, char* argv[]) { auto opt_parse = etix::tool::opt_parse{ argc, argv }; opt_parse.optional("-c", "Path to the configuration file (-c /path/to/conf)", true); opt_parse.optional("-l", "Set log level (-l 4 will only show warnings and errors)", true); opt_parse.optional("-d", "Launch the discovery tool on the given subnet", false); opt_parse.optional("-b", "Launch the bruteforce tool on all discovered devices", false); opt_parse.optional("-t", "Generate thumbnails from detected cameras", false); opt_parse.optional("-g", "Check if the stream can be opened with GStreamer", false); opt_parse.optional("-v", "Display Cameradar's version", false); opt_parse.optional("-h", "Display this help", false); opt_parse.execute(); if (opt_parse.exist("-h")) { opt_parse.print_help(); return std::make_pair(false, opt_parse); } else if (opt_parse.exist("-v")) { print_version(); return std::make_pair(false, opt_parse); } else if (opt_parse.has_error()) { std::cout << "Usage: ./cameradar [option]\n\toptions:\n" << std::endl; opt_parse.print_help(); return std::make_pair(false, opt_parse); } return std::make_pair(true, opt_parse); }
void material_type::load( JsonObject &jsobj ) { mandatory( jsobj, was_loaded, "name", _name, translated_string_reader ); mandatory( jsobj, was_loaded, "bash_resist", _bash_resist ); mandatory( jsobj, was_loaded, "cut_resist", _cut_resist ); mandatory( jsobj, was_loaded, "acid_resist", _acid_resist ); mandatory( jsobj, was_loaded, "elec_resist", _elec_resist ); mandatory( jsobj, was_loaded, "fire_resist", _fire_resist ); mandatory( jsobj, was_loaded, "chip_resist", _chip_resist ); mandatory( jsobj, was_loaded, "density", _density ); optional( jsobj, was_loaded, "salvaged_into", _salvaged_into, "null" ); optional( jsobj, was_loaded, "repaired_with", _repaired_with, "null" ); optional( jsobj, was_loaded, "edible", _edible, false ); optional( jsobj, was_loaded, "soft", _soft, false ); auto arr = jsobj.get_array( "vitamins" ); while( arr.has_more() ) { auto pair = arr.next_array(); _vitamins.emplace( vitamin_id( pair.get_string( 0 ) ), pair.get_float( 1 ) ); } mandatory( jsobj, was_loaded, "bash_dmg_verb", _bash_dmg_verb, translated_string_reader ); mandatory( jsobj, was_loaded, "cut_dmg_verb", _cut_dmg_verb, translated_string_reader ); JsonArray jsarr = jsobj.get_array( "dmg_adj" ); while( jsarr.has_more() ) { _dmg_adj.push_back( _( jsarr.next_string().c_str() ) ); } JsonArray burn_data_array = jsobj.get_array( "burn_data" ); for( size_t intensity = 0; intensity < MAX_FIELD_DENSITY; intensity++ ) { if( burn_data_array.has_more() ) { JsonObject brn = burn_data_array.next_object(); _burn_data[ intensity ] = load_mat_burn_data( brn ); } else { // If not specified, supply default bool flammable = _fire_resist <= ( int )intensity; mat_burn_data mbd; if( flammable ) { mbd.burn = 1; } _burn_data[ intensity ] = mbd; } } }
/* `union` must already be matched. */ static void parse_union_decl(fb_parser_t *P, fb_compound_type_t *ct) { fb_token_t *t0; fb_member_t *member; fb_ref_t *ref; if (!(ct->symbol.ident = match(P, LEX_TOK_ID, "union declaration expected identifier"))) { goto fail; } ct->metadata = parse_metadata(P); if (!((t0 = match(P, '{', "union declaration expected '{'")))) { goto fail; } for (;;) { if (P->token->id != LEX_TOK_ID) { error_tok(P, P->token, "union expects an identifier"); goto fail; } if (P->failed >= FLATCC_MAX_ERRORS) { goto fail; } member = fb_add_member(P, &ct->members); parse_ref(P, &ref); member->type.ref = ref; member->type.type = vt_type_ref; while (ref->link) { ref = ref->link; } /* The union member is the unqualified reference. */ member->symbol.ident = ref->ident; if (optional(P, '=')) { parse_value(P, &member->value, 0, "integral constant expected"); /* Leave detailed type (e.g. no floats) and range checking to a later stage. */ } if (!optional(P, ',') || P->token->id == '}') { break; } P->doc = 0; } advance(P, '}', "union missing closing '}' to match", t0); revert_symbols(&ct->members); /* Add implicit `NONE` member first in the list. */ member = fb_add_member(P, &ct->members); member->symbol.ident = &P->t_none; return; fail: recover2(P, ';', 1, '}', 0); }
static void parse_method(fb_parser_t *P, fb_member_t *fld) { fb_token_t *t; if (!(t = match(P, LEX_TOK_ID, "method expected identifier"))) { goto fail; } fld->symbol.ident = t; if (!match(P, '(', "method expected '(' after identifier")) { goto fail; } parse_type(P, &fld->req_type); if (!match(P, ')', "method expected ')' after request type")) { goto fail; } if (!match(P, ':', "method expected ':' before mandatory response type")) { goto fail; } parse_type(P, &fld->type); if ((t = optional(P, '='))) { error_tok(P, t, "method does not accept an initializer"); goto fail; } fld->metadata = parse_metadata(P); advance(P, ';', "method must be terminated with ';'", 0); return; fail: recover2(P, ';', 1, '}', 0); }
/* `struct` or `table` must already be matched. */ static void parse_compound_type(fb_parser_t *P, fb_compound_type_t *ct) { fb_token_t *t = 0; if (!(t = match(P, LEX_TOK_ID, "Declaration expected an identifier"))) { goto fail; } ct->symbol.ident = t; ct->metadata = parse_metadata(P); if (!(match(P, '{', "Declaration expected '{'"))) { goto fail; } t = P->token; /* Allow empty tables and structs. */ #if 0 if (P->token->id == '}') { error_tok(P, t, "table / struct declaration cannot be empty"); } #endif while (P->token->id != '}') { parse_field(P, fb_add_member(P, &ct->members)); if (P->failed >= FLATCC_MAX_ERRORS) { goto fail; } } if (!optional(P, '}') && t) { error_tok_2(P, P->token, "Declaration missing closing '}' to match", t); } revert_symbols(&ct->members); return; fail: recover(P, '}', 1); }
static void ComplexDictionary::build(string name) { string buffer; while (cin >> buffer) { size_t index = -1; if (buffer.find("//") != string::npos) { if (index = buffer.find("&")) { reversal(buffer); } else if (index = buffer.find("[")) { size_t endIndex = buffer.find("]"); insertEach(buffer, index, endIndex); } else if (index = buffer.find("?")) { optional(buffer, index); } else if (index = buffer.find("!")) { swap(buffer, index); } else words.push_back(buffer); } } reverse(words.begin(), words.end()); }
static void parse_field(fb_parser_t *P, fb_member_t *fld) { fb_token_t *t; if (!(t = match(P, LEX_TOK_ID, "field expected identifier"))) { goto fail; } fld->symbol.ident = t; if (!match(P, ':', "field expected ':' before mandatory type")) { goto fail; } parse_type(P, &fld->type); if (optional(P, '=')) { /* * Because types can be named references, we do not check the * default assignment before the schema is fully parsed. * We allow the initializer to be a name in case it is an enum * name. */ parse_value(P, &fld->value, allow_id_value, "initializer must be of scalar type"); } fld->metadata = parse_metadata(P); advance(P, ';', "field must be terminated with ';'", 0); return; fail: recover2(P, ';', 1, '}', 0); }
PrologLexer::PrologLexer() { lexer.rules[Prolog::Spacing] = loop1(charOf(" \t\n\r")); lexer.rules[Prolog::LParen] = str("("); lexer.rules[Prolog::RParen] = str(")"); lexer.rules[Prolog::LBracket] = str("["); lexer.rules[Prolog::RBracket] = str("]"); lexer.rules[Prolog::OnlyIf] = str(":-"); lexer.rules[Prolog::Eq] = str("="); /* lexer.rules[Prolog::Lt] = str("<"); lexer.rules[Prolog::Gt] = str(">"); lexer.rules[Prolog::Le] = str("<="); lexer.rules[Prolog::Ge] = str(">="); lexer.rules[Prolog::Ne] = str("<>"); */ lexer.rules[Prolog::Dot] = str("."); lexer.rules[Prolog::Comma] = str(","); lexer.rules[Prolog::Semi] = str(";"); lexer.rules[Prolog::Bar] = str("|"); lexer.rules[Prolog::DomainsKw] = str("domains"); lexer.rules[Prolog::PredicatesKw] = str("predicates"); lexer.rules[Prolog::ClausesKw] = str("clauses"); lexer.rules[Prolog::AssertKw] = str("assert"); lexer.rules[Prolog::Str] = seq(str("\""), loop(anyBut(choice(str("\""), str("\n")))), str("\"")); shared_ptr<RegExp> digit = charIs([](QChar c) { return c.isDigit(); },"<digit>"); shared_ptr<RegExp> letter = charIs([](QChar c) { return c.isLetter(); }, "<letter>"); shared_ptr<RegExp> smallLetter = charIs([](QChar c) { return c.isLower(); }, "<lowercase>"); shared_ptr<RegExp> capitalLetter = charIs([](QChar c) { return c.isUpper(); }, "<uppercase>"); shared_ptr<RegExp> alpha = charIs([](QChar c) { return c.isLetterOrNumber(); },"<alphanumeric>"); shared_ptr<RegExp> symbol = charOf("+-/*<>="); shared_ptr<RegExp> digits = seq(loop1(digit), checkNo(letter)); shared_ptr<RegExp> smallLetterOrSymbol = choice(smallLetter, symbol); shared_ptr<RegExp> alphaOrUnderscore = choice(alpha, str("_")); shared_ptr<RegExp> alphaOrSymbol= choice(alpha, symbol); lexer.rules[Prolog::Num] = seq(digits, optional(seq(str("."), digits))); lexer.rules[Prolog::Symbol] = seq(smallLetterOrSymbol, loop(choice(digit, alphaOrSymbol))); lexer.rules[Prolog::Variable] = seq(choice(capitalLetter, str("_")), loop(choice(digit, alphaOrUnderscore))); }
void morale_type_data::load( JsonObject &jo, const std::string & ) { mandatory( jo, was_loaded, "id", id ); mandatory( jo, was_loaded, "text", text, translated_string_reader ); optional( jo, was_loaded, "permanent", permanent, false ); needs_item = text.find( "%s" ) != std::string::npos; }
StorageType Type::storageType() const { if (forceBox_ || requiresBox()) { return StorageType::Box; } if (type() == TypeType::Error) { return StorageType::SimpleOptional; } return optional() ? StorageType::SimpleOptional : StorageType::Simple; }
SecCFObject * SecCFObject::required(CFTypeRef cfTypeRef, OSStatus error) { SecCFObject *object = optional(cfTypeRef); if (!object) MacOSError::throwMe(error); return object; }
static void parse_value(fb_parser_t *P, fb_value_t *v, int flags, const char *error_msg) { fb_token_t *t; fb_token_t *sign; sign = optional(P, '-'); t = P->token; switch (t->id) { case LEX_TOK_INT: read_integer_value(P, t, v, sign != 0); break; case LEX_TOK_FLOAT: read_float_value(P, t, v, sign != 0); break; case tok_kw_true: v->b = 1; v->type = vt_bool; break; case tok_kw_false: v->b = 0; v->type = vt_bool; break; case LEX_TOK_STRING_BEGIN: next(P); parse_string_literal(P, v); if (!(flags & allow_string_value)) { v->type = vt_invalid; error_tok(P, t, error_msg); return; } if (sign) { v->type = vt_invalid; error_tok(P, t, "string constants cannot be signed"); return; } return; case LEX_TOK_ID: parse_ref(P, &v->ref); v->type = vt_name_ref; if (sign) { v->type = vt_invalid; /* Technically they could, but we do not allow it. */ error_tok(P, t, "named values cannot be signed"); } return; default: /* We might have consumed a sign, but never mind that. */ error_tok(P, t, error_msg); return; } if (sign && v->type == vt_bool) { v->type = vt_invalid; error_tok(P, t, "boolean constants cannot be signed"); } next(P); }
void npc_class::load( JsonObject &jo, const std::string & ) { mandatory( jo, was_loaded, "name", name, translated_string_reader ); mandatory( jo, was_loaded, "job_description", job_description, translated_string_reader ); optional( jo, was_loaded, "common", common, true ); bonus_str = load_distribution( jo, "bonus_str" ); bonus_dex = load_distribution( jo, "bonus_dex" ); bonus_int = load_distribution( jo, "bonus_int" ); bonus_per = load_distribution( jo, "bonus_per" ); optional( jo, was_loaded, "shopkeeper_item_group", shopkeeper_item_group, "EMPTY_GROUP" ); optional( jo, was_loaded, "worn_override", worn_override ); optional( jo, was_loaded, "carry_override", carry_override ); optional( jo, was_loaded, "weapon_override", weapon_override ); if( jo.has_array( "traits" ) ) { JsonArray jarr = jo.get_array( "traits" ); while( jarr.has_more() ) { JsonArray jarr_in = jarr.next_array(); traits[ trait_id( jarr_in.get_string( 0 ) ) ] = jarr_in.get_int( 1 ); } } if( jo.has_array( "skills" ) ) { JsonArray jarr = jo.get_array( "skills" ); while( jarr.has_more() ) { JsonObject skill_obj = jarr.next_object(); auto skill_ids = skill_obj.get_tags( "skill" ); if( skill_obj.has_object( "level" ) ) { distribution dis = load_distribution( skill_obj, "level" ); for( const auto &sid : skill_ids ) { skills[ skill_id( sid ) ] = dis; } } else { distribution dis = load_distribution( skill_obj, "bonus" ); for( const auto &sid : skill_ids ) { bonus_skills[ skill_id( sid ) ] = dis; } } } } }
void trap::load( JsonObject &jo, const std::string & ) { mandatory( jo, was_loaded, "id", id ); mandatory( jo, was_loaded, "name", name_ ); if( !assign( jo, "color", color ) ) { jo.throw_error( "missing mandatory member \"color\"" ); } mandatory( jo, was_loaded, "symbol", sym, one_char_symbol_reader ); mandatory( jo, was_loaded, "visibility", visibility ); mandatory( jo, was_loaded, "avoidance", avoidance ); mandatory( jo, was_loaded, "difficulty", difficulty ); // @todo Is there a generic_factory version of this? act = trap_function_from_string( jo.get_string( "action" ) ); optional( jo, was_loaded, "benign", benign, false ); optional( jo, was_loaded, "funnel_radius", funnel_radius_mm, 0 ); assign( jo, "trigger_weight", trigger_weight ); optional( jo, was_loaded, "drops", components ); }
void ma_requirements::load( JsonObject &jo, const std::string & ) { optional( jo, was_loaded, "unarmed_allowed", unarmed_allowed, false ); optional( jo, was_loaded, "melee_allowed", melee_allowed, false ); optional( jo, was_loaded, "req_buffs", req_buffs, auto_flags_reader<mabuff_id>{} ); optional( jo, was_loaded, "req_flags", req_flags, auto_flags_reader<>{} ); optional( jo, was_loaded, "strictly_unarmed", strictly_unarmed, false ); // TODO: De-hardcode the skills and damage types here add_if_exists( jo, min_skill, was_loaded, "min_melee", skill_melee ); add_if_exists( jo, min_skill, was_loaded, "min_unarmed", skill_unarmed ); add_if_exists( jo, min_skill, was_loaded, "min_bashing", skill_bashing ); add_if_exists( jo, min_skill, was_loaded, "min_cutting", skill_cutting ); add_if_exists( jo, min_skill, was_loaded, "min_stabbing", skill_stabbing ); add_if_exists( jo, min_damage, was_loaded, "min_bashing_damage", DT_BASH ); add_if_exists( jo, min_damage, was_loaded, "min_cutting_damage", DT_CUT ); add_if_exists( jo, min_damage, was_loaded, "min_stabbing_damage", DT_STAB ); }
void ter_t::load( JsonObject &jo, const std::string &src ) { map_data_common_t::load( jo, src ); mandatory( jo, was_loaded, "name", name_ ); mandatory( jo, was_loaded, "move_cost", movecost ); optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE ); optional( jo, was_loaded, "trap", trap_id_str ); load_symbol( jo ); trap = tr_null; transparent = false; connect_group = TERCONN_NONE; for( auto &flag : jo.get_string_array( "flags" ) ) { set_flag( flag ); } // connect_group is initialized to none, then terrain flags are set, then finally // connections from JSON are set. This is so that wall flags can set wall connections // but can be overridden by explicit connections in JSON. if( jo.has_member( "connects_to" ) ) { set_connects( jo.get_string( "connects_to" ) ); } optional( jo, was_loaded, "open", open, ter_str_id::NULL_ID() ); optional( jo, was_loaded, "close", close, ter_str_id::NULL_ID() ); optional( jo, was_loaded, "transforms_into", transforms_into, ter_str_id::NULL_ID() ); optional( jo, was_loaded, "roof", roof, ter_str_id::NULL_ID() ); bash.load( jo, "bash", false ); deconstruct.load( jo, "deconstruct", false ); }
void ter_t::load( JsonObject &jo ) { mandatory( jo, was_loaded, "name", name, translated_string_reader ); mandatory( jo, was_loaded, "move_cost", movecost ); optional( jo, was_loaded, "max_volume", max_volume, MAX_VOLUME_IN_SQUARE ); optional( jo, was_loaded, "trap", trap_id_str ); load_symbol( jo ); trap = tr_null; transparent = false; connect_group = TERCONN_NONE; for( auto &flag : jo.get_string_array( "flags" ) ) { set_flag( flag ); } // connect_group is initialised to none, then terrain flags are set, then finally // connections from JSON are set. This is so that wall flags can set wall connections // but can be overridden by explicit connections in JSON. if( jo.has_member( "connects_to" ) ) { set_connects( jo.get_string( "connects_to" ) ); } if( jo.has_member( "examine_action" ) ) { examine = iexamine_function_from_string( jo.get_string( "examine_action" ) ); } else { examine = iexamine_function_from_string( "none" ); } optional( jo, was_loaded, "harvestable", harvestable ); optional( jo, was_loaded, "open", open, NULL_ID ); optional( jo, was_loaded, "close", close, NULL_ID ); optional( jo, was_loaded, "transforms_into", transforms_into, NULL_ID ); optional( jo, was_loaded, "roof", roof, NULL_ID ); if( jo.has_member("harvest_season") ) { const std::string season = jo.get_string( "harvest_season" ); if( season == "SPRING" ) { harvest_season = season_type::SPRING; } else if( season == "SUMMER" ) { harvest_season = season_type::SUMMER; } else if( season == "AUTUMN" ) { harvest_season = season_type::AUTUMN; } else if( season == "WINTER" ) { harvest_season = season_type::WINTER; } else { harvest_season = season_type::AUTUMN; debugmsg( "Invalid harvest season \"%s\" in \"%s\".", season.c_str(), id.c_str() ); } } bash.load( jo, "bash", false ); deconstruct.load( jo, "deconstruct", false ); }
void body_part_struct::load( JsonObject &jo, const std::string & ) { mandatory( jo, was_loaded, "id", id ); mandatory( jo, was_loaded, "name", name ); optional( jo, was_loaded, "name_plural", name_multiple ); mandatory( jo, was_loaded, "heading_singular", name_as_heading_singular ); mandatory( jo, was_loaded, "heading_plural", name_as_heading_multiple ); optional( jo, was_loaded, "hp_bar_ui_text", hp_bar_ui_text ); mandatory( jo, was_loaded, "encumbrance_text", encumb_text ); mandatory( jo, was_loaded, "hit_size", hit_size ); mandatory( jo, was_loaded, "hit_difficulty", hit_difficulty ); mandatory( jo, was_loaded, "hit_size_relative", hit_size_relative ); mandatory( jo, was_loaded, "legacy_id", legacy_id ); token = legacy_id_to_enum( legacy_id ); mandatory( jo, was_loaded, "main_part", main_part ); mandatory( jo, was_loaded, "opposite_part", opposite_part ); part_side = jo.get_enum_value<side>( "side" ); }
void furn_t::load( JsonObject &jo, const std::string &src ) { map_data_common_t::load( jo, src ); mandatory( jo, was_loaded, "name", name_ ); mandatory( jo, was_loaded, "move_cost_mod", movecost ); mandatory( jo, was_loaded, "required_str", move_str_req ); optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE ); optional( jo, was_loaded, "crafting_pseudo_item", crafting_pseudo_item, "" ); optional( jo, was_loaded, "deployed_item", deployed_item ); load_symbol( jo ); transparent = false; for( auto & flag : jo.get_string_array( "flags" ) ) { set_flag( flag ); } optional( jo, was_loaded, "open", open, string_id_reader<furn_t> {}, furn_str_id::NULL_ID() ); optional( jo, was_loaded, "close", close, string_id_reader<furn_t> {}, furn_str_id::NULL_ID() ); bash.load( jo, "bash", true ); deconstruct.load( jo, "deconstruct", true ); }