Example #1
0
void load_effect_type(JsonObject &jo)
{
    effect_type new_etype;
    new_etype.id = jo.get_string("id");

    new_etype.name = jo.get_string("name", "");
    new_etype.desc = jo.get_string("desc", "");

    new_etype.apply_message = jo.get_string("apply_message", "");
    new_etype.remove_message = jo.get_string("remove_message", "");
    new_etype.apply_memorial_log = jo.get_string("apply_memorial_log", "");
    new_etype.remove_memorial_log = jo.get_string("remove_memorial_log", "");

    effect_types[new_etype.id] = new_etype;
}
Example #2
0
bool map_deconstruct_info::load(JsonObject &jsobj, std::string member, bool isfurniture)
{
    if (!jsobj.has_object(member)) {
        return false;
    }
    JsonObject j = jsobj.get_object(member);
    furn_set = j.get_string("furn_set", "");
    if (!isfurniture) {
        ter_set = j.get_string("ter_set");
    }
    can_do = true;

    load_map_bash_item_drop_list(j.get_array("items"), items);
    return true;
}
Example #3
0
bool map_deconstruct_info::load(JsonObject &jsobj, std::string member, bool isfurniture)
{
    if (!jsobj.has_object(member)) {
        return false;
    }
    JsonObject j = jsobj.get_object(member);
    furn_set = j.get_string("furn_set", "");
    if (!isfurniture) {
        ter_set = j.get_string( "ter_set" );
    }
    can_do = true;

    JsonIn& stream = *j.get_raw( "items" );
    drop_group = item_group::load_item_group( stream, "collection" );
    return true;
}
Example #4
0
void sfx::load_playlist( JsonObject &jsobj )
{
    if( !sound_init_success ) {
        return;
    }

    JsonArray jarr = jsobj.get_array( "playlists" );
    while( jarr.has_more() ) {
        JsonObject playlist = jarr.next_object();

        const std::string playlist_id = playlist.get_string( "id" );
        music_playlist playlist_to_load;
        playlist_to_load.shuffle = playlist.get_bool( "shuffle", false );

        JsonArray files = playlist.get_array( "files" );
        while( files.has_more() ) {
            JsonObject entry = files.next_object();
            const music_playlist::entry e{ entry.get_string( "file" ),  entry.get_int( "volume" ) };
            playlist_to_load.entries.push_back( e );
        }

        playlists[playlist_id] = std::move( playlist_to_load );
    }
}
Example #5
0
void Comment::setData(const JsonObject &data, bool signalChange)
{
    QString id = JSON_GET_STRING(data.value(COMMENT_ID_KEY));
    QString name = JSON_GET_STRING(data.value(COMMENT_NAME_KEY));
    QString url = JSON_GET_STRING(data.value(COMMENT_URL_KEY));
    QString dateString = JSON_GET_STRING(data.value(COMMENT_DATE_KEY));
    QDateTime date = QDateTime::fromString(dateString, DATE_TIME_FORMAT);
    QString content = JSON_GET_STRING(data.value(COMMENT_CONTENT_KEY));
    QString parent = JSON_GET_STRING(data.value(COMMENT_PARENT_KEY));
    if (m_id != id) {
        m_id = id;
        if (signalChange) {
            emit idChanged();
        }
    }
    if (m_name != name) {
        m_name = name;
        if (signalChange) {
            emit nameChanged();
        }
    }
    if (m_url != url) {
        m_url = url;
        if (signalChange) {
            emit urlChanged();
        }
    }
    if (m_date != date) {
        m_date = date;
        if (signalChange) {
            emit dateChanged();
        }
    }
    if (m_content != content) {
        m_content = content;
        if (signalChange) {
            emit contentChanged();
        }
    }
    if (m_parent != parent) {
        m_parent = parent;
        if (signalChange) {
            emit parentChanged();
        }
    }
}
Example #6
0
  void visitFunctionStatement(FunctionStatement *node) override {
    JsonObject *obj = new (pool_) JsonObject();
    obj->add(atom_name_, toJson(node->name()));
    startDoc(obj, "function", node->name(), node->loc());

    if (node->token() == TOK_FORWARD)
      obj->add(atom_kind_, toJson("forward"));
    else if (node->token() == TOK_NATIVE)
      obj->add(atom_kind_, toJson("native"));
    else
      obj->add(atom_kind_, toJson("stock"));

    obj->add(atom_returnType_, toJson(node->signature()->returnType()));
    obj->add(atom_parameters_, toJson(node->signature()->parameters()));

    functions_->add(obj);
  }
Example #7
0
bool TournamentConfig::Save(const std::string &fileName)
{
    bool ret = true;

    JsonObject json;

    json.AddValue("version", TOURNAMENT_CONFIG_VERSION);

    JsonArray tournament;
    for (std::vector<Tarot::Distribution>::iterator iter =  mOptions.turns.begin(); iter !=  mOptions.turns.end(); ++iter)
    {
        std::string type;
        std::string file;
        std::uint32_t number = 0U;
        JsonObject obj;

        if (iter->mType == Tarot::Distribution::RANDOM_DEAL)
        {
            type = "random";
            file = "";
        }
        else if (iter->mType == Tarot::Distribution::CUSTOM_DEAL)
        {
            type = "custom";
            file = iter->mFile;
        }
        else
        {
            type = "numbered";
            number = iter->mSeed;
        }

        obj.AddValue("type", type);
        obj.AddValue("file", file);
        obj.AddValue("number", number);
        tournament.AddValue(obj);
    }
    json.AddValue("tournament", tournament);

    if (!JsonWriter::SaveToFile(json, fileName))
    {
        ret = false;
        TLogError("Saving tournament's configuration failed.");
    }
    return ret;
}
Example #8
0
int cRooms::setOffsetTime( JsonObject& root )
{
        int fail=0;
        int succes=0;
	if(root.containsKey("Rt")) {
		if(root["Rt"].is<JsonArray&>()){
			JsonArray& times = root["Rt"];
			
			if (times.size()==(nSetTypes*nRoomTypes*nDayTypes*nSwitch))
			{
				for(int iSet = 0; iSet<nSetTypes; iSet++)
				{
					for(int iRoomType = 0; iRoomType<nRoomTypes; iRoomType++) // Iterate over all Roomtypes (Living, sleeping, hallway, side)
					{
						for(int iDayType = 0; iDayType<nDayTypes; iDayType++)
						{
							for(int iSwitch = 0; iSwitch<nSwitch; iSwitch++)
							{
								int idx = iSwitch+iDayType*(nSwitch)+iRoomType*(nDayTypes)*(nSwitch)+iSet*(nRoomTypes)*(nDayTypes)*(nSwitch);
                                                                if (times[idx].is<long>()) {
                                                                  unsigned long oldTime = TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].time.totalseconds(); 
                                                                  unsigned long newTime = times[idx].as<long>();
                                                                  if((newTime>=0)&&(24*60*60-newTime>=0)&&(newTime!=oldTime)){
                                                                      TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].time.set(newTime);
                                                                      succes=1;
                                                                  }
                                                                }
                                                                else fail=1;
							}
						}
					}
				}
			}
		}
	}
 
	return (!fail)&&(succes);
}
Example #9
0
  void visitTypesetDecl(TypesetDecl *decl) override {
    JsonObject *obj = new (pool_) JsonObject();
    obj->add(atom_name_, toJson(decl->name()));
    startDoc(obj, "typeset", decl->name(), decl->loc());

    JsonList *list = new (pool_) JsonList();
    for (size_t i = 0; i < decl->types()->length(); i++) {
      const TypesetDecl::Entry &entry = decl->types()->at(i);
      JsonObject *te = new (pool_) JsonObject();
      te->add(atom_type_, toJson(entry.te));
      unsigned start, end;
      if (comments_.findCommentFor(entry.loc, &start, &end)) {
        te->add(atom_doc_start_, new (pool_) JsonInt(start));
        te->add(atom_doc_end_, new (pool_) JsonInt(end));
      }
      list->add(te);
    }
    obj->add(cc_.add("types"), list);

    typesets_->add(obj);
  }
Example #10
0
int cRooms::setOffsetTemp( JsonObject& root )
{
        int fail=0;
        int succes=0;
	if(root.containsKey("RTo")) {
		if(root["RTo"].is<JsonArray&>()){
			JsonArray& temps = root["RTo"];
			
			if (temps.size()==(nSetTypes*nRoomTypes*nDayTypes*nSwitch))
			{
				for(int iSet = 0; iSet<nSetTypes; iSet++) // Normal
				{
					for(int iRoomType = 0; iRoomType<nRoomTypes; iRoomType++) // (Living, sleeping, hallway, bath, side)
					{
						for(int iDayType = 0; iDayType<nDayTypes; iDayType++) // Weekend, Workday
						{
							for(int iSwitch = 0; iSwitch<nSwitch; iSwitch++) // 4 switch times
							{
								// Last iteration
								int idx = iSwitch+iDayType*(nSwitch)+iRoomType*(nDayTypes)*(nSwitch)+iSet*(nRoomTypes)*(nDayTypes)*(nSwitch);
               if (temps[idx].is<double>()){
                                                                double temp_ =  temps[idx].as<double>();
                                                                if((temp_>-15.0)&&(temp_<15.0)&&(temp_!=TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].temp)){
                                                                    TempOffsetSchedule[iSet][iRoomType][iDayType][iSwitch].temp = temp_;
                                                                    succes = 1;
                                                                }
               }
               else fail=1;
							}
						}
					}
				}
			}
		}
	}
 
	return ((!fail)&&(succes));
}
Example #11
0
void furn_t::load( JsonObject &jo, const std::string &src )
{
    map_data_common_t::load( jo, src );
    mandatory( jo, was_loaded, "name", name_ );
    mandatory( jo, was_loaded, "move_cost_mod", movecost );
    mandatory( jo, was_loaded, "required_str", move_str_req );
    optional( jo, was_loaded, "max_volume", max_volume, legacy_volume_reader, DEFAULT_MAX_VOLUME_IN_SQUARE );
    optional( jo, was_loaded, "crafting_pseudo_item", crafting_pseudo_item, "" );
    optional( jo, was_loaded, "deployed_item", deployed_item );

    load_symbol( jo );
    transparent = false;

    for( auto & flag : jo.get_string_array( "flags" ) ) {
        set_flag( flag );
    }

    optional( jo, was_loaded, "open", open, string_id_reader<furn_t> {}, furn_str_id::NULL_ID() );
    optional( jo, was_loaded, "close", close, string_id_reader<furn_t> {}, furn_str_id::NULL_ID() );

    bash.load( jo, "bash", true );
    deconstruct.load( jo, "deconstruct", true );
}
Example #12
0
distribution load_distribution( JsonObject &jo, const std::string &name )
{
    if( !jo.has_member( name ) ) {
        return distribution();
    }

    if( jo.has_float( name ) ) {
        return distribution::constant( jo.get_float( name ) );
    }

    if( jo.has_object( name ) ) {
        JsonObject obj = jo.get_object( name );
        return load_distribution( obj );
    }

    jo.throw_error( "Invalid distribution type", name );
    return distribution();
}
Example #13
0
bool DriveCommand::fromJson(JsonObject& cmd) {
  if(!cmd.containsKey("type")) return false;
  
  const char* type = cmd["type"];
  if(strcmp(type, "SET_HEADING") == 0) {
    command = SET_HEADING;
  } else if(strcmp(type, "DRIVE") == 0) {
    command = DRIVE;
  } else {  
    Serial.print("unrecognized type ");
    Serial.println(type);
    return false;
  }
  
  if(!cmd.containsKey("cid") || !cmd.containsKey("pid") || !cmd.containsKey("duration")) {
    return false;
  }
  
  cid = cmd["cid"];
  pid = cmd["pid"];
  duration = cmd["duration"];
  
  if(command == DRIVE) {
    if(!cmd.containsKey("speed") || !cmd.containsKey("heading")) return false;
    
    payload.drive.speed = cmd["speed"];
    payload.drive.heading = cmd["heading"];
    return true;
  } else if(command == SET_HEADING) {
    if(!cmd.containsKey("heading")) return false;
    
    payload.heading.heading = cmd["heading"];
    return true;
  } else {
    return false;
  }
 
}
Example #14
0
void load_bionic(JsonObject &jsobj)
{
    std::string id = jsobj.get_string("id");
    std::string name = _(jsobj.get_string("name").c_str());
    std::string description = _(jsobj.get_string("description").c_str());
    int cost = jsobj.get_int("cost", 0);
    int time = jsobj.get_int("time", 0);
    bool faulty = jsobj.get_bool("faulty", false);
    bool power_source = jsobj.get_bool("power_source", false);
    bool active = jsobj.get_bool("active", false);

    if (faulty) {
        faulty_bionics.push_back(id);
    }
    if (power_source) {
        power_source_bionics.push_back(id);
    }
    if (!active) {
        unpowered_bionics.push_back(id);
    }

    bionics[id] = new bionic_data(name, power_source, active, cost, time, description, faulty);
}
Example #15
0
bool map_bash_info::load(JsonObject &jsobj, std::string member, bool isfurniture) {
    if( jsobj.has_object(member) ) {
        JsonObject j = jsobj.get_object(member);

        if ( jsonint(j, "num_tests", num_tests ) == false ) {
           if ( jsonint(j, "str_min", str_min ) && jsonint(j, "str_max", str_max ) ) {
               num_tests = 1;
           }
        } else if ( num_tests > 0 ) {
           str_min = j.get_int("str_min");
           str_max = j.get_int("str_max");
        }

        jsonint(j, "str_min_blocked", str_min_blocked );
        jsonint(j, "str_max_blocked", str_max_blocked );
        jsonint(j, "str_min_roll", str_min_roll );
        jsonint(j, "explosive", explosive );
        jsonint(j, "chance", chance );
        jsonstring(j, "sound", sound );
        jsonstring(j, "sound_fail", sound_fail );
        jsonstring(j, "furn_set", furn_set );

        if ( jsonstring(j, "ter_set", ter_set ) == false && isfurniture == false ) {
           ter_set = "t_rubble";
           debugmsg("terrain[\"%s\"].bash.ter_set is not set!",jsobj.get_string("id").c_str() );
        }

        if ( j.has_array("items") ) {
            load_map_bash_item_drop_list(j.get_array("items"), items);
        }

//debugmsg("%d/%d %s %s/%s %d",str_min,str_max, ter_set.c_str(), sound.c_str(), sound_fail.c_str(), items.size() );
    return true;
  } else {
    return false;
  }
}
Example #16
0
void safemode::deserialize( JsonIn &jsin )
{
    auto &temp_rules = ( is_character ) ? character_rules : global_rules;
    temp_rules.clear();

    jsin.start_array();
    while( !jsin.end_array() ) {
        JsonObject jo = jsin.get_object();

        const std::string rule = jo.get_string( "rule" );
        const bool active = jo.get_bool( "active" );
        const bool whitelist = jo.get_bool( "whitelist" );
        const Creature::Attitude attitude = ( Creature::Attitude ) jo.get_int( "attitude" );
        const int proximity = jo.get_int( "proximity" );

        temp_rules.push_back(
            rules_class( rule, active, whitelist, attitude, proximity )
        );
    }
}
Example #17
0
void requirement_data::load_requirement( JsonObject &jsobj, const std::string &id )
{
    requirement_data req;

    JsonArray jsarr;
    jsarr = jsobj.get_array( "components" );
    req.load_obj_list( jsarr, req.components );
    jsarr = jsobj.get_array( "qualities" );
    req.load_obj_list( jsarr, req.qualities );
    jsarr = jsobj.get_array( "tools" );
    req.load_obj_list( jsarr, req.tools );

    if( !id.empty() ) {
        req.id_ = requirement_id( id );
    } else if( jsobj.has_string( "id" ) ) {
        req.id_ = requirement_id( jsobj.get_string( "id" ) );
    } else {
        jsobj.throw_error( "id was not specified for requirement" );
    }

    save_requirement( req );
}
Example #18
0
  JsonList *toJson(const ParameterList *params) {
    JsonList *list = new (pool_) JsonList();
    for (size_t i = 0; i < params->length(); i++) {
      VarDecl *decl = params->at(i);
      JsonObject *obj = new (pool_) JsonObject();

      obj->add(atom_type_, toJson(decl, false));

      if (decl->name()) {
        obj->add(atom_name_, toJson(decl->name()));
        obj->add(atom_decl_, toJson(decl, true));
      } else {
        obj->add(atom_name_, toJson("..."));

        AutoString builder = BuildTypeName(decl->te(), nullptr, TypeDiagFlags::Names);
        builder = builder + " ...";
        obj->add(atom_decl_, toJson(builder.ptr()));
      }
      list->add(obj);
    }
    return list;
  }
Example #19
0
bool Comment::isValid(const JsonObject &data)
{
    if (!data.contains(COMMENT_ID_KEY)) {
        return false;
    }
    if (!data.contains(COMMENT_NAME_KEY)) {
        return false;
    }
    if (!data.contains(COMMENT_URL_KEY)) {
        return false;
    }
    if (!data.contains(COMMENT_DATE_KEY)) {
        return false;
    }
    if (!data.contains(COMMENT_CONTENT_KEY)) {
        return false;
    }
    if (!data.contains(COMMENT_PARENT_KEY)) {
        return false;
    }
    return true;
}
Example #20
0
  JsonObject *analyze(ParseTree *tree) {
    functions_ = new (pool_) JsonList();
    methodmaps_ = new (pool_) JsonList();
    enums_ = new (pool_) JsonList();
    constants_ = new (pool_) JsonList();
    typesets_ = new (pool_) JsonList();
    typedefs_ = new (pool_) JsonList();

    for (size_t i = 0; i < tree->statements()->length(); i++) {
      Statement *stmt = tree->statements()->at(i);
      stmt->accept(this);
    }

    JsonObject *obj = new (pool_) JsonObject();
    obj->add(cc_.add("functions"), functions_);
    obj->add(cc_.add("methodmaps"), methodmaps_);
    obj->add(cc_.add("enums"), enums_);
    obj->add(cc_.add("constants"), constants_);
    obj->add(cc_.add("typesets"), typesets_);
    obj->add(cc_.add("typedefs"), typedefs_);
    return obj;
  }
Example #21
0
void load_season_array( JsonObject &jo, const std::string &key, C &container, F load_func )
{
    if( jo.has_string( key ) ) {
        container.fill( load_func( jo.get_string( key ) ) );

    } else if( jo.has_array( key ) ) {
        auto arr = jo.get_array( key );
        if( arr.size() == 1 ) {
            container.fill( load_func( arr.get_string( 0 ) ) );

        } else if( arr.size() == container.size() ) {
            for( auto &e : container ) {
                e = load_func( arr.next_string() );
            }

        } else {
            jo.throw_error( "Incorrect number of entries", key );
        }

    } else {
        jo.throw_error( "Expected string or array", key );
    }
}
/*
 * Handle the universe list callback
 * @param response the HTTPResponse that is associated with the request.
 * @param plugins a list of plugins
 * @param error an error string.
 */
void OladHTTPServer::HandleUniverseList(HTTPResponse *response,
                                       JsonObject *json,
                                       const vector<OlaUniverse> &universes,
                                       const string &error) {
  if (error.empty()) {
    JsonArray *universe_json = json->AddArray("universes");

    vector<OlaUniverse>::const_iterator iter;
    for (iter = universes.begin(); iter != universes.end(); ++iter) {
      JsonObject *universe = universe_json->AppendObject();
      universe->Add("id", iter->Id());
      universe->Add("input_ports", iter->InputPortCount());
      universe->Add("name", iter->Name());
      universe->Add("output_ports", iter->OutputPortCount());
      universe->Add("rdm_devices", iter->RDMDeviceCount());
    }
  }

  response->SetNoCache();
  response->SetContentType(HTTPServer::CONTENT_TYPE_PLAIN);
  response->SendJson(*json);
  delete response;
  delete json;
}
Example #23
0
void fault::load_fault( JsonObject &jo )
{
    fault f;

    f.id_ = fault_id( jo.get_string( "id" ) );
    f.name_ = _( jo.get_string( "name" ).c_str() );
    f.description_ = _( jo.get_string( "description" ).c_str() );

    auto sk = jo.get_array( "skills" );
    while( sk.has_more() ) {
        auto cur = sk.next_array();
        f.skills_.emplace( skill_id( cur.get_string( 0 ) ) , cur.size() >= 2 ? cur.get_int( 1 ) : 1 );
    }

    auto req = jo.get_object( "requirements" );
    f.requirements_.load( req );

    if( faults_all.find( f.id_ ) != faults_all.end() ) {
        jo.throw_error( "parsed fault overwrites existing definition", "id" );
    } else {
        faults_all[ f.id_ ] = f;
        DebugLog( D_INFO, DC_ALL ) << "Loaded fault: " << f.name_;
    }
}
Example #24
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;
    }
}
Example #25
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 );
}
Example #26
0
void load_trap(JsonObject &jo)
{
    std::vector<std::string> drops;
    if(jo.has_member("drops")) {
        JsonArray drops_list = jo.get_array("drops");
        while(drops_list.has_more()) {
            drops.push_back(drops_list.next_string());
        }
    }

    std::string name = jo.get_string("name");
    if (!name.empty()) {
        name = _(name.c_str());
    }
    trap *new_trap = new trap(
            jo.get_string("id"), // "tr_beartrap"
            traplist.size(),     // tr_beartrap
            name, // "bear trap"
            color_from_string(jo.get_string("color")),
            jo.get_string("symbol").at(0),
            jo.get_int("visibility"),
            jo.get_int("avoidance"),
            jo.get_int("difficulty"),
            trap_function_from_string(jo.get_string("action")),
            drops
    );

    new_trap->benign = jo.get_bool("benign", false);
    new_trap->funnel_radius_mm = jo.get_int("funnel_radius", 0);
    new_trap->trigger_weight = jo.get_int("trigger_weight", -1);
    trapmap[new_trap->id] = new_trap->loadid;
    traplist.push_back(new_trap);
}
Example #27
0
 addiction get_next( JsonIn &jin ) const {
     JsonObject jo = jin.get_object();
     return addiction( addiction_type( jo.get_string( "type" ) ), jo.get_int( "intensity" ) );
 }
Example #28
0
 std::pair<skill_id, int> get_next( JsonIn &jin ) const {
     JsonObject jo = jin.get_object();
     return std::pair<skill_id, int>( skill_id( jo.get_string( "name" ) ), jo.get_int( "level" ) );
 }
Example #29
0
void MonsterGroupManager::LoadMonsterGroup( JsonObject &jo )
{
    float mon_upgrade_factor = get_option<float>( "MONSTER_UPGRADE_FACTOR" );

    MonsterGroup g;

    g.name = mongroup_id( jo.get_string( "name" ) );
    bool extending = false;  //If already a group with that name, add to it instead of overwriting it
    if( monsterGroupMap.count( g.name ) != 0 && !jo.get_bool( "override", false ) ) {
        g = monsterGroupMap[g.name];
        extending = true;
    }
    if( !extending
        || jo.has_string( "default" ) ) { //Not mandatory to specify default if extending existing group
        g.defaultMonster = mtype_id( jo.get_string( "default" ) );
    }
    g.is_animal = jo.get_bool( "is_animal", false );
    if( jo.has_array( "monsters" ) ) {
        JsonArray monarr = jo.get_array( "monsters" );

        while( monarr.has_more() ) {
            JsonObject mon = monarr.next_object();
            const mtype_id name = mtype_id( mon.get_string( "monster" ) );

            int freq = mon.get_int( "freq" );
            int cost = mon.get_int( "cost_multiplier" );
            int pack_min = 1;
            int pack_max = 1;
            if( mon.has_member( "pack_size" ) ) {
                JsonArray packarr = mon.get_array( "pack_size" );
                pack_min = packarr.next_int();
                pack_max = packarr.next_int();
            }
            static const time_duration tdfactor = 1_hours;
            time_duration starts = 0_turns;
            time_duration ends = 0_turns;
            if( mon.has_member( "starts" ) ) {
                starts = tdfactor * mon.get_int( "starts" ) * ( mon_upgrade_factor > 0 ? mon_upgrade_factor : 1 );
            }
            if( mon.has_member( "ends" ) ) {
                ends = tdfactor * mon.get_int( "ends" ) * ( mon_upgrade_factor > 0 ? mon_upgrade_factor : 1 );
            }
            MonsterGroupEntry new_mon_group = MonsterGroupEntry( name, freq, cost, pack_min, pack_max, starts,
                                              ends );
            if( mon.has_member( "conditions" ) ) {
                JsonArray conditions_arr = mon.get_array( "conditions" );
                while( conditions_arr.has_more() ) {
                    new_mon_group.conditions.push_back( conditions_arr.next_string() );
                }
            }

            g.monsters.push_back( new_mon_group );
        }
    }
    g.replace_monster_group = jo.get_bool( "replace_monster_group", false );
    g.new_monster_group = mongroup_id( jo.get_string( "new_monster_group_id",
                                       mongroup_id::NULL_ID().str() ) );
    assign( jo, "replacement_time", g.monster_group_time, false, 1_days );
    g.is_safe = jo.get_bool( "is_safe", false );

    g.freq_total = jo.get_int( "freq_total", ( extending ? g.freq_total : 1000 ) );
    if( jo.get_bool( "auto_total", false ) ) { //Fit the max size to the sum of all freqs
        int total = 0;
        for( MonsterGroupEntry &mon : g.monsters ) {
            total += mon.frequency;
        }
        g.freq_total = total;
    }

    monsterGroupMap[g.name] = g;
}
Example #30
0
int curses_start_color(void)
{
    colorpairs = new pairs[100];
    windowsPalette = new RGBQUAD[16];

    //Load the console colors from colors.json
    std::ifstream colorfile(FILENAMES["colors"].c_str(), std::ifstream::in | std::ifstream::binary);
    try{
        JsonIn jsin(colorfile);
        char ch;
        // Manually load the colordef object because the json handler isn't loaded yet.
        jsin.eat_whitespace();
        ch = jsin.peek();
        if( ch == '[' ) {
            jsin.start_array();
            // find type and dispatch each object until array close
            while (!jsin.end_array()) {
                jsin.eat_whitespace();
                char ch = jsin.peek();
                if (ch != '{') {
                    std::stringstream err;
                    err << jsin.line_number() << ": ";
                    err << "expected array of objects but found '";
                    err << ch << "', not '{'";
                    throw err.str();
                }
                JsonObject jo = jsin.get_object();
                load_colors(jo);
                jo.finish();
            }
        } else {
            // not an array?
            std::stringstream err;
            err << jsin.line_number() << ": ";
            err << "expected object or array, but found '" << ch << "'";
            throw err.str();
        }
    }
    catch(std::string e){
        throw FILENAMES["colors"] + ": " + e;
    }

    if(consolecolors.empty())return SetDIBColorTable(backbuffer, 0, 16, windowsPalette);
    windowsPalette[0]  = BGR(ccolor("BLACK"));
    windowsPalette[1]  = BGR(ccolor("RED"));
    windowsPalette[2]  = BGR(ccolor("GREEN"));
    windowsPalette[3]  = BGR(ccolor("BROWN"));
    windowsPalette[4]  = BGR(ccolor("BLUE"));
    windowsPalette[5]  = BGR(ccolor("MAGENTA"));
    windowsPalette[6]  = BGR(ccolor("CYAN"));
    windowsPalette[7]  = BGR(ccolor("GRAY"));
    windowsPalette[8]  = BGR(ccolor("DGRAY"));
    windowsPalette[9]  = BGR(ccolor("LRED"));
    windowsPalette[10] = BGR(ccolor("LGREEN"));
    windowsPalette[11] = BGR(ccolor("YELLOW"));
    windowsPalette[12] = BGR(ccolor("LBLUE"));
    windowsPalette[13] = BGR(ccolor("LMAGENTA"));
    windowsPalette[14] = BGR(ccolor("LCYAN"));
    windowsPalette[15] = BGR(ccolor("WHITE"));
    return SetDIBColorTable(backbuffer, 0, 16, windowsPalette);
}