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

Using the debug menu disables achievements #40292

Merged
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
6 changes: 4 additions & 2 deletions src/achievement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ std::string achievement_tracker::ui_text() const

achievements_tracker::achievements_tracker(
stats_tracker &stats,
const std::function<void( const achievement * )> &achievement_attained_callback ) :
const std::function<void( const achievement *, bool )> &achievement_attained_callback ) :
stats_( &stats ),
achievement_attained_callback_( achievement_attained_callback )
{}
Expand Down Expand Up @@ -594,7 +594,7 @@ void achievements_tracker::report_achievement( const achievement *a, achievement
}
);
if( comp == achievement_completion::completed ) {
achievement_attained_callback_( a );
achievement_attained_callback_( a, is_enabled() );
}
trackers_.erase( tracker_it );
}
Expand Down Expand Up @@ -662,6 +662,7 @@ void achievements_tracker::notify( const cata::event &e )
void achievements_tracker::serialize( JsonOut &jsout ) const
{
jsout.start_object();
jsout.member( "enabled", enabled_ );
jsout.member( "initial_achievements", initial_achievements_ );
jsout.member( "achievements_status", achievements_status_ );
jsout.end_object();
Expand All @@ -670,6 +671,7 @@ void achievements_tracker::serialize( JsonOut &jsout ) const
void achievements_tracker::deserialize( JsonIn &jsin )
{
JsonObject jo = jsin.get_object();
jo.read( "enabled", enabled_ ) || ( enabled_ = true );
jo.read( "initial_achievements", initial_achievements_ );
jo.read( "achievements_status", achievements_status_ );

Expand Down
11 changes: 9 additions & 2 deletions src/achievement.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class achievements_tracker : public event_subscriber

achievements_tracker(
stats_tracker &,
const std::function<void( const achievement * )> &achievement_attained_callback );
const std::function<void( const achievement *, bool )> &achievement_attained_callback );
~achievements_tracker() override;

// Return all scores which are valid now and existed at game start
Expand All @@ -177,6 +177,12 @@ class achievements_tracker : public event_subscriber
achievement_completion is_completed( const string_id<achievement> & ) const;
bool is_hidden( const achievement * ) const;
std::string ui_text_for( const achievement * ) const;
bool is_enabled() const {
return enabled_;
}
void set_enabled( bool enabled ) {
enabled_ = enabled;
}

void clear();
void notify( const cata::event & ) override;
Expand All @@ -187,7 +193,8 @@ class achievements_tracker : public event_subscriber
void init_watchers();

stats_tracker *stats_ = nullptr;
std::function<void( const achievement * )> achievement_attained_callback_;
bool enabled_ = true;
std::function<void( const achievement *, bool )> achievement_attained_callback_;
std::unordered_set<string_id<achievement>> initial_achievements_;

// Class invariant: each valid achievement has exactly one of a watcher
Expand Down
44 changes: 44 additions & 0 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <utility>
#include <vector>

#include "achievement.h"
#include "action.h"
#include "artifact.h"
#include "avatar.h"
Expand Down Expand Up @@ -147,6 +148,7 @@ enum debug_menu_index {
DEBUG_BENCHMARK,
DEBUG_OM_TELEPORT,
DEBUG_TRAIT_GROUP,
DEBUG_ENABLE_ACHIEVEMENTS,
DEBUG_SHOW_MSG,
DEBUG_CRASH_GAME,
DEBUG_MAP_EXTRA,
Expand Down Expand Up @@ -245,6 +247,17 @@ static int info_uilist( bool display_all_entries = true )
return uilist( _( "Info…" ), uilist_initializer );
}

static int game_uilist()
{
std::vector<uilist_entry> uilist_initializer = {
{ uilist_entry( DEBUG_ENABLE_ACHIEVEMENTS, true, 'a', _( "Enable achievements" ) ) },
{ uilist_entry( DEBUG_SHOW_MSG, true, 'd', _( "Show debug message" ) ) },
{ uilist_entry( DEBUG_CRASH_GAME, true, 'C', _( "Crash game (test crash handling)" ) ) },
};

return uilist( _( "Game…" ), uilist_initializer );
}

static int teleport_uilist()
{
const std::vector<uilist_entry> uilist_initializer = {
Expand Down Expand Up @@ -304,6 +317,7 @@ static int debug_menu_uilist( bool display_all_entries = true )
if( display_all_entries ) {
const std::vector<uilist_entry> debug_menu = {
{ uilist_entry( DEBUG_QUIT_NOSAVE, true, 'Q', _( "Quit to main menu" ) ) },
{ uilist_entry( 6, true, 'g', _( "Game…" ) ) },
{ uilist_entry( 2, true, 's', _( "Spawning…" ) ) },
{ uilist_entry( 3, true, 'p', _( "Player…" ) ) },
{ uilist_entry( 4, true, 't', _( "Teleport…" ) ) },
Expand Down Expand Up @@ -345,6 +359,9 @@ static int debug_menu_uilist( bool display_all_entries = true )
case 5:
action = map_uilist();
break;
case 6:
action = game_uilist();
break;

default:
return group;
Expand Down Expand Up @@ -1108,6 +1125,25 @@ void debug()
{
bool debug_menu_has_hotkey = hotkey_for_action( ACTION_DEBUG, false ) != -1;
int action = debug_menu_uilist( debug_menu_has_hotkey );

// For the "cheaty" options, disable achievements when used
achievements_tracker &achievements = g->achievements();
static const std::unordered_set<int> non_cheaty_options = {
DEBUG_SAVE_SCREENSHOT,
DEBUG_GAME_REPORT,
DEBUG_ENABLE_ACHIEVEMENTS,
DEBUG_BENCHMARK,
DEBUG_SHOW_MSG,
};
bool should_disable_achievements = action >= 0 && !non_cheaty_options.count( action );
if( should_disable_achievements && achievements.is_enabled() ) {
if( query_yn( "Using this will disable achievements. Proceed?" ) ) {
achievements.set_enabled( false );
} else {
action = -1;
}
}

g->refresh_all();
avatar &u = g->u;
map &m = g->m;
Expand Down Expand Up @@ -1583,6 +1619,14 @@ void debug()
case DEBUG_TRAIT_GROUP:
trait_group::debug_spawn();
break;
case DEBUG_ENABLE_ACHIEVEMENTS:
if( achievements.is_enabled() ) {
popup( _( "Achievements are already enabled" ) );
} else {
achievements.set_enabled( true );
popup( _( "Achievements enabled" ) );
}
break;
case DEBUG_SHOW_MSG:
debugmsg( "Test debugmsg" );
break;
Expand Down
13 changes: 10 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,12 @@ bool is_valid_in_w_terrain( const point &p )
return p.x >= 0 && p.x < TERRAIN_WINDOW_WIDTH && p.y >= 0 && p.y < TERRAIN_WINDOW_HEIGHT;
}

static void achievement_attained( const achievement *a )
static void achievement_attained( const achievement *a, bool achievements_enabled )
{
g->u.add_msg_if_player( m_good, _( "You completed the achievement \"%s\"." ),
a->name() );
if( achievements_enabled ) {
g->u.add_msg_if_player( m_good, _( "You completed the achievement \"%s\"." ),
a->name() );
}
}

// This is the main game set-up process.
Expand Down Expand Up @@ -3065,6 +3067,11 @@ stats_tracker &game::stats()
return *stats_tracker_ptr;
}

achievements_tracker &game::achievements()
{
return *achievements_tracker_ptr;
}

memorial_logger &game::memorial()
{
return *memorial_logger_ptr;
Expand Down
1 change: 1 addition & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ class game

event_bus &events();
stats_tracker &stats();
achievements_tracker &achievements();
memorial_logger &memorial();
spell_events &spell_events_subscriber();

Expand Down
5 changes: 5 additions & 0 deletions src/scores_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

static std::string get_achievements_text( const achievements_tracker &achievements )
{
if( !achievements.is_enabled() ) {
return _( "Achievements are disabled, probably due to use of the debug menu. "
"If you only used the debug menu to work around a game bug, then you "
"can re-enable achievements via the debug menu (under the Game submenu)." );
}
std::string os;
std::vector<const achievement *> valid_achievements = achievements.valid_achievements();
valid_achievements.erase(
Expand Down
2 changes: 1 addition & 1 deletion tests/stats_tracker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ TEST_CASE( "achievments_tracker", "[stats]" )
event_bus b;
stats_tracker s;
b.subscribe( &s );
achievements_tracker a( s, [&]( const achievement * a ) {
achievements_tracker a( s, [&]( const achievement * a, bool /*achievements_enabled*/ ) {
achievements_completed.emplace( a->id, a );
} );
b.subscribe( &a );
Expand Down