void inventory::form_from_map(game *g, point origin, int range) { 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_flag(sealed, x, y)) 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]); // Kludges for now! ter_id terrain_id = g->m.ter(x, y); furn_id furniture_id = g->m.furn(x, y); if ((g->m.field_at(x, y).findField(fd_fire)) || (terrain_id == t_lava)) { item fire(g->itypes["fire"], 0); fire.charges = 1; add_item(fire); } if (terrain_id == t_water_sh || terrain_id == t_water_dp){ item water(g->itypes["water"], 0); water.charges = 50; add_item(water); } int vpart = -1; vehicle *veh = g->m.veh_at(x, y, vpart); if (veh) { const int kpart = veh->part_with_feature(vpart, vpf_kitchen); const int weldpart = veh->part_with_feature(vpart, vpf_weldrig); if (kpart >= 0) { item hotplate(g->itypes["hotplate"], 0); hotplate.charges = veh->fuel_left("battery", true); add_item(hotplate); item water(g->itypes["water_clean"], 0); water.charges = veh->fuel_left("water"); add_item(water); item pot(g->itypes["pot"], 0); add_item(pot); item pan(g->itypes["pan"], 0); add_item(pan); } if (weldpart >= 0) { item welder(g->itypes["welder"], 0); welder.charges = veh->fuel_left("battery", true); add_item(welder); item soldering_iron(g->itypes["soldering_iron"], 0); soldering_iron.charges = veh->fuel_left("battery", true); add_item(soldering_iron); } } } } }
void inventory::form_from_map(game *g, point origin, int range) { items.clear(); for (int x = origin.x - range; x <= origin.x + range; x++) { for (int y = origin.y - range; y <= origin.y + range; y++) { 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]); // Kludges for now! if (g->m.field_at(x, y).type == fd_fire) { item fire(g->itypes["fire"], 0); fire.charges = 1; add_item(fire); } ter_id terrain_id = g->m.ter(x, y); if (terrain_id == t_toilet || terrain_id == t_water_sh || terrain_id == t_water_dp){ item water(g->itypes["water"], 0); water.charges = 50; add_item(water); } int vpart = -1; vehicle *veh = g->m.veh_at(x, y, vpart); if (veh) { const int kpart = veh->part_with_feature(vpart, vpf_kitchen); if (kpart >= 0) { item hotplate(g->itypes["hotplate"], 0); hotplate.charges = veh->fuel_left(AT_BATT, true); add_item(hotplate); item water(g->itypes["water_clean"], 0); water.charges = veh->fuel_left(AT_WATER); add_item(water); item pot(g->itypes["pot"], 0); add_item(pot); item pan(g->itypes["pan"], 0); add_item(pan); } } } } }
void selectType(char *type, Particle **p) { if (!strcmp(type, "bouble")) bouble(&(*p)); if (!strcmp(type, "smoke")) smoke(&(*p)); if (!strcmp(type, "water")) water(&(*p)); if (!strcmp(type, "ball")) ball(&(*p)); if (!strcmp(type, "wind")) wind(&(*p)); if (!strcmp(type, "siva")) siva(&(*p)); if (!strcmp(type, "sun")) sun(&(*p)); }
int draw(){ drawOutline(); drawMap(); water(); voidBlock(); attron(COLOR_PAIR(6)); mvprintw(12,0,"Block Type:"); return 0; }
int main(int argc, char *argv[]) { loginit(NULL); if (argc < 4) fatal("Expected 3 arguments"); parseargs(argc, argv); rng(&r); int w = strtol(argv[1], NULL, 10); int h = strtol(argv[2], NULL, 10); int d = strtol(argv[3], NULL, 10); Lvl *lvl = lvlnew(d, w, h, 0); unsigned int x0 = 2, y0 = 2; if (randstart) { x0 = rnd(1, w-2); y0 = rnd(1, h-2); } mvsinit(); do{ init(lvl); if (addwater) water(lvl); Loc loc = (Loc) { x0, y0, 0 }; Path *p = pathnew(lvl); pathbuild(lvl, p, loc); pathfree(p); morereach(lvl); closeunits(lvl); }while(closeunreach(lvl) < lvl->w * lvl->h * lvl->d * 0.40); stairs(&r, lvl, x0, y0); bool foundstart = false; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (blk(lvl, x, y, 0)->tile == 'u' || blk(lvl, x, y, 0)->tile == 'U') { foundstart = true; break; } } } assert(foundstart); lvlwrite(stdout, lvl); lvlfree(lvl); return 0; }
int main() { bool quit = false; Timer fps; SDL_Surface *screen = NULL; SDL_Event event; Water water(&screen); //TTF_Font *font = NULL; //SDL_Color textColor = {0, 0, 0}; if( init(&screen) == false ) return 1; if( load_files() == false ) return 2; //water.randomInit(); while( quit == false ) { fps.start(); while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } if (event.type == SDL_MOUSEBUTTONDOWN) if (event.button.button == SDL_BUTTON_LEFT) { if (event.button.y < SCREEN_HEIGHT / 2) water.giveInput(event.button.x, 10); else water.giveInput(event.button.x, -10); } } water.compute(); water.move(); SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 )); water.show(); if( SDL_Flip( screen ) == -1 ) return 3; if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } clean_up(); return 0; }
void inventory::form_from_map(game *g, point origin, int range) { items.clear(); for (int x = origin.x - range; x <= origin.x + range; x++) { for (int y = origin.y - range; y <= origin.y + range; y++) { 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]); // Kludge for now! if (g->m.field_at(x, y).type == fd_fire) { item fire(g->itypes[itm_fire], 0); fire.charges = 1; add_item(fire); } if (g->m.ter(x, y) == t_forge) { item forge(g->itypes[itm_forge], 0); forge.charges = 1; add_item(forge); } if (g->m.ter(x, y) == t_grindstone) { item grind(g->itypes[itm_grindstone], 0); grind.charges = 1; add_item(grind); } if (g->m.ter(x, y) == t_watertub) { item water(g->itypes[itm_forgewater], 0); water.charges = 1; add_item(water); } if (g->m.ter(x, y) == t_crucible) { item crucible(g->itypes[itm_hot_crucible], 0); crucible.charges = 1; add_item(crucible); } if (g->m.ter(x, y) == t_anvil) { item anvil(g->itypes[itm_anvil], 0); anvil.charges = 1; add_item(anvil); } } } }
void inventory::form_from_map(game *g, point origin, int range) { items.clear(); for (int x = origin.x - range; x <= origin.x + range; x++) { for (int y = origin.y - range; y <= origin.y + range; y++) { for (unsigned 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]); // Kludges for now! if (g->m.field_at(x, y).type == fd_fire) { item fire(g->itypes[itm_fire], 0); fire.charges = 1; add_item(fire); } ter_id terrain_id = g->m.ter(x, y); if (terrain_id == t_toilet || terrain_id == t_sink || terrain_id == t_water_sh || terrain_id == t_water_dp){ item water(g->itypes[itm_water], 0); water.charges = 50; add_item(water); } } } }
// Handles interactions with a vehicle in the examine menu. Pickup::interact_results Pickup::interact_with_vehicle( vehicle *veh, const tripoint &pos, int veh_root_part ) { if( veh == nullptr ) { return ITEMS_FROM_GROUND; } std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; const bool has_items_on_ground = g->m.sees_some_items( pos, g->u ); const bool items_are_sealed = g->m.has_flag( "SEALED", pos ); const bool has_kitchen = (veh->part_with_feature(veh_root_part, "KITCHEN") >= 0); const bool has_faucet = (veh->part_with_feature(veh_root_part, "FAUCET") >= 0); const bool has_weldrig = (veh->part_with_feature(veh_root_part, "WELDRIG") >= 0); const bool has_craftrig = (veh->part_with_feature(veh_root_part, "CRAFTRIG") >= 0); const bool has_chemlab = (veh->part_with_feature(veh_root_part, "CHEMLAB") >= 0); const bool has_purify = (veh->part_with_feature(veh_root_part, "WATER_PURIFIER") >=0); const bool has_controls = ((veh->part_with_feature(veh_root_part, "CONTROLS") >= 0) || (veh->part_with_feature(veh_root_part, "CTRL_ELECTRONIC") >=0)); const int cargo_part = veh->part_with_feature(veh_root_part, "CARGO", false); const bool from_vehicle = veh && cargo_part >= 0 && !veh->get_items(cargo_part).empty(); const bool can_be_folded = veh->is_foldable(); const bool is_convertible = (veh->tags.count("convertible") > 0); const bool remotely_controlled = g->remoteveh() == veh; typedef enum { EXAMINE, CONTROL, GET_ITEMS, GET_ITEMS_ON_GROUND, FOLD_VEHICLE, USE_HOTPLATE, FILL_CONTAINER, DRINK, USE_WELDER, USE_PURIFIER, PURIFY_TANK, } options; uimenu selectmenu; selectmenu.addentry( EXAMINE, true, 'e', _("Examine vehicle") ); if( has_controls ) { selectmenu.addentry( CONTROL, true, 'v', _("Control vehicle") ); } if( from_vehicle ) { selectmenu.addentry( GET_ITEMS, true, 'g', _("Get items") ); } if( has_items_on_ground && !items_are_sealed ) { selectmenu.addentry( GET_ITEMS_ON_GROUND, true, 'i', _("Get items on the ground") ); } if( ( can_be_folded || is_convertible ) && !remotely_controlled ) { selectmenu.addentry( FOLD_VEHICLE, true, 'f', _("Fold vehicle") ); } if( ( has_kitchen || has_chemlab ) && veh->fuel_left("battery") > 0) { selectmenu.addentry( USE_HOTPLATE, true, 'h', _("Use the hotplate") ); } if( ( has_kitchen || has_faucet ) && veh->fuel_left("water_clean") > 0) { selectmenu.addentry( FILL_CONTAINER, true, 'c', _("Fill a container with water") ); selectmenu.addentry( DRINK, true, 'd', _("Have a drink") ); } if( has_weldrig && veh->fuel_left("battery") > 0 ) { selectmenu.addentry( USE_WELDER, true, 'w', _("Use the welding rig?") ); } if( ( has_craftrig || has_purify ) && veh->fuel_left("battery") > 0 ) { selectmenu.addentry( USE_PURIFIER, true, 'p', _("Purify water in carried container") ); } if( ( has_craftrig || has_purify ) && veh->fuel_left("battery") > 0 && veh->fuel_left("water") > 0 && veh->fuel_capacity("water_clean") > veh->fuel_left("water_clean") ) { selectmenu.addentry( PURIFY_TANK, true, 'P', _("Purify water in vehicle's tank") ); } int choice; if( selectmenu.entries.size() == 1 ) { choice = selectmenu.entries.front().retval; } else { selectmenu.return_invalid = true; selectmenu.text = _("Select an action"); selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } switch( static_cast<options>( choice ) ) { case USE_HOTPLATE: { //Will be -1 if no battery at all item tmp_hotplate( "hotplate", 0 ); // Drain a ton of power tmp_hotplate.charges = veh->drain( "battery", 100 ); if( tmp_hotplate.is_tool() ) { const auto tmptool = dynamic_cast<const it_tool *>((&tmp_hotplate)->type); if ( tmp_hotplate.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_hotplate ); tmp_hotplate.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_hotplate.charges ); } } return DONE; } case FILL_CONTAINER: { int amt = veh->drain("water_clean", veh->fuel_left("water_clean")); item fill_water( "water_clean", calendar::turn ); fill_water.charges = amt; int back = g->move_liquid(fill_water); if (back >= 0) { veh->refill("water_clean", back); } else { veh->refill("water_clean", amt); } return DONE; } case DRINK: { veh->drain("water_clean", 1); item water( "water_clean", 0 ); g->u.eat(&water, dynamic_cast<const it_comest *>(water.type)); g->u.moves -= 250; return DONE; } case USE_WELDER: { //Will be -1 if no battery at all item tmp_welder( "welder", 0 ); // Drain a ton of power tmp_welder.charges = veh->drain( "battery", 1000 ); if( tmp_welder.is_tool() ) { const auto tmptool = dynamic_cast<const it_tool *>((&tmp_welder)->type); if ( tmp_welder.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_welder ); tmp_welder.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_welder.charges ); } } return DONE; } case USE_PURIFIER: { //Will be -1 if no battery at all item tmp_purifier( "water_purifier", 0 ); // Drain a ton of power tmp_purifier.charges = veh->drain( "battery", veh->fuel_left("battery")); if( tmp_purifier.is_tool() ) { const auto tmptool = dynamic_cast<const it_tool *>((&tmp_purifier)->type); if ( tmp_purifier.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_purifier ); tmp_purifier.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_purifier.charges ); } } return DONE; } case PURIFY_TANK: { const int max_water = std::min( veh->fuel_left("water"), veh->fuel_capacity("water_clean") - veh->fuel_left("water_clean") ); const int purify_amount = std::min( veh->fuel_left("battery"), max_water ); veh->drain( "battery", purify_amount ); veh->drain( "water", purify_amount ); veh->refill( "water_clean", purify_amount ); return DONE; } case FOLD_VEHICLE: veh->fold_up(); return DONE; case CONTROL: if( veh->interact_vehicle_locked() ) { veh->use_controls(pos); } return DONE; case EXAMINE: g->exam_vehicle(*veh, pos ); return DONE; case GET_ITEMS_ON_GROUND: return ITEMS_FROM_GROUND; case GET_ITEMS: return from_vehicle ? ITEMS_FROM_CARGO : ITEMS_FROM_GROUND; } return DONE; }
void run() { if(!initialize()) shutdown("Failed to initialize"); if(!loadContent()) shutdown("Failed to load resources"); Mesh cubeMesh = Mesh::genUnitColoredCube(); MeshBuffer cubeBuffer(cubeMesh); Model cube(cubeBuffer); Mesh waterMesh = Mesh::genUnitColoredPlane(Color(0.57f, 0.63f, 0.98f)); MeshBuffer waterBuffer(waterMesh); Model water(waterBuffer); BufferObject quadVbo; float quadVertices[] = { -1.0f, -1.0f, 0.0f, 0.0f, +1.0f, -1.0f, 1.0f, 0.0f, +1.0f, +1.0f, 1.0f, 1.0f, +1.0f, +1.0f, 1.0f, 1.0f, -1.0f, +1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f }; quadVbo.create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, sizeof(quadVertices), quadVertices); Mesh gridMesh; for(int i = 0; i <= 8; ++i) { float f = (i / 8.0) * 2.0f - 1.0f; int j = gridMesh.getPositionCount(); gridMesh.addPosition(f * 3.0f, 0.0f, -3.0f); gridMesh.addPosition(f * 3.0f, 0.0f, +3.0f); gridMesh.addPosition(-3.0f, 0.0f, f * 3.0f); gridMesh.addPosition(+3.0f, 0.0f, f * 3.0f); gridMesh.addColor(Colors::White); gridMesh.addColor(Colors::White); gridMesh.addColor(Colors::White); gridMesh.addColor(Colors::White); gridMesh.addIndex(j + 0); gridMesh.addIndex(j + 1); gridMesh.addIndex(j + 2); gridMesh.addIndex(j + 3); } MeshBuffer gridBuffer(gridMesh); Model grid(gridBuffer); VertexArray vao; vao.create(); vao.bind(); mat4 perspectiveMatrix = glm::perspective(45.0f, windowWidth / float(windowHeight), 0.05f, 50.0f); // The geometry to be refracted and reflected are stored in these // In addition to RGB values, the world-space height is stored in the alpha-channel // of the refraction texture. // Fresnel equations is used to blend between the two textures RenderTexture refractionRT(windowWidth, windowHeight); RenderTexture reflectionRT(windowWidth, windowHeight); renderer.setClearColor(0.55f, 0.45f, 0.45f, 1.0f); renderer.setClearDepth(1.0); Timer timer; timer.start(); double renderTime = 0.0; while(context.isOpen()) { timer.step(); double time = timer.getElapsedTime(); update(time, timer.getDelta()); double renderStart = timer.getElapsedTime(); MatrixStack viewMatrix; viewMatrix.push(); viewMatrix.translate(0.0f, 0.0f, -3.0f); viewMatrix.rotateX(xAxisRotation); viewMatrix.rotateY(yAxisRotation); renderer.setCullState(CullStates::CullNone); renderer.setDepthTestState(DepthTestStates::LessThanOrEqual); colorShader.begin(); colorShader.setUniform("projection", perspectiveMatrix); cube.pushTransform(); cube.translate(0.0f, 0.0f, 0.0f); cube.scale(0.5f); // Render the geometry to be refracted, store result in rt refractionRT.begin(); renderer.clearColorAndDepth(); colorShader.setUniform("view", viewMatrix.top()); cube.draw(GL_TRIANGLES); grid.draw(GL_LINES); refractionRT.end(); // Render the geometry to be reflected, store result in rt reflectionRT.begin(); renderer.clearColorAndDepth(); viewMatrix.push(); viewMatrix.scale(1.0f, -1.0f, 1.0f); // Reflect about xz-plane colorShader.setUniform("view", viewMatrix.top()); cube.draw(GL_TRIANGLES); viewMatrix.pop(); reflectionRT.end(); colorShader.end(); cube.popTransform(); // Render the water with the previous reflection/refraction texture waterShader.begin(); waterShader.setUniform("time", time); glActiveTexture(GL_TEXTURE0 + 0); refractionRT.bindTexture(); glActiveTexture(GL_TEXTURE0 + 1); reflectionRT.bindTexture(); glActiveTexture(GL_TEXTURE0 + 2); waterNormals.bind(); //waterShader.setUniform("view", viewMatrix.top()); waterShader.setUniform("refraction_tex", 0); waterShader.setUniform("reflection_tex", 1); waterShader.setUniform("water_normals_tex", 2); //waterShader.setUniform("light0_pos", vec3(0.0f, 1.0f, 0.0f)); //waterShader.setUniform("light0_col", vec3(1.0f, 0.8f, 0.5f)); //waterShader.setUniform("ambient", vec3(67.0f/255.0f, 66.0f/255.0f, 63.0f/255.0f)); quadVbo.bind(); waterShader.setAttributefv("position", 2, 4, 0); waterShader.setAttributefv("texel", 2, 4, 2); glDrawArrays(GL_TRIANGLES, 0, 6); quadVbo.unbind(); reflectionRT.unbindTexture(); refractionRT.unbindTexture(); waterNormals.unbind(); waterShader.end(); glActiveTexture(GL_TEXTURE0 + 0); // Render unmirrored scene //colorShader.begin(); //renderer.clearColorAndDepth(); //renderer.setCullState(CullStates::CullNone); //renderer.setBlendState(BlendStates::AlphaBlend); //renderer.setDepthTestState(DepthTestStates::LessThanOrEqual); //colorShader.setUniform("projection", perspectiveMatrix); //colorShader.setUniform("view", viewMatrix.top()); //cube.pushTransform(); //cube.translate(0.0f, 0.4f, 0.0f); //cube.scale(0.5f); //cube.draw(GL_TRIANGLES); /*grid.pushTransform(); grid.translate(0.0f, -0.5f, 0.0f); grid.draw(GL_LINES); grid.popTransform();*/ // Draw mirrored scene to a rendertarget /*rt.begin(); renderer.clearColorAndDepth(); viewMatrix.push(); viewMatrix.scale(1.0f, -1.0f, 1.0f); colorShader.setUniform("view", viewMatrix.top()); cube.draw(GL_TRIANGLES); cube.popTransform(); viewMatrix.pop(); rt.end();*/ // Enable stencil testing and mask out a section containing the water mesh //glEnable(GL_STENCIL_TEST); //glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1 //glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); //glStencilMask(0xFF); // Write to stencil buffer //glDepthMask(GL_FALSE); // Don't write to depth buffer //glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default) //// Draw water mesh //water.pushTransform(); //water.scale(3.0f); //water.draw(GL_TRIANGLES); //water.popTransform(); //colorShader.end(); //// Draw previous rendertarget as a quad masked into the water plane //glStencilFunc(GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1 //glStencilMask(0x00); // Don't write anything to stencil buffer //glDepthMask(GL_TRUE); //glDisable(GL_STENCIL_TEST); viewMatrix.pop(); context.display(); renderTime = timer.getElapsedTime() - renderStart; if(renderTime < 0.013) context.sleep(0.013 - renderTime); if(checkGLErrors(std::cerr)) { std::cin.get(); context.close(); } } waterNormals.dispose(); colorShader.dispose(); waterShader.dispose(); vao.dispose(); context.dispose(); }
void Water::drawTile( const RenderInfo& rinfo, Tile& tile) { bool needDrawAnimations = false; Size areaSize = Size::square(1); if( tile.overlay().isNull() ) { drawLandTile( rinfo, tile ); } else { OverlayPtr overlay = tile.overlay(); if( _isVisibleObject( overlay->type() ) ) { // Base set of visible objects needDrawAnimations = true; areaSize = overlay->size(); } else { int tileNumber = 0; bool haveWater = tile.param( Tile::pFountainWater ) > 0 || tile.param( Tile::pWellWater ) > 0; needDrawAnimations = false; if ( overlay->type() == object::house ) { auto house = overlay.as<House>(); needDrawAnimations = (house->level() <= HouseLevel::hovel) && house->habitants().empty(); tileNumber = config::tile.house-1; haveWater = haveWater || house->hasServiceAccess(Service::fountain) || house->hasServiceAccess(Service::well); } if( !needDrawAnimations ) { tileNumber += (haveWater ? config::layer.haveWater : 0); tileNumber += tile.param( Tile::pReservoirWater ) > 0 ? config::layer.reservoirRange : 0; drawArea( rinfo, overlay->area(), config::layer.water, config::tile.constr + tileNumber ); areaSize = Size::zero; } } if ( needDrawAnimations ) { Point screenPos = tile.mappos() + rinfo.offset; Layer::drawTile( rinfo, tile ); if( _d->showWaterValue ) { auto aqueduct = tile.overlay<Aqueduct>(); if( aqueduct.isValid() ) { Font f = Font::create( "FONT_2" ).withColor( ColorList::red ); int df = aqueduct->water(); f.draw( rinfo.engine.screen(), utils::format( 0xff, "%x", df), screenPos + Point( 20, -80 ), false ); } int wellValue = tile.param( Tile::pWellWater ); int fountainValue = tile.param( Tile::pFountainWater ); int reservoirWater = tile.param( Tile::pReservoirWater ); if( wellValue > 0 || fountainValue > 0 || reservoirWater > 0 ) { std::string text = utils::format( 0xff, "%d/%d/%d", wellValue, fountainValue, reservoirWater ); Font f = Font::create( "FONT_2" ).withColor( ColorList::red ); f.draw( rinfo.engine.screen(), text, screenPos + Point( 20, -80 ), false ); } } registerTileForRendering( tile ); } } if( !needDrawAnimations && ( tile.isWalkable(true) || tile.getFlag( Tile::tlOverlay ) ) ) { _drawLandTile( rinfo, tile, areaSize ); } tile.setRendered(); }
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); } } } } }
// Handles interactions with a vehicle in the examine menu. // Returns the part number that wil accept items if any, or -1 to indicate no cargo part. // Returns -2 if a special interaction was performed and the menu should exit. int Pickup::interact_with_vehicle( vehicle *veh, int posx, int posy, int veh_root_part ) { bool from_vehicle = false; int k_part = 0; int wtr_part = 0; int w_part = 0; int craft_part = 0; int cargo_part = 0; int chempart = 0; int ctrl_part = 0; std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; std::vector<item> here_ground = g->m.i_at(posx, posy); if( veh ) { k_part = veh->part_with_feature(veh_root_part, "KITCHEN"); wtr_part = veh->part_with_feature(veh_root_part, "FAUCET"); w_part = veh->part_with_feature(veh_root_part, "WELDRIG"); craft_part = veh->part_with_feature(veh_root_part, "CRAFTRIG"); chempart = veh->part_with_feature(veh_root_part, "CHEMLAB"); cargo_part = veh->part_with_feature(veh_root_part, "CARGO", false); ctrl_part = veh->part_with_feature(veh_root_part, "CONTROLS"); from_vehicle = veh && cargo_part >= 0 && !veh->parts[cargo_part].items.empty(); menu_items.push_back(_("Examine vehicle")); options_message.push_back(uimenu_entry(_("Examine vehicle"), 'e')); if (ctrl_part >= 0) { menu_items.push_back(_("Control vehicle")); options_message.push_back(uimenu_entry(_("Control vehicle"), 'v')); } if( from_vehicle ) { menu_items.push_back(_("Get items")); options_message.push_back(uimenu_entry(_("Get items"), 'g')); } if(!here_ground.empty()) { menu_items.push_back(_("Get items on the ground")); options_message.push_back(uimenu_entry(_("Get items on the ground"), 'i')); } if((k_part >= 0 || chempart >= 0) && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the hotplate")); options_message.push_back(uimenu_entry(_("Use the hotplate"), 'h')); } if((k_part >= 0 || wtr_part >= 0) && veh->fuel_left("water") > 0) { menu_items.push_back(_("Fill a container with water")); options_message.push_back(uimenu_entry(_("Fill a container with water"), 'c')); menu_items.push_back(_("Have a drink")); options_message.push_back(uimenu_entry(_("Have a drink"), 'd')); } if(w_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the welding rig?")); options_message.push_back(uimenu_entry(_("Use the welding rig?"), 'w')); } if(craft_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the water purifier?")); options_message.push_back(uimenu_entry(_("Use the water purifier?"), 'p')); } int choice; if( menu_items.size() == 1 ) { choice = 0; } else { uimenu selectmenu; selectmenu.return_invalid = true; selectmenu.text = _("Select an action"); selectmenu.entries = options_message; selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } if(choice < 0) { return -2; } if(menu_items[choice] == _("Use the hotplate")) { //Will be -1 if no battery at all item tmp_hotplate( "hotplate", 0 ); // Drain a ton of power tmp_hotplate.charges = veh->drain( "battery", 100 ); if( tmp_hotplate.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_hotplate)->type); if ( tmp_hotplate.charges >= tmptool->charges_per_use ) { tmptool->invoke(&g->u, &tmp_hotplate, false); tmp_hotplate.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_hotplate.charges ); } } return -2; } if(menu_items[choice] == _("Fill a container with water")) { int amt = veh->drain("water", veh->fuel_left("water")); item fill_water( default_ammo("water"), calendar::turn ); fill_water.charges = amt; int back = g->move_liquid(fill_water); if (back >= 0) { veh->refill("water", back); } else { veh->refill("water", amt); } return -2; } if(menu_items[choice] == _("Have a drink")) { veh->drain("water", 1); item water( "water_clean", 0 ); g->u.eat(&water, dynamic_cast<it_comest *>(water.type)); g->u.moves -= 250; return -2; } if(menu_items[choice] == _("Use the welding rig?")) { //Will be -1 if no battery at all item tmp_welder( "welder", 0 ); // Drain a ton of power tmp_welder.charges = veh->drain( "battery", 1000 ); if( tmp_welder.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_welder)->type); if ( tmp_welder.charges >= tmptool->charges_per_use ) { tmptool->invoke( &g->u, &tmp_welder, false ); tmp_welder.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_welder.charges ); } } return -2; } if(menu_items[choice] == _("Use the water purifier?")) { //Will be -1 if no battery at all item tmp_purifier( "water_purifier", 0 ); // Drain a ton of power tmp_purifier.charges = veh->drain( "battery", 100 ); if( tmp_purifier.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_purifier)->type); if ( tmp_purifier.charges >= tmptool->charges_per_use ) { tmptool->invoke( &g->u, &tmp_purifier, false ); tmp_purifier.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_purifier.charges ); } } return -2; } if(menu_items[choice] == _("Control vehicle")) { veh->use_controls(); return -2; } if(menu_items[choice] == _("Examine vehicle")) { g->exam_vehicle(*veh, posx, posy); return -2; } if(menu_items[choice] == _("Get items on the ground")) { from_vehicle = false; } } return from_vehicle ? cargo_part : -1; }
// Handles interactions with a vehicle in the examine menu. Pickup::interact_results Pickup::interact_with_vehicle( vehicle *veh, const tripoint &pos, int veh_root_part ) { if( veh == nullptr ) { return ITEMS_FROM_GROUND; } std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; const bool has_items_on_ground = g->m.sees_some_items( pos, g->u ); const bool items_are_sealed = g->m.has_flag( "SEALED", pos ); const bool has_kitchen = ( veh->part_with_feature( veh_root_part, "KITCHEN" ) >= 0 ); const bool has_faucet = ( veh->part_with_feature( veh_root_part, "FAUCET" ) >= 0 ); const bool has_weldrig = ( veh->part_with_feature( veh_root_part, "WELDRIG" ) >= 0 ); const bool has_chemlab = ( veh->part_with_feature( veh_root_part, "CHEMLAB" ) >= 0 ); const bool has_purify = ( veh->part_with_feature( veh_root_part, "WATER_PURIFIER" ) >= 0 ); const bool has_controls = ( ( veh->part_with_feature( veh_root_part, "CONTROLS" ) >= 0 ) || ( veh->part_with_feature( veh_root_part, "CTRL_ELECTRONIC" ) >= 0 ) ); const int cargo_part = veh->part_with_feature( veh_root_part, "CARGO", false ); const bool from_vehicle = veh && cargo_part >= 0 && !veh->get_items( cargo_part ).empty(); const bool can_be_folded = veh->is_foldable(); const bool is_convertible = ( veh->tags.count( "convertible" ) > 0 ); const bool remotely_controlled = g->remoteveh() == veh; typedef enum { EXAMINE, CONTROL, GET_ITEMS, GET_ITEMS_ON_GROUND, FOLD_VEHICLE, USE_HOTPLATE, FILL_CONTAINER, DRINK, USE_WELDER, USE_PURIFIER, PURIFY_TANK, } options; uimenu selectmenu; selectmenu.addentry( EXAMINE, true, 'e', _( "Examine vehicle" ) ); if( has_controls ) { selectmenu.addentry( CONTROL, true, 'v', _( "Control vehicle" ) ); } if( from_vehicle ) { selectmenu.addentry( GET_ITEMS, true, 'g', _( "Get items" ) ); } if( has_items_on_ground && !items_are_sealed ) { selectmenu.addentry( GET_ITEMS_ON_GROUND, true, 'i', _( "Get items on the ground" ) ); } if( ( can_be_folded || is_convertible ) && !remotely_controlled ) { selectmenu.addentry( FOLD_VEHICLE, true, 'f', _( "Fold vehicle" ) ); } if( ( has_kitchen || has_chemlab ) && veh->fuel_left( "battery" ) > 0 ) { selectmenu.addentry( USE_HOTPLATE, true, 'h', _( "Use the hotplate" ) ); } if( has_faucet && veh->fuel_left( "water_clean" ) > 0 ) { selectmenu.addentry( FILL_CONTAINER, true, 'c', _( "Fill a container with water" ) ); selectmenu.addentry( DRINK, true, 'd', _( "Have a drink" ) ); } if( has_weldrig && veh->fuel_left( "battery" ) > 0 ) { selectmenu.addentry( USE_WELDER, true, 'w', _( "Use the welding rig?" ) ); } if( has_purify && veh->fuel_left( "battery" ) > 0 ) { selectmenu.addentry( USE_PURIFIER, true, 'p', _( "Purify water in carried container" ) ); } if( has_purify && veh->fuel_left( "battery" ) > 0 && veh->fuel_left( "water" ) > 0 && veh->fuel_capacity( "water_clean" ) > veh->fuel_left( "water_clean" ) ) { selectmenu.addentry( PURIFY_TANK, true, 'P', _( "Purify water in vehicle's tank" ) ); } int choice; if( selectmenu.entries.size() == 1 ) { choice = selectmenu.entries.front().retval; } else { selectmenu.return_invalid = true; selectmenu.text = _( "Select an action" ); selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } switch( static_cast<options>( choice ) ) { case USE_HOTPLATE: { item pseudo( "hotplate" ); itype_id ammo = pseudo.ammo_default(); pseudo.ammo_set( ammo, veh->drain( ammo, pseudo.ammo_capacity() ) ); if( pseudo.ammo_sufficient() ) { g->u.invoke_item( &pseudo ); pseudo.ammo_consume( pseudo.ammo_required(), g->u.pos() ); veh->refill( ammo, pseudo.ammo_remaining() ); } return DONE; } case FILL_CONTAINER: g->u.siphon( *veh, "water_clean" ); return DONE; case DRINK: { veh->drain( "water_clean", 1 ); item water( "water_clean", 0 ); g->u.eat( water ); g->u.moves -= 250; return DONE; } case USE_WELDER: { item pseudo( "welder" ); itype_id ammo = pseudo.ammo_default(); pseudo.ammo_set( ammo, veh->drain( ammo, pseudo.ammo_capacity() ) ); if( pseudo.ammo_sufficient() ) { g->u.invoke_item( &pseudo ); pseudo.ammo_consume( pseudo.ammo_required(), g->u.pos() ); veh->refill( ammo, pseudo.ammo_remaining() ); // Evil hack incoming auto &act = g->u.activity; if( act.type == ACT_REPAIR_ITEM ) { // Magic: first tell activity the item doesn't really exist act.index = INT_MIN; // Then tell it to search it on `pos` act.coords.push_back( pos ); // Finally tell it it is the vehicle part with weldrig act.values.resize( 2 ); act.values[1] = veh->part_with_feature( veh_root_part, "WELDRIG" ); } } return DONE; } case USE_PURIFIER: { item pseudo( "water_purifier" ); itype_id ammo = pseudo.ammo_default(); pseudo.ammo_set( ammo, veh->drain( ammo, pseudo.ammo_capacity() ) ); if( pseudo.ammo_sufficient() ) { g->u.invoke_item( &pseudo ); pseudo.ammo_consume( pseudo.ammo_required(), g->u.pos() ); veh->refill( ammo, pseudo.ammo_remaining() ); } return DONE; } case PURIFY_TANK: { const int max_water = std::min( veh->fuel_left( "water" ), veh->fuel_capacity( "water_clean" ) - veh->fuel_left( "water_clean" ) ); const int purify_amount = std::min( veh->fuel_left( "battery" ), max_water ); veh->drain( "battery", purify_amount ); veh->drain( "water", purify_amount ); veh->refill( "water_clean", purify_amount ); return DONE; } case FOLD_VEHICLE: veh->fold_up(); return DONE; case CONTROL: if( veh->interact_vehicle_locked() ) { veh->use_controls( pos ); } return DONE; case EXAMINE: g->exam_vehicle( *veh ); return DONE; case GET_ITEMS_ON_GROUND: return ITEMS_FROM_GROUND; case GET_ITEMS: return from_vehicle ? ITEMS_FROM_CARGO : ITEMS_FROM_GROUND; } return DONE; }
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 doit() { //Image img(600, 400); Image img(1280, 960); img.addRef(); //Set up the scene GeometryGroup scene(ACC_STRUCT); LWObject cow; //cow.read("models/cow.obj", true); cow.read("models/untitled.obj", true); //cow.read("models/house_obj.obj", true); //cow.read("models/3spheretest.obj", true); //cow.read("models/TheDragon.obj", true); cow.addReferencesToScene(scene.primitives); /* ((TexturedPhongShader*)cow.materials[cow.materialMap["Material.001"]].shader.data())->diffTexture->filterMode = Texture::TFM_Bilinear; ((TexturedPhongShader*)cow.materials[cow.materialMap["Material.001"]].shader.data())->ambientTexture->filterMode = Texture::TFM_Bilinear; ((TexturedBumpPhongShader*)cow.materials[cow.materialMap["Material.001"]].shader.data())->bumpTexture->filterMode = Texture::TFM_Bilinear; */ /* SmartPtr<Image> imag; imag->readPNG("models/tiles.png"); SmartPtr<Texture> tiles; tiles->image = imag; ((TexturedBumpPhongShader*)cow.materials[cow.materialMap["Material.001"]].shader.data())->diffTexture = tiles; */ MirrorPhongShader sh77; sh77.diffuseCoef = float4(220.f/255, 193.f/255, 42.f/255, 0); sh77.ambientCoef = sh77.diffuseCoef; sh77.specularCoef = float4::rep(0.0f); sh77.specularExponent = 10000.f; sh77.reflCoef = 0.6f; sh77.addRef(); CheckBoard3DShader check; check.scale = float4::rep(1); check.addRef(); float4 woodenBrownDark = float4(103.f/255,53.f/255,3.f/255,0); float4 woodenBrownLight = float4(167.f/255,86.f/255,7.f/255,0); float4 kBraun = float4(181.f/255,58.f/255,4.f/255,0); float4 dBraun = float4(119.f/255,15.f/255,0.f/255,0); float4 marmorDunkel = float4(0.6,0.6,0.6,0); float4 marmorHell = float4(0.4,0.4,0.4,0); SmartPtr<ProceduralTexture> woodTex = new ProceduralWoodTexture(woodenBrownDark, woodenBrownLight, 0.1f, 0.8f); SmartPtr<ProceduralTexture> marbleTex = new ProceduralMarbleTexture(kBraun,dBraun, 0.8f, 0.8f); SmartPtr<ProceduralTexture> planetTex = new ProceduralPlanetTexture(); SmartPtr<ProceduralTexture> waterTex = new ProceduralWaterTexture(0.5f, 0.9f); SmartPtr<ProceduralTexture> floorMarbleTex = new ProceduralMarbleTexture(marmorHell,marmorDunkel, 0.4f, 0.3f); RefractivePhongShader shader; shader.refractionIndex = 1.6f; shader.diffuseCoef = float4(0.2f, 0.2f, 0, 0); shader.ambientCoef = shader.diffuseCoef; shader.specularCoef = float4::rep(0.8f); shader.specularExponent = 10000.f; shader.transparency = float4::rep(0.7f); shader.addRef(); cow.materials[cow.materialMap["glass"]].shader = &shader; RefractivePhongShader diamondShader; diamondShader.refractionIndex = 2.6f; diamondShader.diffuseCoef = float4(0.2f, 0.2f, 0, 0); diamondShader.ambientCoef = diamondShader.diffuseCoef; diamondShader.specularCoef = float4::rep(0.8f); diamondShader.specularExponent = 10000.f; diamondShader.transparency = float4::rep(0.7f); diamondShader.addRef(); cow.materials[cow.materialMap["diamant"]].shader = &diamondShader; ProceduralBumpShader procBumpShader(marbleTex); procBumpShader.diffuseCoef = float4(110.f/255,54.f/255,9.f/255,0.f); procBumpShader.ambientCoef = procBumpShader.diffuseCoef; procBumpShader.specularCoef = float4::rep(0.3f); procBumpShader.specularExponent = 10000.f; ProceduralBumpShader floor(floorMarbleTex); floor.diffuseCoef = float4(0.5,0.5,0.5,0); floor.ambientCoef = floor.diffuseCoef; floor.specularCoef = float4::rep(0.3f); floor.specularExponent = 10000.f; ProceduralBumpShader planet(planetTex); planet.diffuseCoef = float4(110.f/255,54.f/255,9.f/255,0.f); planet.ambientCoef = planet.diffuseCoef; planet.specularCoef = float4::rep(0.3f); planet.specularExponent = 10000.f; ProceduralBumpShader procBumpShader2(woodTex); procBumpShader2.diffuseCoef = float4(110.f/255,54.f/255,9.f/255,0.f); procBumpShader2.ambientCoef = procBumpShader2.diffuseCoef; procBumpShader2.specularCoef = float4::rep(0.3f); procBumpShader2.specularExponent = 10000.f; ProceduralRefractiveBumpShader water(waterTex); water.refractionIndex = 1.4f; water.diffuseCoef = float4(0.6,0.6,0.8,0.f); water.ambientCoef = water.diffuseCoef; water.specularCoef = float4::rep(0.3f); water.transparency = float4::rep(0.7f); water.specularExponent = 10000.f; water.addRef(); cow.materials[cow.materialMap["water"]].shader = &water; cow.materials[cow.materialMap["dragonskin"]].shader = &procBumpShader; cow.materials[cow.materialMap["podest"]].shader = &procBumpShader2; cow.materials[cow.materialMap["Material.001_stones_diffuse.png"]].shader = &floor; DefaultPhongShader defaultPhong; defaultPhong.diffuseCoef = float4(0.3f,0.3f,0.3f, 0); defaultPhong.ambientCoef = defaultPhong.diffuseCoef; defaultPhong.specularCoef = float4::rep(0.0f); defaultPhong.specularExponent = 10000.f; defaultPhong.addRef(); //cow.materials[cow.materialMap["Gold"]].shader = &sh77; //cow.materials[cow.materialMap["glass"]].shader = &procBumpShader; InfinitePlane p2(Point(-5.f, 0.f, 0.f), Vector(1, 0, 0), &defaultPhong); InfinitePlane p1(Point(0, -2.f, 0), Vector(0, 1, 0), &defaultPhong); //scene.primitives.push_back(&p1); //scene.primitives.push_back(&p2); // sphere test purpose Sphere s2(Point(0.1, 2.0f, 11), 2.0f, &planet); Sphere s3(Point(6.1, 1.0f, 10), 1.0f, &shader); Sphere s4(Point(1.1, 1.5f, 14.5f), 1.5f, &shader); scene.primitives.push_back(&s2); scene.primitives.push_back(&s3); scene.primitives.push_back(&s4); //InfinitePlane plane(Point(0,0.f,0),Vector(0,1,0), &check); PerspectiveCamera cam1(Point(-10.398149f, -7.266083f, 6.348377f), Point(-6.324413f, -2.961229f, 4.203216f), Vector(0, 0, 1), 30, std::make_pair(img.width(), img.height())); //cam1.addRef(); //PerspectiveLensCamera cam3(Point(-10.398149f, -7.266083f, 6.348377f), Point(-6.324413f, -2.961229f, 4.203216f), Vector(0, 0, 1), 30, // std::make_pair(img.width(), img.height()),0.9f,0.0f,1.f,4,false); PerspectiveLensCamera cam4(Point(30.f, 6.f, 0), Point(4,2.f,0), Vector(0, 1, 0), 50, std::make_pair(img.width(), img.height()),0.9f,0.3f,1.f,16,true); //PerspectiveLensCamera cam1(Point(30.f, 0.f, 0.f), Point(0, 0, 0), Vector(0, 1, 0), 60, // std::make_pair(img.width(), img.height()),0.9f,0.0f,1.f,4,true); //cam1.addRef(); PerspectiveCamera cam2(Point(6.f, 1.f, 0.f), Point(0, -1, 0), Vector(0, 1, 0), 60, std::make_pair(img.width(), img.height())); //cam2.addRef(); // index scene scene.rebuildIndex(); //Set up the integrator PhotonMap_Integrator integrator; //IntegratorImpl integrator; integrator.addRef(); integrator.scene = &scene; PointLightSource pls; pls.falloff = float4(0, 0, 1, 0); pls.intensity = float4::rep(0.6f); pls.position = Point(7.f, 3.f, 0.f); integrator.lightSources.push_back(pls); PointLightSource pls2; pls2.falloff = float4(0, 0, 1, 0); pls2.intensity = float4::rep(0.7f); pls2.position = Point(30.f, 6.f, 0.f); integrator.lightSources.push_back(pls2); PointLightSource pls3; pls3.falloff = float4(0, 0, 1, 0); pls3.intensity = float4(0.3f,0.1f,0.1f,0); pls3.position = Point(7.f, 3.f, -8.f); integrator.lightSources.push_back(pls3); integrator.ambientLight = float4::rep(0.1f); integrator.start_photonmapping(); DefaultSampler samp; samp.addRef(); HaltonSampleGenerator halton; halton.sampleCount = 4; //Render Renderer r; r.integrator = &integrator; r.target = &img; r.sampler = &halton; r.camera = &cam4; r.render(32,23); img.writePNG("frey_leonhardt_rc.png"); }
// Handles interactions with a vehicle in the examine menu. interact_results interact_with_vehicle( vehicle *veh, const tripoint &pos, int veh_root_part ) { if( veh == nullptr ) { return ITEMS_FROM_GROUND; } std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; const bool has_items_on_ground = g->m.sees_some_items( pos, g->u ); const bool items_are_sealed = g->m.has_flag( "SEALED", pos ); auto turret = veh->turret_query( pos ); const bool has_kitchen = ( veh->part_with_feature( veh_root_part, "KITCHEN" ) >= 0 ); const bool has_faucet = ( veh->part_with_feature( veh_root_part, "FAUCET" ) >= 0 ); const bool has_weldrig = ( veh->part_with_feature( veh_root_part, "WELDRIG" ) >= 0 ); const bool has_chemlab = ( veh->part_with_feature( veh_root_part, "CHEMLAB" ) >= 0 ); const bool has_purify = ( veh->part_with_feature( veh_root_part, "WATER_PURIFIER" ) >= 0 ); const bool has_controls = ( ( veh->part_with_feature( veh_root_part, "CONTROLS" ) >= 0 ) || ( veh->part_with_feature( veh_root_part, "CTRL_ELECTRONIC" ) >= 0 ) ); const int cargo_part = veh->part_with_feature( veh_root_part, "CARGO", false ); const bool from_vehicle = cargo_part >= 0 && !veh->get_items( cargo_part ).empty(); const bool can_be_folded = veh->is_foldable(); const bool is_convertible = ( veh->tags.count( "convertible" ) > 0 ); const bool remotely_controlled = g->remoteveh() == veh; const int washing_machine_part = veh->part_with_feature( veh_root_part, "WASHING_MACHINE" ); const bool has_washmachine = washing_machine_part >= 0; bool washing_machine_on = ( washing_machine_part == -1 ) ? false : veh->parts[washing_machine_part].enabled; const bool has_monster_capture = ( veh->part_with_feature( veh_root_part, "CAPTURE_MONSTER_VEH" ) >= 0 ); const int monster_capture_part = veh->part_with_feature( veh_root_part, "CAPTURE_MONSTER_VEH" ); typedef enum { EXAMINE, TRACK, CONTROL, CONTROL_ELECTRONICS, GET_ITEMS, GET_ITEMS_ON_GROUND, FOLD_VEHICLE, UNLOAD_TURRET, RELOAD_TURRET, USE_HOTPLATE, FILL_CONTAINER, DRINK, USE_WELDER, USE_PURIFIER, PURIFY_TANK, USE_WASHMACHINE, USE_MONSTER_CAPTURE } options; uimenu selectmenu; selectmenu.addentry( EXAMINE, true, 'e', _( "Examine vehicle" ) ); selectmenu.addentry( TRACK, true, keybind( "TOGGLE_TRACKING" ), veh->tracking_toggle_string() ); if( has_controls ) { selectmenu.addentry( CONTROL, true, 'v', _( "Control vehicle" ) ); selectmenu.addentry( CONTROL_ELECTRONICS, true, keybind( "CONTROL_MANY_ELECTRONICS" ), _( "Control multiple electronics" ) ); } if( has_washmachine ) { selectmenu.addentry( USE_WASHMACHINE, true, 'W', washing_machine_on ? _( "Deactivate the washing machine" ) : _( "Activate the washing machine (1.5 hours)" ) ); } if( from_vehicle && !washing_machine_on ) { selectmenu.addentry( GET_ITEMS, true, 'g', _( "Get items" ) ); } if( has_items_on_ground && !items_are_sealed ) { selectmenu.addentry( GET_ITEMS_ON_GROUND, true, 'i', _( "Get items on the ground" ) ); } if( ( can_be_folded || is_convertible ) && !remotely_controlled ) { selectmenu.addentry( FOLD_VEHICLE, true, 'f', _( "Fold vehicle" ) ); } if( turret.can_unload() ) { selectmenu.addentry( UNLOAD_TURRET, true, 'u', _( "Unload %s" ), turret.name().c_str() ); } if( turret.can_reload() ) { selectmenu.addentry( RELOAD_TURRET, true, 'r', _( "Reload %s" ), turret.name().c_str() ); } if( ( has_kitchen || has_chemlab ) && veh->fuel_left( "battery" ) > 0 ) { selectmenu.addentry( USE_HOTPLATE, true, 'h', _( "Use the hotplate" ) ); } if( has_faucet && veh->fuel_left( "water_clean" ) > 0 ) { selectmenu.addentry( FILL_CONTAINER, true, 'c', _( "Fill a container with water" ) ); selectmenu.addentry( DRINK, true, 'd', _( "Have a drink" ) ); } if( has_weldrig && veh->fuel_left( "battery" ) > 0 ) { selectmenu.addentry( USE_WELDER, true, 'w', _( "Use the welding rig?" ) ); } if( has_purify ) { bool can_purify = veh->fuel_left( "battery" ) >= item::find_type( "water_purifier" )->charges_to_use(); selectmenu.addentry( USE_PURIFIER, can_purify, 'p', _( "Purify water in carried container" ) ); selectmenu.addentry( PURIFY_TANK, can_purify && veh->fuel_left( "water" ), 'P', _( "Purify water in vehicle tank" ) ); } if( has_monster_capture ) { selectmenu.addentry( USE_MONSTER_CAPTURE, true, 'G', _( "Capture or release a creature" ) ); } int choice; if( selectmenu.entries.size() == 1 ) { choice = selectmenu.entries.front().retval; } else { selectmenu.return_invalid = true; selectmenu.text = _( "Select an action" ); selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } auto veh_tool = [&]( const itype_id & obj ) { item pseudo( obj ); if( veh->fuel_left( "battery" ) < pseudo.ammo_required() ) { return false; } auto qty = pseudo.ammo_capacity() - veh->discharge_battery( pseudo.ammo_capacity() ); pseudo.ammo_set( "battery", qty ); g->u.invoke_item( &pseudo ); veh->charge_battery( pseudo.ammo_remaining() ); return true; }; switch( static_cast<options>( choice ) ) { case USE_MONSTER_CAPTURE: { veh->use_monster_capture( monster_capture_part, pos ); return DONE; } case USE_HOTPLATE: veh_tool( "hotplate" ); return DONE; case USE_WASHMACHINE: { veh->use_washing_machine( washing_machine_part ); return DONE; } case FILL_CONTAINER: g->u.siphon( *veh, "water_clean" ); return DONE; case DRINK: { item water( "water_clean", 0 ); if( g->u.eat( water ) ) { veh->drain( "water_clean", 1 ); g->u.moves -= 250; } return DONE; } case USE_WELDER: { if( veh_tool( "welder" ) ) { // Evil hack incoming auto &act = g->u.activity; if( act.id() == activity_id( "ACT_REPAIR_ITEM" ) ) { // Magic: first tell activity the item doesn't really exist act.index = INT_MIN; // Then tell it to search it on `pos` act.coords.push_back( pos ); // Finally tell if it is the vehicle part with welding rig act.values.resize( 2 ); act.values[1] = veh->part_with_feature( veh_root_part, "WELDRIG" ); } } return DONE; } case USE_PURIFIER: veh_tool( "water_purifier" ); return DONE; case PURIFY_TANK: { auto sel = []( const vehicle_part & pt ) { return pt.is_tank() && pt.ammo_current() == "water"; }; auto title = string_format( _( "Purify <color_%s>water</color> in tank" ), get_all_colors().get_name( item::find_type( "water" )->color ).c_str() ); auto &tank = veh_interact::select_part( *veh, sel, title ); if( tank ) { double cost = item::find_type( "water_purifier" )->charges_to_use(); if( veh->fuel_left( "battery" ) < tank.ammo_remaining() * cost ) { //~ $1 - vehicle name, $2 - part name add_msg( m_bad, _( "Insufficient power to purify the contents of the %1$s's %2$s" ), veh->name.c_str(), tank.name().c_str() ); } else { //~ $1 - vehicle name, $2 - part name add_msg( m_good, _( "You purify the contents of the %1$s's %2$s" ), veh->name.c_str(), tank.name().c_str() ); veh->discharge_battery( tank.ammo_remaining() * cost ); tank.ammo_set( "water_clean", tank.ammo_remaining() ); } } return DONE; } case UNLOAD_TURRET: { g->unload( *turret.base() ); return DONE; } case RELOAD_TURRET: { item::reload_option opt = g->u.select_ammo( *turret.base(), true ); if( opt ) { g->u.assign_activity( activity_id( "ACT_RELOAD" ), opt.moves(), opt.qty() ); g->u.activity.targets.emplace_back( turret.base() ); g->u.activity.targets.push_back( std::move( opt.ammo ) ); } return DONE; } case FOLD_VEHICLE: veh->fold_up(); return DONE; case CONTROL: veh->use_controls( pos ); return DONE; case CONTROL_ELECTRONICS: veh->control_electronics(); return DONE; case EXAMINE: g->exam_vehicle( *veh ); return DONE; case TRACK: veh->toggle_tracking( ); return DONE; case GET_ITEMS_ON_GROUND: return ITEMS_FROM_GROUND; case GET_ITEMS: return from_vehicle ? ITEMS_FROM_CARGO : ITEMS_FROM_GROUND; } return DONE; }
void fill_funnels(game *g, int rain_depth_mm_per_hour, bool acid, trap_id t) { int funnel_radius_mm = 0; switch (t) { case tr_funnel: funnel_radius_mm = 380; break; case tr_makeshift_funnel: funnel_radius_mm = 85; break; default: return; } // How many turns should it take for us to collect 1 charge of rainwater? item water(item_controller->find_template("water"), 0); const double charge_ml = (double) (water.weight()) / water.charges; const double PI = 3.14159265358979f; const double surface_area_mm2 = PI * (funnel_radius_mm * funnel_radius_mm); const double vol_mm3_per_hour = surface_area_mm2 * rain_depth_mm_per_hour; const double vol_mm3_per_turn = vol_mm3_per_hour / 600; const double ml_to_mm3 = 1000; const double turns_per_charge = charge_ml * ml_to_mm3 / vol_mm3_per_turn; item *c = NULL; char maxcontains = 0; // Give each funnel on the map a chance to collect the rain. std::set<point> funnel_locs = g->m.trap_locations(t); std::set<point>::iterator i; for (i = funnel_locs.begin(); i != funnel_locs.end(); ++i) { point loc = *i; std::vector<item>& items = g->m.i_at(loc.x, loc.y); if (one_in(turns_per_charge)) { // This funnel has collected some rain! Put the rain in the largest // container here which is either empty or contains some mixture of // impure water and acid. for (int j = 0; j < items.size(); j++) { item *it = &(items[j]); if (it->is_container() && it->has_flag("WATERTIGHT") && it->has_flag("SEALS")) { it_container* ct = dynamic_cast<it_container*>(it->type); if (ct->contains > maxcontains && ( it->contents.empty() || it->contents[0].typeId() == "water" || it->contents[0].typeId() == "water_acid" || it->contents[0].typeId() == "water_acid_weak")) { c = it; maxcontains = ct->contains; } } } } } // If we found an eligible container, add some rain to it (or consider // contaminating its current liquid). if (c != NULL) { const char *typeId = acid ? "water_acid" : "water"; if (c->contents.empty()) { // This is easy. Just add 1 charge of the rain liquid to the container. item ret(item_controller->find_template(typeId), 0); if (!acid) { // Funnels aren't always clean enough for water. ret.poison = one_in(10) ? 1 : 0; } c->put_in(ret); } else { // The container already has a liquid. item &liq = c->contents[0]; it_container* ct = dynamic_cast<it_container*>(c->type); if (liq.charges < ct->contains) { liq.charges++; } if (liq.typeId() == typeId || liq.typeId() == "water_acid_weak") { // The container already contains this liquid or weakly acidic water. // Don't do anything special -- we already added liquid. } else { // The rain is different from what's in the container. // Turn the container's liquid into weak acid with a probability // based on its current volume. // If it's raining acid and this container started with 7 // charges of water, the liquid will now be 1/8th acid or, // equivalently, 1/4th weak acid (the rest being water). A // stochastic approach gives the liquid a 1 in 4 (or 2 in // liquid.charges) chance of becoming weak acid. const bool transmute = x_in_y(2, liq.charges); if (transmute) { item transmuted(item_controller->find_template("water_acid_weak"), 0); transmuted.charges = liq.charges; c->contents[0] = transmuted; } else if (liq.typeId() == "water") { // The container has water, and the acid rain didn't turn it // into weak acid. Poison the water instead, assuming 1 // charge of acid would act like a charge of water with poison 5. int total_poison = liq.poison * (liq.charges - 1) + 5; liq.poison = total_poison / liq.charges; int leftover_poison = total_poison - liq.poison * liq.charges; if (leftover_poison > rng(0, liq.charges)) { liq.poison++; } } } } } }
// Handles interactions with a vehicle in the examine menu. // Returns the part number that will accept items if any, or -1 to indicate no cargo part. // Returns -2 if a special interaction was performed and the menu should exit. int Pickup::interact_with_vehicle( vehicle *veh, const tripoint &pos, int veh_root_part ) { bool from_vehicle = false; int k_part = 0; int wtr_part = 0; int w_part = 0; int craft_part = 0; int cargo_part = 0; int chempart = 0; int ctrl_part = 0; std::vector<std::string> menu_items; std::vector<uimenu_entry> options_message; const bool has_items_on_ground = g->m.sees_some_items( pos, g->u ); const bool items_are_sealed = g->m.has_flag( "SEALED", pos ); if( veh ) { k_part = veh->part_with_feature(veh_root_part, "KITCHEN"); wtr_part = veh->part_with_feature(veh_root_part, "FAUCET"); w_part = veh->part_with_feature(veh_root_part, "WELDRIG"); craft_part = veh->part_with_feature(veh_root_part, "CRAFTRIG"); chempart = veh->part_with_feature(veh_root_part, "CHEMLAB"); cargo_part = veh->part_with_feature(veh_root_part, "CARGO", false); ctrl_part = veh->part_with_feature(veh_root_part, "CONTROLS"); from_vehicle = veh && cargo_part >= 0 && !veh->get_items(cargo_part).empty(); const bool can_be_folded = veh->is_foldable(); const bool is_convertible = (veh->tags.count("convertible") > 0); const bool remotely_controlled = g->remoteveh() == veh; menu_items.push_back(_("Examine vehicle")); options_message.push_back(uimenu_entry(_("Examine vehicle"), 'e')); if (ctrl_part >= 0) { menu_items.push_back(_("Control vehicle")); options_message.push_back(uimenu_entry(_("Control vehicle"), 'v')); } if( from_vehicle ) { menu_items.push_back(_("Get items")); options_message.push_back(uimenu_entry(_("Get items"), 'g')); } if( has_items_on_ground && !items_are_sealed ) { menu_items.push_back(_("Get items on the ground")); options_message.push_back(uimenu_entry(_("Get items on the ground"), 'i')); } if( ( can_be_folded || is_convertible ) && !remotely_controlled ) { menu_items.push_back(_("Fold vehicle")); options_message.push_back(uimenu_entry(_("Fold vehicle"), 'f')); } if((k_part >= 0 || chempart >= 0) && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the hotplate")); options_message.push_back(uimenu_entry(_("Use the hotplate"), 'h')); } if((k_part >= 0 || wtr_part >= 0) && veh->fuel_left("water_clean") > 0) { menu_items.push_back(_("Fill a container with water")); options_message.push_back(uimenu_entry(_("Fill a container with water"), 'c')); menu_items.push_back(_("Have a drink")); options_message.push_back(uimenu_entry(_("Have a drink"), 'd')); } if(w_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the welding rig?")); options_message.push_back(uimenu_entry(_("Use the welding rig?"), 'w')); } if(craft_part >= 0 && veh->fuel_left("battery") > 0) { menu_items.push_back(_("Use the water purifier?")); options_message.push_back(uimenu_entry(_("Use the water purifier?"), 'p')); } int choice; if( menu_items.size() == 1 ) { choice = 0; } else { uimenu selectmenu; selectmenu.return_invalid = true; selectmenu.text = _("Select an action"); selectmenu.entries = options_message; selectmenu.selected = 0; selectmenu.query(); choice = selectmenu.ret; } if(choice < 0) { return -2; } if(menu_items[choice] == _("Use the hotplate")) { //Will be -1 if no battery at all item tmp_hotplate( "hotplate", 0 ); // Drain a ton of power tmp_hotplate.charges = veh->drain( "battery", 100 ); if( tmp_hotplate.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_hotplate)->type); if ( tmp_hotplate.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_hotplate ); tmp_hotplate.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_hotplate.charges ); } } return -2; } if(menu_items[choice] == _("Fill a container with water")) { int amt = veh->drain("water_clean", veh->fuel_left("water_clean")); item fill_water( "water_clean", calendar::turn ); fill_water.charges = amt; int back = g->move_liquid(fill_water); if (back >= 0) { veh->refill("water_clean", back); } else { veh->refill("water_clean", amt); } return -2; } if(menu_items[choice] == _("Have a drink")) { veh->drain("water_clean", 1); item water( "water_clean", 0 ); g->u.eat(&water, dynamic_cast<it_comest *>(water.type)); g->u.moves -= 250; return -2; } if(menu_items[choice] == _("Use the welding rig?")) { //Will be -1 if no battery at all item tmp_welder( "welder", 0 ); // Drain a ton of power tmp_welder.charges = veh->drain( "battery", 1000 ); if( tmp_welder.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_welder)->type); if ( tmp_welder.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_welder ); tmp_welder.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_welder.charges ); } } return -2; } if(menu_items[choice] == _("Use the water purifier?")) { //Will be -1 if no battery at all item tmp_purifier( "water_purifier", 0 ); // Drain a ton of power tmp_purifier.charges = veh->drain( "battery", veh->fuel_left("battery")); if( tmp_purifier.is_tool() ) { it_tool *tmptool = dynamic_cast<it_tool *>((&tmp_purifier)->type); if ( tmp_purifier.charges >= tmptool->charges_per_use ) { g->u.invoke_item( &tmp_purifier ); tmp_purifier.charges -= tmptool->charges_per_use; veh->refill( "battery", tmp_purifier.charges ); } } return -2; } if(menu_items[choice] == _("Fold vehicle")) { veh->fold_up(); return -2; } if(menu_items[choice] == _("Control vehicle") && veh->interact_vehicle_locked()) { veh->use_controls(); return -2; } if(menu_items[choice] == _("Examine vehicle")) { g->exam_vehicle(*veh, pos ); return -2; } if(menu_items[choice] == _("Get items on the ground")) { from_vehicle = false; } } return from_vehicle ? cargo_part : -1; }
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); } } }