|
33 | 33 | #include "catacharset.h" |
34 | 34 | #include "character.h" |
35 | 35 | #include "character_functions.h" |
| 36 | +#include "data_vars.h" |
| 37 | +#include "detached_ptr.h" |
36 | 38 | #include "flag.h" |
37 | 39 | #include "color.h" |
38 | 40 | #include "construction.h" |
|
107 | 109 | #include "uistate.h" |
108 | 110 | #include "units.h" |
109 | 111 | #include "units_utility.h" |
| 112 | +#include "recipe_dictionary.h" |
110 | 113 | #include "value_ptr.h" |
111 | 114 | #include "vehicle.h" |
112 | 115 | #include "vehicle_part.h" |
@@ -7469,6 +7472,188 @@ void iexamine::cardreader_plutgen( player &p, const tripoint &examp ) |
7469 | 7472 | } |
7470 | 7473 | } |
7471 | 7474 |
|
| 7475 | +void iexamine::multicooker( player &p, const tripoint &pos ) |
| 7476 | +{ |
| 7477 | + map &here = get_map(); |
| 7478 | + const furn_id furniture = here.furn( pos ); |
| 7479 | + data_vars::data_set *vars = here.furn_vars( pos ); |
| 7480 | + const tripoint_abs_ms abspos( here.getabs( pos ) ); |
| 7481 | + auto grid = get_distribution_grid_tracker().grid_at( abspos ); |
| 7482 | + int battery = grid.get_resource(); |
| 7483 | + enum { |
| 7484 | + mc_start, mc_stop, mc_take, mc_upgrade |
| 7485 | + }; |
| 7486 | + |
| 7487 | + uilist menu; |
| 7488 | + menu.text = _( "Choose option:" ); |
| 7489 | + |
| 7490 | + if( vars->get( "ACTIVE", false ) ) { |
| 7491 | + if( vars->contains( "STARTTIME" ) && |
| 7492 | + vars->get( "STARTTIME", 0 ) + vars->get( "COOKTIME", 0 ) > to_turn<int>( calendar::turn ) ) { |
| 7493 | + menu.addentry( mc_stop, true, 's', _( "Stop crafting" ) ); |
| 7494 | + } else { |
| 7495 | + menu.addentry( mc_take, true, 't', _( "Remove Product" ) ); |
| 7496 | + } |
| 7497 | + } else { |
| 7498 | + if( battery < vars->get( "CHARGE_START", 0 ) ) { |
| 7499 | + p.add_msg_if_player( _( "Batteries are low." ) ); |
| 7500 | + return; |
| 7501 | + } |
| 7502 | + menu.addentry( mc_start, true, 's', _( "Start crafting " ) ); |
| 7503 | + } |
| 7504 | + |
| 7505 | + menu.query(); |
| 7506 | + int choice = menu.ret; |
| 7507 | + |
| 7508 | + if( choice < 0 ) { |
| 7509 | + return; |
| 7510 | + } |
| 7511 | + |
| 7512 | + if( mc_stop == choice ) { |
| 7513 | + if( query_yn( _( "Really stop?" ) ) ) { |
| 7514 | + vars->erase( "RESULT" ); |
| 7515 | + vars->erase( "ACTIVE" ); |
| 7516 | + vars->erase( "STARTTIME" ); |
| 7517 | + vars->erase( "COOKTIME" ); |
| 7518 | + vars->erase( "BATCHCOUNT" ); |
| 7519 | + vars->erase( "RECIPE" ); |
| 7520 | + } |
| 7521 | + return; |
| 7522 | + } |
| 7523 | + |
| 7524 | + if( mc_take == choice ) { |
| 7525 | + |
| 7526 | + detached_ptr<item> dish = item::spawn( vars->get( "RESULT" ), calendar::turn, |
| 7527 | + vars->get( "BATCHCOUNT", 1 ) ); |
| 7528 | + |
| 7529 | + const std::string dish_name = dish->tname( dish->charges, false ); |
| 7530 | + if( dish->made_of( LIQUID ) ) { |
| 7531 | + if( !p.check_eligible_containers_for_crafting( *recipe_id( vars->get( "RECIPE" ) ), 1 ) ) { |
| 7532 | + p.add_msg_if_player( m_info, _( "You don't have a suitable container to store your %s." ), |
| 7533 | + dish_name ); |
| 7534 | + return; |
| 7535 | + } |
| 7536 | + liquid_handler::handle_all_liquid( std::move( dish ), PICKUP_RANGE ); |
| 7537 | + } else { |
| 7538 | + p.i_add( std::move( dish ) ); |
| 7539 | + } |
| 7540 | + |
| 7541 | + grid.mod_resource( vars->get( "COOKTIME", 0 ) * vars->get( "CRAFTSPEEDMULT", |
| 7542 | + 1.0 ) / 6000 * vars->get( "CHARGE_PER_MIN", 0.0 ) + vars->get( "CHARGE_START", 0.0 ) ); |
| 7543 | + vars->erase( "RESULT" ); |
| 7544 | + vars->erase( "ACTIVE" ); |
| 7545 | + vars->erase( "STARTTIME" ); |
| 7546 | + vars->erase( "COOKTIME" ); |
| 7547 | + vars->erase( "BATCHCOUNT" ); |
| 7548 | + vars->erase( "RECIPE" ); |
| 7549 | + p.add_msg_if_player( m_good, _( "You got the %s from the %s." ), |
| 7550 | + dish_name, furniture->name() ); |
| 7551 | + |
| 7552 | + return; |
| 7553 | + } |
| 7554 | + |
| 7555 | + if( mc_start == choice ) { |
| 7556 | + uilist dmenu; |
| 7557 | + dmenu.text = _( "Choose desired recipe:" ); |
| 7558 | + |
| 7559 | + std::vector<const recipe *> dishes; |
| 7560 | + |
| 7561 | + inventory crafting_inv = g->u.crafting_inventory(); |
| 7562 | + |
| 7563 | + for( itype item : furniture->crafting_pseudo_item_types() ) { |
| 7564 | + crafting_inv.add_item( *item::spawn_temporary( item.get_id(), calendar::start_of_cataclysm ), |
| 7565 | + false ); |
| 7566 | + } |
| 7567 | + crafting_inv.update_quality_cache(); |
| 7568 | + |
| 7569 | + int counter = 0; |
| 7570 | + |
| 7571 | + for( const auto &r : g->u.get_learned_recipes() ) { |
| 7572 | + if( vars->get( "CATEGORYIDS", std::set<std::string>() ).contains( r->subcategory ) || |
| 7573 | + vars->get( "RECIPEIDS", std::set<std::string>() ).contains( r->result().str() ) ) { |
| 7574 | + dishes.push_back( r ); |
| 7575 | + const bool can_make = r->deduped_requirements().can_make_with_inventory( |
| 7576 | + crafting_inv, r->get_component_filter() ); |
| 7577 | + dmenu.addentry( counter++, can_make, -1, string_format( _( "%s (%1.f charges)" ), r->result_name(), |
| 7578 | + r->time * vars->get( "CRAFTSPEEDMULT", 1.0 ) / 6000 * vars->get( "CHARGE_PER_MIN", |
| 7579 | + 0.0 ) + vars->get( "CHARGE_START", 0.0 ) ) ); |
| 7580 | + } |
| 7581 | + } |
| 7582 | + |
| 7583 | + dmenu.query(); |
| 7584 | + |
| 7585 | + int choice = dmenu.ret; |
| 7586 | + |
| 7587 | + if( choice < 0 ) { |
| 7588 | + |
| 7589 | + if( choice == -1024 ) { |
| 7590 | + p.add_msg_if_player( m_warning, |
| 7591 | + _( "You don't know of anything you could craft with this." ) ); |
| 7592 | + } |
| 7593 | + |
| 7594 | + return; |
| 7595 | + } else { |
| 7596 | + const recipe *meal = dishes[choice]; |
| 7597 | + |
| 7598 | + uilist batchmenu; |
| 7599 | + batchmenu.text = _( "Choose batch count:" ); |
| 7600 | + int counter = 0; |
| 7601 | + |
| 7602 | + for( int i = 1; i < 51; i++ ) { |
| 7603 | + const bool can_make = meal->deduped_requirements().can_make_with_inventory( |
| 7604 | + crafting_inv, meal->get_component_filter(), i ); |
| 7605 | + batchmenu.addentry( counter++, can_make, -1, string_format( _( "%s batches (%1.f charges)" ), i, |
| 7606 | + meal->batch_time( i, 1, 0 ) * vars->get( "CRAFTSPEEDMULT", |
| 7607 | + 1.0 ) / 6000 * vars->get( "CHARGE_PER_MIN", 0.0 ) + vars->get( "CHARGE_START", 0.0 ) ) ); |
| 7608 | + } |
| 7609 | + |
| 7610 | + batchmenu.query(); |
| 7611 | + |
| 7612 | + int batchcount = batchmenu.ret; |
| 7613 | + |
| 7614 | + if( batchcount < 0 ) { |
| 7615 | + return; |
| 7616 | + } |
| 7617 | + batchcount++; |
| 7618 | + |
| 7619 | + // Seems to be divided by 100; |
| 7620 | + // See the CHARGE_PER_MIN calc being 6000 instead of 60 |
| 7621 | + int mealtime = meal->batch_time( batchcount, 1, 0 ) * vars->get( "CRAFTSPEEDMULT", 1.0 ) / 100; |
| 7622 | + int all_charges = mealtime / 6000 * vars->get( "CHARGE_PER_MIN", 0.0 ) + vars->get( "CHARGE_START", |
| 7623 | + 0.0 ); |
| 7624 | + |
| 7625 | + if( battery < all_charges ) { |
| 7626 | + |
| 7627 | + p.add_msg_if_player( m_warning, |
| 7628 | + _( "The %s needs %d charges to create this." ), |
| 7629 | + furniture->name(), all_charges ); |
| 7630 | + return; |
| 7631 | + } |
| 7632 | + |
| 7633 | + const auto filter = is_crafting_component; |
| 7634 | + const requirement_data *reqs = |
| 7635 | + meal->deduped_requirements().select_alternative( p, crafting_inv, filter, batchcount ); |
| 7636 | + if( !reqs ) { |
| 7637 | + return; |
| 7638 | + } |
| 7639 | + |
| 7640 | + for( const auto &component : reqs->get_components() ) { |
| 7641 | + p.consume_items( component, batchcount, filter ); |
| 7642 | + } |
| 7643 | + |
| 7644 | + vars->set( "ACTIVE", true ); |
| 7645 | + vars->set( "RECIPE", meal->ident().str() ); |
| 7646 | + vars->set( "RESULT", meal->result().str() ); |
| 7647 | + vars->set( "STARTTIME", to_turn<int>( calendar::turn ) ); |
| 7648 | + vars->set( "COOKTIME", mealtime ); |
| 7649 | + vars->set( "BATCHCOUNT", meal->makes_amount() * batchcount ); |
| 7650 | + |
| 7651 | + p.add_msg_if_player( m_good, _( "The %s begins to hum." ), furniture->name() ); |
| 7652 | + |
| 7653 | + return; |
| 7654 | + } |
| 7655 | + } |
| 7656 | +} |
7472 | 7657 | /** |
7473 | 7658 | * Given then name of one of the above functions, returns the matching function |
7474 | 7659 | * pointer. If no match is found, defaults to iexamine::none but prints out a |
@@ -7566,6 +7751,7 @@ iexamine_function iexamine_function_from_string( const std::string &function_nam |
7566 | 7751 | { "check_power", &iexamine::check_power }, |
7567 | 7752 | { "migo_nerve_cluster", &iexamine::migo_nerve_cluster }, |
7568 | 7753 | { "cardreader_plutgen", &iexamine::cardreader_plutgen }, |
| 7754 | + { "multicooker", &iexamine::multicooker }, |
7569 | 7755 | } |
7570 | 7756 | }; |
7571 | 7757 |
|
|
0 commit comments