Skip to content

Commit

Permalink
Improve location-dependent card naming
Browse files Browse the repository at this point in the history
Put cards into 4 buckets, based on distance to the player. Name and
stack them based on that.
The particular distances could probably use adjustment.
  • Loading branch information
anothersimulacrum committed Jul 18, 2021
1 parent a5b62fc commit 5ab6c6d
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,37 @@ bool item::stacks_with( const item &rhs, bool check_components, bool combine_liq
}
// Guns that differ only by dirt/shot_counter can still stack,
// but other item_vars such as label/note will prevent stacking
const std::vector<std::string> ignore_keys = { "dirt", "shot_counter" };
const std::vector<std::string> ignore_keys = { "dirt", "shot_counter", "spawn_location_omt" };
if( map_without_keys( item_vars, ignore_keys ) != map_without_keys( rhs.item_vars, ignore_keys ) ) {
return false;
}
const std::string omt_loc_var = "spawn_location_omt";
const bool this_has_location = has_var( omt_loc_var );
const bool that_has_location = has_var( omt_loc_var );
if( this_has_location != that_has_location ) {
return false;
}
if( this_has_location && that_has_location ) {
const tripoint_abs_omt this_loc( get_var( "spawn_location_omt", tripoint_zero ) );
const tripoint_abs_omt that_loc( rhs.get_var( "spawn_location_omt", tripoint_zero ) );
const tripoint_abs_omt player_loc( ms_to_omt_copy( get_map().getabs( get_player_character().pos() ) ) );
const int this_dist = rl_dist( player_loc, this_loc );
const int that_dist = rl_dist( player_loc, that_loc );
static const auto get_bucket = []( const int dist ) {
if( dist < 1 ) {
return 0;
} else if( dist < 6 ) {
return 1;
} else if( dist < 30 ) {
return 2;
} else {
return 3;
}
};
if( get_bucket( this_dist ) != get_bucket( that_dist ) ) {
return false;
}
}
if( goes_bad() && rhs.goes_bad() ) {
// Stack items that fall into the same "bucket" of freshness.
// Distant buckets are larger than near ones.
Expand Down Expand Up @@ -4906,6 +4933,20 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t
tagtext += _( " (hallucinogenic)" );
}
}
if( has_var( "spawn_location_omt" ) ) {
tripoint_abs_omt loc( get_var( "spawn_location_omt", tripoint_zero ) );
tripoint_abs_omt player_loc( ms_to_omt_copy( get_map().getabs( player_character.pos() ) ) );
int dist = rl_dist( player_loc, loc );
if( dist < 1 ) {
tagtext += _( " (from here)" );
} else if( dist < 6 ) {
tagtext += _( " (from nearby)" );
} else if( dist < 30 ) {
tagtext += _( " (from this area)" );
} else {
tagtext += _( " (from far away)" );
}
}
if( ethereal ) {
tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) );
} else if( goes_bad() || is_food() ) {
Expand Down

0 comments on commit 5ab6c6d

Please sign in to comment.