From b3dcad09dc2853b5303b33fbb66ba3bc5a85a4bf Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Thu, 11 Feb 2021 14:23:24 -0500 Subject: [PATCH] add a debug mode that shows potential values --- src/action.cpp | 4 ++++ src/action.h | 1 + src/cata_tiles.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++- src/debug_menu.cpp | 5 +++++ src/debug_menu.h | 1 + src/npc.h | 3 +++ 6 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/action.cpp b/src/action.cpp index 578618cb65c7b..8bcf42430d0e1 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -336,6 +336,8 @@ std::string action_ident( action_id act ) return "debug_lighting"; case ACTION_DISPLAY_RADIATION: return "debug_radiation"; + case ACTION_DISPLAY_NPC_ATTACK_POTENTIAL: + return "debug_npc_attack_potential"; case ACTION_TOGGLE_HOUR_TIMER: return "debug_hour_timer"; case ACTION_TOGGLE_DEBUG_MODE: @@ -448,6 +450,7 @@ bool can_action_change_worldstate( const action_id act ) case ACTION_DISPLAY_VISIBILITY: case ACTION_DISPLAY_LIGHTING: case ACTION_DISPLAY_RADIATION: + case ACTION_DISPLAY_NPC_ATTACK_POTENTIAL: case ACTION_DISPLAY_TRANSPARENCY: case ACTION_DISPLAY_REACHABILITY_ZONES: case ACTION_ZOOM_OUT: @@ -886,6 +889,7 @@ action_id handle_action_menu() REGISTER_ACTION( ACTION_DISPLAY_TRANSPARENCY ); REGISTER_ACTION( ACTION_DISPLAY_REACHABILITY_ZONES ); REGISTER_ACTION( ACTION_DISPLAY_RADIATION ); + REGISTER_ACTION( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ); REGISTER_ACTION( ACTION_TOGGLE_DEBUG_MODE ); } else if( category == _( "Interact" ) ) { REGISTER_ACTION( ACTION_EXAMINE ); diff --git a/src/action.h b/src/action.h index 721608c277097..b8db9c42cd158 100644 --- a/src/action.h +++ b/src/action.h @@ -322,6 +322,7 @@ enum action_id : int { ACTION_DISPLAY_TRANSPARENCY, /** Toggle reachability zones map */ ACTION_DISPLAY_REACHABILITY_ZONES, + ACTION_DISPLAY_NPC_ATTACK_POTENTIAL, /** Toggle timing of the game hours */ ACTION_TOGGLE_HOUR_TIMER, /** Not an action, serves as count of enumerated actions */ diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 8db168b6217f5..1c081ab920220 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1042,6 +1042,30 @@ struct tile_render_info { } }; +static std::map display_npc_attack_potential() +{ + avatar &you = get_avatar(); + npc avatar_as_npc; + std::ostringstream os; + JsonOut jsout( os ); + jsout.write( you ); + std::istringstream is( os.str() ); + JsonIn jsin( is ); + jsin.read( avatar_as_npc ); + avatar_as_npc.regen_ai_cache(); + avatar_as_npc.evaluate_best_weapon( nullptr ); + std::map effectiveness_map; + std::vector effectiveness = + avatar_as_npc.get_current_attack()->all_evaluations( avatar_as_npc, nullptr ); + for( const npc_attack_effectiveness &effectiveness_at_point : effectiveness ) { + if( !effectiveness_at_point.value() ) { + continue; + } + effectiveness_map[effectiveness_at_point.target()] = *effectiveness_at_point.value(); + } + return effectiveness_map; +} + void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int height, std::multimap &overlay_strings, color_block_overlay_container &color_blocks ) @@ -1153,7 +1177,14 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int would_apply_vision_effects( here.get_visibility( ch.visibility_cache[np.x][np.y], cache ) ); }; - + std::map npc_attack_effectiveness_map; + int max_npc_effectiveness = 0; + if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) { + npc_attack_effectiveness_map = display_npc_attack_potential(); + for( const std::pair &pair : npc_attack_effectiveness_map ) { + max_npc_effectiveness = std::max( pair.second, max_npc_effectiveness ); + } + } for( int row = min_row; row < max_row; row ++ ) { std::vector draw_points; draw_points.reserve( max_col ); @@ -1237,6 +1268,23 @@ void cata_tiles::draw( const point &dest, const tripoint ¢er, int width, int } } + if( g->display_overlay_state( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ) ) { + if( npc_attack_effectiveness_map.count( pos ) ) { + const int val = npc_attack_effectiveness_map.at( pos ); + short color; + if( val <= 0 ) { + color = catacurses::red; + } else if( val == max_npc_effectiveness ) { + color = catacurses::cyan; + } else { + color = catacurses::white; + } + overlay_strings.emplace( player_to_screen( point( x, y ) ) + half_tile, + formatted_text( std::to_string( val ), color, + direction::NORTH ) ); + } + } + // Add temperature value to the overlay_strings list for every visible tile when // displaying temperature if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) { diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index 067be1391be86..577b095e12980 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -170,6 +170,7 @@ std::string enum_to_string( debug_menu::debug_menu case debug_menu::debug_menu_index::CRASH_GAME: return "CRASH_GAME"; case debug_menu::debug_menu_index::MAP_EXTRA: return "MAP_EXTRA"; case debug_menu::debug_menu_index::DISPLAY_NPC_PATH: return "DISPLAY_NPC_PATH"; + case debug_menu::debug_menu_index::DISPLAY_NPC_ATTACK: return "DISPLAY_NPC_ATTACK"; case debug_menu::debug_menu_index::PRINT_FACTION_INFO: return "PRINT_FACTION_INFO"; case debug_menu::debug_menu_index::PRINT_NPC_MAGIC: return "PRINT_NPC_MAGIC"; case debug_menu::debug_menu_index::QUIT_NOSAVE: return "QUIT_NOSAVE"; @@ -270,6 +271,7 @@ static int info_uilist( bool display_all_entries = true ) { uilist_entry( debug_menu_index::HOUR_TIMER, true, 'E', _( "Toggle hour timer" ) ) }, { uilist_entry( debug_menu_index::TRAIT_GROUP, true, 't', _( "Test trait group" ) ) }, { uilist_entry( debug_menu_index::DISPLAY_NPC_PATH, true, 'n', _( "Toggle NPC pathfinding on map" ) ) }, + { uilist_entry( debug_menu_index::DISPLAY_NPC_ATTACK, true, 'A', _( "Toggle NPC attack potential values on map" ) ) }, { uilist_entry( debug_menu_index::PRINT_FACTION_INFO, true, 'f', _( "Print faction info to console" ) ) }, { uilist_entry( debug_menu_index::PRINT_NPC_MAGIC, true, 'M', _( "Print NPC magic info to console" ) ) }, { uilist_entry( debug_menu_index::TEST_WEATHER, true, 'W', _( "Test weather" ) ) }, @@ -1807,6 +1809,9 @@ void debug() case debug_menu_index::DISPLAY_SCENTS_TYPE_LOCAL: g->display_toggle_overlay( ACTION_DISPLAY_SCENT_TYPE ); break; + case debug_menu_index::DISPLAY_NPC_ATTACK: + g->display_toggle_overlay( ACTION_DISPLAY_NPC_ATTACK_POTENTIAL ); + break; case debug_menu_index::DISPLAY_TEMP: g->display_toggle_overlay( ACTION_DISPLAY_TEMPERATURE ); break; diff --git a/src/debug_menu.h b/src/debug_menu.h index ac67b2c17f472..1a4a32dbcc83d 100644 --- a/src/debug_menu.h +++ b/src/debug_menu.h @@ -64,6 +64,7 @@ enum class debug_menu_index : int { CRASH_GAME, MAP_EXTRA, DISPLAY_NPC_PATH, + DISPLAY_NPC_ATTACK, PRINT_FACTION_INFO, PRINT_NPC_MAGIC, QUIT_NOSAVE, diff --git a/src/npc.h b/src/npc.h index 9d28e68b92895..7cd9a1d5d86cf 100644 --- a/src/npc.h +++ b/src/npc.h @@ -1280,6 +1280,9 @@ class npc : public player npc_short_term_cache ai_cache; public: + const std::shared_ptr get_current_attack() const { + return ai_cache.current_attack; + } /** * Global position, expressed in map square coordinate system * (the most detailed coordinate system), used by the @ref map.