Skip to content

Commit

Permalink
ups map drain
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirmuolio committed May 3, 2021
1 parent da6dbc5 commit 64e6f56
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
13 changes: 2 additions & 11 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ static const itype_id itype_rope_6( "rope_6" );
static const itype_id itype_snare_trigger( "snare_trigger" );
static const itype_id itype_string_36( "string_36" );
static const itype_id itype_toolset( "toolset" );
static const itype_id itype_UPS_off( "UPS_off" );
static const itype_id itype_adv_UPS_off( "adv_UPS_off" );
static const itype_id itype_UPS( "UPS" );

static const skill_id skill_archery( "archery" );
Expand Down Expand Up @@ -11295,16 +11293,9 @@ int Character::consume_ups( int qty, const int radius )
// Slower method for all nearby items (used while crafting)
inventory inv = crafting_inventory( pos(), radius, true );

int adv = inv.charges_of( itype_adv_UPS_off, qty );
if( qty != 0 && adv > 0 ) {
use_charges( itype_adv_UPS_off, adv, radius );
qty -= std::min( qty, adv );
}

int ups = inv.charges_of( itype_UPS_off, qty );
int ups = inv.charges_of( itype_UPS, qty );
if( qty != 0 && ups > 0 ) {
use_charges( itype_UPS_off, ups, radius );
qty -= ups;
qty -= get_map().consume_ups( pos(), radius, ups );
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5127,6 +5127,30 @@ std::list<item> map::use_charges( const tripoint &origin, const int range,
return ret;
}

int map::consume_ups( const tripoint &origin, const int range, int qty )
{
// populate a grid of spots that can be reached
std::vector<tripoint> reachable_pts;
reachable_flood_steps( reachable_pts, origin, range, 1, 100 );

for( const tripoint &p : reachable_pts ) {
if( accessible_items( p ) ) {

map_stack items = i_at( p );
for( auto &elem : items ) {
if( elem.has_flag( flag_IS_UPS ) ) {
qty -= elem.ammo_consume( qty, p, nullptr );
if( qty == 0 ) {
break;
}
}
}
}
}

return qty;
}

std::list<std::pair<tripoint, item *> > map::get_rc_items( const tripoint &p )
{
std::list<std::pair<tripoint, item *> > rc_pairs;
Expand Down
9 changes: 9 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,15 @@ class map
std::list<item> use_charges( const tripoint &origin, int range, const itype_id &type,
int &quantity, const std::function<bool( const item & )> &filter = return_true<item>,
basecamp *bcp = nullptr );

/**
* Consume UPS from UPS sources from area centered at origin.
* @param origin the position of player
* @param range how far the UPS can be used from
* @return Amount of UPS used which will be between 0 and qty
*/
int consume_ups( const tripoint &origin, const int range, int qty );

/*@}*/
std::list<std::pair<tripoint, item *> > get_rc_items( const tripoint &p = { -1, -1, -1 } );

Expand Down
9 changes: 4 additions & 5 deletions src/visitable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,8 @@ static int charges_of_internal( const T &self, const M &main, const itype_id &id
bool found_tool_with_UPS = false;
self.visit_items( [&]( const item * e, item * ) {
if( filter( *e ) ) {
if( e->is_tool() ) {
if( e->typeId() == id && id != itype_UPS_off ) {
if( e->is_tool() && id != itype_UPS_off ) {
if( e->typeId() == id ) {
// includes charges from any included magazine.
qty = sum_no_wrap( qty, e->ammo_remaining() );
if( e->has_flag( STATIC( flag_id( "USE_UPS" ) ) ) ) {
Expand All @@ -754,13 +754,12 @@ static int charges_of_internal( const T &self, const M &main, const itype_id &id
if( e->has_flag( flag_id( "USES_BIONIC_POWER" ) ) ) {
qty = sum_no_wrap( qty, units::to_kilojoule( get_player_character().get_power_level() ) );
}
} else if( id == itype_UPS_off && e->has_flag( STATIC( flag_id( "IS_UPS" ) ) ) ) {
qty = sum_no_wrap( qty, e->ammo_remaining() );
}
if( !e->has_pockets() ) {
return qty < limit ? VisitResponse::SKIP : VisitResponse::ABORT;
}

} else if( id == itype_UPS_off && e->has_flag( STATIC( flag_id( "IS_UPS" ) ) ) ) {
qty = sum_no_wrap( qty, e->ammo_remaining() );
} else if( e->count_by_charges() ) {
if( e->typeId() == id ) {
qty = sum_no_wrap( qty, e->charges );
Expand Down

0 comments on commit 64e6f56

Please sign in to comment.