本文整理汇总了C++中JsonObject::has_int方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::has_int方法的具体用法?C++ JsonObject::has_int怎么用?C++ JsonObject::has_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject::has_int方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
if( jsobj.has_object(member) ) {
JsonObject j = jsobj.get_object(member);
if ( jsonint(j, "num_tests", num_tests ) == false ) {
if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) {
num_tests = 1;
}
} else if ( num_tests > 0 ) {
str_min = j.get_int("str_min");
str_max = j.get_int("str_max");
}
jsonint(j, "str_min_blocked", str_min_blocked );
jsonint(j, "str_max_blocked", str_max_blocked );
jsonint(j, "str_min_roll", str_min_roll );
jsonint(j, "chance", chance );
jsonstring(j, "sound", sound );
jsonstring(j, "sound_fail", sound_fail );
if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) {
ter_set = "t_rubble";
debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() );
}
if ( j.has_array("items") ) {
JsonArray ja = j.get_array("items");
if (ja.size() > 0) {
int c=0;
while ( ja.has_more() ) {
if ( ja.has_object(c) ) {
JsonObject jio = ja.next_object();
if ( jio.has_string("item") && jio.has_int("amount") ) {
if ( jio.has_int("minamount") ) {
map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount"), jio.get_int("minamount") );
jsonint(jio, "chance", drop.chance);
items.push_back(drop);
} else {
map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount") );
jsonint(jio, "chance", drop.chance);
items.push_back(drop);
}
} else {
debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c);
}
} else {
debugmsg("terrain[\"%s\"].bash.items[%d]: invalid entry",jsobj.get_string("id").c_str(),c);
}
c++;
}
}
}
//debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() );
return true;
} else {
return false;
}
}
示例2: load
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" ) );
}
}
示例3: deserialize
void npc_favor::deserialize(JsonIn &jsin)
{
JsonObject jo = jsin.get_object();
type = npc_favor_type(jo.get_int("type"));
jo.read("value", value);
jo.read("itype_id", item_id);
skill = NULL;
if (jo.has_int("skill_id")) {
skill = Skill::skill(jo.get_int("skill_id"));
} else if (jo.has_string("skill_id")) {
skill = Skill::skill(jo.get_string("skill_id"));
}
}
示例4: load_map_bash_item_drop_list
void load_map_bash_item_drop_list(JsonArray ja, std::vector<map_bash_item_drop> &items) {
while ( ja.has_more() ) {
JsonObject jio = ja.next_object();
if ( jio.has_int("minamount") ) {
map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount"), jio.get_int("minamount") );
jsonint(jio, "chance", drop.chance);
items.push_back(drop);
} else {
map_bash_item_drop drop( jio.get_string("item"), jio.get_int("amount") );
jsonint(jio, "chance", drop.chance);
items.push_back(drop);
}
}
}
示例5: load
//.........这里部分代码省略.........
assign( jo, "charges", r.charges );
assign( jo, "result_mult", r.result_mult );
assign( jo, "skill_used", r.skill_used, strict );
if( jo.has_member( "skills_required" ) ) {
auto sk = jo.get_array( "skills_required" );
r.required_skills.clear();
if( sk.empty() ) {
// clear all requirements
} else if( sk.has_array( 0 ) ) {
// multiple requirements
while( sk.has_more() ) {
auto arr = sk.next_array();
r.required_skills[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 );
}
} else {
// single requirement
r.required_skills[skill_id( sk.get_string( 0 ) )] = sk.get_int( 1 );
}
}
// simplified autolearn sets requirements equal to required skills at finalization
if( jo.has_bool( "autolearn" ) ) {
assign( jo, "autolearn", r.autolearn );
} else if( jo.has_array( "autolearn" ) ) {
r.autolearn = true;
auto sk = jo.get_array( "autolearn" );
while( sk.has_more() ) {
auto arr = sk.next_array();
r.autolearn_requirements[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 );
}
}
if( jo.has_member( "decomp_learn" ) ) {
r.learn_by_disassembly.clear();
if( jo.has_int( "decomp_learn" ) ) {
if( !r.skill_used ) {
jo.throw_error( "decomp_learn specified with no skill_used" );
}
assign( jo, "decomp_learn", r.learn_by_disassembly[r.skill_used] );
} else if( jo.has_array( "decomp_learn" ) ) {
auto sk = jo.get_array( "decomp_learn" );
while( sk.has_more() ) {
auto arr = sk.next_array();
r.learn_by_disassembly[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 );
}
}
}
if( !uncraft && jo.has_member( "byproducts" ) ) {
auto bp = jo.get_array( "byproducts" );
r.byproducts.clear();
while( bp.has_more() ) {
auto arr = bp.next_array();
r.byproducts[ arr.get_string( 0 ) ] += arr.size() == 2 ? arr.get_int( 1 ) : 1;
}
}
if( jo.has_member( "book_learn" ) ) {
auto bk = jo.get_array( "book_learn" );
r.booksets.clear();
while( bk.has_more() ) {
auto arr = bk.next_array();
r.booksets.emplace( arr.get_string( 0 ), arr.get_int( 1 ) );
}
}
// recipes not specifying any external requirements inherit from their parent recipe (if any)
if( jo.has_string( "using" ) ) {
r.reqs_external = { { requirement_id( jo.get_string( "using" ) ), 1 } };
} else if( jo.has_array( "using" ) ) {
auto arr = jo.get_array( "using" );
r.reqs_external.clear();
while( arr.has_more() ) {
auto cur = arr.next_array();
r.reqs_external.emplace_back( requirement_id( cur.get_string( 0 ) ), cur.get_int( 1 ) );
}
}
// inline requirements are always replaced (cannot be inherited)
auto req_id = string_format( "inline_%s_%s", uncraft ? "uncraft" : "recipe", r.ident_.c_str() );
requirement_data::load_requirement( jo, req_id );
r.reqs_internal = { { requirement_id( req_id ), 1 } };
if( uncraft ) {
recipe_dict.uncraft[ r.ident_ ] = r;
} else {
recipe_dict.recipes[ r.ident_ ] = r;
}
}
示例6: load
void recipe::load( JsonObject &jo, const std::string &src )
{
bool strict = src == "dda";
abstract = jo.has_string( "abstract" );
if( abstract ) {
ident_ = recipe_id( jo.get_string( "abstract" ) );
} else {
result_ = jo.get_string( "result" );
ident_ = recipe_id( result_ );
}
assign( jo, "time", time, strict, 0 );
assign( jo, "difficulty", difficulty, strict, 0, MAX_SKILL );
assign( jo, "flags", flags );
// automatically set contained if we specify as container
assign( jo, "contained", contained, strict );
contained |= assign( jo, "container", container, strict );
if( jo.has_array( "batch_time_factors" ) ) {
auto batch = jo.get_array( "batch_time_factors" );
batch_rscale = batch.get_int( 0 ) / 100.0;
batch_rsize = batch.get_int( 1 );
}
assign( jo, "charges", charges );
assign( jo, "result_mult", result_mult );
assign( jo, "skill_used", skill_used, strict );
if( jo.has_member( "skills_required" ) ) {
auto sk = jo.get_array( "skills_required" );
required_skills.clear();
if( sk.empty() ) {
// clear all requirements
} else if( sk.has_array( 0 ) ) {
// multiple requirements
while( sk.has_more() ) {
auto arr = sk.next_array();
required_skills[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 );
}
} else {
// single requirement
required_skills[skill_id( sk.get_string( 0 ) )] = sk.get_int( 1 );
}
}
// simplified autolearn sets requirements equal to required skills at finalization
if( jo.has_bool( "autolearn" ) ) {
assign( jo, "autolearn", autolearn );
} else if( jo.has_array( "autolearn" ) ) {
autolearn = true;
auto sk = jo.get_array( "autolearn" );
while( sk.has_more() ) {
auto arr = sk.next_array();
autolearn_requirements[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 );
}
}
if( jo.has_member( "decomp_learn" ) ) {
learn_by_disassembly.clear();
if( jo.has_int( "decomp_learn" ) ) {
if( !skill_used ) {
jo.throw_error( "decomp_learn specified with no skill_used" );
}
assign( jo, "decomp_learn", learn_by_disassembly[skill_used] );
} else if( jo.has_array( "decomp_learn" ) ) {
auto sk = jo.get_array( "decomp_learn" );
while( sk.has_more() ) {
auto arr = sk.next_array();
learn_by_disassembly[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 );
}
}
}
if( jo.has_member( "book_learn" ) ) {
auto bk = jo.get_array( "book_learn" );
booksets.clear();
while( bk.has_more() ) {
auto arr = bk.next_array();
booksets.emplace( arr.get_string( 0 ), arr.size() > 1 ? arr.get_int( 1 ) : -1 );
}
}
// recipes not specifying any external requirements inherit from their parent recipe (if any)
if( jo.has_string( "using" ) ) {
reqs_external = { { requirement_id( jo.get_string( "using" ) ), 1 } };
} else if( jo.has_array( "using" ) ) {
auto arr = jo.get_array( "using" );
reqs_external.clear();
//.........这里部分代码省略.........
示例7: load
void mtype::load( JsonObject &jo, const std::string &src )
{
bool strict = src == "dda";
MonsterGenerator &gen = MonsterGenerator::generator();
// Name and name plural are not translated here, but when needed in
// combination with the actual count in `mtype::nname`.
mandatory( jo, was_loaded, "name", name );
// default behavior: Assume the regular plural form (appending an “s”)
optional( jo, was_loaded, "name_plural", name_plural, name + "s" );
optional( jo, was_loaded, "description", description );
optional( jo, was_loaded, "material", mat, auto_flags_reader<material_id> {} );
optional( jo, was_loaded, "species", species, auto_flags_reader<species_id> {} );
optional( jo, was_loaded, "categories", categories, auto_flags_reader<> {} );
// See monfaction.cpp
if( !was_loaded || jo.has_member( "default_faction" ) ) {
const auto faction = mfaction_str_id( jo.get_string( "default_faction" ) );
default_faction = monfactions::get_or_add_faction( faction );
}
if( !was_loaded || jo.has_member( "symbol" ) ) {
sym = jo.get_string( "symbol" );
if( utf8_wrapper( sym ).display_width() != 1 ) {
jo.throw_error( "monster symbol should be exactly one console cell width", "symbol" );
}
}
if( was_loaded && jo.has_member( "copy-from" ) && looks_like.empty() ) {
looks_like = jo.get_string( "copy-from" );
}
if( jo.has_member( "looks_like" ) ) {
looks_like = jo.get_string( "looks_like" );
}
assign( jo, "color", color );
const typed_flag_reader<decltype( Creature::size_map )> size_reader{ Creature::size_map, "invalid creature size" };
optional( jo, was_loaded, "size", size, size_reader, MS_MEDIUM );
const typed_flag_reader<decltype( gen.phase_map )> phase_reader{ gen.phase_map, "invalid phase id" };
optional( jo, was_loaded, "phase", phase, phase_reader, SOLID );
assign( jo, "diff", difficulty, strict, 0 );
assign( jo, "hp", hp, strict, 1 );
assign( jo, "speed", speed, strict, 0 );
assign( jo, "aggression", agro, strict, -100, 100 );
assign( jo, "morale", morale, strict );
assign( jo, "attack_cost", attack_cost, strict, 0 );
assign( jo, "melee_skill", melee_skill, strict, 0 );
assign( jo, "melee_dice", melee_dice, strict, 0 );
assign( jo, "melee_dice_sides", melee_sides, strict, 0 );
assign( jo, "dodge", sk_dodge, strict, 0 );
assign( jo, "armor_bash", armor_bash, strict, 0 );
assign( jo, "armor_cut", armor_cut, strict, 0 );
assign( jo, "armor_stab", armor_stab, strict, 0 );
assign( jo, "armor_acid", armor_acid, strict, 0 );
assign( jo, "armor_fire", armor_fire, strict, 0 );
assign( jo, "vision_day", vision_day, strict, 0 );
assign( jo, "vision_night", vision_night, strict, 0 );
optional( jo, was_loaded, "starting_ammo", starting_ammo );
optional( jo, was_loaded, "luminance", luminance, 0 );
optional( jo, was_loaded, "revert_to_itype", revert_to_itype, "" );
optional( jo, was_loaded, "attack_effs", atk_effs, mon_attack_effect_reader{} );
// TODO: make this work with `was_loaded`
if( jo.has_array( "melee_damage" ) ) {
JsonArray arr = jo.get_array( "melee_damage" );
melee_damage = load_damage_instance( arr );
} else if( jo.has_object( "melee_damage" ) ) {
melee_damage = load_damage_instance( jo );
}
if( jo.has_int( "melee_cut" ) ) {
int bonus_cut = jo.get_int( "melee_cut" );
melee_damage.add_damage( DT_CUT, bonus_cut );
}
if( jo.has_member( "death_drops" ) ) {
JsonIn &stream = *jo.get_raw( "death_drops" );
death_drops = item_group::load_item_group( stream, "distribution" );
}
assign( jo, "harvest", harvest, strict );
const typed_flag_reader<decltype( gen.death_map )> death_reader{ gen.death_map, "invalid monster death function" };
optional( jo, was_loaded, "death_function", dies, death_reader );
if( dies.empty() ) {
// TODO: really needed? Is an empty `dies` container not allowed?
dies.push_back( mdeath::normal );
}
assign( jo, "emit_fields", emit_fields );
if( jo.has_member( "special_when_hit" ) ) {
JsonArray jsarr = jo.get_array( "special_when_hit" );
const auto iter = gen.defense_map.find( jsarr.get_string( 0 ) );
//.........这里部分代码省略.........
示例8: load
void mtype::load( JsonObject &jo )
{
MonsterGenerator &gen = MonsterGenerator::generator();
// Name and name plural are not translated here, but when needed in
// combination with the actual count in `mtype::nname`.
mandatory( jo, was_loaded, "name", name );
// default behaviour: Assume the regular plural form (appending an “s”)
optional( jo, was_loaded, "name_plural", name_plural, name + "s" );
mandatory( jo, was_loaded, "description", description, translated_string_reader );
// Have to overwrite the default { "hflesh" } here
if( !was_loaded || jo.has_member( "material" ) ) {
mat = { jo.get_string( "material" ) };
}
optional( jo, was_loaded, "species", species, auto_flags_reader<species_id> {} );
optional( jo, was_loaded, "categories", categories, auto_flags_reader<> {} );
// See monfaction.cpp
if( !was_loaded || jo.has_member( "default_faction" ) ) {
const auto faction = mfaction_str_id( jo.get_string( "default_faction" ) );
default_faction = monfactions::get_or_add_faction( faction );
}
if( !was_loaded || jo.has_member( "symbol" ) ) {
sym = jo.get_string( "symbol" );
if( utf8_wrapper( sym ).display_width() != 1 ) {
jo.throw_error( "monster symbol should be exactly one console cell width", "symbol" );
}
}
mandatory( jo, was_loaded, "color", color, color_reader{} );
const typed_flag_reader<decltype( Creature::size_map )> size_reader{ Creature::size_map, "invalid creature size" };
optional( jo, was_loaded, "size", size, size_reader, MS_MEDIUM );
const typed_flag_reader<decltype( gen.phase_map )> phase_reader{ gen.phase_map, "invalid phase id" };
optional( jo, was_loaded, "phase", phase, phase_reader, SOLID );
optional( jo, was_loaded, "diff", difficulty, 0 );
optional( jo, was_loaded, "aggression", agro, 0 );
optional( jo, was_loaded, "morale", morale, 0 );
optional( jo, was_loaded, "speed", speed, 0 );
optional( jo, was_loaded, "attack_cost", attack_cost, 100 );
optional( jo, was_loaded, "melee_skill", melee_skill, 0 );
optional( jo, was_loaded, "melee_dice", melee_dice, 0 );
optional( jo, was_loaded, "melee_dice_sides", melee_sides, 0 );
optional( jo, was_loaded, "dodge", sk_dodge, 0 );
optional( jo, was_loaded, "armor_bash", armor_bash, 0 );
optional( jo, was_loaded, "armor_cut", armor_cut, 0 );
optional( jo, was_loaded, "armor_acid", armor_acid, armor_cut / 2 );
optional( jo, was_loaded, "armor_fire", armor_fire, 0 );
optional( jo, was_loaded, "hp", hp, 0 );
optional( jo, was_loaded, "starting_ammo", starting_ammo );
optional( jo, was_loaded, "luminance", luminance, 0 );
optional( jo, was_loaded, "revert_to_itype", revert_to_itype, "" );
optional( jo, was_loaded, "vision_day", vision_day, 40 );
optional( jo, was_loaded, "vision_night", vision_night, 1 );
optional( jo, was_loaded, "armor_stab", armor_stab, 0.8f * armor_cut );
optional( jo, was_loaded, "attack_effs", atk_effs, mon_attack_effect_reader{} );
// TODO: make this work with `was_loaded`
if( jo.has_array( "melee_damage" ) ) {
JsonArray arr = jo.get_array( "melee_damage" );
melee_damage = load_damage_instance( arr );
} else if( jo.has_object( "melee_damage" ) ) {
melee_damage = load_damage_instance( jo );
}
if( jo.has_int( "melee_cut" ) ) {
int bonus_cut = jo.get_int( "melee_cut" );
melee_damage.add_damage( DT_CUT, bonus_cut );
}
if( jo.has_member( "death_drops" ) ) {
JsonIn &stream = *jo.get_raw( "death_drops" );
death_drops = item_group::load_item_group( stream, "distribution" );
}
const typed_flag_reader<decltype( gen.death_map )> death_reader{ gen.death_map, "invalid monster death function" };
optional( jo, was_loaded, "death_function", dies, death_reader );
if( dies.empty() ) {
// TODO: really needed? Is an empty `dies` container not allowed?
dies.push_back( mdeath::normal );
}
if( jo.has_member( "special_when_hit" ) ) {
JsonArray jsarr = jo.get_array( "special_when_hit" );
const auto iter = gen.defense_map.find( jsarr.get_string( 0 ) );
if( iter == gen.defense_map.end() ) {
jsarr.throw_error( "Invalid monster defense function" );
}
sp_defense = iter->second;
def_chance = jsarr.get_int( 1 );
} else if( !was_loaded ) {
sp_defense = &mdefense::none;
def_chance = 0;
}
if( !was_loaded || jo.has_member( "special_attacks" ) ) {
special_attacks.clear();
special_attacks_names.clear();
//.........这里部分代码省略.........