diff --git a/src/active_item_cache.cpp b/src/active_item_cache.cpp index 974f8e3ff26ba..7764c029b8ca7 100644 --- a/src/active_item_cache.cpp +++ b/src/active_item_cache.cpp @@ -160,7 +160,7 @@ void active_item_cache::rotate_locations( int turns, const point_rel_ms &dim ) for( std::pair> &pair : active_items ) { for( item_reference &ir : pair.second ) { // Should 'rotate' be propaged up to the typed coordinates? - ir.location = point_rel_ms( ir.location.raw().rotate( turns, dim.raw() ) ); + ir.location = ir.location.rotate( turns, dim.raw() ); } } } diff --git a/src/character.cpp b/src/character.cpp index 5c815a11f86be..1bf6c2c82cae1 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -11393,14 +11393,14 @@ action_id Character::get_next_auto_move_direction() if( next_expected_position ) { // Difference between where the character is and where we expect them to be after last auto-move. - tripoint diff = ( pos_bub() - *next_expected_position ).raw().abs(); + tripoint_rel_ms diff = ( pos_bub() - *next_expected_position ).abs(); // This might differ by 1 (in z-direction), since the character might have crossed a ramp, // which teleported them a tile up or down. If the error is in x or y direction, we might as well // give them a turn to recover, as the move still might be vaild. // We cut off at 1 since 2 definitely results in an invalid move. // If the character is still stumbling or stuck, // they will cancel the auto-move on the next cycle (as the distance increases). - if( std::max( { diff.x, diff.y, diff.z } ) > 1 ) { + if( std::max( { diff.x(), diff.y(), diff.z()} ) > 1 ) { // We're off course, possibly stumbling or stuck, cancel auto move return ACTION_NULL; } diff --git a/src/clzones.cpp b/src/clzones.cpp index 6344f3e94b871..908c25a604622 100644 --- a/src/clzones.cpp +++ b/src/clzones.cpp @@ -1497,15 +1497,15 @@ void _rotate_zone( map &target_map, zone_data &zone, int turns ) z_start.x() + z_end.x() == a_end.x() ) { return; } - point z_l_start = z_start.xy().raw().rotate( turns, dim ); - point z_l_end = z_end.xy().raw().rotate( turns, dim ); + point_bub_ms z_l_start = z_start.xy().rotate( turns, dim ); + point_bub_ms z_l_end = z_end.xy().rotate( turns, dim ); tripoint_abs_ms first = - target_map.getglobal( tripoint_bub_ms( std::min( z_l_start.x, z_l_end.x ), - std::min( z_l_start.y, z_l_end.y ), + target_map.getglobal( tripoint_bub_ms( std::min( z_l_start.x(), z_l_end.x() ), + std::min( z_l_start.y(), z_l_end.y() ), z_start.z() ) ); tripoint_abs_ms second = - 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 ), + 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 ); } diff --git a/src/coordinates.h b/src/coordinates.h index b31e4adc3091e..db63fd93a0d83 100644 --- a/src/coordinates.h +++ b/src/coordinates.h @@ -210,6 +210,14 @@ class coord_point_ob : public return this_as_point( this->raw().xy() ); } + constexpr auto abs() const { + return coord_point_ob( this->raw().abs() ); + } + + constexpr auto rotate( int turns, const point &dim = point_south_east ) const { + return coord_point_ob( this->raw().rotate( turns, dim ) ); + } + friend inline this_as_ob operator+( const coord_point_ob &l, const point &r ) { return this_as_ob( l.raw() + r ); } @@ -406,6 +414,14 @@ constexpr inline auto operator-( return coord_point_ob( l.raw() - r.raw() ); } +template +constexpr inline auto operator-( + const coord_point_ob &l ) +{ + using PointResult = decltype( Point() ); + return coord_point_ob( - l.raw() ); +} + // Only relative points can be multiplied by a constant template constexpr inline coord_point_ob operator*( diff --git a/src/game.cpp b/src/game.cpp index e7fc3990b6bea..6c6369c65c8fb 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -11395,8 +11395,7 @@ bool game::phasing_move_enchant( const tripoint &dest_loc, const int phase_dista bool game::can_move_furniture( tripoint fdest, const tripoint &dp ) { - // TODO: Fix when unary operation available - const bool pulling_furniture = dp.xy() == ( point_rel_ms_zero - u.grab_point.xy() ).raw(); + const bool pulling_furniture = dp.xy() == -u.grab_point.xy().raw(); const bool has_floor = m.has_floor_or_water( fdest ); creature_tracker &creatures = get_creature_tracker(); bool is_ramp_or_road = m.has_flag( ter_furn_flag::TFLAG_RAMP_DOWN, fdest ) || @@ -12819,8 +12818,8 @@ void game::update_overmap_seen() continue; } // If circular distances are enabled, scale overmap distances by the diagonality of the sight line. - point abs_delta = delta.raw().abs(); - int max_delta = std::max( abs_delta.x, abs_delta.y ); + point_rel_omt abs_delta = delta.abs(); + int max_delta = std::max( abs_delta.x(), abs_delta.y() ); const float multiplier = trigdist ? std::sqrt( h_squared ) / max_delta : 1; const std::vector line = line_to( ompos, p ); float sight_points = dist; diff --git a/src/grab.cpp b/src/grab.cpp index 9c737aa3c4cd6..d92fed314076d 100644 --- a/src/grab.cpp +++ b/src/grab.cpp @@ -40,13 +40,11 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp ) } const vehicle *veh_under_player = veh_pointer_or_null( m.veh_at( u.pos_bub() ) ); if( grabbed_vehicle == veh_under_player ) { - // TODO: Fix when unary operation available - u.grab_point = tripoint_rel_ms_zero - dp; + u.grab_point = - dp; return false; } - // TODO: Fix when unary operation available - tripoint_rel_ms dp_veh = tripoint_rel_ms_zero - u.grab_point; + tripoint_rel_ms dp_veh = - u.grab_point; const tripoint_rel_ms prev_grab = u.grab_point; tripoint_rel_ms next_grab = u.grab_point; const tileray initial_veh_face = grabbed_vehicle->face; @@ -63,8 +61,7 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp ) pushing = true; } else if( std::abs( dp.x() + dp_veh.x() ) != 2 && std::abs( dp.y() + dp_veh.y() ) != 2 ) { // Not actually moving the vehicle, don't do the checks - // TODO: Fix when unary operation available - u.grab_point = tripoint_rel_ms_zero - ( dp + dp_veh ); + u.grab_point = - ( dp + dp_veh ); return false; } else if( ( dp.x() == prev_grab.x() || dp.y() == prev_grab.y() ) && next_grab.x() != 0 && next_grab.y() != 0 ) { @@ -73,13 +70,11 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp ) dp_veh.x() = dp.x() == -dp_veh.x() ? 0 : dp_veh.x(); dp_veh.y() = dp.y() == -dp_veh.y() ? 0 : dp_veh.y(); - // TODO: Fix when unary operation available - next_grab = tripoint_rel_ms_zero - dp_veh; + next_grab = - dp_veh; zigzag = true; } else { // We are pulling the vehicle - // TODO: Fix when unary operation available - next_grab = tripoint_rel_ms_zero - dp; + next_grab = - dp; pulling = true; } @@ -276,10 +271,8 @@ bool game::grabbed_veh_move( const tripoint_rel_ms &dp ) // Try to place the vehicle in the position player just left rather than "flattening" the zig-zag tripoint_rel_ms final_dp_veh = get_move_dir( dp_veh, next_grab ); if( final_dp_veh == tripoint_rel_ms_min && zigzag ) { - // TODO: Fix when unary operation available - final_dp_veh = get_move_dir( tripoint_rel_ms_zero - prev_grab, tripoint_rel_ms_zero - dp ); - // TODO: Fix when unary operation available - next_grab = tripoint_rel_ms_zero - dp; + final_dp_veh = get_move_dir( - prev_grab, - dp ); + next_grab = - dp; } if( final_dp_veh == tripoint_rel_ms_min ) { diff --git a/src/line.cpp b/src/line.cpp index 6f0648e7b2510..5cb1f7fee16cb 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -30,11 +30,11 @@ void bresenham( const point_bub_ms &p1, const point_bub_ms &p2, int t, // Signs of slope values. const point s( ( d.x() == 0 ) ? 0 : sgn( d.x() ), ( d.y() == 0 ) ? 0 : sgn( d.y() ) ); // Absolute values of slopes x2 to avoid rounding errors. - const point a = d.raw().abs() * 2; + const point_rel_ms a = d.abs() * 2; point_bub_ms cur = p1; - if( a.x == a.y ) { + if( a.x() == a.y() ) { while( cur.x() != p2.x() ) { cur.y() += s.y; cur.x() += s.x; @@ -42,14 +42,14 @@ void bresenham( const point_bub_ms &p1, const point_bub_ms &p2, int t, break; } } - } else if( a.x > a.y ) { + } else if( a.x() > a.y() ) { while( cur.x() != p2.x() ) { if( t > 0 ) { cur.y() += s.y; - t -= a.x; + t -= a.x(); } cur.x() += s.x; - t += a.y; + t += a.y(); if( !interact( cur ) ) { break; } @@ -58,10 +58,10 @@ void bresenham( const point_bub_ms &p1, const point_bub_ms &p2, int t, while( cur.y() != p2.y() ) { if( t > 0 ) { cur.x() += s.x; - t -= a.y; + t -= a.y(); } cur.y() += s.y; - t += a.x; + t += a.x(); if( !interact( cur ) ) { break; } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index f447fedd3fdc0..6eacd2f52f2fb 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -7237,7 +7237,7 @@ void map::rotate( int turns ) // Translate bubble -> global -> current map. const point_bub_ms old( bub_from_abs( get_map().getglobal( np.pos_bub() ).xy() ) ); - const point_bub_ms new_pos( old.raw().rotate( turns, {SEEX * 2, SEEY * 2} ) ); + const point_bub_ms new_pos( old.rotate( turns, {SEEX * 2, SEEY * 2} ) ); np.spawn_at_precise( getglobal( tripoint_bub_ms( new_pos, sq.z() ) ) ); } @@ -7326,7 +7326,7 @@ void map::rotate( int turns ) if( queued_point_sm.y() % 2 != 0 ) { old.y() += SEEY; } - const point_bub_ms new_pos( old.raw().rotate( turns, {SEEX * 2, SEEY * 2} ) ); + const point_bub_ms new_pos( old.rotate( turns, {SEEX * 2, SEEY * 2} ) ); queued_points[queued_point.first] = getglobal( tripoint_bub_ms( new_pos, queued_point.second.z() ) ); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 353693547dacd..6f0c6117ed04e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2571,7 +2571,7 @@ bool vehicle::split_vehicles( map &here, new_vehicle->refresh(); } else { // include refresh - new_vehicle->shift_parts( here, point_zero - mnt_offset ); + new_vehicle->shift_parts( here, - mnt_offset ); } // update the precalc points diff --git a/tests/submap_test.cpp b/tests/submap_test.cpp index 8ec927f6e84a5..02ac388456ab4 100644 --- a/tests/submap_test.cpp +++ b/tests/submap_test.cpp @@ -108,7 +108,7 @@ TEST_CASE( "submap_rotation2", "[submap]" ) for( int x = 0; x < SEEX; x++ ) { for( int y = 0; y < SEEY; y++ ) { point_sm_ms p( x, y ); - point_sm_ms p_after_rotation = point_sm_ms( p.raw().rotate( rotation_turns, {SEEX, SEEY} ) ); + point_sm_ms p_after_rotation = p.rotate( rotation_turns, {SEEX, SEEY} ); CAPTURE( p, p_after_rotation ); CHECK( sm.get_radiation( p_after_rotation ) == sm_copy.get_radiation( p ) );