From d75bd37a1b364da6b171448b3411aa3de9983552 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Thu, 23 Nov 2023 18:32:24 -0500 Subject: [PATCH 1/3] Add debug menu to edit factions --- src/debug_menu.cpp | 193 +++++++++++++++++++++++++++++++++++++++------ src/debug_menu.h | 1 + 2 files changed, 170 insertions(+), 24 deletions(-) diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index e446082e54a5c..b7e47db7919c6 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -252,6 +252,7 @@ std::string enum_to_string( debug_menu::debug_menu case debug_menu::debug_menu_index::TOGGLE_SETUP_MUTATION: return "TOGGLE_SETUP_MUTATION"; case debug_menu::debug_menu_index::NORMALIZE_BODY_STAT: return "NORMALIZE_BODY_STAT"; case debug_menu::debug_menu_index::SIX_MILLION_DOLLAR_SURVIVOR: return "SIX_MILLION_DOLLAR_SURVIVOR"; + case debug_menu::debug_menu_index::EDIT_FACTION: return "EDIT_FACTION"; // *INDENT-ON* case debug_menu::debug_menu_index::last: break; @@ -491,7 +492,7 @@ static int info_uilist( bool display_all_entries = true ) { 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_FACTION_INFO, true, 'f', _( "Print factions 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" ) ) }, { uilist_entry( debug_menu_index::WRITE_GLOBAL_EOCS, true, 'C', _( "Write global effect_on_condition(s) to eocs.output" ) ) }, @@ -601,6 +602,18 @@ static int quick_setup_uilist() return uilist( _( "Quick setup…" ), uilist_initializer ); } +static int faction_uilist() +{ + const std::vector uilist_initializer = { + { uilist_entry( debug_menu_index::EDIT_FACTION, true, 'e', _( "Edit faction" ) ) }, + { uilist_entry( debug_menu_index::PRINT_FACTION_INFO, true, 'p', _( "Print factions info to console" ) ) }, + }; + + return uilist( _( "Faction" ), uilist_initializer ); +} + + + /** * Create the debug menu UI list. * @param display_all_entries: `true` if all entries should be displayed, `false` is some entries should be hidden (for ex. when the debug menu is called from the main menu). @@ -609,19 +622,24 @@ static int quick_setup_uilist() */ static std::optional debug_menu_uilist( bool display_all_entries = true ) { + enum { + D_INFO, D_GAME, D_SPAWNING, D_PLAYER, D_FACTION, D_VEHICLE, D_TELEPORT, D_MAP, D_QUICK_SETUP + }; + std::vector menu = { - { uilist_entry( 1, true, 'i', _( "Info…" ) ) }, + { uilist_entry( D_INFO, true, 'i', _( "Info…" ) ) }, }; if( display_all_entries ) { const std::vector debug_menu = { - { uilist_entry( 6, true, 'g', _( "Game…" ) ) }, - { uilist_entry( 2, true, 's', _( "Spawning…" ) ) }, - { uilist_entry( 3, true, 'p', _( "Player…" ) ) }, - { uilist_entry( 7, true, 'v', _( "Vehicle…" ) ) }, - { uilist_entry( 4, true, 't', _( "Teleport…" ) ) }, - { uilist_entry( 5, true, 'm', _( "Map…" ) ) }, - { uilist_entry( 8, true, 'q', _( "Quick setup…" ) ) }, + { uilist_entry( D_GAME, true, 'g', _( "Game…" ) ) }, + { uilist_entry( D_SPAWNING, true, 's', _( "Spawning…" ) ) }, + { uilist_entry( D_PLAYER, true, 'p', _( "Player…" ) ) }, + { uilist_entry( D_FACTION, true, 'f', _( "Faction…" ) ) }, + { uilist_entry( D_VEHICLE, true, 'v', _( "Vehicle…" ) ) }, + { uilist_entry( D_TELEPORT, true, 't', _( "Teleport…" ) ) }, + { uilist_entry( D_MAP, true, 'm', _( "Map…" ) ) }, + { uilist_entry( D_QUICK_SETUP, true, 'q', _( "Quick setup…" ) ) }, }; // insert debug-only menu right after "Info". @@ -641,28 +659,31 @@ static std::optional debug_menu_uilist( bool display_all_entri int action; switch( group ) { - case 1: + case D_INFO: action = info_uilist( display_all_entries ); break; - case 2: + case D_SPAWNING: action = spawning_uilist(); break; - case 3: + case D_PLAYER: action = player_uilist(); break; - case 4: + case D_FACTION: + action = faction_uilist(); + break; + case D_TELEPORT: action = teleport_uilist(); break; - case 5: + case D_MAP: action = map_uilist(); break; - case 6: + case D_GAME: action = game_uilist(); break; - case 7: + case D_VEHICLE: action = vehicle_uilist(); break; - case 8: + case D_QUICK_SETUP: action = quick_setup_uilist(); break; @@ -1658,12 +1679,12 @@ static void character_edit_hp_menu( Character &you ) static void character_edit_opinion_menu( npc *np ) { uilist smenu; - smenu.addentry( 0, true, 'h', "%s: %d", _( "trust" ), np->op_of_u.trust ); - smenu.addentry( 1, true, 's', "%s: %d", _( "fear" ), np->op_of_u.fear ); - smenu.addentry( 2, true, 't', "%s: %d", _( "value" ), np->op_of_u.value ); - smenu.addentry( 3, true, 'f', "%s: %d", _( "anger" ), np->op_of_u.anger ); - smenu.addentry( 4, true, 'd', "%s: %d", _( "owed" ), np->op_of_u.owed ); - smenu.addentry( 5, true, 'd', "%s: %d", _( "sold" ), np->op_of_u.sold ); + smenu.addentry( 0, true, 't', "%s: %d", _( "trust" ), np->op_of_u.trust ); + smenu.addentry( 1, true, 'f', "%s: %d", _( "fear" ), np->op_of_u.fear ); + smenu.addentry( 2, true, 'v', "%s: %d", _( "value" ), np->op_of_u.value ); + smenu.addentry( 3, true, 'a', "%s: %d", _( "anger" ), np->op_of_u.anger ); + smenu.addentry( 4, true, 'o', "%s: %d", _( "owed" ), np->op_of_u.owed ); + smenu.addentry( 5, true, 's', "%s: %d", _( "sold" ), np->op_of_u.sold ); smenu.query(); int value; @@ -1941,7 +1962,7 @@ static void character_edit_menu() nmenu.addentry( D_MISSION_ADD, true, 'm', "%s", _( "Add mission" ) ); nmenu.addentry( D_CLASS, true, 'c', "%s", _( "Randomize with class" ) ); nmenu.addentry( D_ATTITUDE, true, 'A', "%s", _( "Set attitude" ) ); - nmenu.addentry( D_OPINION, true, 'O', "%s", _( "Set opinion" ) ); + nmenu.addentry( D_OPINION, true, 'O', "%s", _( "Set opinions" ) ); nmenu.addentry( D_PERSONALITY, true, 'P', "%s", _( "Set personality" ) ); } nmenu.query(); @@ -2243,6 +2264,126 @@ static void character_edit_menu() } } +static void faction_edit_opinion_menu( faction *fac ) +{ + uilist smenu; + smenu.addentry( 0, true, 'l', "%s: %d", _( "Like" ), fac->likes_u ); + smenu.addentry( 1, true, 'r', "%s: %d", _( "Respect" ), fac->respects_u ); + smenu.addentry( 2, true, 't', "%s: %d", _( "Trust" ), fac->trusts_u ); + + smenu.query(); + int value; + switch( smenu.ret ) { + case 0: + if( query_int( value, _( "Change like from %d to: " ), fac->likes_u ) ) { + fac->likes_u = value; + } + break; + case 1: + if( query_int( value, _( "Change respect from %d to: " ), fac->respects_u ) ) { + fac->respects_u = value; + } + break; + case 2: + if( query_int( value, _( "Change trust from %d to: " ), fac->trusts_u ) ) { + fac->trusts_u = value; + } + break; + } +} + +static void faction_edit_menu() +{ + + std::vector factions; // Factions that we know of. + for( const auto &elem : g->faction_manager_ptr->all() ) { + factions.push_back( g->faction_manager_ptr->get( elem.first ) ); + } + + if( factions.size() == 0 ) { + return; + } + + uilist factionlist; + int facnum = 0; + for( const auto &faction : factions ) { + factionlist.addentry( facnum++, true, MENU_AUTOASSIGN, "%s", faction->name.c_str() ); + } + + factionlist.w_y_setup = 0; + factionlist.query(); + if( factionlist.ret < 0 || static_cast( factionlist.ret ) >= factions.size() ) { + return; + } + const size_t index = factionlist.ret; + + uilist nmenu; + + auto &fac = factions[index]; + + std::stringstream data; + data << fac->name << std::endl; + data << fac->describe() << std::endl; + data << string_format( _( "Id: %s" ), fac->id.c_str() ) << std::endl; + data << string_format( _( "Wealth: %d" ), fac->wealth ) << " | " + << string_format( _( "Currency: %s" ), fac->currency.obj().nname( fac->wealth ) ) << std::endl; + data << string_format( _( "Size: %d" ), fac->size ) << " | " + << string_format( _( "Power: %d" ), fac->power ) << " | " + << string_format( _( "Food Supply: %d" ), fac->food_supply ) << std::endl; + data << string_format( _( "Like: %d" ), fac->likes_u ) << " | " + << string_format( _( "Respect: %d" ), fac->respects_u ) << " | " + << string_format( _( "Trust: %d" ), fac->trusts_u ) << std::endl; + data << string_format( _( "Known by you: %s" ), fac->known_by_u ? "true" : "false" ) << " | " + << string_format( _( "Lone wolf: %s" ), fac->lone_wolf_faction ? "true" : "false" ) << std::endl; + + nmenu.text = data.str(); + + enum { + D_WEALTH, D_SIZE, D_POWER, D_FOOD, D_OPINION, D_KNOWN, D_LONE + }; + nmenu.addentry( D_WEALTH, true, 'w', "%s", _( "Set wealth" ) ); + nmenu.addentry( D_SIZE, true, 's', "%s", _( "Set size" ) ); + nmenu.addentry( D_POWER, true, 'p', "%s", _( "Set power" ) ); + nmenu.addentry( D_FOOD, true, 'f', "%s", _( "Set food supply" ) ); + nmenu.addentry( D_OPINION, true, 'o', "%s", _( "Set opinions" ) ); + nmenu.addentry( D_KNOWN, true, 'k', "%s", _( "Toggle Known by you" ) ); + nmenu.addentry( D_LONE, true, 'l', "%s", _( "Toggle Lone wolf" ) ); + + nmenu.query(); + int value; + switch( nmenu.ret ) { + case D_WEALTH: + if( query_int( value, _( "Change wealth from %d to: " ), fac->wealth ) ) { + fac->wealth = value; + } + break; + case D_SIZE: + if( query_int( value, _( "Change size from %d to: " ), fac->size ) ) { + fac->size = value; + } + break; + case D_POWER: + if( query_int( value, _( "Change power from %d to: " ), fac->power ) ) { + fac->power = value; + } + break; + case D_FOOD: + if( query_int( value, _( "Change food from %d to: " ), fac->food_supply ) ) { + fac->food_supply = value; + } + break; + case D_OPINION: + faction_edit_opinion_menu( fac ); + break; + case D_KNOWN: + fac->known_by_u = !fac->known_by_u; + break; + case D_LONE: + fac->lone_wolf_faction = !fac->lone_wolf_faction; + break; + } +} + static std::string mission_status_string( mission::mission_status status ) { static const std::map desc{ { @@ -3592,6 +3733,10 @@ void debug() break; } + case debug_menu_index::EDIT_FACTION: + faction_edit_menu(); + break; + case debug_menu_index::last: return; } diff --git a/src/debug_menu.h b/src/debug_menu.h index 7cc5dcaac0bf8..175f6ee8f962f 100644 --- a/src/debug_menu.h +++ b/src/debug_menu.h @@ -105,6 +105,7 @@ enum class debug_menu_index : int { TOGGLE_SETUP_MUTATION, NORMALIZE_BODY_STAT, SIX_MILLION_DOLLAR_SURVIVOR, + EDIT_FACTION, last }; From 701d42600e2c6e48fbc5e7a289a535cd68c92a39 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Thu, 23 Nov 2023 19:17:10 -0500 Subject: [PATCH 2/3] Remove debug menu EDIT_CAMP_LARDER --- src/debug_menu.cpp | 12 ------------ src/debug_menu.h | 1 - 2 files changed, 13 deletions(-) diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index b7e47db7919c6..f4b6f6b0ed5f0 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -240,7 +240,6 @@ std::string enum_to_string( debug_menu::debug_menu case debug_menu::debug_menu_index::TEST_MAP_EXTRA_DISTRIBUTION: return "TEST_MAP_EXTRA_DISTRIBUTION"; case debug_menu::debug_menu_index::NESTED_MAPGEN: return "NESTED_MAPGEN"; case debug_menu::debug_menu_index::VEHICLE_EXPORT: return "VEHICLE_EXPORT"; - case debug_menu::debug_menu_index::EDIT_CAMP_LARDER: return "EDIT_CAMP_LARDER"; case debug_menu::debug_menu_index::VEHICLE_DELETE: return "VEHICLE_DELETE"; case debug_menu::debug_menu_index::VEHICLE_BATTERY_CHARGE: return "VEHICLE_BATTERY_CHARGE"; case debug_menu::debug_menu_index::GENERATE_EFFECT_LIST: return "GENERATE_EFFECT_LIST"; @@ -584,7 +583,6 @@ static int map_uilist() { uilist_entry( debug_menu_index::OM_EDITOR, true, 'O', _( "Overmap editor" ) ) }, { uilist_entry( debug_menu_index::MAP_EXTRA, true, 'm', _( "Spawn map extra" ) ) }, { uilist_entry( debug_menu_index::NESTED_MAPGEN, true, 'n', _( "Spawn nested mapgen" ) ) }, - { uilist_entry( debug_menu_index::EDIT_CAMP_LARDER, true, 'l', _( "Edit the faction camp larder" ) ) }, }; return uilist( _( "Map…" ), uilist_initializer ); @@ -3634,16 +3632,6 @@ void debug() break; } - case debug_menu_index::EDIT_CAMP_LARDER: { - faction *your_faction = get_player_character().get_faction(); - int larder; - if( query_int( larder, _( "Set camp larder kCals to? Currently: %d" ), - your_faction->food_supply ) ) { - your_faction->food_supply = larder; - } - break; - } - case debug_menu_index::IMPORT_FOLLOWER: { cata_path export_dir{ cata_path::root_path::user, "export_dir" }; std::vector npc_files = get_files_from_path( ".npc", diff --git a/src/debug_menu.h b/src/debug_menu.h index 175f6ee8f962f..e6b5befcb5342 100644 --- a/src/debug_menu.h +++ b/src/debug_menu.h @@ -91,7 +91,6 @@ enum class debug_menu_index : int { VEHICLE_DELETE, VEHICLE_EXPORT, GENERATE_EFFECT_LIST, - EDIT_CAMP_LARDER, WRITE_GLOBAL_EOCS, WRITE_GLOBAL_VARS, EDIT_GLOBAL_VARS, From a5d8bc671d68d4c591300f55f44ed52bea3f6a53 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Thu, 23 Nov 2023 21:00:32 -0500 Subject: [PATCH 3/3] Add npc faction change to debug menu --- src/debug_menu.cpp | 58 +++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index f4b6f6b0ed5f0..f59f54cedb9a2 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -1849,6 +1849,32 @@ static void character_edit_desc_menu( Character &you ) } } +static faction *select_faction() +{ + std::vector factions; + for( const auto &elem : g->faction_manager_ptr->all() ) { + factions.push_back( g->faction_manager_ptr->get( elem.first ) ); + } + + if( factions.empty() ) { + return nullptr; + } + + uilist factionlist; + int facnum = 0; + for( const faction *faction : factions ) { + factionlist.addentry( facnum++, true, MENU_AUTOASSIGN, "%s", faction->name.c_str() ); + } + + factionlist.w_y_setup = 0; + factionlist.query(); + if( factionlist.ret < 0 || static_cast( factionlist.ret ) >= factions.size() ) { + return nullptr; + } + + return factions[factionlist.ret]; +} + static void character_edit_menu() { std::vector< tripoint > locations; @@ -1919,7 +1945,7 @@ static void character_edit_menu() D_DESC, D_SKILLS, D_THEORY, D_PROF, D_STATS, D_SPELLS, D_ITEMS, D_DELETE_ITEMS, D_DROP_ITEMS, D_ITEM_WORN, D_HP, D_STAMINA, D_MORALE, D_PAIN, D_NEEDS, D_HEALTHY, D_STATUS, D_MISSION_ADD, D_MISSION_EDIT, D_TELE, D_MUTATE, D_BIONICS, D_CLASS, D_ATTITUDE, D_OPINION, D_PERSONALITY, D_ADD_EFFECT, D_ASTHMA, D_PRINT_VARS, - D_WRITE_EOCS, D_KILL_XP, D_CHECK_TEMP, D_EDIT_VARS + D_WRITE_EOCS, D_KILL_XP, D_CHECK_TEMP, D_EDIT_VARS, D_FACTION }; nmenu.addentry( D_DESC, true, 'D', "%s", _( "Edit description - name, age, height or blood type" ) ); @@ -1962,6 +1988,7 @@ static void character_edit_menu() nmenu.addentry( D_ATTITUDE, true, 'A', "%s", _( "Set attitude" ) ); nmenu.addentry( D_OPINION, true, 'O', "%s", _( "Set opinions" ) ); nmenu.addentry( D_PERSONALITY, true, 'P', "%s", _( "Set personality" ) ); + nmenu.addentry( D_FACTION, true, 'F', "%s", _( "Set faction" ) ); } nmenu.query(); switch( nmenu.ret ) { @@ -2259,6 +2286,13 @@ static void character_edit_menu() you.set_value( "npctalk_var_" + key, value ); break; } + case D_FACTION: { + const faction *fac = select_faction(); + if( fac != nullptr ) { + you.as_npc()->set_fac( fac->id ); + } + break; + } } } @@ -2293,32 +2327,14 @@ static void faction_edit_opinion_menu( faction *fac ) static void faction_edit_menu() { - std::vector factions; // Factions that we know of. - for( const auto &elem : g->faction_manager_ptr->all() ) { - factions.push_back( g->faction_manager_ptr->get( elem.first ) ); - } + faction *const fac = select_faction(); - if( factions.size() == 0 ) { + if( fac == nullptr ) { return; } - uilist factionlist; - int facnum = 0; - for( const auto &faction : factions ) { - factionlist.addentry( facnum++, true, MENU_AUTOASSIGN, "%s", faction->name.c_str() ); - } - - factionlist.w_y_setup = 0; - factionlist.query(); - if( factionlist.ret < 0 || static_cast( factionlist.ret ) >= factions.size() ) { - return; - } - const size_t index = factionlist.ret; - uilist nmenu; - auto &fac = factions[index]; - std::stringstream data; data << fac->name << std::endl; data << fac->describe() << std::endl;