From 1bdfcd014e93b466b850637e634da74e0c4b66a5 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Fri, 20 Dec 2024 11:35:56 +0100 Subject: [PATCH] made zones typed --- src/activity_item_handling.cpp | 6 +- src/clzones.cpp | 182 ++++++++++++++++++++++----------- src/clzones.h | 83 +++++++++++---- src/game.cpp | 115 ++++++++++++++------- src/mapgen.cpp | 2 +- src/npctalk_funcs.cpp | 6 +- src/npctrade_utils.cpp | 10 +- src/trade_ui.cpp | 8 +- src/vehicle.cpp | 8 +- tests/act_build_test.cpp | 6 +- tests/clzones_test.cpp | 16 +-- tests/faction_camp_test.cpp | 4 +- tests/zones_custom_test.cpp | 12 +-- 13 files changed, 301 insertions(+), 157 deletions(-) diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index f9d73d1d9fdde..5a609e688b740 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -1500,8 +1500,7 @@ static std::vector> requirements_map( already_there_spots.push_back( elem ); combined_spots.push_back( elem ); } - // TODO: fix point types - for( const tripoint &elem : mgr.get_point_set_loot( + for( const tripoint_bub_ms &elem : mgr.get_point_set_loot( you.get_location(), distance, you.is_npc(), _fac_id( you ) ) ) { // if there is a loot zone that's already near the work spot, we don't want it to be added twice. if( std::find( already_there_spots.begin(), already_there_spots.end(), @@ -2804,8 +2803,7 @@ static requirement_check_result generic_multi_activity_check_requirement( requirement_id what_we_need; std::vector loot_zone_spots; std::vector combined_spots; - // TODO: fix point types - for( const tripoint &elem : mgr.get_point_set_loot( + for( const tripoint_bub_ms &elem : mgr.get_point_set_loot( abspos, ACTIVITY_SEARCH_DISTANCE, you.is_npc(), _fac_id( you ) ) ) { loot_zone_spots.emplace_back( elem ); combined_spots.emplace_back( elem ); diff --git a/src/clzones.cpp b/src/clzones.cpp index d609bb7008eee..90bcb1edba89e 100644 --- a/src/clzones.cpp +++ b/src/clzones.cpp @@ -670,13 +670,19 @@ bool zone_data::set_type() return false; } -void zone_data::set_position( const std::pair &position, +void zone_data::set_position( const std::pair &position, const bool manual, bool update_avatar, bool skip_cache_update, bool suppress_display_update ) { if( is_vehicle && manual ) { debugmsg( "Tried moving a lootzone bound to a vehicle part" ); return; } + + if( is_personal ) { + debugmsg( "Tried moving a personal lootzone to absolute location" ); + return; + } + bool adjust_display = is_displayed && !suppress_display_update; if( adjust_display ) { @@ -695,6 +701,37 @@ void zone_data::set_position( const std::pair &position, } } +void zone_data::set_position( const std::pair &position, + const bool manual, bool update_avatar, bool skip_cache_update, bool suppress_display_update ) +{ + if( is_vehicle && manual ) { + debugmsg( "Tried moving a lootzone bound to a vehicle part" ); + return; + } + + if( !is_personal ) { + debugmsg( "Tried moving a normal lootzone to relative location" ); + return; + } + + bool adjust_display = is_displayed && !suppress_display_update; + + if( adjust_display ) { + toggle_display(); + } + + personal_start = position.first; + personal_end = position.second; + + if( adjust_display ) { + toggle_display(); + } + + if( !skip_cache_update ) { + zone_manager::get_manager().cache_data( update_avatar ); + } +} + void zone_data::set_enabled( const bool enabled_arg ) { zone_manager::get_manager().zone_edited( *this ); @@ -792,28 +829,32 @@ void zone_data::toggle_display() // Take care of the situation where parts of overlapping zones were erased by the toggling. if( !is_displayed ) { - const point_abs_ms start = point_abs_ms( std::min( this->start.x, this->end.x ), - std::min( this->start.y, this->end.y ) ); + const point_abs_ms start = { std::min( this->start.x(), this->end.x() ), + std::min( this->start.y(), this->end.y() ) + }; - const point_abs_ms end = point_abs_ms( std::max( this->start.x, this->end.x ), - std::max( this->start.y, this->end.y ) ); + const point_abs_ms end = { std::max( this->start.x(), this->end.x() ), + std::max( this->start.y(), this->end.y() ) + }; const inclusive_rectangle zone_rectangle( start, end ); for( zone_manager::ref_zone_data zone : zone_manager::get_manager().get_zones() ) { // Assumes zones are a single Z level only. Also, inclusive_cuboid doesn't have an overlap function... if( zone.get().get_is_displayed() && zone.get().get_type() == this->get_type() && - this->start.z == zone.get().get_start_point().z() ) { + this->start.z() == zone.get().get_start_point().z() ) { const point_abs_ms candidate_begin = zone.get().get_start_point().xy(); const point_abs_ms candidate_stop = zone.get().get_end_point().xy(); - const point_abs_ms candidate_start = point_abs_ms( std::min( candidate_begin.x(), - candidate_stop.x() ), - std::min( candidate_begin.y(), candidate_stop.y() ) ); + const point_abs_ms candidate_start = { std::min( candidate_begin.x(), + candidate_stop.x() ), + std::min( candidate_begin.y(), candidate_stop.y() ) + }; - const point_abs_ms candidate_end = point_abs_ms( std::max( candidate_begin.x(), - candidate_stop.x() ), - std::max( candidate_begin.y(), candidate_stop.y() ) ); + const point_abs_ms candidate_end = { std::max( candidate_begin.x(), + candidate_stop.x() ), + std::max( candidate_begin.y(), candidate_stop.y() ) + }; const inclusive_rectangle candidate_rectangle( candidate_start, candidate_end ); @@ -945,16 +986,16 @@ std::unordered_set zone_manager::get_point_set( const zone_type return type_iter->second; } -std::unordered_set zone_manager::get_point_set_loot( const tripoint_abs_ms &where, +std::unordered_set zone_manager::get_point_set_loot( const tripoint_abs_ms &where, int radius, const faction_id &fac ) const { return get_point_set_loot( where, radius, false, fac ); } -std::unordered_set zone_manager::get_point_set_loot( const tripoint_abs_ms &where, +std::unordered_set zone_manager::get_point_set_loot( const tripoint_abs_ms &where, int radius, bool npc_search, const faction_id &fac ) const { - std::unordered_set res; + std::unordered_set res; map &here = get_map(); for( const std::pair> cache : area_cache ) { zone_type_id type = zone_data::unhash_type( cache.first ); @@ -962,7 +1003,7 @@ std::unordered_set zone_manager::get_point_set_loot( const tripoint_ab if( fac == z_fac && type.str().substr( 0, 4 ) == "LOOT" ) { for( tripoint_abs_ms point : cache.second ) { if( square_dist( where, point ) <= radius ) { - res.emplace( here.bub_from_abs( point ).raw() ); + res.emplace( here.bub_from_abs( point ) ); } } } @@ -973,7 +1014,7 @@ std::unordered_set zone_manager::get_point_set_loot( const tripoint_ab if( fac == z_fac && type.str().substr( 0, 4 ) == "LOOT" ) { for( tripoint_abs_ms point : cache.second ) { if( square_dist( where, point ) <= radius ) { - res.emplace( here.bub_from_abs( point ).raw() ); + res.emplace( here.bub_from_abs( point ) ); } } } @@ -984,7 +1025,7 @@ std::unordered_set zone_manager::get_point_set_loot( const tripoint_ab zone_type_id type = zone_data::unhash_type( cache.first ); if( type == zone_type_NO_NPC_PICKUP ) { for( tripoint_abs_ms point : cache.second ) { - res.erase( here.bub_from_abs( point ).raw() ); + res.erase( here.bub_from_abs( point ) ); } } } @@ -1375,7 +1416,7 @@ const zone_data *zone_manager::get_bottom_zone( // which constructor of the key-value pair we use which depends on new_zone being an rvalue or lvalue and constness. // If you are passing new_zone from a non-const iterator, be prepared for a move! This // may break some iterators like map iterators if you are less specific! -void zone_manager::create_vehicle_loot_zone( vehicle &vehicle, const point &mount_point, +void zone_manager::create_vehicle_loot_zone( vehicle &vehicle, const point_rel_ms &mount_point, zone_data &new_zone, map *pmap ) { //create a vehicle loot zone @@ -1388,38 +1429,47 @@ void zone_manager::create_vehicle_loot_zone( vehicle &vehicle, const point &moun } void zone_manager::add( const std::string &name, const zone_type_id &type, const faction_id &fac, - const bool invert, const bool enabled, const tripoint &start, - const tripoint &end, const shared_ptr_fast &options, const bool personal, + const bool invert, const bool enabled, const tripoint_abs_ms &start, + const tripoint_abs_ms &end, const shared_ptr_fast &options, bool silent, map *pmap ) { map &here = pmap == nullptr ? get_map() : *pmap; - zone_data new_zone = zone_data( name, type, fac, invert, enabled, start, end, options, personal ); + zone_data new_zone = zone_data( name, type, fac, invert, enabled, start, end, options ); // only non personal zones can be vehicle zones - if( !personal ) { - optional_vpart_position const vp = here.veh_at( here.bub_from_abs( tripoint_abs_ms( start ) ) ); - if( vp && vp->vehicle().get_owner() == fac && vp.cargo() ) { - // TODO:Allow for loot zones on vehicles to be larger than 1x1 - if( start == end && - ( silent || query_yn( _( "Bind this zone to the cargo part here?" ) ) ) ) { - // TODO: refactor zone options for proper validation code - if( !silent && - ( type == zone_type_FARM_PLOT || type == zone_type_CONSTRUCTION_BLUEPRINT ) ) { - popup( _( "You cannot add that type of zone to a vehicle." ), PF_NONE ); - return; - } - - create_vehicle_loot_zone( vp->vehicle(), vp->mount_pos().raw(), new_zone, pmap ); + optional_vpart_position const vp = here.veh_at( here.bub_from_abs( start ) ); + if( vp && vp->vehicle().get_owner() == fac && vp.cargo() ) { + // TODO:Allow for loot zones on vehicles to be larger than 1x1 + if( start == end && + ( silent || query_yn( _( "Bind this zone to the cargo part here?" ) ) ) ) { + // TODO: refactor zone options for proper validation code + if( !silent && + ( type == zone_type_FARM_PLOT || type == zone_type_CONSTRUCTION_BLUEPRINT ) ) { + popup( _( "You cannot add that type of zone to a vehicle." ), PF_NONE ); return; } + + create_vehicle_loot_zone( vp->vehicle(), vp->mount_pos(), new_zone, pmap ); + return; } } //Create a regular zone zones.push_back( new_zone ); - if( personal ) { - num_personal_zones++; - } + cache_data(); +} + +void zone_manager::add( const std::string &name, const zone_type_id &type, const faction_id &fac, + const bool invert, const bool enabled, const tripoint_rel_ms &start, + const tripoint_rel_ms &end, const shared_ptr_fast &options, + bool silent, map *pmap ) +{ + map &here = pmap == nullptr ? get_map() : *pmap; + zone_data new_zone = zone_data( name, type, fac, invert, enabled, start, end, options ); + + //Create a regular zone + zones.push_back( new_zone ); + num_personal_zones++; cache_data(); } @@ -1507,7 +1557,7 @@ void _rotate_zone( map &target_map, zone_data &zone, int turns ) target_map.getglobal( tripoint_bub_ms( std::max( z_l_start.x(), z_l_end.x() ), std::max( z_l_start.y(), z_l_end.y() ), z_end.z() ) ); - zone.set_position( std::make_pair( first.raw(), second.raw() ), false, true, false, true ); + zone.set_position( std::make_pair( first, second ), false, true, false, true ); } } @@ -1622,8 +1672,13 @@ void zone_data::serialize( JsonOut &json ) const json.member( "is_vehicle", is_vehicle ); json.member( "is_personal", is_personal ); json.member( "cached_shift", cached_shift ); - json.member( "start", start ); - json.member( "end", end ); + if( is_personal ) { + json.member( "start", personal_start ); + json.member( "end", personal_end ); + } else { + json.member( "start", start ); + json.member( "end", end ); + } json.member( "is_displayed", is_displayed ); options->serialize( json ); json.end_object(); @@ -1664,19 +1719,29 @@ void zone_data::deserialize( const JsonObject &data ) } //Legacy support if( data.has_member( "start_x" ) ) { - tripoint s; - tripoint e; - data.read( "start_x", s.x ); - data.read( "start_y", s.y ); - data.read( "start_z", s.z ); - data.read( "end_x", e.x ); - data.read( "end_y", e.y ); - data.read( "end_z", e.z ); - start = s; - end = e; + tripoint_abs_ms s; + tripoint_abs_ms e; + data.read( "start_x", s.x() ); + data.read( "start_y", s.y() ); + data.read( "start_z", s.z() ); + data.read( "end_x", e.x() ); + data.read( "end_y", e.y() ); + data.read( "end_z", e.z() ); + if( is_personal ) { + personal_start = tripoint_rel_ms( s.raw() ); + personal_end = tripoint_rel_ms( e.raw() ); + } else { + start = s; + end = e; + } } else { - data.read( "start", start ); - data.read( "end", end ); + if( is_personal ) { + data.read( "start", personal_start ); + data.read( "end", personal_end ); + } else { + data.read( "start", start ); + data.read( "end", end ); + } } if( data.has_member( "is_displayed" ) ) { data.read( "is_displayed", is_displayed ); @@ -1804,18 +1869,19 @@ void zone_manager::revert_vzones() } } -void mapgen_place_zone( tripoint const &start, tripoint const &end, zone_type_id const &type, +void mapgen_place_zone( tripoint_abs_ms const &start, tripoint_abs_ms const &end, + zone_type_id const &type, faction_id const &fac, std::string const &name, std::string const &filter, map *pmap ) { zone_manager &mgr = zone_manager::get_manager(); auto options = zone_options::create( type ); - tripoint const s_ = std::min( start, end ); - tripoint const e_ = std::max( start, end ); + tripoint_abs_ms const s_ = std::min( start, end ); + tripoint_abs_ms const e_ = std::max( start, end ); if( type == zone_type_LOOT_CUSTOM || type == zone_type_LOOT_ITEM_GROUP ) { if( dynamic_cast( &*options ) != nullptr ) { dynamic_cast( &*options )->set_mark( filter ); } } - mgr.add( name, type, fac, false, true, s_, e_, options, false, true, pmap ); + mgr.add( name, type, fac, false, true, s_, e_, options, true, pmap ); } diff --git a/src/clzones.h b/src/clzones.h index 1df5fb703331d..376003d3b8e6f 100644 --- a/src/clzones.h +++ b/src/clzones.h @@ -356,10 +356,12 @@ class zone_data // if the zone has been turned off for an action bool temporarily_disabled; // NOLINT(cata-serialize) bool is_vehicle; - tripoint start; - tripoint end; + tripoint_abs_ms start; + tripoint_abs_ms end; //centered on the player bool is_personal; + tripoint_rel_ms personal_start; + tripoint_rel_ms personal_end; // for personal zones a cached value for the global shift to where the player was at activity start tripoint_abs_ms cached_shift; shared_ptr_fast options; @@ -373,17 +375,19 @@ class zone_data temporarily_disabled = false; is_vehicle = false; is_personal = false; - start = tripoint::zero; - end = tripoint::zero; - cached_shift = {}; + start = tripoint_abs_ms::zero; + end = tripoint_abs_ms::zero; + personal_start = tripoint_rel_ms::zero; + personal_end = tripoint_rel_ms::zero; + cached_shift = tripoint_abs_ms::zero; options = nullptr; is_displayed = false; } zone_data( const std::string &_name, const zone_type_id &_type, const faction_id &_faction, bool _invert, const bool _enabled, - const tripoint &_start, const tripoint &_end, - const shared_ptr_fast &_options = nullptr, bool personal = false, + const tripoint_abs_ms &_start, const tripoint_abs_ms &_end, + const shared_ptr_fast &_options = nullptr, bool _is_displayed = false ) { name = _name; type = _type; @@ -391,7 +395,7 @@ class zone_data invert = _invert; enabled = _enabled; is_vehicle = false; - is_personal = personal; + is_personal = false; start = _start; end = _end; is_displayed = _is_displayed; @@ -404,13 +408,40 @@ class zone_data } } + zone_data( const std::string &_name, const zone_type_id &_type, const faction_id &_faction, + bool _invert, const bool _enabled, + const tripoint_rel_ms &_start, const tripoint_rel_ms &_end, + const shared_ptr_fast &_options = nullptr, + bool _is_displayed = false ) { + name = _name; + type = _type; + faction = _faction; + invert = _invert; + enabled = _enabled; + is_vehicle = false; + is_personal = true; + personal_start = _start; + personal_end = _end; + is_displayed = _is_displayed; + + // ensure that supplied options is of correct class + if( _options == nullptr || !zone_options::is_valid( type, *_options ) ) { + options = zone_options::create( type ); + } else { + options = _options; + } + } + // returns true if name is changed bool set_name(); // returns true if type is changed bool set_type(); // We need to be able to suppress the display of zones when the movement is part of a map rotation, as the underlying // field is automatically rotated by the map rotation itself. - void set_position( const std::pair &position, bool manual = true, + // One version for personal zones and one for the rest + void set_position( const std::pair &position, bool manual = true, + bool update_avatar = true, bool skip_cache_update = false, bool suppress_display_update = false ); + void set_position( const std::pair &position, bool manual = true, bool update_avatar = true, bool skip_cache_update = false, bool suppress_display_update = false ); void set_enabled( bool enabled_arg ); void set_temporary_disabled( bool enabled_arg ); @@ -472,15 +503,15 @@ class zone_data } tripoint_abs_ms get_start_point() const { if( is_personal ) { - return start + cached_shift; + return cached_shift + personal_start; } - return tripoint_abs_ms{ start }; + return start; } tripoint_abs_ms get_end_point() const { if( is_personal ) { - return end + cached_shift; + return cached_shift + personal_end; } - return tripoint_abs_ms{ end }; + return end; } void update_cached_shift( const tripoint_abs_ms &player_loc ) { cached_shift = player_loc; @@ -503,9 +534,9 @@ class zone_data // if it is personal then the zone is local if( is_personal ) { return inclusive_cuboid( - start + cached_shift, end + cached_shift ).contains( p ); + cached_shift + personal_start, cached_shift + personal_end ).contains( p ); } - return inclusive_cuboid( start, end ).contains( p.raw() ); + return inclusive_cuboid( start, end ).contains( p ); } void serialize( JsonOut &json ) const; void deserialize( const JsonObject &data ); @@ -556,18 +587,27 @@ class zone_manager void clear(); + // For addition of regular and vehicle zones + void add( const std::string &name, const zone_type_id &type, const faction_id &faction, + bool invert, bool enabled, + const tripoint_abs_ms &start, const tripoint_abs_ms &end, + const shared_ptr_fast &options = nullptr, + bool silent = false, map *pmap = nullptr ); + + // For addition of personal zones void add( const std::string &name, const zone_type_id &type, const faction_id &faction, bool invert, bool enabled, - const tripoint &start, const tripoint &end, - const shared_ptr_fast &options = nullptr, bool personal = false, + const tripoint_rel_ms &start, const tripoint_rel_ms &end, + const shared_ptr_fast &options = nullptr, bool silent = false, map *pmap = nullptr ); + // get first matching zone const zone_data *get_zone_at( const tripoint_abs_ms &where, const zone_type_id &type, const faction_id &fac = your_fac ) const; // get all matching zones (useful for LOOT_CUSTOM and LOOT_ITEM_GROUP) std::vector get_zones_at( const tripoint_abs_ms &where, const zone_type_id &type, const faction_id &fac = your_fac ) const; - void create_vehicle_loot_zone( class vehicle &vehicle, const point &mount_point, + void create_vehicle_loot_zone( class vehicle &vehicle, const point_rel_ms &mount_point, zone_data &new_zone, map *pmap = nullptr ); bool remove( zone_data &zone ); @@ -614,9 +654,9 @@ class zone_manager void swap( zone_data &a, zone_data &b ); void rotate_zones( map &target_map, int turns ); // list of tripoints of zones that are loot zones only - std::unordered_set get_point_set_loot( + std::unordered_set get_point_set_loot( const tripoint_abs_ms &where, int radius, const faction_id &fac = your_fac ) const; - std::unordered_set get_point_set_loot( + std::unordered_set get_point_set_loot( const tripoint_abs_ms &where, int radius, bool npc_search, const faction_id &fac = your_fac ) const; @@ -636,7 +676,8 @@ class zone_manager void deserialize( const JsonValue &jv ); }; -void mapgen_place_zone( tripoint const &start, tripoint const &end, zone_type_id const &type, +void mapgen_place_zone( tripoint_abs_ms const &start, tripoint_abs_ms const &end, + zone_type_id const &type, faction_id const &fac = your_fac, std::string const &name = {}, std::string const &filter = {}, map *pmap = nullptr ); diff --git a/src/game.cpp b/src/game.cpp index 89b45d876ccd7..8a67662422081 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7049,7 +7049,7 @@ void game::zones_manager() // In C++20 we could have the return type depend on the parameter using // if constexpr( personal ) but for now it will just return tripoints. auto query_position = - [&]( bool personal = false ) -> std::optional> { + [&]( ) -> std::optional> { on_out_of_scope invalidate_current_ui( [&]() { ui.mark_resize(); @@ -7077,31 +7077,64 @@ void game::zones_manager() const look_around_result second = look_around( /*show_window=*/false, center, *first.position, true, true, false ); if( second.position ) { - if( personal ) { - tripoint first_rel( - std::min( first.position->x() - u.posx(), second.position->x() - u.posx() ), - std::min( first.position->y() - u.posy(), second.position->y() - u.posy() ), - std::min( first.position->z() - u.posz(), second.position->z() - u.posz() ) ); - tripoint second_rel( - std::max( first.position->x() - u.posx(), second.position->x() - u.posx() ), - std::max( first.position->y() - u.posy(), second.position->y() - u.posy() ), - std::max( first.position->z() - u.posz(), second.position->z() - u.posz() ) ); - return { { first_rel, second_rel } }; - } tripoint_abs_ms first_abs = - m.getglobal( - tripoint_bub_ms( - std::min( first.position->x(), second.position->x() ), - std::min( first.position->y(), second.position->y() ), - std::min( first.position->z(), second.position->z() ) ) ); + m.getglobal( + tripoint_bub_ms( + std::min( first.position->x(), second.position->x() ), + std::min( first.position->y(), second.position->y() ), + std::min( first.position->z(), second.position->z() ) ) ); tripoint_abs_ms second_abs = - m.getglobal( - tripoint_bub_ms( - std::max( first.position->x(), second.position->x() ), - std::max( first.position->y(), second.position->y() ), - std::max( first.position->z(), second.position->z() ) ) ); + m.getglobal( + tripoint_bub_ms( + std::max( first.position->x(), second.position->x() ), + std::max( first.position->y(), second.position->y() ), + std::max( first.position->z(), second.position->z() ) ) ); - return { { first_abs.raw(), second_abs.raw() } }; + return { { first_abs, second_abs } }; + } + } + + return std::nullopt; + }; + + auto query_personal_position = + [&]() -> std::optional> { + on_out_of_scope invalidate_current_ui( [&]() + { + ui.mark_resize(); + } ); + restore_on_out_of_scope show_prev( show ); + restore_on_out_of_scope zone_start_prev( zone_start ); + restore_on_out_of_scope zone_end_prev( zone_end ); + show = false; + zone_start = std::nullopt; + zone_end = std::nullopt; + ui.mark_resize(); + + static_popup popup; + popup.on_top( true ); + popup.message( "%s", _( "Select first point." ) ); + + tripoint_bub_ms center = u.pos_bub() + u.view_offset; + + const look_around_result first = + look_around( /*show_window=*/false, center, center, false, true, false ); + if( first.position ) + { + popup.message( "%s", _( "Select second point." ) ); + + const look_around_result second = look_around( /*show_window=*/false, center, *first.position, + true, true, false ); + if( second.position ) { + tripoint_rel_ms first_rel( + std::min( first.position->x() - u.posx(), second.position->x() - u.posx() ), + std::min( first.position->y() - u.posy(), second.position->y() - u.posy() ), + std::min( first.position->z() - u.posz(), second.position->z() - u.posz() ) ); + tripoint_rel_ms second_rel( + std::max( first.position->x() - u.posx(), second.position->x() - u.posx() ), + std::max( first.position->y() - u.posy(), second.position->y() - u.posy() ), + std::max( first.position->z() - u.posz(), second.position->z() - u.posz() ) ); + return { { first_rel, second_rel } }; } } @@ -7236,9 +7269,8 @@ void game::zones_manager() } } - // TODO: fix point types mgr.add( name, id, get_player_character().get_faction()->id, false, true, - position->first, position->second, options, false ); + position->first, position->second, options ); zones = get_zones(); active_index = zone_cnt - 1; @@ -7282,15 +7314,15 @@ void game::zones_manager() } const std::string &name = maybe_name.value(); - const auto position = query_position( true ); + const std::optional> position = + query_personal_position( ); if( !position ) { break; } //add a zone that is relative to the avatar position - // TODO: fix point types mgr.add( name, id, get_player_character().get_faction()->id, false, true, - position->first, position->second, options, true ); + position->first, position->second, options ); zones = get_zones(); active_index = zone_cnt - 1; @@ -7386,14 +7418,21 @@ void game::zones_manager() } break; case 4: { - const auto pos = query_position( zone.get_is_personal() ); - // FIXME: this comparison is nonsensival in the - // personal zone case because it's between different - // coordinate systems. - if( pos && ( pos->first != zone.get_start_point().raw() || - pos->second != zone.get_end_point().raw() ) ) { - zone.set_position( *pos ); - stuff_changed = true; + if( zone.get_is_personal() ) { + const std::optional> pos = query_personal_position(); + if( pos && ( u.get_location() + pos->first != zone.get_start_point() || + u.get_location() + pos->second != zone.get_end_point() ) ) { + zone.set_position( { pos->first, pos->second } ); + stuff_changed = true; + + } + } else { + const std::optional> pos = query_position(); + if( pos && ( pos->first != zone.get_start_point() || + pos->second != zone.get_end_point() ) ) { + zone.set_position( { pos->first, pos->second } ); + stuff_changed = true; + } } break; } @@ -7429,9 +7468,9 @@ void game::zones_manager() if( zone.get_is_personal() ) { const tripoint_rel_ms new_start_point_rl = new_start_point - u.get_location(); const tripoint_rel_ms new_end_point_rl = new_end_point - u.get_location(); - zone.set_position( std::make_pair( new_start_point_rl.raw(), new_end_point_rl.raw() ) ); + zone.set_position( std::make_pair( new_start_point_rl, new_end_point_rl ) ); } else { - zone.set_position( std::make_pair( new_start_point.raw(), new_end_point.raw() ) ); + zone.set_position( std::make_pair( new_start_point, new_end_point ) ); } stuff_changed = true; } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index d3ce5ca0ada1a..f537e56db7581 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -3485,7 +3485,7 @@ class jmapgen_zone : public jmapgen_piece dat.zlevel() + z.get() ) ); const tripoint_abs_ms end = dat.m.getglobal( tripoint_bub_ms( int( x.valmax ), int( y.valmax ), dat.zlevel() + z.get() ) ); - mapgen_place_zone( start.raw(), end.raw(), chosen_zone_type, chosen_faction, name, filter, &dat.m ); + mapgen_place_zone( start, end, chosen_zone_type, chosen_faction, name, filter, &dat.m ); } void check( const std::string &oter_name, const mapgen_parameters ¶meters, diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index 807fe415c6290..4ef037f1b411a 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -1292,9 +1292,9 @@ void talk_function::distribute_food_auto( npc &p ) const tripoint_abs_ms bottom_right = npc_abs_loc + point::south_east; std::string zone_name = "ERROR IF YOU SEE THIS (dummy zone talk_function::distribute_food_auto)"; const faction_id &fac_id = p.get_fac_id(); - mgr.add( zone_name, zone_type_CAMP_FOOD, fac_id, false, true, top_left.raw(), bottom_right.raw() ); - mgr.add( zone_name, zone_type_CAMP_STORAGE, fac_id, false, true, top_left.raw(), - bottom_right.raw() ); + mgr.add( zone_name, zone_type_CAMP_FOOD, fac_id, false, true, top_left, bottom_right ); + mgr.add( zone_name, zone_type_CAMP_STORAGE, fac_id, false, true, top_left, + bottom_right ); npc_camp->distribute_food( false ); // Now we clean up all camp zones, though there SHOULD only be the two we just made auto lambda_remove_zones = [&mgr, &fac_id]( zone_type_id type_to_remove ) { diff --git a/src/npctrade_utils.cpp b/src/npctrade_utils.cpp index 6dce766e37de2..665dbe46ebcff 100644 --- a/src/npctrade_utils.cpp +++ b/src/npctrade_utils.cpp @@ -104,11 +104,11 @@ void add_fallback_zone( npc &guy ) if( points.empty() ) { zmgr.add( fallback_name, zone_type_LOOT_UNSORTED, fac_id, false, true, - loc.raw() + tripoint::north_west, loc.raw() + tripoint::south_east ); + loc + tripoint::north_west, loc + tripoint::south_east ); } else { for( tripoint_abs_ms const &t : points ) { - zmgr.add( fallback_name, zone_type_LOOT_UNSORTED, fac_id, false, true, t.raw(), - t.raw() ); + zmgr.add( fallback_name, zone_type_LOOT_UNSORTED, fac_id, false, true, t, + t ); } } DebugLog( DebugLevel::D_WARNING, DebugClass::D_GAME ) @@ -157,13 +157,13 @@ std::list distribute_items_to_npc_zones( std::list &items, npc &guy void consume_items_in_zones( npc &guy, time_duration const &elapsed ) { - std::unordered_set const src = zone_manager::get_manager().get_point_set_loot( + std::unordered_set const src = zone_manager::get_manager().get_point_set_loot( guy.get_location(), PICKUP_RANGE, guy.get_fac_id() ); consume_cache cache; map &here = get_map(); - for( tripoint const &pt : src ) { + for( tripoint_bub_ms const &pt : src ) { consume_queue consumed; std::list stack = here.items_with( pt, [&guy]( item const & it ) { diff --git a/src/trade_ui.cpp b/src/trade_ui.cpp index b30fbf43fb3a1..ec484ef9b42a2 100644 --- a/src/trade_ui.cpp +++ b/src/trade_ui.cpp @@ -121,12 +121,12 @@ trade_ui::trade_ui( party_t &you, npc &trader, currency_t cost, std::string titl zone_manager &zmgr = zone_manager::get_manager(); - std::unordered_set const src = + std::unordered_set const src = zmgr.get_point_set_loot( trader.get_location(), PICKUP_RANGE, trader.get_fac_id() ); - for( tripoint const &pt : src ) { - _panes[_trader]->add_map_items( pt ); - _panes[_trader]->add_vehicle_items( pt ); + for( tripoint_bub_ms const &pt : src ) { + _panes[_trader]->add_map_items( pt.raw() ); + _panes[_trader]->add_vehicle_items( pt.raw() ); } } else if( !trader.is_player_ally() ) { _panes[_trader]->add_nearby_items( 1 ); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 1e40a08b7dc41..69e6b1179f6cf 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1898,7 +1898,7 @@ bool vehicle::merge_rackable_vehicle( vehicle *carry_veh, const std::vector for( auto &new_zone : new_zones ) { zone_manager::get_manager().create_vehicle_loot_zone( - *this, new_zone.first.raw(), new_zone.second ); + *this, new_zone.first, new_zone.second ); } // Now that we've added zones to this vehicle, we need to make sure their positions @@ -2635,7 +2635,7 @@ bool vehicle::split_vehicles( map &here, // because we need only to move the zone once per mount, not per part. If we move per // part, we will end up with duplicates of the zone per part on the same mount for( std::pair zone : new_zones ) { - zone_manager::get_manager().create_vehicle_loot_zone( *new_vehicle, zone.first.raw(), zone.second ); + zone_manager::get_manager().create_vehicle_loot_zone( *new_vehicle, zone.first, zone.second ); } // create_vehicle_loot_zone marks the vehicle as not dirty but since we got these zones @@ -6306,7 +6306,7 @@ void vehicle::place_zones( map &pmap ) const for( vehicle_prototype::zone_def const &d : type->zone_defs ) { tripoint_abs_ms const pt = pmap.getglobal( tripoint_bub_ms( rebase_bub( pos.raw() + d.pt ), pmap.get_abs_sub().z() ) ); - mapgen_place_zone( pt.raw(), pt.raw(), d.zone_type, get_owner(), d.name, d.filter, &pmap ); + mapgen_place_zone( pt, pt, d.zone_type, get_owner(), d.name, d.filter, &pmap ); } } @@ -8580,7 +8580,7 @@ bool vehicle::refresh_zones() } tripoint_abs_ms zone_pos = here.getglobal( bub_part_pos( part_idx ) ); //Set the position of the zone to that part - zone.set_position( std::pair( zone_pos.raw(), zone_pos.raw() ), false, false, + zone.set_position( std::pair( zone_pos, zone_pos ), false, false, true ); new_zones.emplace( z.first, zone ); } diff --git a/tests/act_build_test.cpp b/tests/act_build_test.cpp index 6ed7b6a7131ae..4ab82cabe2237 100644 --- a/tests/act_build_test.cpp +++ b/tests/act_build_test.cpp @@ -86,11 +86,11 @@ construction setup_testcase( Character &u, std::string const &constr, tripoint_abs_ms const build_abs = here.getglobal( build_loc ); faction_id const fac = u.get_faction()->id; - zmgr.add( constr + " loot zone", zone_type_LOOT_UNSORTED, fac, false, true, loot_abs.raw(), - loot_abs.raw() ); + zmgr.add( constr + " loot zone", zone_type_LOOT_UNSORTED, fac, false, true, loot_abs, + loot_abs ); zmgr.add( constr + " construction zone", zone_type_CONSTRUCTION_BLUEPRINT, fac, false, - true, build_abs.raw(), build_abs.raw(), options ); + true, build_abs, build_abs, options ); for( auto const *cons : constructions_by_group( build.group ) ) { for( auto const &comp : cons->requirements->get_components() ) { diff --git a/tests/clzones_test.cpp b/tests/clzones_test.cpp index 9bfd5d1d7801f..f1f4b5e10b961 100644 --- a/tests/clzones_test.cpp +++ b/tests/clzones_test.cpp @@ -53,11 +53,11 @@ int count_items_or_charges( const tripoint src, const itype_id &id, return _count_items_or_charges( get_map().i_at( src ), id ); } -void create_tile_zone( const std::string &name, const zone_type_id &zone_type, tripoint pos, +void create_tile_zone( const std::string &name, const zone_type_id &zone_type, tripoint_abs_ms pos, bool veh = false ) { zone_manager &zm = zone_manager::get_manager(); - zm.add( name, zone_type, faction_your_followers, false, true, pos, pos, nullptr, false, veh ); + zm.add( name, zone_type, faction_your_followers, false, true, pos, pos, nullptr, veh ); } } // namespace @@ -85,8 +85,8 @@ TEST_CASE( "zone_unloading_ammo_belts", "[zones][items][ammo_belt][activities][u vp->vehicle().set_owner( dummy ); } - create_tile_zone( "Unsorted", zone_type_LOOT_UNSORTED, start.raw(), in_vehicle ); - create_tile_zone( "Unload All", zone_type_UNLOAD_ALL, start.raw(), in_vehicle ); + create_tile_zone( "Unsorted", zone_type_LOOT_UNSORTED, start, in_vehicle ); + create_tile_zone( "Unload All", zone_type_UNLOAD_ALL, start, in_vehicle ); item ammo_belt = item( itype_belt223, calendar::turn ); ammo_belt.ammo_set( ammo_belt.ammo_default() ); @@ -126,8 +126,8 @@ TEST_CASE( "zone_sorting_comestibles_", "[zones][items][food][activities]" ) zone_manager &zm = zone_manager::get_manager(); const tripoint_abs_ms origin_pos; - create_tile_zone( "Food", zone_type_LOOT_FOOD, tripoint::east ); - create_tile_zone( "Drink", zone_type_LOOT_DRINK, tripoint::west ); + create_tile_zone( "Food", zone_type_LOOT_FOOD, tripoint_abs_ms::zero + tripoint::east ); + create_tile_zone( "Drink", zone_type_LOOT_DRINK, tripoint_abs_ms::zero + tripoint::west ); SECTION( "without perishable zones" ) { GIVEN( "a non-perishable food" ) { @@ -176,8 +176,8 @@ TEST_CASE( "zone_sorting_comestibles_", "[zones][items][food][activities]" ) } SECTION( "with perishable zones" ) { - create_tile_zone( "PFood", zone_type_LOOT_PFOOD, tripoint::north ); - create_tile_zone( "PDrink", zone_type_LOOT_PDRINK, tripoint::south ); + create_tile_zone( "PFood", zone_type_LOOT_PFOOD, tripoint_abs_ms::zero + tripoint::north ); + create_tile_zone( "PDrink", zone_type_LOOT_PDRINK, tripoint_abs_ms::zero + tripoint::south ); GIVEN( "a non-perishable food" ) { item nonperishable_food( "test_bitter_almond" ); diff --git a/tests/faction_camp_test.cpp b/tests/faction_camp_test.cpp index c3c8b6416aabe..5ab4bf3265bdc 100644 --- a/tests/faction_camp_test.cpp +++ b/tests/faction_camp_test.cpp @@ -26,9 +26,9 @@ TEST_CASE( "camp_calorie_counting", "[camp]" ) clear_map(); map &m = get_map(); const tripoint_abs_ms zone_loc = m.getglobal( tripoint_bub_ms{ 5, 5, 0 } ); - mapgen_place_zone( zone_loc.raw(), zone_loc.raw(), zone_type_CAMP_FOOD, your_fac, {}, + mapgen_place_zone( zone_loc, zone_loc, zone_type_CAMP_FOOD, your_fac, {}, "food" ); - mapgen_place_zone( zone_loc.raw(), zone_loc.raw(), zone_type_CAMP_STORAGE, your_fac, {}, + mapgen_place_zone( zone_loc, zone_loc, zone_type_CAMP_STORAGE, your_fac, {}, "storage" ); faction *camp_faction = get_player_character().get_faction(); const tripoint_abs_omt this_omt = project_to( zone_loc ); diff --git a/tests/zones_custom_test.cpp b/tests/zones_custom_test.cpp index 4ab1d43e46553..8ecd02687d62f 100644 --- a/tests/zones_custom_test.cpp +++ b/tests/zones_custom_test.cpp @@ -31,18 +31,18 @@ TEST_CASE( "zones_custom", "[zones]" ) } CAPTURE( num, bag_plastic.display_name() ); - mapgen_place_zone( zone_loc.raw() + tripoint::north_west, zone_loc.raw() + tripoint::south_east, + mapgen_place_zone( zone_loc + tripoint::north_west, zone_loc + tripoint::south_east, zone_type_LOOT_CUSTOM, your_fac, {}, "completely unrelated overlap" ); - mapgen_place_zone( zone_loc.raw(), zone_hammer_end.raw(), zone_type_LOOT_CUSTOM, your_fac, {}, + mapgen_place_zone( zone_loc, zone_hammer_end, zone_type_LOOT_CUSTOM, your_fac, {}, "hammer" ); - mapgen_place_zone( zone_loc.raw(), zone_bowsaw_end.raw(), zone_type_LOOT_CUSTOM, your_fac, {}, + mapgen_place_zone( zone_loc, zone_bowsaw_end, zone_type_LOOT_CUSTOM, your_fac, {}, "c:tools,-hammer" ); - mapgen_place_zone( zone_loc.raw(), zone_testgroup_end.raw(), zone_type_LOOT_ITEM_GROUP, your_fac, {}, + mapgen_place_zone( zone_loc, zone_testgroup_end, zone_type_LOOT_ITEM_GROUP, your_fac, {}, "test_event_item_spawn" ); - mapgen_place_zone( zone_loc.raw(), zone_groupbatt_end.raw(), zone_type_LOOT_ITEM_GROUP, your_fac, {}, + mapgen_place_zone( zone_loc, zone_groupbatt_end, zone_type_LOOT_ITEM_GROUP, your_fac, {}, "test_group_disp" ); tripoint_abs_ms const m_zone_loc = m.getglobal( tripoint_bub_ms{-5, -5, 0 } ); - mapgen_place_zone( m_zone_loc.raw(), m_zone_loc.raw(), zone_type_LOOT_CUSTOM, your_fac, {}, + mapgen_place_zone( m_zone_loc, m_zone_loc, zone_type_LOOT_CUSTOM, your_fac, {}, "plastic bag" ); zone_manager &zmgr = zone_manager::get_manager();