void inventory::form_from_map(point origin, int range, bool assign_invlet)
{
    items.clear();
    for (int x = origin.x - range; x <= origin.x + range; x++) {
        for (int y = origin.y - range; y <= origin.y + range; y++) {
            if (g->m.has_furn(x, y) && g->m.accessable_furniture(origin.x, origin.y, x, y, range)) {
                const furn_t &f = g->m.furn_at(x, y);
                itype *type = f.crafting_pseudo_item_type();
                if (type != NULL) {
                    item furn_item(type->id, 0);
                    const itype *ammo = f.crafting_ammo_item_type();
                    if (ammo != NULL) {
                        furn_item.charges = count_charges_in_list(ammo, g->m.i_at(x, y));
                    }
                    furn_item.item_tags.insert("PSEUDO");
                    add_item(furn_item);
                }
            }
            if(g->m.accessable_items(origin.x, origin.y, x, y, range)) {
                continue;
            }
            for (auto &i : g->m.i_at(x, y)) {
                if (!i.made_of(LIQUID)) {
                    add_item(i, false, assign_invlet);
                }
            }
            // Kludges for now!
            ter_id terrain_id = g->m.ter(x, y);
            if (g->m.has_nearby_fire(x, y, 0)) {
                item fire("fire", 0);
                fire.charges = 1;
                add_item(fire);
            }
            if (terrain_id == t_water_sh || terrain_id == t_water_dp || terrain_id == t_water_pool) {
                item water("water", 0);
                water.charges = 50;
                add_item(water);
            }
            if (terrain_id == t_swater_sh || terrain_id == t_swater_dp) {
                item swater("salt_water", 0);
                swater.charges = 50;
                add_item(swater);
            }
            // add cvd forge from terrain
            if (terrain_id == t_cvdmachine) {
                item cvd_machine("cvd_machine", 0);
                cvd_machine.charges = 1;
                cvd_machine.item_tags.insert("PSEUDO");
                add_item(cvd_machine);
            }
            // kludge that can probably be done better to check specifically for toilet water to use in
            // crafting
            if (furnlist[g->m.furn(x, y)].examine == &iexamine::toilet) {
                // get water charges at location
                std::vector<item> toiletitems = g->m.i_at(x, y);
                int waterindex = -1;
                for (size_t i = 0; i < toiletitems.size(); ++i) {
                    if (toiletitems[i].typeId() == "water") {
                        waterindex = i;
                        break;
                    }
                }
                if (waterindex >= 0 && toiletitems[waterindex].charges > 0) {
                    add_item(toiletitems[waterindex]);
                }
            }

            // keg-kludge
            if (furnlist[g->m.furn(x, y)].examine == &iexamine::keg) {
                std::vector<item> liq_contained = g->m.i_at(x, y);
                for (auto &i : liq_contained)
                    if (i.made_of(LIQUID)) {
                        add_item(i);
                    }
            }

            int vpart = -1;
            vehicle *veh = g->m.veh_at(x, y, vpart);

            if (veh) {
                //Adds faucet to kitchen stuff; may be horribly wrong to do such....
                //ShouldBreak into own variable
                const int kpart = veh->part_with_feature(vpart, "KITCHEN");
                const int faupart = veh->part_with_feature(vpart, "FAUCET");
                const int weldpart = veh->part_with_feature(vpart, "WELDRIG");
                const int craftpart = veh->part_with_feature(vpart, "CRAFTRIG");
                const int forgepart = veh->part_with_feature(vpart, "FORGE");
                const int chempart = veh->part_with_feature(vpart, "CHEMLAB");
                const int cargo = veh->part_with_feature(vpart, "CARGO");

                if (cargo >= 0) {
                    *this += std::list<item>(veh->parts[cargo].items.begin(), veh->parts[cargo].items.end());
                }

                if(faupart >= 0 ) {
                    item water("water_clean", 0);
                    water.charges = veh->fuel_left("water");
                    add_item(water);
                }

                if (kpart >= 0) {
                    item hotplate("hotplate", 0);
                    hotplate.charges = veh->fuel_left("battery");
                    hotplate.item_tags.insert("PSEUDO");
                    add_item(hotplate);

                    item water("water_clean", 0);
                    water.charges = veh->fuel_left("water");
                    add_item(water);

                    item pot("pot", 0);
                    pot.item_tags.insert("PSEUDO");
                    add_item(pot);
                    item pan("pan", 0);
                    pan.item_tags.insert("PSEUDO");
                    add_item(pan);
                }
                if (weldpart >= 0) {
                    item welder("welder", 0);
                    welder.charges = veh->fuel_left("battery");
                    welder.item_tags.insert("PSEUDO");
                    add_item(welder);

                    item soldering_iron("soldering_iron", 0);
                    soldering_iron.charges = veh->fuel_left("battery");
                    soldering_iron.item_tags.insert("PSEUDO");
                    add_item(soldering_iron);
                }
                if (craftpart >= 0) {
                    item vac_sealer("vac_sealer", 0);
                    vac_sealer.charges = veh->fuel_left("battery");
                    vac_sealer.item_tags.insert("PSEUDO");
                    add_item(vac_sealer);

                    item dehydrator("dehydrator", 0);
                    dehydrator.charges = veh->fuel_left("battery");
                    dehydrator.item_tags.insert("PSEUDO");
                    add_item(dehydrator);

                    item press("press", 0);
                    press.charges = veh->fuel_left("battery");
                    press.item_tags.insert("PSEUDO");
                    add_item(press);
                }
                if (forgepart >= 0) {
                    item forge("forge", 0);
                    forge.charges = veh->fuel_left("battery");
                    forge.item_tags.insert("PSEUDO");
                    add_item(forge);
                }
                if (chempart >= 0) {
                    item hotplate("hotplate", 0);
                    hotplate.charges = veh->fuel_left("battery");
                    hotplate.item_tags.insert("PSEUDO");
                    add_item(hotplate);

                    item chemistry_set("chemistry_set", 0);
                    chemistry_set.charges = veh->fuel_left("battery");
                    chemistry_set.item_tags.insert("PSEUDO");
                    add_item(chemistry_set);
                }
            }
        }
    }
}
Beispiel #2
0
void inventory::form_from_map( const tripoint &origin, int range, bool assign_invlet )
{
    items.clear();
    for( const tripoint &p : g->m.points_in_radius( origin, range ) ) {
        if (g->m.has_furn( p ) && g->m.accessible_furniture( origin, p, range )) {
            const furn_t &f = g->m.furn( p ).obj();
            const itype *type = f.crafting_pseudo_item_type();
            if (type != NULL) {
                const itype *ammo = f.crafting_ammo_item_type();
                item furn_item( type, calendar::turn, ammo ? count_charges_in_list( ammo, g->m.i_at( p ) ) : 0 );
                furn_item.item_tags.insert("PSEUDO");
                add_item(furn_item);
            }
        }
        if( !g->m.accessible_items( origin, p, range ) ) {
            continue;
        }
        for (auto &i : g->m.i_at( p )) {
            if (!i.made_of(LIQUID)) {
                add_item(i, false, assign_invlet);
            }
        }
        // Kludges for now!
        ter_id terrain_id = g->m.ter( p );
        if (g->m.has_nearby_fire( p, 0 )) {
            item fire("fire", 0);
            fire.charges = 1;
            add_item(fire);
        }
        // Handle any water from infinite map sources.
        item water = g->m.water_from( p );
        if( !water.is_null() ) {
            add_item( water );
        }
        // add cvd forge from terrain
        if (terrain_id == t_cvdmachine) {
            item cvd_machine("cvd_machine", 0);
            cvd_machine.charges = 1;
            cvd_machine.item_tags.insert("PSEUDO");
            add_item(cvd_machine);
        }
        // kludge that can probably be done better to check specifically for toilet water to use in
        // crafting
        if (g->m.furn( p ).obj().examine == &iexamine::toilet) {
            // get water charges at location
            auto toilet = g->m.i_at( p );
            auto water = toilet.end();
            for( auto candidate = toilet.begin(); candidate != toilet.end(); ++candidate ) {
                if( candidate->typeId() == "water" ) {
                    water = candidate;
                    break;
                }
            }
            if( water != toilet.end() && water->charges > 0) {
                add_item( *water );
            }
        }

        // keg-kludge
        if (g->m.furn( p ).obj().examine == &iexamine::keg) {
            auto liq_contained = g->m.i_at( p );
            for( auto &i : liq_contained ) {
                if( i.made_of(LIQUID) ) {
                    add_item(i);
                }
            }
        }

        // WARNING: The part below has a bug that's currently quite minor
        // When a vehicle has multiple faucets in range, available water is
        //  multiplied by the number of faucets.
        // Same thing happens for all other tools and resources, but not cargo
        int vpart = -1;
        vehicle *veh = g->m.veh_at( p, vpart );

        if( veh == nullptr ) {
            continue;
        }

        //Adds faucet to kitchen stuff; may be horribly wrong to do such....
        //ShouldBreak into own variable
        const int kpart = veh->part_with_feature(vpart, "KITCHEN");
        const int faupart = veh->part_with_feature(vpart, "FAUCET");
        const int weldpart = veh->part_with_feature(vpart, "WELDRIG");
        const int craftpart = veh->part_with_feature(vpart, "CRAFTRIG");
        const int forgepart = veh->part_with_feature(vpart, "FORGE");
        const int chempart = veh->part_with_feature(vpart, "CHEMLAB");
        const int cargo = veh->part_with_feature(vpart, "CARGO");

        if (cargo >= 0) {
            *this += std::list<item>( veh->get_items(cargo).begin(),
                                      veh->get_items(cargo).end() );
        }

        if(faupart >= 0 ) {
            item clean_water("water_clean", 0);
            clean_water.charges = veh->fuel_left("water_clean");
            add_item(clean_water);

            item water("water", 0);
            water.charges = veh->fuel_left("water");
            // TODO: Poison
            add_item(water);
        }

        if (kpart >= 0) {
            item hotplate("hotplate", 0);
            hotplate.charges = veh->fuel_left("battery", true);
            hotplate.item_tags.insert("PSEUDO");
            add_item(hotplate);

            item clean_water("water_clean", 0);
            clean_water.charges = veh->fuel_left("water_clean");
            add_item(clean_water);

            item water("water", 0);
            water.charges = veh->fuel_left("water");
            // TODO: Poison
            add_item(water);

            item pot("pot", 0);
            pot.item_tags.insert("PSEUDO");
            add_item(pot);
            item pan("pan", 0);
            pan.item_tags.insert("PSEUDO");
            add_item(pan);
        }
        if (weldpart >= 0) {
            item welder("welder", 0);
            welder.charges = veh->fuel_left("battery", true);
            welder.item_tags.insert("PSEUDO");
            add_item(welder);

            item soldering_iron("soldering_iron", 0);
            soldering_iron.charges = veh->fuel_left("battery", true);
            soldering_iron.item_tags.insert("PSEUDO");
            add_item(soldering_iron);
        }
        if (craftpart >= 0) {
            item vac_sealer("vac_sealer", 0);
            vac_sealer.charges = veh->fuel_left("battery", true);
            vac_sealer.item_tags.insert("PSEUDO");
            add_item(vac_sealer);

            item dehydrator("dehydrator", 0);
            dehydrator.charges = veh->fuel_left("battery", true);
            dehydrator.item_tags.insert("PSEUDO");
            add_item(dehydrator);

            item press("press", 0);
            press.charges = veh->fuel_left("battery", true);
            press.item_tags.insert("PSEUDO");
            add_item(press);
        }
        if (forgepart >= 0) {
            item forge("forge", 0);
            forge.charges = veh->fuel_left("battery", true);
            forge.item_tags.insert("PSEUDO");
            add_item(forge);
        }
        if (chempart >= 0) {
            item hotplate("hotplate", 0);
            hotplate.charges = veh->fuel_left("battery", true);
            hotplate.item_tags.insert("PSEUDO");
            add_item(hotplate);

            item chemistry_set("chemistry_set", 0);
            chemistry_set.charges = veh->fuel_left("battery", true);
            chemistry_set.item_tags.insert("PSEUDO");
            add_item(chemistry_set);
        }
    }
}
Beispiel #3
0
void inventory::form_from_map(game *g, point origin, int range, bool assign_invlet)
{
 items.clear();
 for (int x = origin.x - range; x <= origin.x + range; x++) {
  for (int y = origin.y - range; y <= origin.y + range; y++) {
   int junk;
   if (g->m.has_flag("SEALED", x, y) ||
       ((origin.x != x || origin.y != y) &&
        !g->m.clear_path( origin.x, origin.y, x, y, range, 1, 100, junk ) ) ) {
     continue;
   }
   for (int i = 0; i < g->m.i_at(x, y).size(); i++)
    if (!g->m.i_at(x, y)[i].made_of(LIQUID))
     add_item(g->m.i_at(x, y)[i], false, assign_invlet);
// Kludges for now!
   ter_id terrain_id = g->m.ter(x, y);
   if ((g->m.field_at(x, y).findField(fd_fire)) || (terrain_id == t_lava)) {
    item fire(itypes["fire"], 0);
    fire.charges = 1;
    add_item(fire);
   }
   if (terrain_id == t_water_sh || terrain_id == t_water_dp){
    item water(itypes["water"], 0);
    water.charges = 50;
    add_item(water);
   }
   // kludge that can probably be done better to check specifically for toilet water to use in
   // crafting
   if (furnlist[g->m.furn(x,y)].examine == &iexamine::toilet){
    // get water charges at location
     std::vector<item> toiletitems = g->m.i_at(x,y);
     int waterindex = -1;
     for (int i = 0; i < toiletitems.size(); ++i){
        if (toiletitems[i].typeId() == "water"){
            waterindex = i;
            break;
        }
     }
     if (waterindex >= 0 && toiletitems[waterindex].charges > 0){
        add_item(toiletitems[waterindex]);
     }

   }

   int vpart = -1;
   vehicle *veh = g->m.veh_at(x, y, vpart);

   if (veh) {
     const int kpart = veh->part_with_feature(vpart, "KITCHEN");
     const int weldpart = veh->part_with_feature(vpart, "WELDRIG");
     const int craftpart = veh->part_with_feature(vpart, "CRAFTRIG");
     const int forgepart = veh->part_with_feature(vpart, "FORGE");
     const int chempart = veh->part_with_feature(vpart, "CHEMLAB");

     if (kpart >= 0) {
       item hotplate(itypes["hotplate"], 0);
       hotplate.charges = veh->fuel_left("battery", true);
       add_item(hotplate);

       item water(itypes["water_clean"], 0);
       water.charges = veh->fuel_left("water");
       add_item(water);

       item pot(itypes["pot"], 0);
       add_item(pot);
       item pan(itypes["pan"], 0);
       add_item(pan);
       }
     if (weldpart >= 0) {
       item welder(itypes["welder"], 0);
       welder.charges = veh->fuel_left("battery", true);
       add_item(welder);

       item soldering_iron(itypes["soldering_iron"], 0);
       soldering_iron.charges = veh->fuel_left("battery", true);
       add_item(soldering_iron);
       }
     if (craftpart >= 0) {
       item vac_sealer(itypes["vac_sealer"], 0);
       vac_sealer.charges = veh->fuel_left("battery", true);
       add_item(vac_sealer);

       item dehydrator(itypes["dehydrator"], 0);
       dehydrator.charges = veh->fuel_left("battery", true);
       add_item(dehydrator);

       item press(itypes["press"], 0);
       press.charges = veh->fuel_left("battery", true);
       add_item(press);
       }
     if (forgepart >= 0) {
       item forge(itypes["forge"], 0);
       forge.charges = veh->fuel_left("battery", true);
       add_item(forge);
       }
     if (chempart >= 0) {
       item hotplate(itypes["hotplate"], 0);
       hotplate.charges = veh->fuel_left("battery", true);
       add_item(hotplate);

       item chemistry_set(itypes["chemistry_set"], 0);
       chemistry_set.charges = veh->fuel_left("battery", true);
       add_item(chemistry_set);
       }
     }
   }

  }
 }
void inventory::form_from_map( map &m, const tripoint &origin, int range, bool assign_invlet,
                               bool clear_path )
{
    items.clear();
    for( const tripoint &p : m.points_in_radius( origin, range ) ) {
        // can not reach this -> can not access its contents
        if( clear_path ) {
            if( origin != p && !m.clear_path( origin, p, range, 1, 100 ) ) {
                continue;
            }
        }
        if( m.has_furn( p ) ) {
            const furn_t &f = m.furn( p ).obj();
            const itype *type = f.crafting_pseudo_item_type();
            if( type != nullptr ) {
                const itype *ammo = f.crafting_ammo_item_type();
                item furn_item( type, calendar::turn, 0 );
                furn_item.item_tags.insert( "PSEUDO" );
                furn_item.charges = ammo ? count_charges_in_list( ammo, m.i_at( p ) ) : 0;
                add_item( furn_item );
            }
        }
        if( m.accessible_items( p ) ) {
            for( auto &i : m.i_at( p ) ) {
                if( !i.made_of( LIQUID ) ) {
                    add_item( i, false, assign_invlet );
                }
            }
        }
        // Kludges for now!
        if( m.has_nearby_fire( p, 0 ) ) {
            item fire( "fire", 0 );
            fire.charges = 1;
            add_item( fire );
        }
        // Handle any water from infinite map sources.
        item water = m.water_from( p );
        if( !water.is_null() ) {
            add_item( water );
        }
        // kludge that can probably be done better to check specifically for toilet water to use in
        // crafting
        if( m.furn( p ).obj().examine == &iexamine::toilet ) {
            // get water charges at location
            auto toilet = m.i_at( p );
            auto water = toilet.end();
            for( auto candidate = toilet.begin(); candidate != toilet.end(); ++candidate ) {
                if( candidate->typeId() == "water" ) {
                    water = candidate;
                    break;
                }
            }
            if( water != toilet.end() && water->charges > 0 ) {
                add_item( *water );
            }
        }

        // keg-kludge
        if( m.furn( p ).obj().examine == &iexamine::keg ) {
            auto liq_contained = m.i_at( p );
            for( auto &i : liq_contained ) {
                if( i.made_of( LIQUID ) ) {
                    add_item( i );
                }
            }
        }

        // WARNING: The part below has a bug that's currently quite minor
        // When a vehicle has multiple faucets in range, available water is
        //  multiplied by the number of faucets.
        // Same thing happens for all other tools and resources, but not cargo
        const optional_vpart_position vp = m.veh_at( p );
        if( !vp ) {
            continue;
        }
        vehicle *const veh = &vp->vehicle();

        //Adds faucet to kitchen stuff; may be horribly wrong to do such....
        //ShouldBreak into own variable
        const cata::optional<vpart_reference> kpart = vp.part_with_feature( "KITCHEN", true );
        const cata::optional<vpart_reference> faupart = vp.part_with_feature( "FAUCET", true );
        const cata::optional<vpart_reference> weldpart = vp.part_with_feature( "WELDRIG", true );
        const cata::optional<vpart_reference> craftpart = vp.part_with_feature( "CRAFTRIG", true );
        const cata::optional<vpart_reference> forgepart = vp.part_with_feature( "FORGE", true );
        const cata::optional<vpart_reference> kilnpart = vp.part_with_feature( "KILN", true );
        const cata::optional<vpart_reference> chempart = vp.part_with_feature( "CHEMLAB", true );
        const cata::optional<vpart_reference> cargo = vp.part_with_feature( "CARGO", true );

        if( cargo ) {
            const auto items = veh->get_items( cargo->part_index() );
            *this += std::list<item>( items.begin(), items.end() );
        }

        if( faupart ) {
            for( const auto &it : veh->fuels_left() ) {
                item fuel( it.first, 0 );
                if( fuel.made_of( LIQUID ) ) {
                    fuel.charges = it.second;
                    add_item( fuel );
                }
            }
        }

        if( kpart ) {
            item hotplate( "hotplate", 0 );
            hotplate.charges = veh->fuel_left( "battery", true );
            hotplate.item_tags.insert( "PSEUDO" );
            add_item( hotplate );

            item pot( "pot", 0 );
            pot.item_tags.insert( "PSEUDO" );
            add_item( pot );
            item pan( "pan", 0 );
            pan.item_tags.insert( "PSEUDO" );
            add_item( pan );
        }
        if( weldpart ) {
            item welder( "welder", 0 );
            welder.charges = veh->fuel_left( "battery", true );
            welder.item_tags.insert( "PSEUDO" );
            add_item( welder );

            item soldering_iron( "soldering_iron", 0 );
            soldering_iron.charges = veh->fuel_left( "battery", true );
            soldering_iron.item_tags.insert( "PSEUDO" );
            add_item( soldering_iron );
        }
        if( craftpart ) {
            item vac_sealer( "vac_sealer", 0 );
            vac_sealer.charges = veh->fuel_left( "battery", true );
            vac_sealer.item_tags.insert( "PSEUDO" );
            add_item( vac_sealer );

            item dehydrator( "dehydrator", 0 );
            dehydrator.charges = veh->fuel_left( "battery", true );
            dehydrator.item_tags.insert( "PSEUDO" );
            add_item( dehydrator );

            item food_processor( "food_processor", 0 );
            food_processor.charges = veh->fuel_left( "battery", true );
            food_processor.item_tags.insert( "PSEUDO" );
            add_item( food_processor );

            item press( "press", 0 );
            press.charges = veh->fuel_left( "battery", true );
            press.item_tags.insert( "PSEUDO" );
            add_item( press );
        }
        if( forgepart ) {
            item forge( "forge", 0 );
            forge.charges = veh->fuel_left( "battery", true );
            forge.item_tags.insert( "PSEUDO" );
            add_item( forge );
        }
        if( kilnpart ) {
            item kiln( "kiln", 0 );
            kiln.charges = veh->fuel_left( "battery", true );
            kiln.item_tags.insert( "PSEUDO" );
            add_item( kiln );
        }
        if( chempart ) {
            item hotplate( "hotplate", 0 );
            hotplate.charges = veh->fuel_left( "battery", true );
            hotplate.item_tags.insert( "PSEUDO" );
            add_item( hotplate );

            item chemistry_set( "chemistry_set", 0 );
            chemistry_set.charges = veh->fuel_left( "battery", true );
            chemistry_set.item_tags.insert( "PSEUDO" );
            add_item( chemistry_set );
        }
    }
}