From c2b407f0c66792b0483bedf871d24de6d32067a4 Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github> Date: Wed, 5 Jun 2024 21:58:10 +0200 Subject: [PATCH 1/7] Make farm_action a method of basecamp class. Preparation to infer plots for plowing from expansion data so that #73761 can be fixed. --- src/basecamp.h | 2 ++ src/faction_camp.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/basecamp.h b/src/basecamp.h index 16e03cc4dd15b..60fa3b37adf00 100644 --- a/src/basecamp.h +++ b/src/basecamp.h @@ -443,6 +443,8 @@ class basecamp * @param op whether to plow, plant, or harvest */ bool farm_return( const mission_id &miss_id, const tripoint_abs_omt &omt_tgt ); + std::pair farm_action( const tripoint_abs_omt &omt_tgt, farm_ops op, + const npc_ptr &comp = nullptr ); void fortifications_return( const mission_id &miss_id ); bool salt_water_pipe_swamp_return( const mission_id &miss_id, const comp_list &npc_list ); diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index df4c93a03c1d7..91d647efb20b1 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -3543,8 +3543,8 @@ static bool farm_valid_seed( const item &itm ) return itm.is_seed() && itm.typeId() != itype_marloss_seed && itm.typeId() != itype_fungal_seeds; } -static std::pair farm_action( const tripoint_abs_omt &omt_tgt, farm_ops op, - const npc_ptr &comp = nullptr ) +std::pair basecamp::farm_action( const tripoint_abs_omt &omt_tgt, farm_ops op, + const npc_ptr &comp ) { size_t plots_cnt = 0; std::string crops; From 88e5487257dd0165fe30501417d942d8fe231b7a Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github> Date: Thu, 6 Jun 2024 08:09:46 +0200 Subject: [PATCH 2/7] Make farm_action use relative expansion coordinates. Using dir instead of absolute overmap coordinates allows to access available upgrades from basecamp expansions. This is also more in line with other basecamp missions. --- src/basecamp.h | 8 ++++---- src/faction_camp.cpp | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/basecamp.h b/src/basecamp.h index 60fa3b37adf00..b9dee654cc5aa 100644 --- a/src/basecamp.h +++ b/src/basecamp.h @@ -336,7 +336,7 @@ class basecamp std::string gathering_description(); /// Returns a string for the number of plants that are harvestable, plots ready to plant, /// and ground that needs tilling - std::string farm_description( const tripoint_abs_omt &farm_pos, size_t &plots_count, + std::string farm_description( const point &dir, size_t &plots_count, farm_ops operation ); /// Returns the description of a camp crafting options. converts fire charges to charcoal, /// allows dark crafting @@ -392,7 +392,7 @@ class basecamp void start_salt_water_pipe( const mission_id &miss_id ); void continue_salt_water_pipe( const mission_id &miss_id ); void start_combat_mission( const mission_id &miss_id, float exertion_level ); - void start_farm_op( const tripoint_abs_omt &omt_tgt, const mission_id &miss_id, + void start_farm_op( const point &dir, const mission_id &miss_id, float exertion_level ); ///Display items listed in @ref equipment to let the player pick what to give the departing ///NPC, loops until quit or empty. @@ -442,8 +442,8 @@ class basecamp * @param omt_tgt the overmap pos3 of the farm_ops * @param op whether to plow, plant, or harvest */ - bool farm_return( const mission_id &miss_id, const tripoint_abs_omt &omt_tgt ); - std::pair farm_action( const tripoint_abs_omt &omt_tgt, farm_ops op, + bool farm_return( const mission_id &miss_id, const point &dir ); + std::pair farm_action( const point &dir, farm_ops op, const npc_ptr &comp = nullptr ); void fortifications_return( const mission_id &miss_id ); bool salt_water_pipe_swamp_return( const mission_id &miss_id, diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 91d647efb20b1..45e46c19d7277 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -786,7 +786,6 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p const std::string dir_id = base_camps::all_directions.at( dir ).id; const std::string dir_abbr = base_camps::all_directions.at( dir ).bracket_abbr.translated(); - const tripoint_abs_omt omt_trg = omt_pos + dir; { // return legacy workers. How old is this legacy?... @@ -1307,7 +1306,7 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p if( npc_list.empty() ) { entry = _( "Notes:\n" "Plow any spaces that have reverted to dirt or grass.\n\n" ) + - farm_description( omt_trg, plots, farm_ops::plow ) + + farm_description( dir, plots, farm_ops::plow ) + _( "\n\n" "Skill used: fabrication\n" "Difficulty: N/A\n" @@ -1335,7 +1334,7 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p entry = _( "Notes:\n" "Plant designated seeds in the spaces that have already been " "tilled.\n\n" ) + - farm_description( omt_trg, plots, farm_ops::plant ) + + farm_description( dir, plots, farm_ops::plant ) + _( "\n\n" "Skill used: survival\n" "Difficulty: N/A\n" @@ -1349,7 +1348,7 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p "Positions: 0/1\n" ); mission_key.add_start( miss_id, name_display_of( miss_id ), entry, - plots > 0 && warm_enough_to_plant( omt_trg ) ); + plots > 0 && warm_enough_to_plant( omt_pos + dir ) ); } else { entry = action_of( miss_id.id ); bool avail = update_time_left( entry, npc_list ); @@ -1364,7 +1363,7 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p if( npc_list.empty() ) { entry = _( "Notes:\n" "Harvest any plants that are ripe and bring the produce back.\n\n" ) + - farm_description( omt_trg, plots, farm_ops::harvest ) + + farm_description( dir, plots, farm_ops::harvest ) + _( "\n\n" "Skill used: survival\n" "Difficulty: N/A\n" @@ -1718,8 +1717,6 @@ bool basecamp::handle_mission( const ui_mission_id &miss_id ) const point &miss_dir = miss_id.id.dir.value(); // All missions should supply dir. Bug if they don't, so blow up during testing. - const tripoint_abs_omt omt_trg = omt_pos + miss_dir; - switch( miss_id.id.id ) { case Camp_Distribute_Food: distribute_food(); @@ -1943,9 +1940,9 @@ bool basecamp::handle_mission( const ui_mission_id &miss_id ) case Camp_Plant: case Camp_Harvest: if( miss_id.ret ) { - farm_return( miss_id.id, omt_trg ); + farm_return( miss_id.id, miss_dir ); } else { - start_farm_op( omt_trg, miss_id.id, MODERATE_EXERCISE ); + start_farm_op( miss_dir, miss_id.id, MODERATE_EXERCISE ); } break; @@ -3543,12 +3540,15 @@ static bool farm_valid_seed( const item &itm ) return itm.is_seed() && itm.typeId() != itype_marloss_seed && itm.typeId() != itype_fungal_seeds; } -std::pair basecamp::farm_action( const tripoint_abs_omt &omt_tgt, farm_ops op, +std::pair basecamp::farm_action( const point &dir, farm_ops op, const npc_ptr &comp ) { size_t plots_cnt = 0; std::string crops; + const auto e_data = expansions.find( dir ); + const tripoint_abs_omt omt_tgt = e_data->second.pos; + const auto is_dirtmound = []( const tripoint & pos, tinymap & bay1, tinymap & bay2 ) { return ( bay1.ter( pos ) == ter_t_dirtmound ) && ( !bay2.has_furn( pos ) ); }; @@ -3675,7 +3675,7 @@ std::pair basecamp::farm_action( const tripoint_abs_omt &om return std::make_pair( plots_cnt, crops ); } -void basecamp::start_farm_op( const tripoint_abs_omt &omt_tgt, const mission_id &miss_id, +void basecamp::start_farm_op( const point &dir, const mission_id &miss_id, float exertion_level ) { farm_ops op = farm_ops::plow; @@ -3690,7 +3690,7 @@ void basecamp::start_farm_op( const tripoint_abs_omt &omt_tgt, const mission_id return; } - std::pair farm_data = farm_action( omt_tgt, op ); + std::pair farm_data = farm_action( dir, op ); size_t plots_cnt = farm_data.first; if( !plots_cnt ) { return; @@ -4591,7 +4591,7 @@ bool basecamp::survey_return( const mission_id &miss_id ) return true; } -bool basecamp::farm_return( const mission_id &miss_id, const tripoint_abs_omt &omt_tgt ) +bool basecamp::farm_return( const mission_id &miss_id, const point &dir ) { farm_ops op; if( miss_id.id == Camp_Plow ) { @@ -4612,7 +4612,7 @@ bool basecamp::farm_return( const mission_id &miss_id, const tripoint_abs_omt &o return false; } - farm_action( omt_tgt, op, comp ); + farm_action( dir, op, comp ); Character &player_character = get_player_character(); //Give any seeds the NPC didn't use back to you. @@ -5488,10 +5488,10 @@ std::string basecamp::gathering_description() return output; } -std::string basecamp::farm_description( const tripoint_abs_omt &farm_pos, size_t &plots_count, +std::string basecamp::farm_description( const point &dir, size_t &plots_count, farm_ops operation ) { - std::pair farm_data = farm_action( farm_pos, operation ); + std::pair farm_data = farm_action( dir, operation ); std::string entry; plots_count = farm_data.first; switch( operation ) { From 9f8f379ed4cb5206251152daa2069f7b2fa7752e Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github> Date: Thu, 6 Jun 2024 08:22:15 +0200 Subject: [PATCH 3/7] Add mapgen update from expansions to farm_action. Necessary to get dirtmound terrain from basecamp upgrades into the reference map that farm_action compares to. Fixes #73761. --- src/faction_camp.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 45e46c19d7277..5f6f5e08e89f6 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -3582,10 +3582,42 @@ std::pair basecamp::farm_action( const point &dir, farm_ops if( !farm_json ) { farm_json = std::make_unique(); mapgendata dat( omt_tgt, *farm_json->cast_to_map(), 0, calendar::turn, nullptr ); - if( !run_mapgen_func( dat.terrain_type()->get_mapgen_id(), dat ) ) { + std::string omt_id = dat.terrain_type()->get_mapgen_id(); + if( !run_mapgen_func( omt_id, dat ) ) { debugmsg( "Failed to run mapgen for farm map" ); break; } + // Add mapgen from expansion upgrades to fake_map + for( auto const &provide : e_data->second.provides ) { + if ( !recipe_id( provide.first ).is_valid() ) { + continue; + } + const recipe &making = *recipe_id( provide.first ); + const update_mapgen_id update_id = making.get_blueprint(); + if ( !has_update_mapgen_for( update_id )) { + continue; + } + bool mirror_horizontal; + bool mirror_vertical; + int rotation; + if( !extract_and_check_orientation_flags( making.ident(), + dir, + mirror_horizontal, + mirror_vertical, + rotation, + "farm_action failed to apply orientation flags to the %s upgrade", + "" ) ) { + continue; + } + farm_json->rotate( 4 - rotation ); + farm_json->mirror( mirror_horizontal, mirror_vertical ); + if ( !run_mapgen_update_func( update_id, dat, false ) ) { + debugmsg( "farm_action failed to apply the %s map update to %s", + provide.first, omt_id ); + } + farm_json->rotate( rotation ); + farm_json->mirror( mirror_horizontal, mirror_vertical ); + } } // Needs to be plowed to match json if( is_dirtmound( pos, *farm_json, farm_map ) && is_unplowed( pos, farm_map ) ) { From c7fe9affc0e7468de0ef07de3495dd5ea5b6363f Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:19:48 +0200 Subject: [PATCH 4/7] Apply suggestions from code review Whitespace formatting corrected. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/basecamp.h | 2 +- src/faction_camp.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/basecamp.h b/src/basecamp.h index b9dee654cc5aa..cd9372615aa06 100644 --- a/src/basecamp.h +++ b/src/basecamp.h @@ -444,7 +444,7 @@ class basecamp */ bool farm_return( const mission_id &miss_id, const point &dir ); std::pair farm_action( const point &dir, farm_ops op, - const npc_ptr &comp = nullptr ); + const npc_ptr &comp = nullptr ); void fortifications_return( const mission_id &miss_id ); bool salt_water_pipe_swamp_return( const mission_id &miss_id, const comp_list &npc_list ); diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 5f6f5e08e89f6..0e18fc0c3e8ce 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -3589,12 +3589,12 @@ std::pair basecamp::farm_action( const point &dir, farm_ops } // Add mapgen from expansion upgrades to fake_map for( auto const &provide : e_data->second.provides ) { - if ( !recipe_id( provide.first ).is_valid() ) { + if( !recipe_id( provide.first ).is_valid() ) { continue; } const recipe &making = *recipe_id( provide.first ); const update_mapgen_id update_id = making.get_blueprint(); - if ( !has_update_mapgen_for( update_id )) { + if( !has_update_mapgen_for( update_id ) ) { continue; } bool mirror_horizontal; @@ -3611,7 +3611,7 @@ std::pair basecamp::farm_action( const point &dir, farm_ops } farm_json->rotate( 4 - rotation ); farm_json->mirror( mirror_horizontal, mirror_vertical ); - if ( !run_mapgen_update_func( update_id, dat, false ) ) { + if( !run_mapgen_update_func( update_id, dat, false ) ) { debugmsg( "farm_action failed to apply the %s map update to %s", provide.first, omt_id ); } From c903fcd26b42f089541d0f952d4bed2d765b7d03 Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github> Date: Fri, 7 Jun 2024 09:48:19 +0200 Subject: [PATCH 5/7] Fixed debug message in case orientation flags fail. --- src/faction_camp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 0e18fc0c3e8ce..af813cf490bd6 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -3605,8 +3605,8 @@ std::pair basecamp::farm_action( const point &dir, farm_ops mirror_horizontal, mirror_vertical, rotation, - "farm_action failed to apply orientation flags to the %s upgrade", - "" ) ) { + "%s failed to apply orientation flags to the %s upgrade", + "farm_action" ) ) { continue; } farm_json->rotate( 4 - rotation ); From 3886f8de9c696c6c5657f14ca6cb6094f5740e65 Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github> Date: Mon, 10 Jun 2024 13:27:38 +0200 Subject: [PATCH 6/7] Use smallmap instead of tinymap for farm_action. This will ensure that blueprints having multiple z-levels can be applied correctly to the reference farm map. --- src/faction_camp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index af813cf490bd6..4490477ac94bf 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -3564,10 +3564,10 @@ std::pair basecamp::farm_action( const point &dir, farm_ops } // farm_map is what the area actually looks like - tinymap farm_map; + smallmap farm_map; farm_map.load( omt_tgt, false ); // farm_json is what the area should look like according to jsons (loaded on demand) - std::unique_ptr farm_json; + std::unique_ptr farm_json; tripoint mapmin = tripoint( 0, 0, omt_tgt.z() ); tripoint mapmax = tripoint( 2 * SEEX - 1, 2 * SEEY - 1, omt_tgt.z() ); bool done_planting = false; @@ -3580,7 +3580,7 @@ std::pair basecamp::farm_action( const point &dir, farm_ops switch( op ) { case farm_ops::plow: { if( !farm_json ) { - farm_json = std::make_unique(); + farm_json = std::make_unique(); mapgendata dat( omt_tgt, *farm_json->cast_to_map(), 0, calendar::turn, nullptr ); std::string omt_id = dat.terrain_type()->get_mapgen_id(); if( !run_mapgen_func( omt_id, dat ) ) { From c86d76c437625ed2d6a31717259d9e5f0e02a7ab Mon Sep 17 00:00:00 2001 From: silvadomi <171120271+silvadomi@users.noreply.github> Date: Mon, 10 Jun 2024 13:29:01 +0200 Subject: [PATCH 7/7] Update farming mission description. Ensure that mission description is consistent with what happens in the mission. --- src/faction_camp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 4490477ac94bf..66958100c15eb 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -1311,7 +1311,7 @@ void basecamp::get_available_missions_by_dir( mission_data &mission_key, const p "Skill used: fabrication\n" "Difficulty: N/A\n" "Effects:\n" - "> Restores only the plots created in the last expansion upgrade.\n" + "> Restores farm plots created in previous expansion upgrades.\n" "> Does not damage existing crops.\n\n" "Risk: None\n" "Intensity: Moderate\n"