From 5ab6c6d6aba0d41e9ee51b2e03d967c3fbb62fcb Mon Sep 17 00:00:00 2001 From: anothersimulacrum Date: Sun, 18 Jul 2021 10:07:52 -0700 Subject: [PATCH] Improve location-dependent card naming 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. --- src/item.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/item.cpp b/src/item.cpp index 4c9c72aae1fbe..d529b142bae2b 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -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 ignore_keys = { "dirt", "shot_counter" }; + const std::vector 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. @@ -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() ) {