Exemplo n.º 1
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);
}
Exemplo n.º 2
0
void game::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());
        }
    }

    trap *new_trap = new trap(
            jo.get_string("id"), // "tr_beartrap"
            g->traps.size(),     // tr_beartrap
            jo.get_string("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("player_action")),
            trap_function_mon_from_string(jo.get_string("monster_action")),
            drops
    );
    
    new_trap->benign = jo.get_bool("benign", false);
    new_trap->funnel_radius_mm = jo.get_int("funnel_radius", 0);
    trapmap[new_trap->id] = new_trap->loadid;
    traps.push_back(new_trap);
}
Exemplo n.º 3
0
void trap::load( JsonObject &jo )
{
    std::unique_ptr<trap> trap_ptr( new trap() );
    trap &t = *trap_ptr;

    if( jo.has_member( "drops" ) ) {
        JsonArray drops_list = jo.get_array( "drops" );
        while( drops_list.has_more() ) {
            t.components.push_back( drops_list.next_string() );
        }
    }
    t.name = jo.get_string( "name" );
    if( !t.name.empty() ) {
        t.name = _( t.name.c_str() );
    }
    t.id = trap_str_id( jo.get_string( "id" ) );
    t.loadid = trap_id( traplist.size() );
    t.color = color_from_string( jo.get_string( "color" ) );
    t.sym = jo.get_string( "symbol" ).at( 0 );
    t.visibility = jo.get_int( "visibility" );
    t.avoidance = jo.get_int( "avoidance" );
    t.difficulty = jo.get_int( "difficulty" );
    t.act = trap_function_from_string( jo.get_string( "action" ) );
    t.benign = jo.get_bool( "benign", false );
    t.funnel_radius_mm = jo.get_int( "funnel_radius", 0 );
    t.trigger_weight = jo.get_int( "trigger_weight", -1 );

    trapmap[t.id] = t.loadid;
    traplist.push_back( &t );
    trap_ptr.release();
    if( t.is_funnel() ) {
        funnel_traps.push_back( &t );
    }
}
Exemplo n.º 4
0
void trap::load( JsonObject &jo, const std::string & )
{
    mandatory( jo, was_loaded, "id", id );
    mandatory( jo, was_loaded, "name", name_ );
    if( !assign( jo, "color", color ) ) {
        jo.throw_error( "missing mandatory member \"color\"" );
    }
    mandatory( jo, was_loaded, "symbol", sym, one_char_symbol_reader );
    mandatory( jo, was_loaded, "visibility", visibility );
    mandatory( jo, was_loaded, "avoidance", avoidance );
    mandatory( jo, was_loaded, "difficulty", difficulty );
    // @todo Is there a generic_factory version of this?
    act = trap_function_from_string( jo.get_string( "action" ) );

    optional( jo, was_loaded, "benign", benign, false );
    optional( jo, was_loaded, "funnel_radius", funnel_radius_mm, 0 );
    assign( jo, "trigger_weight", trigger_weight );
    optional( jo, was_loaded, "drops", components );
}