void talk_function::bionic_install( npc &p ) { std::vector<item *> bionic_inv = g->u.items_with( []( const item & itm ) { return itm.is_bionic(); } ); if( bionic_inv.empty() ) { popup( _( "You have no bionics to install!" ) ); return; } std::vector<itype_id> bionic_types; std::vector<std::string> bionic_names; for( auto &bio : bionic_inv ) { if( std::find( bionic_types.begin(), bionic_types.end(), bio->typeId() ) == bionic_types.end() ) { if( !g->u.has_bionic( bionic_id( bio->typeId() ) ) || bio->typeId() == "bio_power_storage" || bio->typeId() == "bio_power_storage_mkII" ) { bionic_types.push_back( bio->typeId() ); bionic_names.push_back( bio->tname() + " - " + format_money( bio->price( true ) * 2 ) ); } } } // Choose bionic if applicable int bionic_index = uilist( _( "Which bionic do you wish to have installed?" ), bionic_names ); // Did we cancel? if( bionic_index < 0 ) { popup( _( "You decide to hold off..." ) ); return; } const item tmp = item( bionic_types[bionic_index], 0 ); const itype &it = *tmp.type; unsigned int price = tmp.price( true ) * 2; if( price > g->u.cash ) { popup( _( "You can't afford the procedure..." ) ); return; } //Makes the doctor awesome at installing but not perfect if( g->u.install_bionics( it, p, false, 20 ) ) { g->u.cash -= price; p.cash += price; g->u.amount_of( bionic_types[bionic_index] ); std::vector<item_comp> comps; comps.push_back( item_comp( tmp.typeId(), 1 ) ); g->u.consume_items( comps, 1 ); } }
int npc::value(item &it) { int ret = it.price() / 50; skill best = best_skill(); if (best != sk_unarmed) { int weapon_val = it.weapon_value(sklevel) - weapon.weapon_value(sklevel); if (weapon_val > 0) ret += weapon_val; } if (it.is_food()) { it_comest* comest = dynamic_cast<it_comest*>(it.type); if (comest->nutr > 0 || comest->quench > 0) ret++; if (hunger > 40) ret += (comest->nutr + hunger - 40) / 6; if (thirst > 40) ret += (comest->quench + thirst - 40) / 4; } if (it.is_ammo()) { it_ammo* ammo = dynamic_cast<it_ammo*>(it.type); it_gun* gun; if (weapon.is_gun()) { gun = dynamic_cast<it_gun*>(weapon.type); if (ammo->type == gun->ammo) ret += 14; } for (int i = 0; i < inv.size(); i++) { if (inv[i].is_gun()) { gun = dynamic_cast<it_gun*>(inv[i].type); if (ammo->type == gun->ammo) ret += 6; } } } if (it.is_book()) { it_book* book = dynamic_cast<it_book*>(it.type); if (book->intel <= int_cur) { ret += book->fun; if (sklevel[book->type] < book->level && sklevel[book->type] >= book->req) ret += book->level * 3; } } // TODO: Sometimes we want more than one tool? Also we don't want EVERY tool. if (it.is_tool() && !has_amount(itype_id(it.type->id), 1)) { ret += 8; } // TODO: Artifact hunting from relevant factions // ALSO TODO: Bionics hunting from relevant factions if (fac_has_job(FACJOB_DRUGS) && it.is_food() && (dynamic_cast<it_comest*>(it.type))->addict >= 5) ret += 10; if (fac_has_job(FACJOB_DOCTORS) && it.type->id >= itm_bandages && it.type->id <= itm_prozac) ret += 10; if (fac_has_value(FACVAL_BOOKS) && it.is_book()) ret += 14; if (fac_has_job(FACJOB_SCAVENGE)) { // Computed last for _reasons_. ret += 6; ret *= 1.3; } return ret; }