本文整理汇总了C++中JsonObject::get_raw方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::get_raw方法的具体用法?C++ JsonObject::get_raw怎么用?C++ JsonObject::get_raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject::get_raw方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_symbol
void map_data_common_t::load_symbol( JsonObject &jo )
{
load_season_array( *jo.get_raw( "symbol" ), symbol_, string_to_symbol );
const bool has_color = jo.has_member( "color" );
const bool has_bgcolor = jo.has_member( "bgcolor" );
if( has_color && has_bgcolor ) {
jo.throw_error( "Found both color and bgcolor, only one of these is allowed." );
} else if( has_color ) {
load_season_array( *jo.get_raw( "color" ), color_, color_from_json );
} else if( has_bgcolor ) {
load_season_array( *jo.get_raw( "bgcolor" ), color_, bgcolor_from_json );
} else {
jo.throw_error( "Missing member: one of: \"color\", \"bgcolor\" must exist." );
}
}
示例2: load
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
if( !jsobj.has_object(member) ) {
return false;
}
JsonObject j = jsobj.get_object(member);
str_min = j.get_int("str_min", 0);
str_max = j.get_int("str_max", 0);
str_min_blocked = j.get_int("str_min_blocked", -1);
str_max_blocked = j.get_int("str_max_blocked", -1);
str_min_supported = j.get_int("str_min_supported", -1);
str_max_supported = j.get_int("str_max_supported", -1);
str_min_roll = j.get_int("str_min_roll", str_min);
str_max_roll = j.get_int("str_min_roll", str_max);
explosive = j.get_int("explosive", -1);
sound_vol = j.get_int("sound_vol", -1);
sound_fail_vol = j.get_int("sound_fail_vol", -1);
collapse_radius = j.get_int( "collapse_radius", 1 );
destroy_only = j.get_bool("destroy_only", false);
bash_below = j.get_bool("bash_below", false);
sound = j.get_string("sound", _("smash!"));
sound_fail = j.get_string("sound_fail", _("thump!"));
if( isfurniture ) {
furn_set = j.get_string("furn_set", "f_null");
} else {
ter_set = j.get_string( "ter_set" );
}
if( j.has_member( "items" ) ) {
JsonIn& stream = *j.get_raw( "items" );
drop_group = item_group::load_item_group( stream, "collection" );
} else {
drop_group = "EMPTY_GROUP";
}
if( j.has_array("tent_centers") ) {
load_map_bash_tent_centers( j.get_array("tent_centers"), tent_centers );
}
return true;
}
示例3: load
/**
* Reads in a vehicle part from a JsonObject.
*/
void vpart_info::load( JsonObject &jo, const std::string &src )
{
vpart_info def;
if( jo.has_string( "copy-from" ) ) {
auto const base = vpart_info_all.find( vpart_id( jo.get_string( "copy-from" ) ) );
auto const ab = abstract_parts.find( vpart_id( jo.get_string( "copy-from" ) ) );
if( base != vpart_info_all.end() ) {
def = base->second;
} else if( ab != abstract_parts.end() ) {
def = ab->second;
} else {
deferred.emplace_back( jo.str(), src );
return;
}
}
if( jo.has_string( "abstract" ) ) {
def.id = vpart_id( jo.get_string( "abstract" ) );
} else {
def.id = vpart_id( jo.get_string( "id" ) );
}
assign( jo, "name", def.name_ );
assign( jo, "item", def.item );
assign( jo, "location", def.location );
assign( jo, "durability", def.durability );
assign( jo, "damage_modifier", def.dmg_mod );
assign( jo, "power", def.power );
assign( jo, "epower", def.epower );
assign( jo, "fuel_type", def.fuel_type );
assign( jo, "default_ammo", def.default_ammo );
assign( jo, "folded_volume", def.folded_volume );
assign( jo, "size", def.size );
assign( jo, "difficulty", def.difficulty );
assign( jo, "bonus", def.bonus );
assign( jo, "flags", def.flags );
if( jo.has_member( "requirements" ) ) {
auto reqs = jo.get_object( "requirements" );
parse_vp_reqs( reqs, def.id.str(), "install", def.install_reqs, def.install_skills, def.install_moves );
parse_vp_reqs( reqs, def.id.str(), "removal", def.removal_reqs, def.removal_skills, def.removal_moves );
parse_vp_reqs( reqs, def.id.str(), "repair", def.repair_reqs, def.repair_skills, def.repair_moves );
def.legacy = false;
}
if( jo.has_member( "symbol" ) ) {
def.sym = jo.get_string( "symbol" )[ 0 ];
}
if( jo.has_member( "broken_symbol" ) ) {
def.sym_broken = jo.get_string( "broken_symbol" )[ 0 ];
}
if( jo.has_member( "color" ) ) {
def.color = color_from_string( jo.get_string( "color" ) );
}
if( jo.has_member( "broken_color" ) ) {
def.color_broken = color_from_string( jo.get_string( "broken_color" ) );
}
if( jo.has_member( "breaks_into" ) ) {
JsonIn& stream = *jo.get_raw( "breaks_into" );
def.breaks_into_group = item_group::load_item_group( stream, "collection" );
}
auto qual = jo.get_array( "qualities" );
if( !qual.empty() ) {
def.qualities.clear();
while( qual.has_more() ) {
auto pair = qual.next_array();
def.qualities[ quality_id( pair.get_string( 0 ) ) ] = pair.get_int( 1 );
}
}
if( jo.has_member( "damage_reduction" ) ) {
JsonObject dred = jo.get_object( "damage_reduction" );
def.damage_reduction = load_damage_array( dred );
} else {
def.damage_reduction.fill( 0.0f );
}
if( jo.has_string( "abstract" ) ) {
abstract_parts[def.id] = def;
} else {
vpart_info_all[def.id] = def;
}
}
示例4: 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, "melee_cut", melee_cut, 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 );
// TODO: allow adding/removing specific entries if `was_loaded` is true
if( jo.has_array( "attack_effs" ) ) {
JsonArray jsarr = jo.get_array( "attack_effs" );
while( jsarr.has_more() ) {
JsonObject e = jsarr.next_object();
mon_effect_data new_eff( efftype_id( e.get_string( "id" ) ), e.get_int( "duration", 0 ),
get_body_part_token( e.get_string( "bp", "NUM_BP" ) ), e.get_bool( "permanent", false ),
e.get_int( "chance", 100 ) );
atk_effs.push_back( new_eff );
}
}
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 );
}
// TODO: allow overriding/adding/removing those if `was_loaded` is true
gen.load_special_defense( this, jo, "special_when_hit" );
gen.load_special_attacks( this, jo, "special_attacks" );
// Disable upgrading when JSON contains `"upgrades": false`, but fallback to the
// normal behavior (including error checking) if "upgrades" is not boolean or not `false`.
if( jo.has_bool( "upgrades" ) && !jo.get_bool( "upgrades" ) ) {
upgrade_group = mongroup_id::NULL_ID;
upgrade_into = mtype_id::NULL_ID;
upgrades = false;
} else if( jo.has_member( "upgrades" ) ) {
JsonObject up = jo.get_object( "upgrades" );
optional( up, was_loaded, "half_life", half_life, -1 );
optional( up, was_loaded, "into_group", upgrade_group, auto_flags_reader<mongroup_id> {}, mongroup_id::NULL_ID );
optional( up, was_loaded, "into", upgrade_into, auto_flags_reader<mtype_id> {}, mtype_id::NULL_ID );
upgrades = true;
}
//.........这里部分代码省略.........
示例5: load
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" ) ) {
traits = trait_group::load_trait_group( *jo.get_raw( "traits" ), "collection" );
}
/* Mutation rounds can be specified as follows:
* "mutation_rounds": {
* "ANY" : { "constant": 1 },
* "INSECT" : { "rng": [1, 3] }
* }
*/
if( jo.has_object( "mutation_rounds" ) ) {
const std::map<std::string, mutation_category_trait> &mutation_categories =
mutation_category_trait::get_all();
auto jo2 = jo.get_object( "mutation_rounds" );
for( auto &mutation : jo2.get_member_names() ) {
auto category_match = [&mutation]( std::pair<const std::string, mutation_category_trait> p ) {
return p.second.id == mutation;
};
if( std::find_if( mutation_categories.begin(), mutation_categories.end(),
category_match ) == mutation_categories.end() ) {
debugmsg( "Unrecognized mutation category %s", mutation );
continue;
}
auto distrib = jo2.get_object( mutation );
mutation_rounds[mutation] = load_distribution( distrib );
}
}
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;
}
}
}
}
}
示例6: 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 ) );
//.........这里部分代码省略.........
示例7: load_monster
void MonsterGenerator::load_monster(JsonObject &jo)
{
const mtype_id mid = mtype_id( jo.get_string("id") );
if (mon_templates.count(mid) > 0) {
delete mon_templates[mid];
}
mtype *newmon = new mtype;
newmon->id = mid;
newmon->name = jo.get_string("name").c_str();
if(jo.has_member("name_plural")) {
newmon->name_plural = jo.get_string("name_plural");
} else {
// default behaviour: Assume the regular plural form (appending an “s”)
newmon->name_plural = newmon->name + "s";
}
newmon->description = _(jo.get_string("description").c_str());
// Have to overwrite the default { "hflesh" } here
newmon->mat = { jo.get_string("material") };
for( auto &s : jo.get_tags( "species" ) ) {
newmon->species.insert( species_id( s ) );
}
newmon->categories = jo.get_tags("categories");
// See monfaction.cpp
newmon->default_faction =
monfactions::get_or_add_faction( mfaction_str_id( jo.get_string("default_faction") ) );
newmon->sym = jo.get_string("symbol");
if( utf8_wrapper( newmon->sym ).display_width() != 1 ) {
jo.throw_error( "monster symbol should be exactly one console cell width", "symbol" );
}
newmon->color = color_from_string(jo.get_string("color"));
newmon->size = get_from_string(jo.get_string("size", "MEDIUM"), Creature::size_map, MS_MEDIUM);
newmon->phase = get_from_string(jo.get_string("phase", "SOLID"), phase_map, SOLID);
newmon->difficulty = jo.get_int("diff", 0);
newmon->agro = jo.get_int("aggression", 0);
newmon->morale = jo.get_int("morale", 0);
newmon->speed = jo.get_int("speed", 0);
newmon->attack_cost = jo.get_int("attack_cost", 100);
newmon->melee_skill = jo.get_int("melee_skill", 0);
newmon->melee_dice = jo.get_int("melee_dice", 0);
newmon->melee_sides = jo.get_int("melee_dice_sides", 0);
newmon->melee_cut = jo.get_int("melee_cut", 0);
newmon->sk_dodge = jo.get_int("dodge", 0);
newmon->armor_bash = jo.get_int("armor_bash", 0);
newmon->armor_cut = jo.get_int("armor_cut", 0);
newmon->hp = jo.get_int("hp", 0);
jo.read("starting_ammo", newmon->starting_ammo);
newmon->luminance = jo.get_float("luminance", 0);
newmon->revert_to_itype = jo.get_string( "revert_to_itype", "" );
newmon->vision_day = jo.get_int("vision_day", 40);
newmon->vision_night = jo.get_int("vision_night", 1);
if (jo.has_array("attack_effs")) {
JsonArray jsarr = jo.get_array("attack_effs");
while (jsarr.has_more()) {
JsonObject e = jsarr.next_object();
mon_effect_data new_eff(e.get_string("id", "null"), e.get_int("duration", 0),
get_body_part_token( e.get_string("bp", "NUM_BP") ), e.get_bool("permanent", false),
e.get_int("chance", 100));
newmon->atk_effs.push_back(new_eff);
}
}
if( jo.has_member( "death_drops" ) ) {
JsonIn& stream = *jo.get_raw( "death_drops" );
newmon->death_drops = item_group::load_item_group( stream, "distribution" );
}
newmon->dies = get_death_functions(jo, "death_function");
load_special_defense(newmon, jo, "special_when_hit");
load_special_attacks(newmon, jo, "special_attacks");
if (jo.has_member("upgrades")) {
JsonObject upgrades = jo.get_object("upgrades");
newmon->half_life = upgrades.get_int("half_life", -1);
newmon->upgrade_group = mongroup_id( upgrades.get_string("into_group", mongroup_id::NULL_ID.str() ) );
newmon->upgrade_into = mtype_id( upgrades.get_string("into", mtype_id::NULL_ID.str() ) );
newmon->upgrades = true;
}
std::set<std::string> flags, anger_trig, placate_trig, fear_trig;
flags = jo.get_tags("flags");
anger_trig = jo.get_tags("anger_triggers");
placate_trig = jo.get_tags("placate_triggers");
fear_trig = jo.get_tags("fear_triggers");
newmon->flags = get_set_from_tags(flags, flag_map, MF_NULL);
newmon->anger = get_set_from_tags(anger_trig, trigger_map, MTRIG_NULL);
newmon->fear = get_set_from_tags(fear_trig, trigger_map, MTRIG_NULL);
newmon->placate = get_set_from_tags(placate_trig, trigger_map, MTRIG_NULL);
mon_templates[mid] = newmon;
}
示例8: load
//.........这里部分代码省略.........
while( arr.has_more() ) {
auto cur = arr.next_array();
def.install_reqs.emplace_back( requirement_id( cur.get_string( 0 ) ), cur.get_int( 1 ) );
}
} else {
auto req_id = std::string( "inline_vehins_" ) += def.id.str();
requirement_data::load_requirement( ins, req_id );
def.install_reqs = { { requirement_id( req_id ), 1 } };
}
def.legacy = false;
}
if( reqs.has_object( "removal" ) ) {
auto rem = reqs.get_object( "removal" );
auto sk = rem.get_array( "skills" );
if( !sk.empty() ) {
def.removal_skills.clear();
}
while( sk.has_more() ) {
auto cur = sk.next_array();
def.removal_skills.emplace( skill_id( cur.get_string( 0 ) ) , cur.size() >= 2 ? cur.get_int( 1 ) : 1 );
}
assign( rem, "time", def.removal_moves );
if( rem.has_string( "using" ) ) {
def.removal_reqs = { { requirement_id( rem.get_string( "using" ) ), 1 } };
} else if( rem.has_array( "using" ) ) {
auto arr = rem.get_array( "using" );
while( arr.has_more() ) {
auto cur = arr.next_array();
def.removal_reqs.emplace_back( requirement_id( cur.get_string( 0 ) ), cur.get_int( 1 ) );
}
} else {
auto req_id = std::string( "inline_vehins_" ) += def.id.str();
requirement_data::load_requirement( rem, req_id );
def.removal_reqs = { { requirement_id( req_id ), 1 } };
}
def.legacy = false;
}
if( jo.has_member( "symbol" ) ) {
def.sym = jo.get_string( "symbol" )[ 0 ];
}
if( jo.has_member( "broken_symbol" ) ) {
def.sym_broken = jo.get_string( "broken_symbol" )[ 0 ];
}
if( jo.has_member( "color" ) ) {
def.color = color_from_string( jo.get_string( "color" ) );
}
if( jo.has_member( "broken_color" ) ) {
def.color_broken = color_from_string( jo.get_string( "broken_color" ) );
}
if( jo.has_member( "breaks_into" ) ) {
JsonIn& stream = *jo.get_raw( "breaks_into" );
def.breaks_into_group = item_group::load_item_group( stream, "collection" );
}
auto qual = jo.get_array( "qualities" );
if( !qual.empty() ) {
def.qualities.clear();
while( qual.has_more() ) {
auto pair = qual.next_array();
def.qualities[ quality_id( pair.get_string( 0 ) ) ] = pair.get_int( 1 );
}
}
if( jo.has_member( "damage_reduction" ) ) {
JsonObject dred = jo.get_object( "damage_reduction" );
def.damage_reduction = load_damage_array( dred );
} else {
def.damage_reduction.fill( 0.0f );
}
if( jo.has_string( "abstract" ) ) {
abstract_parts[ def.id ] = def;
return;
}
auto const iter = vehicle_part_types.find( def.id );
if( iter != vehicle_part_types.end() ) {
// Entry in the map already exists, so the pointer in the vector is already correct
// and does not need to be changed, only the int-id needs to be taken from the old entry.
def.loadid = iter->second.loadid;
iter->second = def;
} else {
// The entry is new, "generate" a new int-id and link the new entry from the vector.
def.loadid = vpart_id( vehicle_part_int_types.size() );
vpart_info &new_entry = vehicle_part_types[ def.id ];
new_entry = def;
vehicle_part_int_types.push_back( &new_entry );
}
}
示例9: load
/**
* Reads in a vehicle part from a JsonObject.
*/
void vpart_info::load( JsonObject &jo )
{
vpart_info next_part;
next_part.id = vpart_str_id( jo.get_string( "id" ) );
next_part.name = _(jo.get_string("name").c_str());
next_part.sym = jo.get_string("symbol")[0];
next_part.color = color_from_string(jo.get_string("color"));
next_part.sym_broken = jo.get_string("broken_symbol")[0];
next_part.color_broken = color_from_string(jo.get_string("broken_color"));
next_part.dmg_mod = jo.has_member("damage_modifier") ? jo.get_int("damage_modifier") : 100;
next_part.durability = jo.get_int("durability");
next_part.power = jo.get_int("power", 0);
next_part.epower = jo.get_int("epower", 0);
next_part.folded_volume = jo.get_int("folded_volume", 0);
next_part.range = jo.get_int( "range", 12 );
next_part.size = jo.get_int( "size", 0 );
//Handle the par1 union as best we can by accepting any ONE of its elements
int element_count = (jo.has_member("par1") ? 1 : 0)
+ (jo.has_member("wheel_width") ? 1 : 0)
+ (jo.has_member("bonus") ? 1 : 0);
if(element_count == 0) {
//If not specified, assume 0
next_part.par1 = 0;
} else if(element_count == 1) {
if(jo.has_member("par1")) {
next_part.par1 = jo.get_int("par1");
} else if(jo.has_member("wheel_width")) {
next_part.par1 = jo.get_int("wheel_width");
} else { //bonus
next_part.par1 = jo.get_int("bonus");
}
} else {
//Too many
debugmsg("Error parsing vehicle part '%s': \
Use AT MOST one of: par1, wheel_width, bonus",
next_part.name.c_str());
//Keep going to produce more messages if other parts are wrong
next_part.par1 = 0;
}
next_part.fuel_type = jo.get_string( "fuel_type", "null" );
next_part.item = jo.get_string("item");
next_part.difficulty = jo.get_int("difficulty");
next_part.location = jo.has_member("location") ? jo.get_string("location") : "";
JsonArray jarr = jo.get_array("flags");
while (jarr.has_more()) {
next_part.set_flag( jarr.next_string() );
}
if( jo.has_member( "breaks_into" ) ) {
JsonIn& stream = *jo.get_raw( "breaks_into" );
next_part.breaks_into_group = item_group::load_item_group( stream, "collection" );
} else {
next_part.breaks_into_group = "EMPTY_GROUP";
}
//Calculate and cache z-ordering based off of location
// list_order is used when inspecting the vehicle
if(next_part.location == "on_roof") {
next_part.z_order = 9;
next_part.list_order = 3;
} else if(next_part.location == "on_cargo") {
next_part.z_order = 8;
next_part.list_order = 6;
} else if(next_part.location == "center") {
next_part.z_order = 7;
next_part.list_order = 7;
} else if(next_part.location == "under") {
//Have wheels show up over frames
next_part.z_order = 6;
next_part.list_order = 10;
} else if(next_part.location == "structure") {
next_part.z_order = 5;
next_part.list_order = 1;
} else if(next_part.location == "engine_block") {
//Should be hidden by frames
next_part.z_order = 4;
next_part.list_order = 8 ;
} else if (next_part.location == "on_battery_mount"){
//Should be hidden by frames
next_part.z_order = 3;
next_part.list_order = 10;
} else if(next_part.location == "fuel_source") {
//Should be hidden by frames
next_part.z_order = 3;
next_part.list_order = 9;
} else if(next_part.location == "roof") {
//Shouldn't be displayed
next_part.z_order = -1;
next_part.list_order = 4;
} else if(next_part.location == "armor") {
//Shouldn't be displayed (the color is used, but not the symbol)
next_part.z_order = -2;
next_part.list_order = 2;
//.........这里部分代码省略.........
示例10: deserialize
/*
* load npc
*/
void npc::deserialize(JsonIn &jsin)
{
JsonObject data = jsin.get_object();
json_load_common_variables(data);
int misstmp, classtmp, flagstmp, atttmp, tmpid;
data.read("id",tmpid); setID(tmpid);
data.read("name",name);
data.read("marked_for_death", marked_for_death);
data.read("dead", dead);
if ( data.read( "myclass", classtmp) ) {
myclass = npc_class( classtmp );
}
data.read("personality", personality);
data.read("wandx",wandx);
data.read("wandy",wandy);
data.read("wandf",wandf);
data.read("omx",omx);
data.read("omy",omy);
data.read("omz",omz);
data.read("mapx",mapx);
data.read("mapy",mapy);
data.read("plx",plx);
data.read("ply",ply);
data.read("goalx",goal.x);
data.read("goaly",goal.y);
data.read("goalz",goal.z);
if ( data.read("mission",misstmp) ) {
mission = npc_mission( misstmp );
}
if ( data.read( "flags", flagstmp) ) {
flags = flagstmp;
}
if ( data.read( "attitude", atttmp) ) {
attitude = npc_attitude(atttmp);
}
inv.clear();
if ( data.has_member("inv") ) {
JsonIn *invin = data.get_raw("inv");
inv.json_load_items( *invin );
}
worn.clear();
data.read("worn",worn);
weapon.contents.clear();
data.read("weapon",weapon);
data.read("op_of_u",op_of_u);
data.read("chatbin",chatbin);
data.read("combat_rules",combat_rules);
}
示例11: 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 );
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" );
}
}
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();
add_special_attacks( jo, "special_attacks" );
} else {
// Note: special_attacks left as is, new attacks are added to it!
//.........这里部分代码省略.........