Skip to content

Commit

Permalink
AIM: when cannot wear, try to wield
Browse files Browse the repository at this point in the history
  • Loading branch information
Brambor committed Apr 22, 2024
1 parent 0a3e18c commit e9d07b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ int advanced_inventory::print_header( advanced_inventory_pane &pane, aim_locatio
data_location == AIM_CONTAINER ? "><" :
squares[data_location].can_store_in_vehicle() ||
data_location == AIM_PARENT ? "<>" : "[]";
bool in_vehicle = pane.in_vehicle() && squares[data_location].id == area && sel == area &&
bool in_vehicle = pane.in_vehicle() && data_location == area && sel == area &&
area != AIM_ALL;
bool all_brackets = area == AIM_ALL && ( data_location >= AIM_SOUTHWEST &&
data_location <= AIM_NORTHEAST );
Expand Down Expand Up @@ -1468,6 +1468,9 @@ void advanced_inventory::start_activity(
if( destarea == AIM_WORN ) {
const wear_activity_actor act( target_items, quantities );
player_character.assign_activity( act );
} else if( destarea == AIM_WIELD ) {
player_character.assign_activity(
wield_activity_actor( target_items.front(), quantities.front() ) );
} else if( destarea == AIM_INVENTORY ) {
const std::optional<tripoint> starting_pos = from_vehicle
? std::nullopt
Expand Down Expand Up @@ -1572,9 +1575,23 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
cata_assert( !sitem->items.empty() );
avatar &player_character = get_avatar();
if( destarea == AIM_WORN ) {
ret_val<void> can_wear = player_character.can_wear( *sitem->items.front().get_item() );
if( !can_wear.success() ) {
popup_getkey( can_wear.c_str(), PF_GET_KEY );
const item &itm = *sitem->items.front().get_item();
ret_val<void> can_wear = player_character.can_wear( itm );
ret_val<void> can_wield = player_character.can_wield( itm );
if( can_wear.success() ) {
} else if( can_wield.success() ) {
destarea = AIM_WIELD;
std::string err = can_wear.c_str();
err += "\n";
err += _( "Wield instead?" );
if( !query_yn( err ) ) {
return false;
}
} else {
std::string err = can_wear.c_str();
err += "\n";
err += can_wield.c_str();
popup_getkey( err.c_str(), PF_GET_KEY );
return false;
}
}
Expand Down Expand Up @@ -1628,6 +1645,11 @@ bool advanced_inventory::action_move_item( advanced_inv_listitem *sitem,
// exit so that the activity can be carried out
exit = true;

} else if( srcarea == AIM_INVENTORY && destarea == AIM_WIELD ) {
do_return_entry();
const wield_activity_actor act( sitem->items.front(), amount_to_move );
player_character.assign_activity( act );
exit = true;
} else if( srcarea == AIM_INVENTORY ||
( srcarea == AIM_WORN && sitem->items.front() != player_character.get_wielded_item() ) ) {

Expand Down Expand Up @@ -2138,7 +2160,7 @@ bool advanced_inventory::query_charges( aim_location destarea, const advanced_in

// Check volume, this should work the same for inventory, map and vehicles, but not for worn
const int room_for = it.charges_per_volume( free_volume );
if( amount > room_for && squares[destarea].id != AIM_WORN ) {
if( amount > room_for && destarea != AIM_WORN && destarea != AIM_WIELD ) {
if( room_for <= 0 ) {
if( destarea == AIM_INVENTORY ) {
popup_getkey( _( "You have no space for the %s." ), it.tname() );
Expand All @@ -2152,6 +2174,7 @@ bool advanced_inventory::query_charges( aim_location destarea, const advanced_in
// Map and vehicles have a maximal item count, check that. Inventory does not have this.
if( destarea != AIM_INVENTORY &&
destarea != AIM_WORN &&
destarea != AIM_WIELD &&
destarea != AIM_CONTAINER ) {
const int cntmax = p.max_size - p.get_item_count();
// For items counted by charges, adding it adds 0 items if something there stacks with it.
Expand All @@ -2171,7 +2194,7 @@ bool advanced_inventory::query_charges( aim_location destarea, const advanced_in
}
Character &player_character = get_player_character();
// Inventory has a weight capacity, map and vehicle don't have that
if( destarea == AIM_INVENTORY || destarea == AIM_WORN ) {
if( destarea == AIM_INVENTORY || destarea == AIM_WORN || destarea == AIM_WIELD ) {
const units::mass unitweight = it.weight() / ( by_charges ? it.charges : 1 );
const units::mass max_weight = player_character.weight_capacity() * 4 -
player_character.weight_carried();
Expand Down
2 changes: 2 additions & 0 deletions src/advanced_inv_area.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum aim_location : char {
AIM_PARENT,
AIM_WORN,
NUM_AIM_LOCATIONS,
// cannot be selected, destination for when wearing item fails but item can be WIELDed
AIM_WIELD,
// only useful for AIM_ALL
AIM_AROUND_BEGIN = AIM_SOUTHWEST,
AIM_AROUND_END = AIM_NORTHEAST
Expand Down

0 comments on commit e9d07b7

Please sign in to comment.