Skip to content

Commit

Permalink
Port overmap mission arrow fix (CleverRaven#53971)
Browse files Browse the repository at this point in the history
Co-authored-by: olanti-p <[email protected]>
  • Loading branch information
Fris0uman and olanti-p authored Jan 4, 2022
1 parent c85948c commit b50c696
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,29 +704,41 @@ static cata::optional<std::pair<tripoint_abs_omt, std::string>> get_mission_arro
}
const tripoint_abs_omt mission_target = get_avatar().get_active_mission_target();

std::string mission_arrow_variant = "mission_cursor";
std::string mission_arrow_variant;
if( overmap_area.contains( mission_target.raw() ) ) {
mission_arrow_variant = "mission_cursor";
return std::make_pair( mission_target, mission_arrow_variant );
}

const std::vector<tripoint> mission_trajectory = line_to( center.raw(),
tripoint( mission_target.raw().xy(), center.raw().z ) );

cata::optional<tripoint> prev;
int z = 0;
for( const tripoint &traj_pt : mission_trajectory ) {
if( !overmap_area.contains( traj_pt ) ) {
z = prev->z - traj_pt.z;
break;
inclusive_rectangle<point> area_flat( overmap_area.p_min.xy(), overmap_area.p_max.xy() );
if( area_flat.contains( mission_target.raw().xy() ) ) {
int area_z = center.z();
if( mission_target.z() > area_z ) {
mission_arrow_variant = "mission_arrow_up";
} else {
mission_arrow_variant = "mission_arrow_down";
}
prev = traj_pt;
return std::make_pair( tripoint_abs_omt( mission_target.xy(), area_z ), mission_arrow_variant );
}

if( !prev ) {
debugmsg( "ERROR: trajectory for mission in overmap failed" );
const std::vector<tripoint> traj = line_to( center.raw(),
tripoint( mission_target.raw().xy(), center.raw().z ) );

if( traj.empty() ) {
debugmsg( "Failed to gen overmap mission trajectory %s %s",
center.to_string(), mission_target.to_string() );
return cata::nullopt;
}


tripoint arr_pos = traj[0];
for( auto it = traj.rbegin(); it != traj.rend(); it++ ) {
if( overmap_area.contains( *it ) ) {
arr_pos = *it;
break;
}
}

const int north_border_y = ( overmap_area.p_max.y - overmap_area.p_min.y ) / 3;
const int south_border_y = north_border_y * 2;
const int west_border_x = ( overmap_area.p_max.x - overmap_area.p_min.x ) / 3;
Expand All @@ -747,24 +759,18 @@ static cata::optional<std::pair<tripoint_abs_omt, std::string>> get_mission_arro
const inclusive_cuboid<tripoint> east_sector( east_pmin, overmap_area.p_max );

mission_arrow_variant = "mission_arrow_";
if( z == 0 ) {
if( north_sector.contains( *prev ) ) {
mission_arrow_variant += 'n';
} else if( south_sector.contains( *prev ) ) {
mission_arrow_variant += 's';
}
if( west_sector.contains( *prev ) ) {
mission_arrow_variant += 'w';
} else if( east_sector.contains( *prev ) ) {
mission_arrow_variant += 'e';
}
} else if( z > 0 ) {
mission_arrow_variant += "down";
} else {
mission_arrow_variant += "up";
if( north_sector.contains( arr_pos ) ) {
mission_arrow_variant += 'n';
} else if( south_sector.contains( arr_pos ) ) {
mission_arrow_variant += 's';
}
if( west_sector.contains( arr_pos ) ) {
mission_arrow_variant += 'w';
} else if( east_sector.contains( arr_pos ) ) {
mission_arrow_variant += 'e';
}

return std::make_pair( tripoint_abs_omt( *prev ), mission_arrow_variant );
return std::make_pair( tripoint_abs_omt( arr_pos ), mission_arrow_variant );
}

std::string cata_tiles::get_omt_id_rotation_and_subtile(
Expand Down

0 comments on commit b50c696

Please sign in to comment.