Exemplo n.º 1
0
void load_technique(JsonObject &jo)
{
    ma_technique tec;

    tec.id = jo.get_string("id");
    tec.name = jo.get_string("name", "");
	if (!tec.name.empty()) {
		tec.name = _(tec.name.c_str());
	}

    JsonArray jsarr = jo.get_array("messages");
    while (jsarr.has_more()) {
        tec.messages.push_back(_(jsarr.next_string().c_str()));
    }

    tec.reqs.unarmed_allowed = jo.get_bool("unarmed_allowed", false);
    tec.reqs.melee_allowed = jo.get_bool("melee_allowed", false);
    tec.reqs.min_melee = jo.get_int("min_melee", 0);
    tec.reqs.min_unarmed = jo.get_int("min_unarmed", 0);

    tec.reqs.min_bashing = jo.get_int("min_bashing", 0);
    tec.reqs.min_cutting = jo.get_int("min_cutting", 0);
    tec.reqs.min_stabbing = jo.get_int("min_stabbing", 0);

    tec.reqs.min_bashing_damage = jo.get_int("min_bashing_damage", 0);
    tec.reqs.min_cutting_damage = jo.get_int("min_cutting_damage", 0);

    tec.reqs.req_buffs = jo.get_tags("req_buffs");
    tec.reqs.req_flags = jo.get_tags("req_flags");

    tec.crit_tec = jo.get_bool("crit_tec", false);
    tec.defensive = jo.get_bool("defensive", false);
    tec.disarms = jo.get_bool("disarms", false);
    tec.dodge_counter = jo.get_bool("dodge_counter", false);
    tec.block_counter = jo.get_bool("block_counter", false);
    tec.miss_recovery = jo.get_bool("miss_recovery", false);
    tec.grab_break = jo.get_bool("grab_break", false);
    tec.flaming = jo.get_bool("flaming", false);    

    tec.hit = jo.get_int("pain", 0);
    tec.bash = jo.get_int("bash", 0);
    tec.cut = jo.get_int("cut", 0);
    tec.pain = jo.get_int("pain", 0);

    tec.weighting = jo.get_int("weighting", 1);

    tec.bash_mult = jo.get_float("bash_mult", 1.0);
    tec.cut_mult = jo.get_float("cut_mult", 1.0);
    tec.speed_mult = jo.get_float("speed_mult", 1.0);

    tec.down_dur = jo.get_int("down_dur", 0);
    tec.stun_dur = jo.get_int("stun_dur", 0);
    tec.knockback_dist = jo.get_int("knockback_dist", 0);
    tec.knockback_spread = jo.get_int("knockback_spread", 0);

    tec.aoe = jo.get_string("aoe", "");
    tec.flags = jo.get_tags("flags");
    
    ma_techniques[tec.id] = tec;
}
Exemplo n.º 2
0
void MonsterGenerator::load_species(JsonObject &jo)
{
    // id, flags, triggers (anger, placate, fear)
    std::string sid;
    if (jo.has_member("id")) {
        sid = jo.get_string("id");
        int species_num = mon_species.size();
        if (mon_species.count(sid) > 0) {
            species_num = mon_species[sid]->short_id; // Keep it or weird things may happen
            delete mon_species[sid];
        }

        std::set<std::string> sflags, sanger, sfear, splacate;
        sflags = jo.get_tags("flags");
        sanger = jo.get_tags("anger_triggers");
        sfear  = jo.get_tags("fear_triggers");
        splacate = jo.get_tags("placate_triggers");

        std::set<m_flag> flags = get_set_from_tags(sflags, flag_map, MF_NULL);
        std::set<monster_trigger> anger, fear, placate;
        anger = get_set_from_tags(sanger, trigger_map, MTRIG_NULL);
        fear = get_set_from_tags(sfear, trigger_map, MTRIG_NULL);
        placate = get_set_from_tags(splacate, trigger_map, MTRIG_NULL);

        species_type *new_species = new species_type(species_num, sid, flags, anger, fear, placate);

        mon_species[sid] = new_species;
    }
}
Exemplo n.º 3
0
void monfactions::load_monster_faction( JsonObject &jo )
{
    // Factions inherit values from their parent factions - this is set during finalization
    std::set< std::string > by_mood, neutral, friendly;
    by_mood = jo.get_tags( "by_mood" );
    neutral = jo.get_tags( "neutral" );
    friendly = jo.get_tags( "friendly" );
    // Need to make sure adding new factions won't invalidate our current faction's reference
    // That +1 is for base faction
    faction_list.reserve( faction_list.size() + by_mood.size() + neutral.size() + friendly.size() + 1 );
    prealloc( by_mood );
    prealloc( neutral );
    prealloc( friendly );

    std::string name = jo.get_string( "name" );
    mfaction_id cur_id = get_or_add_faction( mfaction_str_id( name ) );
    std::string base_faction = jo.get_string( "base_faction", "" );
    mfaction_id base_id = get_or_add_faction( mfaction_str_id( base_faction ) );
    // Don't get the reference until here (to avoid vector reallocation messing it up)
    monfaction &faction = faction_list[cur_id];
    faction.base_faction = base_id;

    add_to_attitude_map( by_mood, faction.attitude_map, MFA_BY_MOOD );
    add_to_attitude_map( neutral, faction.attitude_map, MFA_NEUTRAL );
    add_to_attitude_map( friendly, faction.attitude_map, MFA_FRIENDLY );
}
Exemplo n.º 4
0
void Item_factory::load_gun(JsonObject& jo)
{
    it_gun* gun_template = new it_gun();
    gun_template->ammo = jo.get_string("ammo");
    gun_template->skill_used = Skill::skill(jo.get_string("skill"));
    gun_template->dmg_bonus = jo.get_int("ranged_damage");
    gun_template->range = jo.get_int("range");
    gun_template->dispersion = jo.get_int("dispersion");
    gun_template->recoil = jo.get_int("recoil");
    gun_template->durability = jo.get_int("durability");
    gun_template->burst = jo.get_int("burst");
    gun_template->clip = jo.get_int("clip_size");
    gun_template->reload_time = jo.get_int("reload");
    gun_template->pierce = jo.get_int("pierce", 0);
    gun_template->ammo_effects = jo.get_tags("ammo_effects");

    if ( jo.has_array("valid_mod_locations") ) {
        JsonArray jarr = jo.get_array("valid_mod_locations");
        while (jarr.has_more()){
            JsonArray curr = jarr.next_array();
            gun_template->valid_mod_locations.insert(std::pair<std::string, int>(curr.get_string(0), curr.get_int(1)));
            gun_template->occupied_mod_locations.insert(std::pair<std::string, int>(curr.get_string(0), 0));
        }
    }

    itype *new_item_template = gun_template;
    load_basic_info(jo, new_item_template);
}
Exemplo n.º 5
0
void it_artifact_armor::deserialize(JsonObject &jo)
{
    id = jo.get_string("id");
    name = jo.get_string("name");
    description = jo.get_string("description");
    sym = jo.get_int("sym");
    color = int_to_color(jo.get_int("color"));
    price = jo.get_int("price");
    m1 = jo.get_string("m1");
    m2 = jo.get_string("m2");
    volume = jo.get_int("volume");
    weight = jo.get_int("weight");
    melee_dam = jo.get_int("melee_dam");
    melee_cut = jo.get_int("melee_cut");
    m_to_hit = jo.get_int("m_to_hit");
    item_tags = jo.get_tags("item_flags");

    covers = jo.get_int("covers");
    encumber = jo.get_int("encumber");
    coverage = jo.get_int("coverage");
    thickness = jo.get_int("material_thickness");
    env_resist = jo.get_int("env_resist");
    warmth = jo.get_int("warmth");
    storage = jo.get_int("storage");
    power_armor = jo.get_bool("power_armor");

    JsonArray ja = jo.get_array("effects_worn");
    while (ja.has_more()) {
        effects_worn.push_back((art_effect_passive)ja.next_int());
    }
}
Exemplo n.º 6
0
void load_martial_art(JsonObject &jo)
{
    martialart ma;
    JsonArray jsarr;

    ma.id = jo.get_string("id");
    ma.name = _(jo.get_string("name").c_str());
    ma.description = _(jo.get_string("description").c_str());

    jsarr = jo.get_array("static_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.static_buffs.push_back(load_buff(jsobj));
    }

    jsarr = jo.get_array("onmove_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.onmove_buffs.push_back(load_buff(jsobj));
    }

    jsarr = jo.get_array("onhit_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.onhit_buffs.push_back(load_buff(jsobj));
    }

    jsarr = jo.get_array("onattack_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.onattack_buffs.push_back(load_buff(jsobj));
    }

    jsarr = jo.get_array("ondodge_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.ondodge_buffs.push_back(load_buff(jsobj));
    }

    jsarr = jo.get_array("onblock_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.onblock_buffs.push_back(load_buff(jsobj));
    }

    jsarr = jo.get_array("ongethit_buffs");
    while (jsarr.has_more()) {
        JsonObject jsobj = jsarr.next_object();
        ma.onblock_buffs.push_back(load_buff(jsobj));
    }

    ma.techniques = jo.get_tags("techniques");

    ma.leg_block = jo.get_int("leg_block", -1);
    ma.arm_block = jo.get_int("arm_block", -1);

    martialarts[ma.id] = ma;
}
Exemplo n.º 7
0
void mtype::remove_special_attacks( JsonObject &jo, const std::string &member_name )
{
    for( const std::string &name : jo.get_tags( member_name ) ) {
        special_attacks.erase( name );
        const auto iter = std::find( special_attacks_names.begin(), special_attacks_names.end(), name );
        if( iter != special_attacks_names.end() ) {
            special_attacks_names.erase( iter );
        }
    }
}
void load_overlay_ordering_into_array( JsonObject &jsobj, std::map<std::string, int> &orderarray )
{
    JsonArray jarr = jsobj.get_array( "overlay_ordering" );
    while( jarr.has_more() ) {
        JsonObject ordering = jarr.next_object();
        int order = ordering.get_int( "order" );
        for( auto &id : ordering.get_tags( "id" ) ) {
            orderarray[id] = order;
        }
    }
}
Exemplo n.º 9
0
void start_location::load_location( JsonObject &jsonobj )
{
    start_location new_location;

    new_location._ident = jsonobj.get_string("ident");
    new_location._name = jsonobj.get_string("name");
    new_location._target = jsonobj.get_string("target");
    new_location._flags = jsonobj.get_tags("flags");

    _locations[new_location._ident] = new_location;
}
Exemplo n.º 10
0
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" ) );
    }
}
Exemplo n.º 11
0
void it_artifact_armor::deserialize(JsonObject &jo)
{
    id = jo.get_string("id");
    name = jo.get_string("name");
    description = jo.get_string("description");
    sym = jo.get_int("sym");
    color = int_to_color(jo.get_int("color"));
    price = jo.get_int("price");
    // LEGACY: Since it seems artifacts get serialized out to disk, and they're
    // dynamic, we need to allow for them to be read from disk for, oh, I guess
    // quite some time. Loading and saving once will write things out as a JSON
    // array.
    if (jo.has_string("m1")) {
        materials.push_back(jo.get_string("m1"));
    }
    if (jo.has_string("m2")) {
        materials.push_back(jo.get_string("m2"));
    }
    // Assumption, perhaps dangerous, that we won't wind up with m1 and m2 and
    // a materials array in our serialized objects at the same time.
    if (jo.has_array("materials")) {
        JsonArray jarr = jo.get_array("materials");
        for (int i = 0; i < jarr.size(); ++i) {
            materials.push_back(jarr.get_string(i));
        }
    }
    if (materials.size() == 0) {
        // I don't think we need this, but a lot of code seems to want at least
        // one material and I'm not sure I found every single corner case.
        materials.push_back("null");
    }
    volume = jo.get_int("volume");
    weight = jo.get_int("weight");
    melee_dam = jo.get_int("melee_dam");
    melee_cut = jo.get_int("melee_cut");
    m_to_hit = jo.get_int("m_to_hit");
    item_tags = jo.get_tags("item_flags");

    jo.read( "covers", covers);
    encumber = jo.get_int("encumber");
    coverage = jo.get_int("coverage");
    thickness = jo.get_int("material_thickness");
    env_resist = jo.get_int("env_resist");
    warmth = jo.get_int("warmth");
    storage = jo.get_int("storage");
    power_armor = jo.get_bool("power_armor");

    JsonArray ja = jo.get_array("effects_worn");
    while (ja.has_more()) {
        effects_worn.push_back((art_effect_passive)ja.next_int());
    }
}
Exemplo n.º 12
0
void MonsterGenerator::load_monster(JsonObject &jo)
{
    // id
    std::string mid;
    if (jo.has_member("id")){
        mid = 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());
        newmon->description = _(jo.get_string("description").c_str());

        newmon->mat = jo.get_string("material");

        newmon->species = jo.get_tags("species");
        newmon->categories = jo.get_tags("categories");

        newmon->sym = jo.get_string("symbol")[0]; // will fail here if there is no symbol
        newmon->color = color_from_string(jo.get_string("color"));
        newmon->size = get_from_string(jo.get_string("size", "MEDIUM"), 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->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->item_chance = jo.get_int("item_chance", 0);
        newmon->hp = jo.get_int("hp", 0);
        newmon->sp_freq = jo.get_int("special_freq", 0);
        newmon->luminance = jo.get_float("luminance", 0);

        newmon->dies = get_death_functions(jo, "death_function");
        newmon->sp_attack = get_attack_function(jo, "special_attack");

        std::set<std::string> flags, anger_trig, placate_trig, fear_trig, cats;
        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;
    }
}
Exemplo n.º 13
0
void MonsterGenerator::load_species(JsonObject &jo)
{
    const species_id sid( jo.get_string( "id" ) );
    if (mon_species.count(sid) > 0) {
        delete mon_species[sid];
    }

    std::set<std::string> sflags, sanger, sfear, splacate;
    sflags = jo.get_tags("flags");
    sanger = jo.get_tags("anger_triggers");
    sfear  = jo.get_tags("fear_triggers");
    splacate = jo.get_tags("placate_triggers");

    std::set<m_flag> flags = get_set_from_tags(sflags, flag_map, MF_NULL);
    std::set<monster_trigger> anger, fear, placate;
    anger = get_set_from_tags(sanger, trigger_map, MTRIG_NULL);
    fear = get_set_from_tags(sfear, trigger_map, MTRIG_NULL);
    placate = get_set_from_tags(splacate, trigger_map, MTRIG_NULL);

    species_type *new_species = new species_type(sid, flags, anger, fear, placate);

    mon_species[sid] = new_species;
}
Exemplo n.º 14
0
void MonsterGenerator::load_species(JsonObject &jo)
{
    // id, flags, triggers (anger, placate, fear)
    std::string sid;
    if (jo.has_member("id")){
        sid = jo.get_string("id");

        std::set<std::string> sflags, sanger, sfear, splacate;
        sflags = jo.get_tags("flags");
        sanger = jo.get_tags("anger_triggers");
        sfear  = jo.get_tags("fear_triggers");
        splacate = jo.get_tags("placate_triggers");

        std::set<m_flag> flags = get_set_from_tags(sflags, flag_map, MF_NULL);
        std::set<monster_trigger> anger, fear, placate;
        anger = get_set_from_tags(sanger, trigger_map, MTRIG_NULL);
        fear = get_set_from_tags(sfear, trigger_map, MTRIG_NULL);
        placate = get_set_from_tags(splacate, trigger_map, MTRIG_NULL);

        species_type *new_species = new species_type(sid, flags, anger, fear, placate);

        mon_species[sid] = new_species;
    }
}
Exemplo n.º 15
0
std::vector<void (mdeath::*)(monster*)> MonsterGenerator::get_death_functions(JsonObject& jo, std::string member)
{
    std::vector<void (mdeath::*)(monster*)> deaths;

    std::set<std::string> death_flags = jo.get_tags(member);

    std::set<std::string>::iterator it = death_flags.begin();
    for (; it != death_flags.end(); ++it) {
        deaths.push_back(death_map[*it]);
    }

    if (deaths.size() == 0)
        deaths.push_back(death_map["NORMAL"]);
    return deaths;
}
Exemplo n.º 16
0
void Skill::load_skill(JsonObject &jsobj)
{
    skill_id ident = skill_id( jsobj.get_string("ident") );
    skills.erase(std::remove_if(begin(skills), end(skills), [&](Skill const &s) {
        return s._ident == ident; }), end(skills));

    std::string name           = _(jsobj.get_string("name").c_str());
    std::string description    = _(jsobj.get_string("description").c_str());
    std::set<std::string> tags = jsobj.get_tags("tags");

    DebugLog( D_INFO, DC_ALL ) << "Loaded skill: " << name;

    skills.emplace_back(std::move(ident), std::move(name), std::move(description),
                        std::move(tags));
}
Exemplo n.º 17
0
void it_artifact_tool::deserialize(JsonObject &jo)
{
    id = jo.get_string("id");
    name = jo.get_string("name");
    description = jo.get_string("description");
    sym = jo.get_int("sym");
    color = int_to_color(jo.get_int("color"));
    price = jo.get_int("price");
    m1 = jo.get_string("m1");
    m2 = jo.get_string("m2");
    volume = jo.get_int("volume");
    weight = jo.get_int("weight");
    melee_dam = jo.get_int("melee_dam");
    melee_cut = jo.get_int("melee_cut");
    m_to_hit = jo.get_int("m_to_hit");
    item_tags = jo.get_tags("item_flags");

    max_charges = jo.get_long("max_charges");
    def_charges = jo.get_long("def_charges");

    std::vector<int> rand_charges;
    JsonArray jarr = jo.get_array("rand_charges");
    while (jarr.has_more()){
        rand_charges.push_back(jarr.next_long());
    }

    charges_per_use = jo.get_int("charges_per_use");
    turns_per_charge = jo.get_int("turns_per_charge");
    ammo = jo.get_string("ammo");
    revert_to = jo.get_string("revert_to");

    charge_type = (art_charge)jo.get_int("charge_type");

    JsonArray ja = jo.get_array("effects_wielded");
    while (ja.has_more()) {
        effects_wielded.push_back((art_effect_passive)ja.next_int());
    }

    ja = jo.get_array("effects_activated");
    while (ja.has_more()) {
        effects_activated.push_back((art_effect_active)ja.next_int());
    }

    ja = jo.get_array("effects_carried");
    while (ja.has_more()) {
        effects_carried.push_back((art_effect_passive)ja.next_int());
    }
}
Exemplo n.º 18
0
void Skill::load_skill( JsonObject &jsobj )
{
    skill_id ident = skill_id( jsobj.get_string( "ident" ) );
    skills.erase( std::remove_if( begin( skills ), end( skills ), [&]( const Skill & s ) {
        return s._ident == ident;
    } ), end( skills ) );

    const Skill sk( ident, _( jsobj.get_string( "name" ) ), _( jsobj.get_string( "description" ) ),
                    jsobj.get_tags( "tags" ) );

    if( sk.is_contextual_skill() ) {
        contextual_skills[sk.ident()] = sk;
    } else {
        skills.push_back( sk );
    }
}
Exemplo n.º 19
0
void Item_factory::load_ammo(JsonObject& jo)
{
    it_ammo* ammo_template = new it_ammo();
    ammo_template->type = jo.get_string("ammo_type");
    ammo_template->casing = jo.get_string("casing", "");
    ammo_template->damage = jo.get_int("damage");
    ammo_template->pierce = jo.get_int("pierce");
    ammo_template->range = jo.get_int("range");
    ammo_template->dispersion = jo.get_int("dispersion");
    ammo_template->recoil = jo.get_int("recoil");
    ammo_template->count = jo.get_int("count");
    ammo_template->stack_size = jo.get_int("stack_size", ammo_template->count);
    ammo_template->ammo_effects = jo.get_tags("effects");

    itype *new_item_template = ammo_template;
    load_basic_info(jo, new_item_template);
}
Exemplo n.º 20
0
void Item_factory::load_gun(JsonObject& jo)
{
    it_gun* gun_template = new it_gun();
    gun_template->ammo = jo.get_string("ammo");
    gun_template->skill_used = Skill::skill(jo.get_string("skill"));
    gun_template->dmg_bonus = jo.get_int("ranged_damage");
    gun_template->range = jo.get_int("range");
    gun_template->dispersion = jo.get_int("dispersion");
    gun_template->recoil = jo.get_int("recoil");
    gun_template->durability = jo.get_int("durability");
    gun_template->burst = jo.get_int("burst");
    gun_template->clip = jo.get_int("clip_size");
    gun_template->reload_time = jo.get_int("reload");
    gun_template->pierce = jo.get_int("pierce", 0);
    gun_template->ammo_effects = jo.get_tags("ammo_effects");

    itype *new_item_template = gun_template;
    load_basic_info(jo, new_item_template);
}
Exemplo n.º 21
0
void Item_factory::load_gunmod(JsonObject& jo)
{
    it_gunmod* gunmod_template = new it_gunmod();
    gunmod_template->damage = jo.get_int("damage_modifier", 0);
    gunmod_template->loudness = jo.get_int("loudness_modifier", 0);
    gunmod_template->newtype = jo.get_string("ammo_modifier");
    gunmod_template->used_on_pistol = is_mod_target(jo, "mod_targets", "pistol");
    gunmod_template->used_on_shotgun = is_mod_target(jo, "mod_targets", "shotgun");
    gunmod_template->used_on_smg = is_mod_target(jo, "mod_targets", "smg");
    gunmod_template->used_on_rifle = is_mod_target(jo, "mod_targets", "rifle");
    gunmod_template->dispersion = jo.get_int("dispersion_modifier", 0);
    gunmod_template->recoil = jo.get_int("recoil_modifier", 0);
    gunmod_template->burst = jo.get_int("burst_modifier", 0);
    gunmod_template->clip = jo.get_int("clip_size_modifier", 0);
    gunmod_template->acceptible_ammo_types = jo.get_tags("acceptable_ammo");

    itype *new_item_template = gunmod_template;
    load_basic_info(jo, new_item_template);
}
Exemplo n.º 22
0
std::vector<mon_action_death> MonsterGenerator::get_death_functions(JsonObject &jo,
        std::string member)
{
    std::vector<mon_action_death> deaths;

    std::set<std::string> death_flags = jo.get_tags(member);

    std::set<std::string>::iterator it = death_flags.begin();
    for (; it != death_flags.end(); ++it) {
        if ( death_map.find(*it) != death_map.end() ) {
            deaths.push_back(death_map[*it]);
        } else {
            jo.throw_error("Invalid death_function");
        }
    }

    if (deaths.empty()) {
        deaths.push_back(death_map["NORMAL"]);
    }
    return deaths;
}
Exemplo n.º 23
0
void mission_type::load( JsonObject &jo, const std::string &src )
{
    const bool strict = src == "dda";

    mandatory( jo, was_loaded, "name", name );

    mandatory( jo, was_loaded, "difficulty", difficulty );
    mandatory( jo, was_loaded, "value", value );

    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( std::any_of( origins.begin(), origins.end(), []( mission_origin origin ) {
    return origin == ORIGIN_ANY_NPC || origin == ORIGIN_OPENER_NPC || origin == ORIGIN_SECONDARY;
} ) ) {
        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 );
    if( jo.has_string( "start" ) ) {
        assign_function( jo, "start", start, mission_function_map );
    } else if( jo.has_member( "start" ) ) {
        JsonObject j_start = jo.get_object( "start" );
        parse_start( j_start );
    }
    assign_function( jo, "end", end, mission_function_map );
    assign_function( jo, "fail", fail, mission_function_map );

    assign( jo, "deadline_low", deadline_low, false, 1_days );
    assign( jo, "deadline_high", deadline_high, false, 1_days );

    if( jo.has_member( "followup" ) ) {
        follow_up = mission_type_id( jo.get_string( "followup" ) );
    }

    if( jo.has_member( "monster_species" ) ) {
        monster_species = species_id( jo.get_string( "monster_species" ) );
    }
    if( jo.has_member( "monster_type" ) ) {
        monster_type = mtype_id( jo.get_string( "monster_type" ) );
    }

    if( jo.has_member( "monster_kill_goal" ) ) {
        monster_kill_goal = jo.get_int( "monster_kill_goal" );
    }

    assign( jo, "destination", target_id, strict );
}
Exemplo n.º 24
0
void load_construction(JsonObject &jo)
{
    construction *con = new construction;
    JsonArray temp;

    con->description = _(jo.get_string("description").c_str());
    con->difficulty = jo.get_int("difficulty");
    con->time = jo.get_int("time");

    temp = jo.get_array("tools");
    while (temp.has_more()) {
        std::vector<component> tool_choices;
        JsonArray ja = temp.next_array();
        while (ja.has_more()) {
            std::string name = ja.next_string();
            tool_choices.push_back(component(name, 1));
        }
        con->tools.push_back(tool_choices);
    }

    temp = jo.get_array("components");
    while (temp.has_more()) {
        std::vector<component> comp_choices;
        JsonArray ja = temp.next_array();
        while (ja.has_more()) {
            JsonArray comp = ja.next_array();
            std::string name = comp.get_string(0);
            int quant = comp.get_int(1);
            comp_choices.push_back(component(name, quant));
        }
        con->components.push_back(comp_choices);
    }

    con->pre_terrain = jo.get_string("pre_terrain", "");
    if (con->pre_terrain.size() > 1
            && con->pre_terrain[0] == 'f'
            && con->pre_terrain[1] == '_') {
        con->pre_is_furniture = true;
    } else {
        con->pre_is_furniture = false;
    }

    con->post_terrain = jo.get_string("post_terrain", "");
    if (con->post_terrain.size() > 1
            && con->post_terrain[0] == 'f'
            && con->post_terrain[1] == '_') {
        con->post_is_furniture = true;
    } else {
        con->post_is_furniture = false;
    }

    con->pre_flags = jo.get_tags("pre_flags");

    std::string prefunc = jo.get_string("pre_special", "");
    if (prefunc == "check_empty") {
        con->pre_special = &construct::check_empty;
    } else if (prefunc == "check_support") {
        con->pre_special = &construct::check_support;
    } else {
        // should probably print warning if not ""
        con->pre_special = &construct::check_nothing;
    }

    std::string postfunc = jo.get_string("post_special", "");
    if (postfunc == "done_tree") {
        con->post_special = &construct::done_tree;
    } else if (postfunc == "done_trunk_log") {
        con->post_special = &construct::done_trunk_log;
    } else if (postfunc == "done_trunk_plank") {
        con->post_special = &construct::done_trunk_plank;
    } else if (postfunc == "done_vehicle") {
        con->post_special = &construct::done_vehicle;
    } else if (postfunc == "done_deconstruct") {
        con->post_special = &construct::done_deconstruct;
    } else {
        // ditto, should probably warn here
        con->post_special = &construct::done_nothing;
    }

    con->id = constructions.size();
    constructions.push_back(con);
    constructions_by_desc[con->description].push_back(con);
}
Exemplo n.º 25
0
ma_buff load_buff(JsonObject &jo)
{
    ma_buff buff;

    buff.id = jo.get_string("id");

    buff.name = _(jo.get_string("name").c_str());
    buff.description = _(jo.get_string("description").c_str());

    buff.buff_duration = jo.get_int("buff_duration", 2);
    buff.max_stacks = jo.get_int("max_stacks", 1);

    buff.reqs.unarmed_allowed = jo.get_bool("unarmed_allowed", false);
    buff.reqs.melee_allowed = jo.get_bool("melee_allowed", false);

    buff.reqs.min_melee = jo.get_int("min_melee", 0);
    buff.reqs.min_unarmed = jo.get_int("min_unarmed", 0);

    buff.dodges_bonus = jo.get_int("bonus_dodges", 0);
    buff.blocks_bonus = jo.get_int("bonus_blocks", 0);

    buff.hit = jo.get_int("hit", 0);
    buff.bash = jo.get_int("bash", 0);
    buff.cut = jo.get_int("cut", 0);
    buff.dodge = jo.get_int("dodge", 0);
    buff.speed = jo.get_int("speed", 0);
    buff.block = jo.get_int("block", 0);

    buff.arm_bash = jo.get_int("arm_bash", 0);
    buff.arm_cut = jo.get_int("arm_cut", 0);

    buff.bash_stat_mult = jo.get_float("bash_mult", 1.0);
    buff.cut_stat_mult = jo.get_float("cut_mult", 1.0);

    buff.hit_str = jo.get_float("hit_str", 0.0);
    buff.hit_dex = jo.get_float("hit_dex", 0.0);
    buff.hit_int = jo.get_float("hit_int", 0.0);
    buff.hit_per = jo.get_float("hit_per", 0.0);

    buff.bash_str = jo.get_float("bash_str", 0.0);
    buff.bash_dex = jo.get_float("bash_dex", 0.0);
    buff.bash_int = jo.get_float("bash_int", 0.0);
    buff.bash_per = jo.get_float("bash_per", 0.0);

    buff.cut_str = jo.get_float("cut_str", 0.0);
    buff.cut_dex = jo.get_float("cut_dex", 0.0);
    buff.cut_int = jo.get_float("cut_int", 0.0);
    buff.cut_per = jo.get_float("cut_per", 0.0);

    buff.dodge_str = jo.get_float("dodge_str", 0.0);
    buff.dodge_dex = jo.get_float("dodge_dex", 0.0);
    buff.dodge_int = jo.get_float("dodge_int", 0.0);
    buff.dodge_per = jo.get_float("dodge_per", 0.0);

    buff.block_str = jo.get_float("block_str", 0.0);
    buff.block_dex = jo.get_float("block_dex", 0.0);
    buff.block_int = jo.get_float("block_int", 0.0);
    buff.block_per = jo.get_float("block_per", 0.0);

    buff.quiet = jo.get_bool("quiet", false);
    buff.throw_immune = jo.get_bool("throw_immune", false);

    buff.reqs.req_buffs = jo.get_tags("req_buffs");

    ma_buffs[buff.id] = buff;

    return buff;
}
Exemplo n.º 26
0
void mutation_branch::load( JsonObject &jsobj )
{
    const std::string id = jsobj.get_string( "id" );
    mutation_branch &new_mut = mutation_data[id];

    JsonArray jsarr;
    new_mut.name = _(jsobj.get_string("name").c_str());
    new_mut.description = _(jsobj.get_string("description").c_str());
    new_mut.points = jsobj.get_int("points");
    new_mut.visibility = jsobj.get_int("visibility", 0);
    new_mut.ugliness = jsobj.get_int("ugliness", 0);
    new_mut.startingtrait = jsobj.get_bool("starting_trait", false);
    new_mut.mixed_effect = jsobj.get_bool("mixed_effect", false);
    new_mut.activated = jsobj.get_bool("active", false);
    new_mut.starts_active = jsobj.get_bool("starts_active", false);
    new_mut.destroys_gear = jsobj.get_bool("destroys_gear", false);
    new_mut.allow_soft_gear = jsobj.get_bool("allow_soft_gear", false);
    new_mut.cost = jsobj.get_int("cost", 0);
    new_mut.cooldown = jsobj.get_int("time",0);
    new_mut.hunger = jsobj.get_bool("hunger",false);
    new_mut.thirst = jsobj.get_bool("thirst",false);
    new_mut.fatigue = jsobj.get_bool("fatigue",false);
    new_mut.valid = jsobj.get_bool("valid", true);
    new_mut.purifiable = jsobj.get_bool("purifiable", true);
    for( auto & s : jsobj.get_string_array( "initial_ma_styles" ) ) {
        new_mut.initial_ma_styles.push_back( matype_id( s ) );
    }

    JsonArray bodytemp_array = jsobj.get_array( "bodytemp_modifiers" );
    if( bodytemp_array.has_more() ) {
        new_mut.bodytemp_min = bodytemp_array.get_int( 0 );
        new_mut.bodytemp_max = bodytemp_array.get_int( 1 );
    }
    new_mut.bodytemp_sleep = jsobj.get_int( "bodytemp_sleep", 0 );
    new_mut.threshold = jsobj.get_bool("threshold", false);
    new_mut.profession = jsobj.get_bool("profession", false);

    auto vr = jsobj.get_array( "vitamin_rates" );
    while( vr.has_more() ) {
        auto pair = vr.next_array();
        new_mut.vitamin_rates[ vitamin_id( pair.get_string( 0 ) ) ] = pair.get_int( 1 );
    }

    load_mutation_mods(jsobj, "passive_mods", new_mut.mods);
    /* Not currently supported due to inability to save active mutation state
    load_mutation_mods(jsobj, "active_mods", new_mut.mods); */

    new_mut.prereqs = jsobj.get_string_array( "prereqs" );
    // Helps to be able to have a trait require more than one other trait
    // (Individual prereq-lists are "OR", not "AND".)
    // Traits shoud NOT appear in both lists for a given mutation, unless
    // you want that trait to satisfy both requirements.
    // These are additional to the first list.
    new_mut.prereqs2 = jsobj.get_string_array( "prereqs2" );
    // Dedicated-purpose prereq slot for Threshold mutations
    // Stuff like Huge might fit in more than one mutcat post-threshold, so yeah
    new_mut.threshreq = jsobj.get_string_array( "threshreq" );
    new_mut.cancels = jsobj.get_string_array( "cancels" );
    new_mut.replacements = jsobj.get_string_array( "changes_to" );
    new_mut.additions = jsobj.get_string_array( "leads_to" );
    new_mut.flags = jsobj.get_tags( "flags" );
    jsarr = jsobj.get_array("category");
    while (jsarr.has_more()) {
        std::string s = jsarr.next_string();
        new_mut.category.push_back(s);
        mutations_category[s].push_back(id);
    }
    jsarr = jsobj.get_array("wet_protection");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        std::string part_id = jo.get_string("part");
        int ignored = jo.get_int("ignored", 0);
        int neutral = jo.get_int("neutral", 0);
        int good = jo.get_int("good", 0);
        tripoint protect = tripoint(ignored, neutral, good);
        new_mut.protection[get_body_part_token( part_id )] = protect;
    }

    jsarr = jsobj.get_array("encumbrance_always");
    while (jsarr.has_more()) {
        JsonArray jo = jsarr.next_array();
        std::string part_id = jo.next_string();
        int enc = jo.next_int();
        new_mut.encumbrance_always[get_body_part_token( part_id )] = enc;
    }

    jsarr = jsobj.get_array("encumbrance_covered");
    while (jsarr.has_more()) {
        JsonArray jo = jsarr.next_array();
        std::string part_id = jo.next_string();
        int enc = jo.next_int();
        new_mut.encumbrance_covered[get_body_part_token( part_id )] = enc;
    }

    jsarr = jsobj.get_array("restricts_gear");
    while( jsarr.has_more() ) {
        new_mut.restricts_gear.insert( get_body_part_token( jsarr.next_string() ) );
    }

    jsarr = jsobj.get_array( "armor" );
    while( jsarr.has_more() ) {
        JsonObject jo = jsarr.next_object();
        auto parts = jo.get_tags( "parts" );
        std::set<body_part> bps;
        for( const std::string &part_string : parts ) {
            if( part_string == "ALL" ) {
                // Shorthand, since many muts protect whole body
                for( size_t i = 0; i < num_bp; i++ ) {
                    bps.insert( static_cast<body_part>( i ) );
                }
            } else {
                bps.insert( get_body_part_token( part_string ) );
            }
        }

        resistances res = load_resistances_instance( jo );

        for( body_part bp : bps ) {
            new_mut.armor[ bp ] = res;
        }
    }
}
Exemplo n.º 27
0
void load_construction(JsonObject &jo)
{
    construction con;
    con.id = constructions.size();

    con.description = _(jo.get_string("description").c_str());
    con.skill = skill_id( jo.get_string( "skill", skill_carpentry.str() ) );
    con.difficulty = jo.get_int("difficulty");
    con.category = jo.get_string("category", "OTHER");
    // constructions use different time units in json, this makes it compatible
    // with recipes/requirements, TODO: should be changed in json
    con.time = jo.get_int("time") * 1000;

    if( jo.has_string( "using" ) ) {
        con.requirements = requirement_id( jo.get_string( "using" ) );
    } else {
        // Warning: the IDs may change!
        std::string req_id = string_format( "inline_construction_%i", con.id );
        requirement_data::load_requirement( jo, req_id );
        con.requirements = requirement_id( req_id );
    }

    con.pre_terrain = jo.get_string("pre_terrain", "");
    if (con.pre_terrain.size() > 1
        && con.pre_terrain[0] == 'f'
        && con.pre_terrain[1] == '_') {
        con.pre_is_furniture = true;
    } else {
        con.pre_is_furniture = false;
    }

    con.post_terrain = jo.get_string("post_terrain", "");
    if (con.post_terrain.size() > 1
        && con.post_terrain[0] == 'f'
        && con.post_terrain[1] == '_') {
        con.post_is_furniture = true;
    } else {
        con.post_is_furniture = false;
    }

    con.pre_flags = jo.get_tags("pre_flags");

    std::string prefunc = jo.get_string("pre_special", "");
    if (prefunc == "check_empty") {
        con.pre_special = &construct::check_empty;
    } else if (prefunc == "check_support") {
        con.pre_special = &construct::check_support;
    } else if (prefunc == "check_deconstruct") {
        con.pre_special = &construct::check_deconstruct;
    } else if (prefunc == "check_up_OK") {
        con.pre_special = &construct::check_up_OK;
    } else if (prefunc == "check_down_OK") {
        con.pre_special = &construct::check_down_OK;
    } else {
        if (prefunc != "") {
            debugmsg("Unknown pre_special function: %s", prefunc.c_str());
        }
        con.pre_special = &construct::check_nothing;
    }

    std::string postfunc = jo.get_string("post_special", "");
    if (postfunc == "done_tree") {
        con.post_special = &construct::done_tree;
    } else if (postfunc == "done_trunk_log") {
        con.post_special = &construct::done_trunk_log;
    } else if (postfunc == "done_trunk_plank") {
        con.post_special = &construct::done_trunk_plank;
    } else if (postfunc == "done_vehicle") {
        con.post_special = &construct::done_vehicle;
    } else if (postfunc == "done_deconstruct") {
        con.post_special = &construct::done_deconstruct;
    } else if (postfunc == "done_dig_stair") {
        con.post_special = &construct::done_dig_stair;
    } else if (postfunc == "done_mine_downstair") {
        con.post_special = &construct::done_mine_downstair;
    } else if (postfunc == "done_mine_upstair") {
        con.post_special = &construct::done_mine_upstair;
    } else if (postfunc == "done_window_curtains") {
        con.post_special = &construct::done_window_curtains;
    } else {
        if (postfunc != "") {
            debugmsg("Unknown post_special function: %s", postfunc.c_str());
        }
        con.post_special = &construct::done_nothing;
    }

    constructions.push_back(con);
}
Exemplo n.º 28
0
void MonsterGenerator::load_monster(JsonObject &jo)
{
    // id
    std::string mid;
    if (jo.has_member("id")) {
        mid = 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());

        newmon->mat = jo.get_string("material");

        newmon->species = jo.get_tags("species");
        newmon->categories = jo.get_tags("categories");

        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"), 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->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", "" );
        
        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),
                                    body_parts[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_string("death_drops")) {
            newmon->death_drops = jo.get_string("death_drops");
        } else if (jo.has_object("death_drops")) {
            JsonObject death_frop_json = jo.get_object("death_drops");
            // Make up a group name, should be unique (include the monster id),
            newmon->death_drops = newmon->id + "_death_drops_auto";
            const std::string subtype = death_frop_json.get_string("subtype", "distribution");
            // and load the entry as a standard item group using the made up name.
            item_group::load_item_group(death_frop_json, newmon->death_drops, subtype);
        } else if (jo.has_member("death_drops")) {
            jo.throw_error("invalid type, must be string or object", "death_drops");
        }

        newmon->dies = get_death_functions(jo, "death_function");
        load_special_defense(newmon, jo, "special_when_hit");
        load_special_attacks(newmon, jo, "special_attacks");

        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;
    }
}
Exemplo n.º 29
0
void Item_factory::load_basic_info(JsonObject& jo, itype* new_item_template)
{
    std::string new_id = jo.get_string("id");
    new_item_template->id = new_id;
    m_templates[new_id] = new_item_template;

    // And then proceed to assign the correct field
    new_item_template->price = jo.get_int("price");
    new_item_template->name = _(jo.get_string("name").c_str());
    new_item_template->sym = jo.get_string("symbol")[0];
    new_item_template->color = color_from_string(jo.get_string("color"));
    new_item_template->description = _(jo.get_string("description").c_str());
    if(jo.has_member("material")){
      set_material_from_json(jo, "material", new_item_template);
    } else {
      new_item_template->m1 = "null";
      new_item_template->m2 = "null";
    }
    Item_tag new_phase = "solid";
    if(jo.has_member("phase")){
        new_phase = jo.get_string("phase");
    }
    new_item_template->phase = phase_from_tag(new_phase);
    new_item_template->volume = jo.get_int("volume");
    new_item_template->weight = jo.get_int("weight");
    new_item_template->melee_dam = jo.get_int("bashing");
    new_item_template->melee_cut = jo.get_int("cutting");
    new_item_template->m_to_hit = jo.get_int("to_hit");

    new_item_template->light_emission = 0;

    /*
    List of current flags
    FIT - Reduces encumbrance by one
    SKINTIGHT - Reduces layer penalty
    VARSIZE - Can be made to fit via tailoring
    OVERSIZE - Can always be worn no matter encumbrance/mutations/bionics/etc
    POCKETS - Will increase warmth for hands if hands are cold and the player is wielding nothing
    HOOD - Will increase warmth for head if head is cold and player's head isn't encumbered
    RAINPROOF - Works like a raincoat to protect from rain effects
    WATCH - Shows the current time, instead of sun/moon position
    ALARMCLOCK - Has an alarmclock feature
    FANCY - Less than practical clothing meant primarily to convey a certain image.
    SUPER_FANCY - Clothing suitable for the most posh of events.
    LIGHT_* - light emission, sets cached int light_emission
    USE_EAT_VERB - Use the eat verb, even if it's a liquid(soup, jam etc.)
    STURDY - Clothing is made to be armor. Prevents damage to armor unless it is penetrated.

    Container-only flags:
    SEALS
    RIGID
    WATERTIGHT
    */
    new_item_template->item_tags = jo.get_tags("flags");
    if ( new_item_template->item_tags.size() > 0 ) {
        for( std::set<std::string>::const_iterator it = new_item_template->item_tags.begin();
        it != new_item_template->item_tags.end(); ++it ) {
            set_intvar(std::string(*it), new_item_template->light_emission, 1, 10000);
        }
    }

    if( jo.has_member("qualities") ){
        set_qualities_from_json(jo, "qualities", new_item_template);
    }

    new_item_template->techniques = jo.get_tags("techniques");

    new_item_template->use = (!jo.has_member("use_action") ? &iuse::none :
                              use_from_string(jo.get_string("use_action")));
}
Exemplo n.º 30
0
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;
}