void clear_game( const ter_id &terrain )
{
    // Set to turn 0 to prevent solars from producing power
    calendar::turn = 0;
    for( monster &critter : g->all_monsters() ) {
        g->remove_zombie( critter );
    }

    g->unload_npcs();

    // Move player somewhere safe
    g->u.setpos( tripoint( 0, 0, 0 ) );
    // Blind the player to avoid needless drawing-related overhead
    g->u.add_effect( effect_blind, 1_turns, num_bp, true );

    for( const tripoint &p : g->m.points_in_rectangle( tripoint( 0, 0, 0 ),
            tripoint( MAPSIZE * SEEX, MAPSIZE * SEEY, 0 ) ) ) {
        g->m.furn_set( p, furn_id( "f_null" ) );
        g->m.ter_set( p, terrain );
        g->m.trap_set( p, trap_id( "tr_null" ) );
        g->m.i_clear( p );
    }

    for( wrapped_vehicle &veh : g->m.get_vehicles( tripoint( 0, 0, 0 ), tripoint( MAPSIZE * SEEX,
            MAPSIZE * SEEY, 0 ) ) ) {
        g->m.destroy_vehicle( veh.v );
    }

    g->m.build_map_cache( 0, true );
}
Exemplo n.º 2
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.º 3
0
int_id<trap> string_id<trap>::id() const
{
    const auto iter = trapmap.find( *this );
    if( iter == trapmap.end() ) {
        debugmsg( "invalid trap id %s", c_str() );
        return trap_id();
    }
    return iter->second;
}
Exemplo n.º 4
0
void mapbuffer::load()
{
    if (!master_game) {
        debugmsg("Can't load mapbuffer without a master_game");
        return;
    }
    std::map<tripoint, submap*>::iterator it;
    std::ifstream fin;
    fin.open("save/maps.txt");
    if (!fin.is_open())
        return;

    int itx, ity, t, d, a, num_submaps, num_loaded = 0;
    item it_tmp;
    std::string databuff;
    fin >> num_submaps;

    while (!fin.eof()) {
        if (num_loaded % 100 == 0)
            popup_nowait(_("Please wait as the map loads [%d/%d]"),
                         num_loaded, num_submaps);
        int locx, locy, locz, turn;
        submap* sm = new submap;
        fin >> locx >> locy >> locz >> turn;
        sm->turn_last_touched = turn;
        int turndif = (master_game ? int(master_game->turn) - turn : 0);
        if (turndif < 0)
            turndif = 0;
// Load terrain
        for (int j = 0; j < SEEY; j++) {
            for (int i = 0; i < SEEX; i++) {
                int tmpter;
                fin >> tmpter;
                sm->ter[i][j] = ter_id(tmpter);
                sm->frn[i][j] = f_null;
                sm->itm[i][j].clear();
                sm->trp[i][j] = tr_null;
                //sm->fld[i][j] = field(); //not needed now
                sm->graf[i][j] = graffiti();
            }
        }
// Load irradiation
        for (int j = 0; j < SEEY; j++) {
            for (int i = 0; i < SEEX; i++) {
                int radtmp;
                fin >> radtmp;
                radtmp -= int(turndif / 100);	// Radiation slowly decays
                if (radtmp < 0)
                    radtmp = 0;
                sm->rad[i][j] = radtmp;
            }
        }
// Load items and traps and fields and spawn points and vehicles
        std::string string_identifier;
        do {
            fin >> string_identifier; // "----" indicates end of this submap
            t = 0;
            if (string_identifier == "I") {
                fin >> itx >> ity;
                getline(fin, databuff); // Clear out the endline
                getline(fin, databuff);
                it_tmp.load_info(databuff, master_game);
                sm->itm[itx][ity].push_back(it_tmp);
                if (it_tmp.active)
                    sm->active_item_count++;
            } else if (string_identifier == "C") {
                getline(fin, databuff); // Clear out the endline
                getline(fin, databuff);
                int index = sm->itm[itx][ity].size() - 1;
                it_tmp.load_info(databuff, master_game);
                sm->itm[itx][ity][index].put_in(it_tmp);
                if (it_tmp.active)
                    sm->active_item_count++;
            } else if (string_identifier == "T") {
                fin >> itx >> ity >> t;
                sm->trp[itx][ity] = trap_id(t);
            } else if (string_identifier == "f") {
Exemplo n.º 5
0
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// edit traps
int editmap::edit_trp(point coords)
{
    int ret = 0;
    int pwh = TERRAIN_WINDOW_HEIGHT - infoHeight - 1;

    WINDOW *w_picktrap = newwin(pwh, width, VIEW_OFFSET_Y, TERRAIN_WINDOW_WIDTH + VIEW_OFFSET_X);
    wborder(w_picktrap, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
            LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
    int tmax = pwh - 4;
    int tshift = 0;
    int subch = 0;
    if ( trsel == -1 ) {
        trsel = cur_trap;
    }
    std::string trids[num_trap_types];
    trids[0] = _("-clear-");
    do {
        uphelp("[s/tab] shape select, [m]ove, [v] showall",
               "[enter] change, [t] change/quit, [q]uit", "Traps");

        if( trsel < tshift ) {
            tshift = trsel;
        } else if ( trsel > tshift + tmax ) {
            tshift = trsel - tmax;
        }
        std::string tnam;
        for ( int t = tshift; t <= tshift + tmax; t++ ) {
            mvwprintz(w_picktrap, t + 1 - tshift, 1, c_white, "%s", padding.c_str());
            if ( t < num_trap_types ) {
                tnam = ( g->traps[t]->name.size() == 0 ? trids[t] : g->traps[t]->name );
                mvwputch(w_picktrap, t + 1 - tshift, 2, g->traps[t]->color, g->traps[t]->sym);
                mvwprintz(w_picktrap, t + 1 - tshift, 4, (trsel == t ? h_white : ( cur_trap == t ? c_green : c_ltgray ) ), "%d %s", t, tnam.c_str() );
            }
        }
        wrefresh(w_picktrap);

        subch = (int)getch();
        if(subch == KEY_UP) {
            trsel--;
        } else if (subch == KEY_DOWN) {
            trsel++;
        } else if ( subch == KEY_ENTER || subch == '\n' || subch == 't' ) {
            if ( trsel < num_trap_types && trsel >= 0 ) {
                trset = trsel;
            }
            for(int t = 0; t < target_list.size(); t++ ) {
                g->m.add_trap(target_list[t].x, target_list[t].y, trap_id(trset));
            }
            if ( subch == 't' ) {
                subch = KEY_ESCAPE;
            }
            update_view(false);
        } else if ( subch == 's' || subch == '\t' || subch == 'm' ) {
            int sel_tmp = trsel;
            select_shape(editshape, ( subch == 'm' ? 1 : 0 ) );
            sel_frn = sel_tmp;
        } else if ( subch == 'v' ) {
            uberdraw = !uberdraw;
            update_view(false);
        }

        if( trsel < 0 ) {
            trsel = num_trap_types - 1;
        } else if ( trsel >= num_trap_types ) {
            trsel = 0;
        }

    } while ( ! menu_escape ( subch ) );
    werase(w_picktrap);
    wrefresh(w_picktrap);
    delwin(w_picktrap);

    wrefresh(w_info);

    return ret;
}