Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and fix various line finding functions #71605

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8fca280
initial commit
Lumi-Virtual Feb 8, 2024
2fbfad6
Merge remote-tracking branch 'upstream/master' into lines-fixes-and-u…
Lumi-Virtual Apr 14, 2024
4bc10fc
Merge branch 'CleverRaven:master' into lines-fixes-and-updates
Lumi-Virtual Apr 16, 2024
8a51701
Merge remote-tracking branch 'upstream/master' into lines-fixes-and-u…
Lumi-Virtual Apr 16, 2024
e1d2d9b
Merge remote-tracking branch 'upstream/master' into lines-fixes-and-u…
Lumi-Virtual Apr 16, 2024
508eefa
idk whats happening with this commit i hope it goes well
Lumi-Virtual Apr 16, 2024
17d62bb
Merge branch 'lines-fixes-and-updates' of https://github.com/Lumi-Vir…
Lumi-Virtual Apr 16, 2024
05a1f4e
maybe this will pass tests !
Lumi-Virtual Apr 16, 2024
25b8101
missed a few
Lumi-Virtual Apr 16, 2024
8221198
a few more
Lumi-Virtual Apr 16, 2024
e18b7a7
it would be nice if it told me all of these at the same time >w>
Lumi-Virtual Apr 16, 2024
7d1999c
i wonder how many more itl be before it builds
Lumi-Virtual Apr 16, 2024
95b2944
test cases, and a few small edits. this time with astyle actually run…
Lumi-Virtual Apr 17, 2024
ab7e8f7
hopefully thats all that was messed up
Lumi-Virtual Apr 17, 2024
13390b3
well map shouldnt have been calculating the bresenham offset like tha…
Lumi-Virtual Apr 17, 2024
a0c392f
if this fixes it i think i know where the problem is
Lumi-Virtual Apr 17, 2024
58f8a56
i think this is the only time where line_to returning the start tile …
Lumi-Virtual Apr 17, 2024
837efb0
the canon line had a few silly boundary checks :P
Lumi-Virtual Apr 17, 2024
4482443
this should in theory pass all the tests now ?
Lumi-Virtual Apr 17, 2024
b2c1770
ah this is probably what clang tidy wanted
Lumi-Virtual Apr 17, 2024
0a73690
cleaned up the bresenham functions and added complete z support, plus…
Lumi-Virtual Apr 18, 2024
a2de4bf
idk why the compile failed there, i didnt touch any of the things it …
Lumi-Virtual Apr 18, 2024
f4c016e
just kicking the tests
Lumi-Virtual Apr 18, 2024
4349523
middle axis assignment was faulty
Lumi-Virtual Apr 19, 2024
24b19a9
astyle fix
Lumi-Virtual Apr 19, 2024
194299b
Merge remote-tracking branch 'upstream/master' into lines-fixes-and-u…
Lumi-Virtual Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6414,16 +6414,18 @@ void chop_tree_activity_actor::finish( player_activity &act, Character &who )
circle[( circle_center + 3 ) % circle_size]
}; // Fall towards to the right
for( const point &direc : candidates ) {
bool cantuse = false;
bool can_use = true;

tripoint proposed_to = pos + point( 3 * direc.x, 3 * direc.y );
std::vector<tripoint> rough_tree_line = line_to( pos, proposed_to );
for( const tripoint &elem : rough_tree_line ) {
if( creatures.creature_at( elem ) ) {
cantuse = true;
break;
line_to_2( pos, proposed_to, [&creatures, &can_use]( std::vector<tripoint> &new_line ) {
if( creatures.creature_at( new_line.back() ) ) {
can_use = false;
return false;
}
}
if( !cantuse ) {
return true;
} );

if( can_use ) {
direction = tripoint( direc, pos.z );
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg, const tri
}

//Use find clear path to draw the trajectory with optimal initial tile offsets.
trajectory = here.find_clear_path( source, target );
// TODO: account for the kind of projectile it is and what it can go though or not
trajectory = find_line_to_2( source, target );

add_msg_debug( debugmode::DF_BALLISTIC,
"missed_by_tiles: %.2f; missed_by: %.2f; target (orig/hit): %d,%d,%d/%d,%d,%d",
Expand Down
17 changes: 9 additions & 8 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ bool Character::overmap_los( const tripoint_abs_omt &omt, int sight_points ) con
return false;
}

const std::vector<tripoint_abs_omt> line = line_to( ompos, omt );
const std::vector<tripoint_abs_omt> line = line_to_omt( ompos, omt );
for( size_t i = 0; i < line.size() && sight_points >= 0; i++ ) {
const tripoint_abs_omt &pt = line[i];
const oter_id &ter = overmap_buffer.ter( pt );
Expand Down Expand Up @@ -10522,16 +10522,17 @@ std::vector<Creature *> Character::get_targetable_creatures( const int range, bo
bool can_see = ( ( sees( critter ) || sees_with_infrared( critter ) ) && here.sees( pos(), critter.pos(), 100 ) );
if( can_see && melee ) //handles the case where we can see something with glass in the way for melee attacks
{
std::vector<tripoint> path = here.find_clear_path( pos(), critter.pos() );
for( const tripoint &point : path ) {
if( here.impassable( point ) &&
std::vector<tripoint> path = find_line_to_2( pos(), critter.pos(),
[this, &here ]( std::vector<tripoint> &new_line ) {
if( here.impassable( new_line.back() ) &&
!( weapon.has_flag( flag_SPEAR ) && // Fences etc. Spears can stab through those
here.has_flag( ter_furn_flag::TFLAG_THIN_OBSTACLE,
point ) ) ) { //this mirrors melee.cpp function reach_attack
can_see = false;
break;
new_line.back() ) ) ) { //this mirrors melee.cpp function reach_attack
return false;
}
}
return true;
} );
can_see = path.back() == pos();
}
bool in_range = std::round( rl_dist_exact( pos(), critter.pos() ) ) <= range;
// TODO: get rid of fake npcs (pos() check)
Expand Down
6 changes: 3 additions & 3 deletions src/coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,10 @@ direction direction_from( const coords::coord_point<Point, Origin, Scale, LhsInB

template<typename Point, coords::origin Origin, coords::scale Scale, bool LhsInBounds, bool RhsInBounds>
std::vector < coords::coord_point < Point, Origin, Scale, LhsInBounds &&RhsInBounds >>
line_to( const coords::coord_point<Point, Origin, Scale, LhsInBounds> &loc1,
const coords::coord_point<Point, Origin, Scale, RhsInBounds> &loc2 )
line_to_omt( const coords::coord_point<Point, Origin, Scale, LhsInBounds> &loc1,
const coords::coord_point<Point, Origin, Scale, RhsInBounds> &loc2 )
{
std::vector<Point> raw_result = line_to( loc1.raw(), loc2.raw() );
std::vector<Point> raw_result = line_to_2( loc1.raw(), loc2.raw() );
std::vector < coords::coord_point < Point, Origin, Scale, LhsInBounds &&RhsInBounds >> result;
std::transform( raw_result.begin(), raw_result.end(), std::back_inserter( result ),
[]( const Point & p ) {
Expand Down
25 changes: 12 additions & 13 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ Creature *Creature::auto_find_hostile_target( int range, int &boo_hoo, int area
// Hack: trying yo avoid turret LOS blocking by frames bug by trying to see target from vehicle boundary
// Or turret wallhack for turret's car
// TODO: to visibility checking another way, probably using 3D FOV
std::vector<tripoint> path_to_target = line_to( pos(), m->pos() );
path_to_target.insert( path_to_target.begin(), pos() );
std::vector<tripoint> path_to_target = line_through_2( pos(), m->pos() );

// Getting point on vehicle boundaries and on line between target and turret
bool continueFlag = true;
Expand Down Expand Up @@ -1339,17 +1338,18 @@ void Creature::longpull( const std::string &name, const tripoint &p )
return;
}

std::vector<tripoint> path = line_to( pos(), p, 0, 0 );
Creature *c = nullptr;
for( const tripoint &path_p : path ) {
c = get_creature_tracker().creature_at( path_p );
if( c == nullptr && get_map().impassable( path_p ) ) {
add_msg_if_player( m_warning, _( "There's an obstacle in the way!" ) );
return;
}
if( c != nullptr ) {
break;
std::vector<tripoint> path = line_to_2( pos(), p, [&c]( std::vector<tripoint> &new_line ) {
c = get_creature_tracker().creature_at( new_line.back() );
if( ( c == nullptr && get_map().impassable( new_line.back() ) )
|| c != nullptr ) {
return false;
}
return true;
} );
if( c == nullptr && get_map().impassable( path.back() ) ) {
add_msg_if_player( m_warning, _( "There's an obstacle in the way!" ) );
return;
}
if( c == nullptr || !sees( *c ) ) {
// TODO: Latch onto objects?
Expand All @@ -1369,8 +1369,7 @@ void Creature::longpull( const std::string &name, const tripoint &p )
if( c->is_avatar() ) {
add_msg( m_warning, _( "%1$s pulls you in with their %2$s!" ), disp_name( false, true ), name );
}
c->move_to( tripoint_abs_ms( line_to( get_location().raw(), c->get_location().raw(), 0,
0 ).front() ) );
c->move_to( tripoint_abs_ms( line_to_2( get_location().raw(), c->get_location().raw() ).front() ) );
c->add_effect( effect_stunned, 1_seconds );
sounds::sound( c->pos(), 5, sounds::sound_t::combat, _( "Shhhk!" ) );
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ std::pair<std::string, nc_color> display::overmap_tile_symbol_color( const avata
ter_color = red_background( ter_color );
found_mi = true;
} else if( edge_tile ) {
std::vector<tripoint_abs_omt> plist = line_to( u_loc, target );
std::vector<tripoint_abs_omt> plist = line_to_omt( u_loc, target );
if( std::find( plist.begin(), plist.end(), omt ) != plist.end() ) {
ter_color = c_red;
ter_sym = "*";
Expand Down
9 changes: 4 additions & 5 deletions src/drawing_primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

void draw_line( const std::function<void( const point & )> &set, const point &p1, const point &p2 )
{
std::vector<point> line = line_to( p1, p2, 0 );
for( point &i : line ) {
set( i );
}
set( p1 );
line_through_2( p1, p2, [&set]( std::vector<point> &new_line ) {
set( new_line.back() );
return true;
} );
}

void draw_square( const std::function<void( const point & )> &set, point p1, point p2 )
Expand Down
4 changes: 2 additions & 2 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ void editmap::uber_draw_ter( const catacurses::window &w, map *m )
if( refresh_mplans ) {
monster *mon = dynamic_cast<monster *>( critter );
if( mon != nullptr && mon->has_dest() ) {
for( auto &location : line_to( mon->get_location(), mon->get_dest() ) ) {
for( auto &location : line_to_omt( mon->get_location(), mon->get_dest() ) ) {
hilights["mplan"].points[m->getlocal( location )] = 1;
}
}
Expand Down Expand Up @@ -1633,7 +1633,7 @@ void editmap::recalc_target( shapetype shape )
}
break;
case editmap_line:
target_list = line_to( origin, target, 0, 0 );
target_list = line_to_2( origin, target );
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,7 @@ void basecamp::start_fortifications( const mission_id &miss_id, float exertion_l
return;
}
if( miss_id.parameters == faction_wall_level_n_1_string ) {
std::vector<tripoint_abs_omt> tmp_line = line_to( stop, start );
std::vector<tripoint_abs_omt> tmp_line = line_to_omt( stop, start );
int line_count = tmp_line.size();
int yes_count = 0;
for( tripoint_abs_omt &elem : tmp_line ) {
Expand All @@ -2847,11 +2847,11 @@ void basecamp::start_fortifications( const mission_id &miss_id, float exertion_l
if( ( change_x && stop.x() < start.x() ) || ( change_y && stop.y() < start.y() ) ) {
//line_to doesn't include the origin point
fortify_om.push_back( stop );
std::vector<tripoint_abs_omt> tmp_line = line_to( stop, start );
std::vector<tripoint_abs_omt> tmp_line = line_to_omt( stop, start );
fortify_om.insert( fortify_om.end(), tmp_line.begin(), tmp_line.end() );
} else {
fortify_om.push_back( start );
std::vector<tripoint_abs_omt> tmp_line = line_to( start, stop );
std::vector<tripoint_abs_omt> tmp_line = line_to_omt( start, stop );
fortify_om.insert( fortify_om.end(), tmp_line.begin(), tmp_line.end() );
}
int trips = 0;
Expand Down Expand Up @@ -5019,7 +5019,7 @@ void om_range_mark( const tripoint_abs_omt &origin, int range, bool add_notes,
void om_line_mark( const tripoint_abs_omt &origin, const tripoint_abs_omt &dest, bool add_notes,
const std::string &message )
{
std::vector<tripoint_abs_omt> note_pts = line_to( origin, dest );
std::vector<tripoint_abs_omt> note_pts = line_to_omt( origin, dest );

for( tripoint_abs_omt &pt : note_pts ) {
if( add_notes ) {
Expand Down Expand Up @@ -5087,7 +5087,7 @@ bool om_set_hide_site( npc &comp, const tripoint_abs_omt &omt_tgt,
time_duration companion_travel_time_calc( const tripoint_abs_omt &omt_pos,
const tripoint_abs_omt &omt_tgt, time_duration work, int trips, int haulage )
{
std::vector<tripoint_abs_omt> journey = line_to( omt_pos, omt_tgt );
std::vector<tripoint_abs_omt> journey = line_to_omt( omt_pos, omt_tgt );
return companion_travel_time_calc( journey, work, trips, haulage );
}

Expand Down Expand Up @@ -5154,7 +5154,7 @@ std::vector<tripoint_abs_omt> om_companion_path( const tripoint_abs_omt &start,
if( last == spt ) {
break;
}
std::vector<tripoint_abs_omt> note_pts = line_to( last, spt );
std::vector<tripoint_abs_omt> note_pts = line_to_omt( last, spt );
scout_points.insert( scout_points.end(), note_pts.begin(), note_pts.end() );
om_line_mark( last, spt );
range -= rl_dist( spt.xy(), last.xy() );
Expand Down
10 changes: 4 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4854,10 +4854,8 @@ void game::knockback( const tripoint &s, const tripoint &t, int force, int stun,
{
std::vector<tripoint> traj;
traj.clear();
traj = line_to( s, t, 0, 0 );
traj.insert( traj.begin(), s ); // how annoying, line_to() doesn't include the originating point!
traj = continue_line( traj, force );
traj.insert( traj.begin(), t ); // how annoying, continue_line() doesn't either!
traj = continue_line( line_through_2( s, t ), force );
traj.insert( traj.begin(), t ); // continue_line() doesn't include the originating point

knockback( traj, stun, dam_mult );
}
Expand Down Expand Up @@ -8069,7 +8067,7 @@ void draw_trail( const tripoint &start, const tripoint &end, const bool bDrawX )
tripoint center = player_character.pos() + player_character.view_offset;
if( start != end ) {
//Draw trail
pts = line_to( start, end, 0, 0 );
pts = line_to_2( start, end );
} else {
//Draw point
pts.emplace_back( start );
Expand Down Expand Up @@ -12639,7 +12637,7 @@ void game::update_overmap_seen()
point abs_delta = delta.raw().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<tripoint_abs_omt> line = line_to( ompos, p );
const std::vector<tripoint_abs_omt> line = line_to_omt( ompos, p );
float sight_points = dist;
for( auto it = line.begin();
it != line.end() && sight_points >= 0; ++it ) {
Expand Down
24 changes: 19 additions & 5 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3442,10 +3442,10 @@ std::optional<int> iuse::grenade_inc_act( Character *p, item *, const tripoint &
int num_flames = rng( 3, 5 );
for( int current_flame = 0; current_flame < num_flames; current_flame++ ) {
tripoint dest( pos + point( rng( -5, 5 ), rng( -5, 5 ) ) );
std::vector<tripoint> flames = line_to( pos, dest, 0, 0 );
for( tripoint &flame : flames ) {
here.add_field( flame, fd_fire, rng( 0, 2 ) );
}
line_to_2( pos, dest, [&here]( std::vector<tripoint> &new_line ) {
here.add_field( new_line.back(), fd_fire, rng( 0, 2 ) );
return true;
} );
}
explosion_handler::explosion( p, pos, 8, 0.8, true );
for( const tripoint &dest : here.points_in_radius( pos, 2 ) ) {
Expand Down Expand Up @@ -6565,13 +6565,27 @@ std::optional<int> iuse::camera( Character *p, item *it, const tripoint & )
bool incorrect_focus = false;
tripoint_range<tripoint> aim_bounds = here.points_in_radius( aim_point, 2 );

std::vector<tripoint> trajectory = line_to( p->pos(), aim_point, 0, 0 );
std::vector<tripoint> trajectory = line_to_2( p->pos(), aim_point );
trajectory.push_back( aim_point );

p->mod_moves( -to_moves<int>( 1_seconds ) * 0.5 );
sounds::sound( p->pos(), 8, sounds::sound_t::activity, _( "Click." ), true, "tool",
"camera_shutter" );

/*
// TODO: The whole camera for loop is SO janky
std::vector<tripoint> trajectory = line_to_2( p->pos(), aim_point,
[&here, &p]( std::vector<tripoint> &new_line ) {
// TODO: It would be nice to give the cameras unique vision stats
// so that they see things independent of the player's vision.
if( !p->sees( new_line.back() ) ) {
return false;
}
return true;
} );
trajectory.pop_back(); // This tile isn't visible
*/

for( std::vector<tripoint>::iterator point_it = trajectory.begin();
point_it != trajectory.end();
++point_it ) {
Expand Down
Loading
Loading