Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight OMTs revealed by maps #70482

Merged
merged 5 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,13 @@
"name": "Toggle city labels",
"bindings": [ { "input_method": "keyboard_char", "key": "C" }, { "input_method": "keyboard_code", "key": "c", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "TOGGLE_MAP_REVEALS",
"category": "OVERMAP",
"name": "Toggle highlighting map reveals",
"bindings": [ { "input_method": "keyboard_char", "key": "V" }, { "input_method": "keyboard_code", "key": "v", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "TOGGLE_HORDES",
Expand Down
2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ class Character : public Creature, public visitable
int get_mod_stat_from_bionic( const character_stat &Stat ) const;
// route for overmap-scale traveling
std::vector<tripoint_abs_omt> omt_path;
// Container of OMTs to highlight as having been revealed
std::vector<tripoint_abs_omt> map_revealed_omts;
bool is_using_bionic_weapon() const;
bionic_uid get_weapon_bionic_uid() const;

Expand Down
2 changes: 2 additions & 0 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ void uistatedata::serialize( JsonOut &json ) const
json.member( "overmap_show_land_use_codes", overmap_show_land_use_codes );
json.member( "overmap_show_city_labels", overmap_show_city_labels );
json.member( "overmap_show_hordes", overmap_show_hordes );
json.member( "overmap_show_revealed_omts", overmap_show_revealed_omts );
json.member( "overmap_show_forest_trails", overmap_show_forest_trails );
json.member( "vmenu_show_items", vmenu_show_items );
json.member( "list_item_sort", list_item_sort );
Expand Down Expand Up @@ -434,6 +435,7 @@ void uistatedata::deserialize( const JsonObject &jo )
jo.read( "overmap_show_land_use_codes", overmap_show_land_use_codes );
jo.read( "overmap_show_city_labels", overmap_show_city_labels );
jo.read( "overmap_show_hordes", overmap_show_hordes );
jo.read( "overmap_show_revealed_omts", overmap_show_revealed_omts );
jo.read( "overmap_show_forest_trails", overmap_show_forest_trails );
jo.read( "hidden_recipes", hidden_recipes );
jo.read( "favorite_recipes", favorite_recipes );
Expand Down
4 changes: 4 additions & 0 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,8 @@ void reveal_map_actor::reveal_targets( const tripoint_abs_omt &center,
target.second );
for( const tripoint_abs_omt &place : places ) {
overmap_buffer.reveal( place, reveal_distance );
// Should be replaced with the character using the item passed as an argument if NPCs ever learn to use maps
get_avatar().map_revealed_omts.emplace_back( place );
}
}

Expand All @@ -1206,6 +1208,8 @@ std::optional<int> reveal_map_actor::use( Character *p, item &it, const tripoint
}
const tripoint_abs_omt center( it.get_var( "reveal_map_center_omt",
p->global_omt_location().raw() ) );
// Clear highlight on previously revealed OMTs before revealing new ones
p->map_revealed_omts.clear();
for( const auto &omt : omt_types ) {
for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
reveal_targets( tripoint_abs_omt( center.xy(), z ), omt, 0 );
Expand Down
12 changes: 12 additions & 0 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ static void draw_ascii(
100;
// Whether showing hordes is currently enabled
const bool showhordes = uistate.overmap_show_hordes;
const bool show_map_revealed = uistate.overmap_show_revealed_omts;

const oter_id forest = oter_forest.id();

Expand Down Expand Up @@ -645,6 +646,8 @@ static void draw_ascii(
size_t count = 0;
};
std::unordered_set<tripoint_abs_omt> npc_path_route;
std::unordered_set<tripoint_abs_omt> newly_revealed( player_character.map_revealed_omts.begin(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are only using newly_revealed variable inside of if statement below, so it could be put there and it won't populate it each time even if overmap uistate does not imply showing map revealed omts.

player_character.map_revealed_omts.end() ) ;
std::unordered_map<point_abs_omt, int> player_path_route;
std::unordered_map<tripoint_abs_omt, npc_coloring> npc_color;
auto npcs_near_player = overmap_buffer.get_npcs_near_player( sight_points );
Expand Down Expand Up @@ -782,6 +785,11 @@ static void draw_ascii(
// npc path
ter_color = c_red;
ter_sym = "!";
} else if( blink && show_map_revealed &&
newly_revealed.find( omp ) != newly_revealed.end() ) {
// Revealed maps
ter_color = c_magenta;
ter_sym = "&";
} else if( blink && showhordes &&
overmap_buffer.get_horde_size( omp ) >= HORDE_VISIBILITY_SIZE &&
( get_and_assign_los( los, player_character, omp, sight_points ) ||
Expand Down Expand Up @@ -1213,6 +1221,7 @@ static void draw_om_sidebar(
print_hint( "TOGGLE_LAND_USE_CODES", uistate.overmap_show_land_use_codes ? c_pink : c_magenta );
print_hint( "TOGGLE_CITY_LABELS", uistate.overmap_show_city_labels ? c_pink : c_magenta );
print_hint( "TOGGLE_HORDES", uistate.overmap_show_hordes ? c_pink : c_magenta );
print_hint( "TOGGLE_MAP_REVEALS", uistate.overmap_show_revealed_omts ? c_pink : c_magenta );
print_hint( "TOGGLE_EXPLORED", is_explored ? c_pink : c_magenta );
print_hint( "TOGGLE_FAST_SCROLL", fast_scroll ? c_pink : c_magenta );
print_hint( "TOGGLE_FOREST_TRAILS", uistate.overmap_show_forest_trails ? c_pink : c_magenta );
Expand Down Expand Up @@ -1818,6 +1827,7 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
ictxt.register_action( "TOGGLE_HORDES" );
ictxt.register_action( "TOGGLE_LAND_USE_CODES" );
ictxt.register_action( "TOGGLE_CITY_LABELS" );
ictxt.register_action( "TOGGLE_MAP_REVEALS" );
ictxt.register_action( "TOGGLE_EXPLORED" );
ictxt.register_action( "TOGGLE_FAST_SCROLL" );
ictxt.register_action( "TOGGLE_OVERMAP_WEATHER" );
Expand Down Expand Up @@ -1978,6 +1988,8 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig,
uistate.overmap_show_hordes = !uistate.overmap_show_hordes;
} else if( action == "TOGGLE_CITY_LABELS" ) {
uistate.overmap_show_city_labels = !uistate.overmap_show_city_labels;
} else if( action == "TOGGLE_MAP_REVEALS" ) {
uistate.overmap_show_revealed_omts = !uistate.overmap_show_revealed_omts;
} else if( action == "TOGGLE_EXPLORED" ) {
overmap_buffer.toggle_explored( curs );
} else if( action == "TOGGLE_OVERMAP_WEATHER" ) {
Expand Down
7 changes: 7 additions & 0 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
you.overmap_sight_range( g->light_level( you.posz() ) ) :
100;
const bool showhordes = uistate.overmap_show_hordes;
const bool show_map_revealed = uistate.overmap_show_revealed_omts;
const bool viewing_weather = uistate.overmap_debug_weather || uistate.overmap_visible_weather;
o = origin.raw().xy();

Expand Down Expand Up @@ -924,6 +925,12 @@ void cata_tiles::draw_om( const point &dest, const tripoint_abs_omt &center_abs_
0, 0, ll, false );
}

std::vector<tripoint_abs_omt> &revealed_highlights = get_avatar().map_revealed_omts;
auto it = std::find( revealed_highlights.begin(), revealed_highlights.end(), omp );
if( blink && show_map_revealed && it != revealed_highlights.end() ) {
draw_from_id_string( "highlight", omp.raw(), 0, 0, lit_level::LIT, false );
}

Comment on lines +928 to +933
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be something like this to avoid iterating through map_revealed_omts when overmap uistate does not imply showing map revealed omts:

            if( blink && show_map_revealed ) {
                if( it != revealed_highlights.end() ) {
                    std::vector<tripoint_abs_omt> &revealed_highlights = get_avatar().map_revealed_omts;
                    auto it = std::find( revealed_highlights.begin(), revealed_highlights.end(), omp );
                    draw_from_id_string( "highlight", omp.raw(), 0, 0, lit_level::LIT, false );
                }
            }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real problem is using std::find on a vector of points. This is simply O(n²), and will always be slow. The points need to be stored in a hash table (or a set, which uses a hash table internally) so that testing for membership can be O(1).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to search for anything if data would not even be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that is certainly true as well. It’s just that the time is dominated by searching the whole list for every single tile that might be drawn.

if( see ) {
if( blink && uistate.overmap_debug_mongroup ) {
const std::vector<mongroup *> mgroups = overmap_buffer.monsters_at( omp );
Expand Down
1 change: 1 addition & 0 deletions src/uistate.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class uistatedata
bool overmap_show_land_use_codes = false; // toggle land use code sym/color for terrain
bool overmap_show_city_labels = true;
bool overmap_show_hordes = true;
bool overmap_show_revealed_omts = true;
bool overmap_show_forest_trails = true;
bool overmap_visible_weather = false;
bool overmap_debug_weather = false;
Expand Down
Loading