From c4d697d16e45fe7fae551503d5bb652a0d691357 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 17 Aug 2023 17:04:01 +0100 Subject: [PATCH 1/5] Initial --- src/overmap.cpp | 55 ++++++++++++++++++++++++++++++-------- src/overmap_connection.cpp | 41 ++++++++++++++++++++++++++-- src/overmap_connection.h | 4 ++- 3 files changed, 86 insertions(+), 14 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index 6bdaaa8368b22..abcf5b9e143b8 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1397,18 +1397,41 @@ struct fixed_overmap_special_data : overmap_special_data { if( initial_dir != cube_direction::last ) { initial_dir = initial_dir + dir; } - if( cit ) { - om.build_connection( cit.pos, rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ); + + bool made_connection = false; + const overmap_connection &connection = *elem.connection; + const cata::flat_set, unsigned int> &origin_terrains = connection.origin_terrains; + + if( connection.connection.origin_is_city() ) { + if( cit ) { + if( om.build_connection_better_name_than_this_hopefully( cit.pos, rp.xy(), elem.p.z, *elem.connection, + must_be_unexplored, initial_dir ) ) { + made_connection = true; + } + } + } else { + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, elem.connection.origin_max_distance ) ) { + for( const std::pair &origin_terrain : *elem.connection.origin_terrains ) { + if( !made_connection && om.check_ot( origin_terrain.first, origin_terrain.second, nearby_point ) ) { + if( om.build_connection_better_name_than_this_hopefully( + nearby_point.xy(), rp.xy(), elem.p.z, *elem.connection, + must_be_unexplored, initial_dir ) ) { + made_connection = true; + } + } + } + } } - // if no city present, search for nearby road within 50 tiles and make - // connection to it instead - else { - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 50 ) ) { - if( om.check_ot( "road", ot_match_type::contains, nearby_point ) ) { - om.build_connection( - nearby_point.xy(), rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ); + if ( !made_connection ) { + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 100 ) ) { //What's the max number you can use here? + for( const std::pair &connection_terrain : *elem.connection.connection_terrains ) { + if( !made_connection && om.check_ot( connection_terrain.first, connection_terrain.second, nearby_point ) ) { + if( om.build_connection_better_name_than_this_hopefully( + nearby_point.xy(), rp.xy(), elem.p.z, *elem.connection, + must_be_unexplored, initial_dir ) ) { + made_connection = true; + } + } } } } @@ -5668,6 +5691,16 @@ void overmap::build_connection( z, initial_dir ); } +bool overmap::build_connection_better_name_than_this_hopefully( + const point_om_omt &source, const point_om_omt &dest, int z, + const overmap_connection &connection, const bool must_be_unexplored, + const cube_direction initial_dir ) +{ + build_connection( + connection, lay_out_connection( connection, source, dest, z, must_be_unexplored ), + z, initial_dir ); +} + // connect the points to each other using a minimum spanning tree // plus rare extra connections to make loops void overmap::connect_closest_points( const std::vector &points, int z, diff --git a/src/overmap_connection.cpp b/src/overmap_connection.cpp index 1704a8d0496c1..8a4c2f252c958 100644 --- a/src/overmap_connection.cpp +++ b/src/overmap_connection.cpp @@ -51,8 +51,24 @@ void overmap_connection::subtype::load( const JsonObject &jo ) { const auto flag_reader = make_flag_reader( connection_subtype_flag_map, "connection subtype flag" ); - - mandatory( jo, false, "terrain", terrain ); + + if( !jo.has_string( "terrain" ) ) { + JsonObject jio = jo.get_object( "terrain" ) ) { + if( jio.test_string() ) { + terrain.first = ( jio.get_string() ); + terrain.second = ot_match_type::type; + } else { + JsonObject pairobj = jio.get_object(); + terrain.first = ( pairobj.get_string( "om_terrain" ) ); + terrain.second = pairobj.get_enum_value( "om_terrain_match_type", + ot_match_type::contains ); + } + } + } else { + terrain.first = jo.get_string( "terrain" ); + terrain.second = ot_match_type::type; + } + mandatory( jo, false, "locations", locations ); optional( jo, false, "basic_cost", basic_cost, 0 ); @@ -101,6 +117,27 @@ bool overmap_connection::has( const int_id &oter ) const void overmap_connection::load( const JsonObject &jo, const std::string_view ) { mandatory( jo, false, "subtypes", subtypes ); + + for( const JsonObject entry : jo.get_array( "origin" ) ) { + + std::pair origin_terrain_partial; + std::pair, unsigned int> origin_terrain; + + origin_terrain_partial.first = ( entry.get_string( "om_terrain" ) ); + if( entry.has_string( "om_terrain_match_type" ) ) { + origin_terrain_partial.second = entry.get_enum_value( "om_terrain_match_type", + ot_match_type::type ); + } else { + origin_terrain_partial.second = ot_match_type::type; + } + origin_terrain.first = origin_terrain_partial; + if ( entry.has_string( "max_distance" ) ) { + origin_terrain.second = static_cast( entry.get_string( "max_distance" ) ); + } else { + origin_terrain.second = 100; + } + origin_terrains.insert( origin_terrain ); + } } void overmap_connection::check() const diff --git a/src/overmap_connection.h b/src/overmap_connection.h index 3d6fde7fc0959..56e88e32b5c68 100644 --- a/src/overmap_connection.h +++ b/src/overmap_connection.h @@ -24,7 +24,7 @@ class overmap_connection public: enum class flag : int { orthogonal }; - string_id terrain; + std::pair terrain; int basic_cost = 0; @@ -52,6 +52,8 @@ class overmap_connection void check() const; void finalize(); + const cata::flat_set, unsigned int>> origin_terrains; + string_id id; std::vector, mod_id>> src; bool was_loaded = false; From ffdf766e7a677bca7e289373ed0ecb8c03badfe9 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 17 Aug 2023 18:43:46 +0100 Subject: [PATCH 2/5] *cross fingers* --- src/overmap.cpp | 90 ++++++++++++++++++++++---------------- src/overmap_connection.cpp | 36 +++++++++------ src/overmap_connection.h | 3 +- 3 files changed, 76 insertions(+), 53 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index abcf5b9e143b8..eb018774cf551 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1397,47 +1397,71 @@ struct fixed_overmap_special_data : overmap_special_data { if( initial_dir != cube_direction::last ) { initial_dir = initial_dir + dir; } - - bool made_connection = false; + const overmap_connection &connection = *elem.connection; - const cata::flat_set, unsigned int> &origin_terrains = connection.origin_terrains; + cata::flat_set, unsigned int>> origin_terrains = connection.origin_terrains; + point_om_omt connection_point; + point_om_omt origin_connection_point; + point_om_omt city_connection_point; + int distance_to_origin; + int distance_to_city; + + bool find_city() { + if( connection.has_city_origin && cit ) { + distance_to_city = cit.get_distance_from( rp ); + city_connection_point = cit.pos; + return true; + } + return false; + } - if( connection.connection.origin_is_city() ) { - if( cit ) { - if( om.build_connection_better_name_than_this_hopefully( cit.pos, rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ) ) { - made_connection = true; - } + bool find_origin() { + int max_range = 0; + for ( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { + max_range = std::max( max_range, origin_terrain.second; } - } else { - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, elem.connection.origin_max_distance ) ) { - for( const std::pair &origin_terrain : *elem.connection.origin_terrains ) { - if( !made_connection && om.check_ot( origin_terrain.first, origin_terrain.second, nearby_point ) ) { - if( om.build_connection_better_name_than_this_hopefully( - nearby_point.xy(), rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ) ) { - made_connection = true; + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, max_range ) ) { + while( !origin_terrains.empty() ) { + for( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { + if( origin_terrain.second < range ) { + //ideally remove it from from origin_terrains + continue; + } + if( om.check_ot( origin_terrain.first.first, origin_terrain.first.second, nearby_point ) ) { + origin_connection_point = nearby_point.xy(); + distance_to_origin = rp.get_distance_from( nearby_point ); + return true; } } } } + return false; } - if ( !made_connection ) { - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 100 ) ) { //What's the max number you can use here? - for( const std::pair &connection_terrain : *elem.connection.connection_terrains ) { - if( !made_connection && om.check_ot( connection_terrain.first, connection_terrain.second, nearby_point ) ) { - if( om.build_connection_better_name_than_this_hopefully( - nearby_point.xy(), rp.xy(), elem.p.z, *elem.connection, - must_be_unexplored, initial_dir ) ) { - made_connection = true; - } - } + + bool find_connection() { + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 200 ) ) { + if( connection.has( nearby_point.ter() ) ) { + connection_point = nearest_point.xy; + return true; } } + return false; + } + + if( find_origin() || find_city() ) { + if( distance_to_origin < distance_to_city ) { + connection_point = origin_connection_point; + } else { + connection_point = city_connection_point; + } + } else if ( find_connection() ) { + om.build_connection( connection_point, rp.xy(), elem.p.z, connection, + must_be_unexplored, initial_dir ) ); + } else { + debugmsg( "Failed to form any \"%s\" connection to special.", connection.id.c_str() ); //Find the specials id to name } } } - return result; } @@ -5691,16 +5715,6 @@ void overmap::build_connection( z, initial_dir ); } -bool overmap::build_connection_better_name_than_this_hopefully( - const point_om_omt &source, const point_om_omt &dest, int z, - const overmap_connection &connection, const bool must_be_unexplored, - const cube_direction initial_dir ) -{ - build_connection( - connection, lay_out_connection( connection, source, dest, z, must_be_unexplored ), - z, initial_dir ); -} - // connect the points to each other using a minimum spanning tree // plus rare extra connections to make loops void overmap::connect_closest_points( const std::vector &points, int z, diff --git a/src/overmap_connection.cpp b/src/overmap_connection.cpp index 8a4c2f252c958..5802777028f81 100644 --- a/src/overmap_connection.cpp +++ b/src/overmap_connection.cpp @@ -118,25 +118,33 @@ void overmap_connection::load( const JsonObject &jo, const std::string_view ) { mandatory( jo, false, "subtypes", subtypes ); - for( const JsonObject entry : jo.get_array( "origin" ) ) { + for( const JsonValue entry : jo.get_array( "origin" ) ) { std::pair origin_terrain_partial; std::pair, unsigned int> origin_terrain; - - origin_terrain_partial.first = ( entry.get_string( "om_terrain" ) ); - if( entry.has_string( "om_terrain_match_type" ) ) { - origin_terrain_partial.second = entry.get_enum_value( "om_terrain_match_type", - ot_match_type::type ); - } else { - origin_terrain_partial.second = ot_match_type::type; - } - origin_terrain.first = origin_terrain_partial; - if ( entry.has_string( "max_distance" ) ) { - origin_terrain.second = static_cast( entry.get_string( "max_distance" ) ); + + if( entry.test_string() ) { + if ( entry == "city" ) { + has_city_origin = true; + } else { + entry.throw_error( "Terrains should be in an object" ); + } } else { - origin_terrain.second = 100; + origin_terrain_partial.first = ( entry.get_string( "om_terrain" ) ); + if( entry.has_string( "om_terrain_match_type" ) ) { + origin_terrain_partial.second = entry.get_enum_value( "om_terrain_match_type", + ot_match_type::type ); + } else { + origin_terrain_partial.second = ot_match_type::type; + } + origin_terrain.first = origin_terrain_partial; + if ( entry.has_string( "max_distance" ) ) { + origin_terrain.second = static_cast( entry.get_string( "max_distance" ) ); + } else { + origin_terrain.second = 100; + } + origin_terrains.insert( origin_terrain ); } - origin_terrains.insert( origin_terrain ); } } diff --git a/src/overmap_connection.h b/src/overmap_connection.h index 56e88e32b5c68..815fd9fdab773 100644 --- a/src/overmap_connection.h +++ b/src/overmap_connection.h @@ -24,7 +24,7 @@ class overmap_connection public: enum class flag : int { orthogonal }; - std::pair terrain; + string_id terrain; //TODO: Make this std::pair int basic_cost = 0; @@ -53,6 +53,7 @@ class overmap_connection void finalize(); const cata::flat_set, unsigned int>> origin_terrains; + bool has_city_origin = false; string_id id; std::vector, mod_id>> src; From ee840b3925e0ab55ae26efbd58d83276eaa77a6f Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:02:30 +0100 Subject: [PATCH 3/5] Moved the functions out --- src/overmap.cpp | 88 +++++++++++++++++++------------------- src/overmap_connection.cpp | 33 ++++---------- src/overmap_connection.h | 1 + 3 files changed, 55 insertions(+), 67 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index eb018774cf551..43fa6c603fa68 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1155,6 +1155,50 @@ struct overmap_special_data { const city &cit, bool must_be_unexplored ) const = 0; }; +bool find_city( const city &cit, const tripoint_om_omt &rp ) { + if( connection.has_city_origin && cit ) { + distance_to_city = cit.get_distance_from( rp ); + if ( distance_to_city <= city_origin_max_distance ) { + city_connection_point = cit.pos; + return true; + } + } + return false; +} + +bool find_origin() { + int max_range = 0; + for ( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { + max_range = std::max( max_range, origin_terrain.second; + } + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, max_range ) ) { + while( !origin_terrains.empty() ) { + for( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { + if( origin_terrain.second < range ) { + //ideally remove it from from origin_terrains + continue; + } + if( om.check_ot( origin_terrain.first.first, origin_terrain.first.second, nearby_point ) ) { + origin_connection_point = nearby_point.xy(); + distance_to_origin = rp.get_distance_from( nearby_point ); + return true; + } + } + } + } + return false; +} + +bool find_connection() { + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 50 ) ) { + if( connection.has( nearby_point.ter() ) ) { + connection_point = nearest_point.xy; + return true; + } + } + return false; +} + struct fixed_overmap_special_data : overmap_special_data { fixed_overmap_special_data() = default; explicit fixed_overmap_special_data( const overmap_special_terrain &ter ) @@ -1405,50 +1449,8 @@ struct fixed_overmap_special_data : overmap_special_data { point_om_omt city_connection_point; int distance_to_origin; int distance_to_city; - - bool find_city() { - if( connection.has_city_origin && cit ) { - distance_to_city = cit.get_distance_from( rp ); - city_connection_point = cit.pos; - return true; - } - return false; - } - - bool find_origin() { - int max_range = 0; - for ( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { - max_range = std::max( max_range, origin_terrain.second; - } - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, max_range ) ) { - while( !origin_terrains.empty() ) { - for( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { - if( origin_terrain.second < range ) { - //ideally remove it from from origin_terrains - continue; - } - if( om.check_ot( origin_terrain.first.first, origin_terrain.first.second, nearby_point ) ) { - origin_connection_point = nearby_point.xy(); - distance_to_origin = rp.get_distance_from( nearby_point ); - return true; - } - } - } - } - return false; - } - - bool find_connection() { - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 200 ) ) { - if( connection.has( nearby_point.ter() ) ) { - connection_point = nearest_point.xy; - return true; - } - } - return false; - } - if( find_origin() || find_city() ) { + if( find_origin() || find_city( cit, rp ) ) { if( distance_to_origin < distance_to_city ) { connection_point = origin_connection_point; } else { diff --git a/src/overmap_connection.cpp b/src/overmap_connection.cpp index 5802777028f81..5031cc0b89056 100644 --- a/src/overmap_connection.cpp +++ b/src/overmap_connection.cpp @@ -51,24 +51,8 @@ void overmap_connection::subtype::load( const JsonObject &jo ) { const auto flag_reader = make_flag_reader( connection_subtype_flag_map, "connection subtype flag" ); - - if( !jo.has_string( "terrain" ) ) { - JsonObject jio = jo.get_object( "terrain" ) ) { - if( jio.test_string() ) { - terrain.first = ( jio.get_string() ); - terrain.second = ot_match_type::type; - } else { - JsonObject pairobj = jio.get_object(); - terrain.first = ( pairobj.get_string( "om_terrain" ) ); - terrain.second = pairobj.get_enum_value( "om_terrain_match_type", - ot_match_type::contains ); - } - } - } else { - terrain.first = jo.get_string( "terrain" ); - terrain.second = ot_match_type::type; - } - + + mandatory( jo, false, "terrain", terrain ); mandatory( jo, false, "locations", locations ); optional( jo, false, "basic_cost", basic_cost, 0 ); @@ -118,16 +102,17 @@ void overmap_connection::load( const JsonObject &jo, const std::string_view ) { mandatory( jo, false, "subtypes", subtypes ); - for( const JsonValue entry : jo.get_array( "origin" ) ) { + for( const JsonObject entry : jo.get_array( "origin" ) ) { std::pair origin_terrain_partial; std::pair, unsigned int> origin_terrain; - if( entry.test_string() ) { - if ( entry == "city" ) { - has_city_origin = true; + if( entry.has_bool( "city" ) ) { + has_city_origin = entry.get_bool( "city" ); + if ( entry.has_string( "max_distance" ) ) { + city_origin_max_distance = static_cast( entry.get_string( "max_distance" ) ); } else { - entry.throw_error( "Terrains should be in an object" ); + city_origin_max_distance = 50; } } else { origin_terrain_partial.first = ( entry.get_string( "om_terrain" ) ); @@ -141,7 +126,7 @@ void overmap_connection::load( const JsonObject &jo, const std::string_view ) if ( entry.has_string( "max_distance" ) ) { origin_terrain.second = static_cast( entry.get_string( "max_distance" ) ); } else { - origin_terrain.second = 100; + origin_terrain.second = 50; } origin_terrains.insert( origin_terrain ); } diff --git a/src/overmap_connection.h b/src/overmap_connection.h index 815fd9fdab773..75fafe048cfde 100644 --- a/src/overmap_connection.h +++ b/src/overmap_connection.h @@ -54,6 +54,7 @@ class overmap_connection const cata::flat_set, unsigned int>> origin_terrains; bool has_city_origin = false; + int city_origin_max_distance; string_id id; std::vector, mod_id>> src; From e3466998d27ae2ac93455979cae2e1d194a54dfe Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 17 Aug 2023 20:37:06 +0100 Subject: [PATCH 4/5] Compiles but hangs if you try to use it --- src/overmap.cpp | 106 +++++++++++++++++++------------------ src/overmap_connection.cpp | 27 +++------- src/overmap_connection.h | 2 +- 3 files changed, 63 insertions(+), 72 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index 43fa6c603fa68..1c2fff8ea7369 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1155,50 +1155,6 @@ struct overmap_special_data { const city &cit, bool must_be_unexplored ) const = 0; }; -bool find_city( const city &cit, const tripoint_om_omt &rp ) { - if( connection.has_city_origin && cit ) { - distance_to_city = cit.get_distance_from( rp ); - if ( distance_to_city <= city_origin_max_distance ) { - city_connection_point = cit.pos; - return true; - } - } - return false; -} - -bool find_origin() { - int max_range = 0; - for ( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { - max_range = std::max( max_range, origin_terrain.second; - } - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, max_range ) ) { - while( !origin_terrains.empty() ) { - for( const std::pair, unsigned int> &origin_terrain : origin_terrains ) { - if( origin_terrain.second < range ) { - //ideally remove it from from origin_terrains - continue; - } - if( om.check_ot( origin_terrain.first.first, origin_terrain.first.second, nearby_point ) ) { - origin_connection_point = nearby_point.xy(); - distance_to_origin = rp.get_distance_from( nearby_point ); - return true; - } - } - } - } - return false; -} - -bool find_connection() { - for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 50 ) ) { - if( connection.has( nearby_point.ter() ) ) { - connection_point = nearest_point.xy; - return true; - } - } - return false; -} - struct fixed_overmap_special_data : overmap_special_data { fixed_overmap_special_data() = default; explicit fixed_overmap_special_data( const overmap_special_terrain &ter ) @@ -1443,14 +1399,64 @@ struct fixed_overmap_special_data : overmap_special_data { } const overmap_connection &connection = *elem.connection; - cata::flat_set, unsigned int>> origin_terrains = connection.origin_terrains; + cata::flat_set, int>> origin_terrains = connection.origin_terrains; point_om_omt connection_point; point_om_omt origin_connection_point; point_om_omt city_connection_point; - int distance_to_origin; - int distance_to_city; + int distance_to_origin = INT_MAX; + int distance_to_city = INT_MAX; + + auto find_city = [&] () { + if( connection.has_city_origin && cit ) { + distance_to_city = cit.get_distance_from( rp ); + if ( distance_to_city <= connection.city_origin_max_distance ) { + city_connection_point = cit.pos; + return true; + } + } + return false; + }; + + //Using this rather than a generic distance so it matches city's get_distance_from + auto get_distance_between = [&] ( tripoint_om_omt a, tripoint_om_omt b ) { + return std::max( static_cast( trig_dist( a, b ) ), 0 ); + }; - if( find_origin() || find_city( cit, rp ) ) { + auto find_origin = [&] () { + int max_range = 0; + for ( const std::pair, int> &origin_terrain : origin_terrains ) { + max_range = std::max( max_range, origin_terrain.second ); + } + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, max_range ) ) { + while( !origin_terrains.empty() ) { + for( const std::pair, int> &origin_terrain : origin_terrains ) { + const int distance = get_distance_between( rp, nearby_point ); + if( origin_terrain.second < distance ) { + //Ideally remove it from origin_terrains + continue; + } + if( om.check_ot( origin_terrain.first.first, origin_terrain.first.second, nearby_point ) ) { + origin_connection_point = nearby_point.xy(); + distance_to_origin = distance; + return true; + } + } + } + } + return false; + }; + + auto find_connection = [&] () { + for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 50 ) ) { + if( connection.has( om.ter( nearby_point ) ) ) { + connection_point = nearby_point.xy(); + return true; + } + } + return false; + }; + + if( find_origin() || find_city() ) { if( distance_to_origin < distance_to_city ) { connection_point = origin_connection_point; } else { @@ -1458,9 +1464,7 @@ struct fixed_overmap_special_data : overmap_special_data { } } else if ( find_connection() ) { om.build_connection( connection_point, rp.xy(), elem.p.z, connection, - must_be_unexplored, initial_dir ) ); - } else { - debugmsg( "Failed to form any \"%s\" connection to special.", connection.id.c_str() ); //Find the specials id to name + must_be_unexplored, initial_dir ); } } } diff --git a/src/overmap_connection.cpp b/src/overmap_connection.cpp index 5031cc0b89056..4ebaffdf20e59 100644 --- a/src/overmap_connection.cpp +++ b/src/overmap_connection.cpp @@ -105,29 +105,16 @@ void overmap_connection::load( const JsonObject &jo, const std::string_view ) for( const JsonObject entry : jo.get_array( "origin" ) ) { std::pair origin_terrain_partial; - std::pair, unsigned int> origin_terrain; + std::pair, int> origin_terrain; - if( entry.has_bool( "city" ) ) { - has_city_origin = entry.get_bool( "city" ); - if ( entry.has_string( "max_distance" ) ) { - city_origin_max_distance = static_cast( entry.get_string( "max_distance" ) ); - } else { - city_origin_max_distance = 50; - } + if( entry.has_member( "city" ) ) { + mandatory( entry, false, "city", has_city_origin ); + optional( entry, false, "max_distance", city_origin_max_distance, 50 ); } else { - origin_terrain_partial.first = ( entry.get_string( "om_terrain" ) ); - if( entry.has_string( "om_terrain_match_type" ) ) { - origin_terrain_partial.second = entry.get_enum_value( "om_terrain_match_type", - ot_match_type::type ); - } else { - origin_terrain_partial.second = ot_match_type::type; - } + mandatory( entry, false, "om_terrain", origin_terrain_partial.first ); + optional( entry, false, "om_terrain_match_type", origin_terrain_partial.second, ot_match_type::type ); origin_terrain.first = origin_terrain_partial; - if ( entry.has_string( "max_distance" ) ) { - origin_terrain.second = static_cast( entry.get_string( "max_distance" ) ); - } else { - origin_terrain.second = 50; - } + optional( entry, false, "max_distance", origin_terrain.second, 50 ); origin_terrains.insert( origin_terrain ); } } diff --git a/src/overmap_connection.h b/src/overmap_connection.h index 75fafe048cfde..2de8d1b9d973e 100644 --- a/src/overmap_connection.h +++ b/src/overmap_connection.h @@ -52,7 +52,7 @@ class overmap_connection void check() const; void finalize(); - const cata::flat_set, unsigned int>> origin_terrains; + cata::flat_set, int>> origin_terrains; bool has_city_origin = false; int city_origin_max_distance; From eca47441085270ccd7502803892270f81c953b3b Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 17 Aug 2023 20:57:59 +0100 Subject: [PATCH 5/5] Astyle Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/overmap.cpp | 30 ++++++++++++++++-------------- src/overmap_connection.cpp | 4 ++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/overmap.cpp b/src/overmap.cpp index 1c2fff8ea7369..b925567a2ffeb 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1399,17 +1399,18 @@ struct fixed_overmap_special_data : overmap_special_data { } const overmap_connection &connection = *elem.connection; - cata::flat_set, int>> origin_terrains = connection.origin_terrains; + cata::flat_set, int>> origin_terrains = + connection.origin_terrains; point_om_omt connection_point; point_om_omt origin_connection_point; point_om_omt city_connection_point; int distance_to_origin = INT_MAX; int distance_to_city = INT_MAX; - - auto find_city = [&] () { + + auto find_city = [&]() { if( connection.has_city_origin && cit ) { distance_to_city = cit.get_distance_from( rp ); - if ( distance_to_city <= connection.city_origin_max_distance ) { + if( distance_to_city <= connection.city_origin_max_distance ) { city_connection_point = cit.pos; return true; } @@ -1418,18 +1419,20 @@ struct fixed_overmap_special_data : overmap_special_data { }; //Using this rather than a generic distance so it matches city's get_distance_from - auto get_distance_between = [&] ( tripoint_om_omt a, tripoint_om_omt b ) { + auto get_distance_between = [&]( tripoint_om_omt a, tripoint_om_omt b ) { return std::max( static_cast( trig_dist( a, b ) ), 0 ); }; - - auto find_origin = [&] () { + + auto find_origin = [&]() { int max_range = 0; - for ( const std::pair, int> &origin_terrain : origin_terrains ) { + for( const std::pair, int> &origin_terrain : + origin_terrains ) { max_range = std::max( max_range, origin_terrain.second ); } for( const tripoint_om_omt &nearby_point : closest_points_first( rp, max_range ) ) { while( !origin_terrains.empty() ) { - for( const std::pair, int> &origin_terrain : origin_terrains ) { + for( const std::pair, int> &origin_terrain : + origin_terrains ) { const int distance = get_distance_between( rp, nearby_point ); if( origin_terrain.second < distance ) { //Ideally remove it from origin_terrains @@ -1445,8 +1448,8 @@ struct fixed_overmap_special_data : overmap_special_data { } return false; }; - - auto find_connection = [&] () { + + auto find_connection = [&]() { for( const tripoint_om_omt &nearby_point : closest_points_first( rp, 50 ) ) { if( connection.has( om.ter( nearby_point ) ) ) { connection_point = nearby_point.xy(); @@ -1455,16 +1458,15 @@ struct fixed_overmap_special_data : overmap_special_data { } return false; }; - if( find_origin() || find_city() ) { if( distance_to_origin < distance_to_city ) { connection_point = origin_connection_point; } else { connection_point = city_connection_point; } - } else if ( find_connection() ) { + } else if( find_connection() ) { om.build_connection( connection_point, rp.xy(), elem.p.z, connection, - must_be_unexplored, initial_dir ); + must_be_unexplored, initial_dir ); } } } diff --git a/src/overmap_connection.cpp b/src/overmap_connection.cpp index 4ebaffdf20e59..9872a038d10c4 100644 --- a/src/overmap_connection.cpp +++ b/src/overmap_connection.cpp @@ -106,13 +106,13 @@ void overmap_connection::load( const JsonObject &jo, const std::string_view ) std::pair origin_terrain_partial; std::pair, int> origin_terrain; - if( entry.has_member( "city" ) ) { mandatory( entry, false, "city", has_city_origin ); optional( entry, false, "max_distance", city_origin_max_distance, 50 ); } else { mandatory( entry, false, "om_terrain", origin_terrain_partial.first ); - optional( entry, false, "om_terrain_match_type", origin_terrain_partial.second, ot_match_type::type ); + optional( entry, false, "om_terrain_match_type", origin_terrain_partial.second, + ot_match_type::type ); origin_terrain.first = origin_terrain_partial; optional( entry, false, "max_distance", origin_terrain.second, 50 ); origin_terrains.insert( origin_terrain );