From 2ef326b4f6b6b6903c8e60379edfa15f06406d7a Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Sun, 3 Nov 2024 18:07:06 -0500 Subject: [PATCH] Add option to set all companion job priorities at once --- src/faction_camp.cpp | 27 +++++++++++++++++---------- src/npc.cpp | 6 ++++++ src/npc.h | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 5e1a30d770a42..ff893cef3a63f 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -2446,8 +2446,8 @@ void basecamp::job_assignment_ui() smenu.text = _( "Assign job priority (0 to disable)" ); int count = 0; std::vector job_vec = cur_npc->job.get_prioritised_vector(); - smenu.addentry( count, true, 'C', _( "Clear all priorities" ) ); - count++; + smenu.addentry( count++, true, 'C', _( "Clear all priorities" ) ); + smenu.addentry( count++, true, 'S', _( "Set all priorities" ) ); for( const activity_id &elem : job_vec ) { player_activity test_act = player_activity( elem ); const int priority = cur_npc->job.get_priority_of_job( elem ); @@ -2461,16 +2461,23 @@ void basecamp::job_assignment_ui() } if( smenu.ret == 0 ) { cur_npc->job.clear_all_priorities(); - } else if( smenu.ret > 0 && smenu.ret <= static_cast( job_vec.size() ) ) { - activity_id sel_job = job_vec[size_t( smenu.ret - 1 )]; + } else if( smenu.ret == 1 ) { + const int priority = string_input_popup() + .title( _( "Priority for all jobs " ) ) + .width( 20 ) + .only_digits( true ) + .query_int(); + cur_npc->job.set_all_priorities( priority ); + } else if( smenu.ret > 1 && smenu.ret <= static_cast( job_vec.size() ) + 1 ) { + activity_id sel_job = job_vec[size_t( smenu.ret - 2 )]; player_activity test_act = player_activity( sel_job ); const std::string formatted = string_format( _( "Priority for %s " ), test_act.get_verb() ); - const int amount = string_input_popup() - .title( formatted ) - .width( 20 ) - .only_digits( true ) - .query_int(); - cur_npc->job.set_task_priority( sel_job, amount ); + const int priority = string_input_popup() + .title( formatted ) + .width( 20 ) + .only_digits( true ) + .query_int(); + cur_npc->job.set_task_priority( sel_job, priority ); } else { break; } diff --git a/src/npc.cpp b/src/npc.cpp index 032b24d567a0b..91bdbe346c4de 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -183,6 +183,12 @@ bool job_data::set_task_priority( const activity_id &task, int new_priority ) } return false; } +void job_data::set_all_priorities( int new_priority ) +{ + for( auto &elem : task_priorities ) { + elem.second = new_priority; + } +} void job_data::clear_all_priorities() { for( auto &elem : task_priorities ) { diff --git a/src/npc.h b/src/npc.h index 564c97550aad6..8ffbc0e44bf1d 100644 --- a/src/npc.h +++ b/src/npc.h @@ -161,6 +161,7 @@ class job_data std::unordered_map fetch_history; bool set_task_priority( const activity_id &task, int new_priority ); + void set_all_priorities( int new_priority ); void clear_all_priorities(); bool has_job() const; int get_priority_of_job( const activity_id &req_job ) const;