From 0f88696c7eac42ed1f2a9b2203386ad4b96201e2 Mon Sep 17 00:00:00 2001 From: eltank <8000047+eltank@users.noreply.github.com> Date: Sat, 18 Sep 2021 21:53:50 -0700 Subject: [PATCH] Fix zone rotation in faction camp farms --- src/faction_camp.cpp | 26 +++++++++++++++----------- src/map.cpp | 7 +++---- src/map.h | 18 ++---------------- src/mapgen.cpp | 19 ++++++------------- 4 files changed, 26 insertions(+), 44 deletions(-) diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 764b8493e75d1..5ddae87360c1e 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -2402,16 +2402,11 @@ static std::pair farm_action( const tripoint_abs_omt &omt_t seed_inv = comp->companion_mission_inv.items_with( farm_valid_seed ); } - //farm_json is what the area should look like according to jsons - tinymap farm_json; - // We're probably going to rotate this tinymap to match the actual map. - // Let's make sure we don't move NPCs around when doing this. - farm_json.no_rotate_npcs = true; - // TODO: fix point types - farm_json.generate( project_to( omt_tgt ).raw(), calendar::turn ); - //farm_map is what the area actually looks like + // farm_map is what the area actually looks like tinymap farm_map; farm_map.load( project_to( omt_tgt ), false ); + // farm_json is what the area should look like according to jsons (loaded on demand) + 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; @@ -2422,15 +2417,24 @@ static std::pair farm_action( const tripoint_abs_omt &omt_t break; } switch( op ) { - case farm_ops::plow: - //Needs to be plowed to match json - if( is_dirtmound( pos, farm_json, farm_map ) && is_unplowed( pos, farm_map ) ) { + case farm_ops::plow: { + if( !farm_json ) { + farm_json = std::make_unique(); + mapgendata dat( omt_tgt, *farm_json, 0, calendar::turn, nullptr ); + if( !run_mapgen_func( dat.terrain_type()->get_mapgen_id(), dat ) ) { + debugmsg( "Failed to run mapgen for farm map" ); + break; + } + } + // Needs to be plowed to match json + if( is_dirtmound( pos, *farm_json, farm_map ) && is_unplowed( pos, farm_map ) ) { plots_cnt += 1; if( comp ) { farm_map.ter_set( pos, t_dirtmound ); } } break; + } case farm_ops::plant: if( is_dirtmound( pos, farm_map, farm_map ) ) { plots_cnt += 1; diff --git a/src/map.cpp b/src/map.cpp index da4221e143487..48fee5d0a0a55 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -7637,8 +7637,7 @@ bool tinymap::inbounds( const tripoint &p ) const // set up a map just long enough scribble on it // this tinymap should never, ever get saved -fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type, - const int fake_map_z ) +fake_map::fake_map( const ter_id &ter_type ) { const tripoint tripoint_below_zero( 0, 0, fake_map_z ); @@ -7648,8 +7647,8 @@ fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_ std::unique_ptr sm = std::make_unique(); sm->set_all_ter( ter_type ); - sm->set_all_furn( fur_type ); - sm->set_all_traps( trap_type ); + sm->set_all_furn( f_null ); + sm->set_all_traps( tr_null ); setsubmap( get_nonant( { gridx, gridy, fake_map_z } ), sm.get() ); diff --git a/src/map.h b/src/map.h index b4a9e4eff142c..17f0e3163eb6f 100644 --- a/src/map.h +++ b/src/map.h @@ -322,14 +322,6 @@ class map // NOLINTNEXTLINE(performance-noexcept-move-constructor) map &operator=( map && ); - /** - * Tinymaps will ocassionally need to skip npc rotation in map::rotate - * Here's a little trigger for them to opt out. We won't be doing that here, though - */ - virtual bool skip_npc_rotation() const { - return false; - } - /** * Sets a dirty flag on the a given cache. * @@ -2099,12 +2091,6 @@ class tinymap : public map public: tinymap() : map( 2, false ) {} bool inbounds( const tripoint &p ) const override; - - /** Sometimes you need to generate and rotate a tinymap without touching npcs */ - bool skip_npc_rotation() const override { - return no_rotate_npcs; - } - bool no_rotate_npcs = false; }; class fake_map : public tinymap @@ -2112,8 +2098,8 @@ class fake_map : public tinymap private: std::vector> temp_submaps_; public: - fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type, - int fake_map_z ); + explicit fake_map( const ter_id &ter_type = t_dirt ); ~fake_map() override; + static constexpr int fake_map_z = -OVERMAP_DEPTH; }; #endif // CATA_SRC_MAP_H diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 81458dde363a9..4662c371fa239 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -6110,11 +6110,6 @@ void map::rotate( int turns, const bool setpos_safe ) overmap_buffer.get_npcs_near( tripoint_abs_sm( abs_sub ), radius ); for( const shared_ptr_fast &i : npcs ) { npc &np = *i; - // I know we could break out earlier and waste less cycles, this is just easier. - // This is here for tinymaps who don't need to rotate NPCs. - if( skip_npc_rotation() ) { - break; - } const tripoint sq = np.get_location().raw(); real_coords np_rc; np_rc.fromabs( sq.xy() ); @@ -7028,8 +7023,6 @@ bool run_mapgen_update_func( const std::string &update_mapgen_id, mapgendata &da std::pair, std::map> get_changed_ids_from_update( const std::string &update_mapgen_id ) { - const int fake_map_z = -9; - std::map terrains; std::map furnitures; @@ -7039,23 +7032,23 @@ std::pair, std::map> get_changed_ids_from_up return std::make_pair( terrains, furnitures ); } - ::fake_map fake_map( f_null, t_dirt, tr_null, fake_map_z ); + fake_map tmp_map( t_dirt ); oter_id any = oter_id( "field" ); // just need a variable here, it doesn't need to be valid const regional_settings dummy_settings; mapgendata fake_md( any, any, any, any, any, any, any, any, any, any, 0, dummy_settings, - fake_map, any, {}, 0.0f, calendar::turn, nullptr ); + tmp_map, any, {}, 0.0f, calendar::turn, nullptr ); if( update_function->second[0]->update_map( fake_md ) ) { - for( const tripoint &pos : fake_map.points_on_zlevel( fake_map_z ) ) { - ter_id ter_at_pos = fake_map.ter( pos ); + for( const tripoint &pos : tmp_map.points_on_zlevel( fake_map::fake_map_z ) ) { + ter_id ter_at_pos = tmp_map.ter( pos ); if( ter_at_pos != t_dirt ) { terrains[ter_at_pos] += 1; } - if( fake_map.has_furn( pos ) ) { - furn_id furn_at_pos = fake_map.furn( pos ); + if( tmp_map.has_furn( pos ) ) { + furn_id furn_at_pos = tmp_map.furn( pos ); furnitures[furn_at_pos] += 1; } }