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

Change NPC faction from debug menu #69693

Merged
merged 3 commits into from
Nov 24, 2023
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
223 changes: 186 additions & 37 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ std::string enum_to_string<debug_menu::debug_menu_index>( 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";
Expand All @@ -252,6 +251,7 @@ std::string enum_to_string<debug_menu::debug_menu_index>( 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;
Expand Down Expand Up @@ -491,7 +491,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" ) ) },
Expand Down Expand Up @@ -583,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 );
Expand All @@ -601,6 +600,18 @@ static int quick_setup_uilist()
return uilist( _( "Quick setup…" ), uilist_initializer );
}

static int faction_uilist()
{
const std::vector<uilist_entry> 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).
Expand All @@ -609,19 +620,24 @@ static int quick_setup_uilist()
*/
static std::optional<debug_menu_index> 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<uilist_entry> menu = {
{ uilist_entry( 1, true, 'i', _( "Info…" ) ) },
{ uilist_entry( D_INFO, true, 'i', _( "Info…" ) ) },
};

if( display_all_entries ) {
const std::vector<uilist_entry> 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".
Expand All @@ -641,28 +657,31 @@ static std::optional<debug_menu_index> 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;

Expand Down Expand Up @@ -1658,12 +1677,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;
Expand Down Expand Up @@ -1830,6 +1849,32 @@ static void character_edit_desc_menu( Character &you )
}
}

static faction *select_faction()
{
std::vector<faction *> 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<size_t>( factionlist.ret ) >= factions.size() ) {
return nullptr;
}

return factions[factionlist.ret];
}

static void character_edit_menu()
{
std::vector< tripoint > locations;
Expand Down Expand Up @@ -1900,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" ) );
Expand Down Expand Up @@ -1941,8 +1986,9 @@ 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.addentry( D_FACTION, true, 'F', "%s", _( "Set faction" ) );
}
nmenu.query();
switch( nmenu.ret ) {
Expand Down Expand Up @@ -2240,6 +2286,115 @@ 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;
}
}
}

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()
{

faction *const fac = select_faction();

if( fac == nullptr ) {
return;
}

uilist nmenu;

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;
}
}

Expand Down Expand Up @@ -3493,16 +3648,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<cata_path> npc_files = get_files_from_path( ".npc",
Expand Down Expand Up @@ -3592,6 +3737,10 @@ void debug()
break;
}

case debug_menu_index::EDIT_FACTION:
faction_edit_menu();
break;

case debug_menu_index::last:
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -105,6 +104,7 @@ enum class debug_menu_index : int {
TOGGLE_SETUP_MUTATION,
NORMALIZE_BODY_STAT,
SIX_MILLION_DOLLAR_SURVIVOR,
EDIT_FACTION,
last
};

Expand Down
Loading