Ejemplo n.º 1
0
void profession::load_profession(JsonObject &jsobj)
{
    profession prof;
    JsonArray jsarr;

    prof._ident = jsobj.get_string("ident");
    prof._name = _(jsobj.get_string("name").c_str());
    prof._description = _(jsobj.get_string("description").c_str());
    prof._point_cost = jsobj.get_int("points");

    jsarr = jsobj.get_array("items");
    while (jsarr.has_more()) {
        prof.add_item(jsarr.next_string());
    }
    jsarr = jsobj.get_array("skills");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        prof.add_skill(jo.get_string("name"),
                       jo.get_int("level"));
    }
    jsarr = jsobj.get_array("addictions");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        prof.add_addiction(addiction_type(jo.get_string("type")),
                           jo.get_int("intensity"));
    }
    jsarr = jsobj.get_array("flags");
    while (jsarr.has_more()) {
        prof.flags.insert(jsarr.next_string());
    }

    _all_profs[prof._ident] = prof;
    //dout(D_INFO) << "Loaded profession: " << prof._name;
}
Ejemplo n.º 2
0
void profession::load_profession(JsonObject &jsobj)
{
    profession prof;
    JsonArray jsarr;

    prof._ident = jsobj.get_string("ident");
    //If the "name" is an object then we have to deal with gender-specific titles,
    if(jsobj.has_object("name")) {
        JsonObject name_obj = jsobj.get_object("name");
        prof._name_male = pgettext("profession_male", name_obj.get_string("male").c_str());
        prof._name_female = pgettext("profession_female", name_obj.get_string("female").c_str());
    } else {
        // Same profession names for male and female in English.
        // Still need to different names in other languages.
        const std::string name = jsobj.get_string("name");
        prof._name_female = pgettext("profession_female", name.c_str());
        prof._name_male = pgettext("profession_male", name.c_str());
    }

    const std::string desc = jsobj.get_string("description").c_str();
    prof._description_male = pgettext("prof_desc_male", desc.c_str());
    prof._description_female = pgettext("prof_desc_female", desc.c_str());

    prof._point_cost = jsobj.get_int("points");

    JsonObject items_obj = jsobj.get_object("items");
    prof.add_items_from_jsonarray(items_obj.get_array("both"), "both");
    prof.add_items_from_jsonarray(items_obj.get_array("male"), "male");
    prof.add_items_from_jsonarray(items_obj.get_array("female"), "female");

    jsarr = jsobj.get_array("skills");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        prof.add_skill(jo.get_string("name"),
                       jo.get_int("level"));
    }
    jsarr = jsobj.get_array("addictions");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        prof.add_addiction(addiction_type(jo.get_string("type")),
                           jo.get_int("intensity"));
    }
    jsarr = jsobj.get_array("CBMs");
    while (jsarr.has_more()) {
        prof.add_CBM(jsarr.next_string());
    }
    jsarr = jsobj.get_array("flags");
    while (jsarr.has_more()) {
        prof.flags.insert(jsarr.next_string());
    }

    _all_profs[prof._ident] = prof;
    DebugLog( D_INFO, DC_ALL ) << "Loaded profession: " << prof._ident;
}
Ejemplo n.º 3
0
void Item_factory::load_comestible(JsonObject& jo)
{
    it_comest* comest_template = new it_comest();
    comest_template->comesttype = jo.get_string("comestible_type");
    comest_template->tool = jo.get_string("tool", "null");
    comest_template->container = jo.get_string("container", "null");
    comest_template->quench = jo.get_int("quench", 0);
    comest_template->nutr = jo.get_int("nutrition", 0);
    comest_template->spoils = jo.get_int("spoils_in", 0);
    comest_template->addict = jo.get_int("addiction_potential", 0);
    comest_template->charges = jo.get_int("charges", 0);
    if(jo.has_member("stack_size")) {
      comest_template->stack_size = jo.get_int("stack_size");
    } else {
      comest_template->stack_size = comest_template->charges;
    }
    comest_template->stim = jo.get_int("stim", 0);
    comest_template->healthy = jo.get_int("heal", 0);
    comest_template->fun = jo.get_int("fun", 0);
    comest_template->add = addiction_type(jo.get_string("addiction_type"));

    itype *new_item_template = comest_template;
    load_basic_info(jo, new_item_template);
}
Ejemplo n.º 4
0
 addiction get_next( JsonIn &jin ) const {
     JsonObject jo = jin.get_object();
     return addiction( addiction_type( jo.get_string( "type" ) ), jo.get_int( "intensity" ) );
 }
Ejemplo n.º 5
0
 void erase_next( JsonIn &jin, C &container ) const {
     const add_type type = addiction_type( jin.get_string() );
     reader_detail::handler<C>().erase_if( container, [&type]( const addiction & e ) {
         return e.type == type;
     } );
 }
Ejemplo n.º 6
0
void profession::load_profession(JsonObject &jsobj)
{
    profession prof;
    JsonArray jsarr;

    prof._ident = jsobj.get_string("ident");
    //If the "name" is an object then we have to deal with gender-specific titles,
    //otherwise we assume "name" is a string and use its value for prof._name
    if(jsobj.has_object("name")) {
        JsonObject name_obj=jsobj.get_object("name");
        prof._name_male = _(name_obj.get_string("male").c_str());
        prof._name_female = _(name_obj.get_string("female").c_str());
        prof._name = "";
    }
    else {
        // Json only has a gender neutral name, construct additional
        // gender specific names using a prefix.
        // extract_json_strings.py contains code that automatically adds
        // these constructed strings to the translation table.
        const std::string name = jsobj.get_string("name");
        const std::string name_female = std::string("female ") + name;
        const std::string name_male = std::string("male ") + name;
        // Now attempt to translate them...
        prof._name = _(name.c_str());
        prof._name_female = _(name_female.c_str());
        prof._name_male = _(name_male.c_str());
        // ... if it fails, translate the gender prefix and use it to
        // construct generic specific names:
        if (prof._name_female == name_female) {
            //~ player info: "female <gender unspecific profession>"
            prof._name_female = string_format(_("female %s"), prof._name.c_str());
        }
        if (prof._name_male == name_male) {
            //~ player info: "male <gender unspecific profession>"
            prof._name_male = string_format(_("male %s"), prof._name.c_str());
        }
    }

    prof._description = _(jsobj.get_string("description").c_str());
    prof._point_cost = jsobj.get_int("points");

    JsonObject items_obj=jsobj.get_object("items");
    prof.add_items_from_jsonarray(items_obj.get_array("both"), "both");
    prof.add_items_from_jsonarray(items_obj.get_array("male"), "male");
    prof.add_items_from_jsonarray(items_obj.get_array("female"), "female");

    jsarr = jsobj.get_array("skills");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        prof.add_skill(jo.get_string("name"),
                       jo.get_int("level"));
    }
    jsarr = jsobj.get_array("addictions");
    while (jsarr.has_more()) {
        JsonObject jo = jsarr.next_object();
        prof.add_addiction(addiction_type(jo.get_string("type")),
                           jo.get_int("intensity"));
    }
    jsarr = jsobj.get_array("CBMs");
    while (jsarr.has_more()) {
        prof.add_CBM(jsarr.next_string());
    }
    jsarr = jsobj.get_array("flags");
    while (jsarr.has_more()) {
        prof.flags.insert(jsarr.next_string());
    }

    _all_profs[prof._ident] = prof;
    //dout(D_INFO) << "Loaded profession: " << prof._name;
}
Ejemplo n.º 7
0
// Load values from this data file into m_templates
void Item_factory::load_item_templates_from(const std::string file_name) throw (std::string){
    catajson all_items(file_name);

    if(! json_good())
    	throw (std::string)"Could not open " + file_name;

    if (! all_items.is_array())
        throw file_name + (std::string)"is not an array of item_templates";

    //Crawl through and extract the items
    for (all_items.set_begin(); all_items.has_curr(); all_items.next()) {
        catajson entry = all_items.curr();
        // The one element we absolutely require for an item definition is an id
        if(!entry.has("id") || !entry.get("id").is_string())
        {
            debugmsg("Item definition skipped, no id found or id was malformed.");
        }
        else
        {
            Item_tag new_id = entry.get("id").as_string();

            // If everything works out, add the item to the group list...
            // unless a similar item is already there
            if(m_templates.find(new_id) != m_templates.end())
            {
                debugmsg("Item definition skipped, id %s already exists.", new_id.c_str());
            }
            else
            {
                itype* new_item_template;
                if (!entry.has("type"))
                {
                    new_item_template = new itype();
                }
                else
                {
                    std::string type_label = entry.get("type").as_string();
                    if (type_label == "GUNMOD")
                    {
                        it_gunmod* gunmod_template = new it_gunmod();
                        gunmod_template->damage = entry.get("damage_modifier").as_int();;
                        gunmod_template->loudness = entry.get("loudness_modifier").as_int();
                        gunmod_template->newtype = entry.get("ammo_modifier").as_string();
                        gunmod_template->used_on_pistol = is_mod_target(entry.get("mod_targets"), "pistol");
                        gunmod_template->used_on_shotgun = is_mod_target(entry.get("mod_targets"), "shotgun");
                        gunmod_template->used_on_smg = is_mod_target(entry.get("mod_targets"), "smg");
                        gunmod_template->used_on_rifle = is_mod_target(entry.get("mod_targets"), "rifle");
                        gunmod_template->dispersion = entry.get("dispersion_modifier").as_int();
                        gunmod_template->recoil = entry.get("recoil_modifier").as_int();
                        gunmod_template->burst = entry.get("burst_modifier").as_int();
                        gunmod_template->clip = entry.get("clip_size_modifier").as_int();
                        if( entry.has("acceptable_ammo") ) {
                            tags_from_json( entry.get("acceptable_ammo"),
                                            gunmod_template->acceptible_ammo_types );
                        }
                        new_item_template = gunmod_template;
                    }
                    else if (type_label == "COMESTIBLE")
                    {
                        it_comest* comest_template = new it_comest();
                        comest_template->comesttype = entry.get("comestible_type").as_string();
                        comest_template->tool = entry.get("tool").as_string();
                        comest_template->container = entry.get("container").as_string();
                        comest_template->quench = entry.get("quench").as_int();
                        comest_template->nutr = entry.get("nutrition").as_int();
                        comest_template->spoils = entry.get("spoils_in").as_int();
                        comest_template->addict = entry.get("addiction_potential").as_int();
                        comest_template->charges = entry.get("charges").as_int();
                        comest_template->stim = entry.get("stim").as_int();
                        comest_template->healthy = entry.get("heal").as_int();
                        comest_template->fun = entry.get("fun").as_int();
                        comest_template->add = addiction_type(entry.get("addiction_type").as_string());
                        new_item_template = comest_template;
                    }
                    else if (type_label == "GUN")
                    {
                        it_gun* gun_template = new it_gun();
                        gun_template->ammo = entry.get("ammo").as_string();
                        gun_template->skill_used = Skill::skill(entry.get("skill").as_string());
                        gun_template->dmg_bonus = entry.get("ranged_damage").as_int();
                        gun_template->range = entry.get("range").as_int();
                        gun_template->dispersion = entry.get("dispersion").as_int();
                        gun_template->recoil = entry.get("recoil").as_int();
                        gun_template->durability = entry.get("durability").as_int();
                        gun_template->burst = entry.get("burst").as_int();
                        gun_template->clip = entry.get("clip_size").as_int();
                        gun_template->reload_time = entry.get("reload").as_int();
                        gun_template->pierce = entry.has("pierce") ? entry.get("pierce").as_int() : 0;
                        if( entry.has("ammo_effects") ) {
                            tags_from_json(entry.get("ammo_effects"), gun_template->ammo_effects);
                        }

                        new_item_template = gun_template;
                    }
                    else if (type_label == "TOOL")
                    {
                        it_tool* tool_template = new it_tool();
                        tool_template->ammo = entry.get("ammo").as_string();
                        tool_template->max_charges = entry.get("max_charges").as_int();
                        tool_template->def_charges = entry.get("initial_charges").as_int();
                        tool_template->charges_per_use = entry.get("charges_per_use").as_int();
                        tool_template->turns_per_charge = entry.get("turns_per_charge").as_int();
                        tool_template->revert_to = entry.get("revert_to").as_string();

                        new_item_template = tool_template;
                    }
                    else if (type_label == "AMMO")
                    {
                        it_ammo* ammo_template = new it_ammo();
                        ammo_template->type = entry.get("ammo_type").as_string();
                        if(entry.has("casing")) {
                            ammo_template->casing = entry.get("casing").as_string();
                        }
                        ammo_template->damage = entry.get("damage").as_int();
                        ammo_template->pierce = entry.get("pierce").as_int();
                        ammo_template->range = entry.get("range").as_int();
                        ammo_template->dispersion =
                            entry.get("dispersion").as_int();
                        ammo_template->recoil = entry.get("recoil").as_int();
                        ammo_template->count = entry.get("count").as_int();
                        if( entry.has("effects") ) {
                            tags_from_json(entry.get("effects"), ammo_template->ammo_effects);
                        }

                        new_item_template = ammo_template;
                    }
                    else if (type_label == "ARMOR")
                    {
                        it_armor* armor_template = new it_armor();

                        armor_template->encumber = entry.get("encumberance").as_int();
                        armor_template->coverage = entry.get("coverage").as_int();
                        armor_template->thickness = entry.get("material_thickness").as_int();
                        armor_template->env_resist = entry.get("enviromental_protection").as_int();
                        armor_template->warmth = entry.get("warmth").as_int();
                        armor_template->storage = entry.get("storage").as_int();
                        armor_template->power_armor = entry.has("power_armor") ? entry.get("power_armor").as_bool() : false;
                        armor_template->covers = entry.has("covers") ?
                          flags_from_json(entry.get("covers"),"bodyparts") : 0;

                        new_item_template = armor_template;
                    }
                    else if (type_label == "BOOK")
                    {
                        it_book* book_template = new it_book();

                        book_template->level = entry.get("max_level").as_int();
                        book_template->req = entry.get("required_level").as_int();
                        book_template->fun = entry.get("fun").as_int();
                        book_template->intel = entry.get("intelligence").as_int();
                        book_template->time = entry.get("time").as_int();
                        book_template->type = Skill::skill(entry.get("skill").as_string());

                        new_item_template = book_template;
                    }
                    else if (type_label == "CONTAINER")
                    {
                        it_container* container_template = new it_container();

                        container_template->contains = entry.get("contains").as_int();

                        new_item_template = container_template;
                    }
                    else
                    {
                        debugmsg("Item definition for %s skipped, unrecognized type: %s", new_id.c_str(),
                                 type_label.c_str());
                        break;
                    }
                }
                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 = entry.get("price").as_int();
                new_item_template->name = _(entry.get("name").as_string().c_str());
                new_item_template->sym = entry.get("symbol").as_char();
                new_item_template->color = color_from_string(entry.get("color").as_string());
                new_item_template->description = _(entry.get("description").as_string().c_str());
                if(entry.has("material")){
                  set_material_from_json(new_id, entry.get("material"));
                } else {
                  new_item_template->m1 = "null";
                  new_item_template->m2 = "null";
                }
                Item_tag new_phase = "solid";
                if(entry.has("phase")){
                    new_phase = entry.get("phase").as_string();
                }
                new_item_template->phase = phase_from_tag(new_phase);
                new_item_template->volume = entry.get("volume").as_int();
                new_item_template->weight = entry.get("weight").as_int();
                new_item_template->melee_dam = entry.get("bashing").as_int();
                new_item_template->melee_cut = entry.get("cutting").as_int();
                new_item_template->m_to_hit = entry.get("to_hit").as_int();

                if( entry.has("flags") )
                {
                    new_item_template->item_tags = entry.get("flags").as_tags();
                    /*
                    List of current flags
                    FIT - Reduces encumberance by one
                    VARSIZE - Can be made to fit via tailoring
                    OVERSIZE - Can always be worn no matter encumberance/mutations/bionics/etc
                    HOOD - Will increase warmth for head if head is cold and player is not wearing a helmet (headwear of material that is not wool or cotton)
                    POCKETS - Will increase warmth for hands if hands are cold and the player is wielding nothing
                    WATCH - Shows the current time, instead of sun/moon position
                    ALARMCLOCK - Has an alarmclock feature
                    MALE_TYPICAL - Typically only worn by men.
                    FEMALE_TYPICAL - Typically only worn by women.
                    USE_EAT_VERB - Use the eat verb, even if it's a liquid(soup, jam etc.)

                    Container-only flags:
                    SEALS
                    RIGID
                    WATERTIGHT
                    */
                }

                new_item_template->techniques = (!entry.has("techniques") ? 0 :
                                                 flags_from_json(entry.get("techniques"), "techniques"));
                new_item_template->use = (!entry.has("use_action") ? &iuse::none :
                                          use_from_string(entry.get("use_action").as_string()));
            }
        }
    }
    if(!json_good())
        throw "There was an error reading " + file_name;
}
Ejemplo n.º 8
0
profmap profession::load_professions()
{
    profmap allProfs;
    catajson profsRaw("data/raw/professions.json");

    unsigned int id = 0;
    for (profsRaw.set_begin(); profsRaw.has_curr(); profsRaw.next())
    {
        ++id;
        catajson currProf = profsRaw.curr();
        std::string ident = currProf.get("ident").as_string();
        std::string name = currProf.get("name").as_string();
        std::string description = currProf.get("description").as_string();
        signed int points = currProf.get("points").as_int();

        profession newProfession(id, ident, name, description, points);

        catajson items = currProf.get("items");
        for (items.set_begin(); items.has_curr(); items.next())
        {
            newProfession.add_item(items.curr().as_string());
        }

        // Addictions are optional
        if (currProf.has("addictions"))
        {
            catajson addictions = currProf.get("addictions");
            for (addictions.set_begin(); addictions.has_curr(); addictions.next())
            {
                catajson currAdd = addictions.curr();
                std::string type_str = currAdd.get("type").as_string();
                add_type type = addiction_type(type_str);
                int intensity = currAdd.get("intensity").as_int();
                newProfession.add_addiction(type,intensity);
            }
        }
        // Skills are optional as well
        if (currProf.has("skills"))
        {
            catajson skills = currProf.get("skills");
            for (skills.set_begin(); skills.has_curr(); skills.next())
            {
                catajson currSkill = skills.curr();
                std::string skill_str = currSkill.get("name").as_string();
                // Verifying this skill exists MUST happen later since the
                // skills have not yet been loaded at this point.
                int level = currSkill.get("level").as_int();
                newProfession.add_skill(skill_str, level);
            }
        }
        //optional mutations
        if (currProf.has("mutations"))
        {
            catajson mutations = currProf.get("mutations");
            for (mutations.set_begin(); mutations.has_curr(); mutations.next())
            {
                newProfession.add_mutation(mutations.curr().as_string());
            }
        }
        allProfs[ident] = newProfession;
    }

    return allProfs;
}