Skip to content

Commit

Permalink
add a debug mode that shows potential values
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Mar 11, 2021
1 parent 958c933 commit b3dcad0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
50 changes: 49 additions & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,30 @@ struct tile_render_info {
}
};

static std::map<tripoint, int> 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<tripoint, int> effectiveness_map;
std::vector<npc_attack_effectiveness> 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 &center, int width, int height,
std::multimap<point, formatted_text> &overlay_strings,
color_block_overlay_container &color_blocks )
Expand Down Expand Up @@ -1153,7 +1177,14 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
would_apply_vision_effects( here.get_visibility( ch.visibility_cache[np.x][np.y],
cache ) );
};

std::map<tripoint, int> 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<const tripoint, int> &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<tile_render_info> draw_points;
draw_points.reserve( max_col );
Expand Down Expand Up @@ -1237,6 +1268,23 @@ void cata_tiles::draw( const point &dest, const tripoint &center, 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] ) {
Expand Down
5 changes: 5 additions & 0 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ std::string enum_to_string<debug_menu::debug_menu_index>( 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";
Expand Down Expand Up @@ -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" ) ) },
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,9 @@ class npc : public player

npc_short_term_cache ai_cache;
public:
const std::shared_ptr<npc_attack> 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.
Expand Down

0 comments on commit b3dcad0

Please sign in to comment.